增加设置视图可用的yarn命令
This commit is contained in:
@@ -4,35 +4,41 @@ using System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using DG.Tweening;
|
||||
using Yarn.Unity;
|
||||
using Yarn.Unity;
|
||||
|
||||
public class EyeTransitionManager : MonoBehaviour
|
||||
{
|
||||
// 视图过渡的持续时间
|
||||
public float zoomDuration = 1f;
|
||||
|
||||
// 黑屏图片
|
||||
public Image blackScreenImage;
|
||||
//public RectTransform faceRectTransform;
|
||||
//public UFProcess ufProcess; // 需要引用UFProcess组件
|
||||
public MemoryProcess memoryProcess; // 需要引用 MemoryProcess 组件
|
||||
|
||||
// MemoryProcess 组件的引用
|
||||
public MemoryProcess memoryProcess;
|
||||
|
||||
// 视图配置类
|
||||
[System.Serializable]
|
||||
public class ViewConfig
|
||||
{
|
||||
public GameObject viewPanel;
|
||||
public GameObject viewPanel; // 视图的面板
|
||||
public Button activateButton; // 视图的激活按钮(MainView除外)
|
||||
public Button returnToMainViewButton; // 视图的返回MainView按钮
|
||||
//public Vector2 viewScale; // 视图的缩放
|
||||
//public Vector2 viewPosition; // 视图的位置
|
||||
public ViewState viewState;
|
||||
public ViewState viewState; // 视图的状态
|
||||
public bool isAvailable = true; // 视图是否可用
|
||||
}
|
||||
|
||||
// 在 Unity 编辑器中配置视图(不包括MainView)
|
||||
[SerializeField]
|
||||
private List<ViewConfig> viewConfigs; // 在 Unity 编辑器中配置视图(不包括MainView)
|
||||
private List<ViewConfig> viewConfigs;
|
||||
|
||||
// 视图状态和视图配置的映射
|
||||
private Dictionary<ViewState, ViewConfig> viewConfigDictionary;
|
||||
|
||||
// 是否正在进行视图过渡
|
||||
private bool isTransitioning = false;
|
||||
|
||||
// 视图状态枚举
|
||||
public enum ViewState
|
||||
{
|
||||
MainView,
|
||||
@@ -42,21 +48,24 @@ public class EyeTransitionManager : MonoBehaviour
|
||||
// 为未来的视图添加更多状态
|
||||
}
|
||||
|
||||
// 当前的视图状态,默认为 MainView
|
||||
private ViewState currentViewState = ViewState.MainView;
|
||||
|
||||
// 视图更改请求的事件
|
||||
public delegate void ViewChangeRequestedHandler(ViewState targetViewState);
|
||||
public event ViewChangeRequestedHandler OnViewChangeRequested;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
// 初始化视图
|
||||
InitializeView();
|
||||
|
||||
// 初始化视图状态和视图配置的映射
|
||||
viewConfigDictionary = new Dictionary<ViewState, ViewConfig>();
|
||||
|
||||
foreach (var config in viewConfigs)
|
||||
{
|
||||
viewConfigDictionary[config.viewState] = config;
|
||||
if (config.activateButton != null)
|
||||
if (config.activateButton != null)
|
||||
{
|
||||
// 绑定非MainView的视图激活按钮
|
||||
config.activateButton.onClick.AddListener(() => StartTransition(config.viewState));
|
||||
@@ -66,22 +75,22 @@ public class EyeTransitionManager : MonoBehaviour
|
||||
// 绑定每个视图的返回MainView按钮
|
||||
config.returnToMainViewButton.onClick.AddListener(() => StartTransition(ViewState.MainView));
|
||||
}
|
||||
// 更新按钮的可用性
|
||||
config.activateButton.interactable = config.isAvailable;
|
||||
}
|
||||
}
|
||||
|
||||
private void InitializeView()
|
||||
{
|
||||
// 默认激活MainView
|
||||
// 默认激活 MainView
|
||||
SetView(ViewState.MainView);
|
||||
}
|
||||
|
||||
private void SetView(ViewState viewState)
|
||||
{
|
||||
// 如果是MainView,就设置为默认值
|
||||
// 如果是 MainView,就设置为默认值
|
||||
if (viewState == ViewState.MainView)
|
||||
{
|
||||
//faceRectTransform.localScale = Vector2.one; // 或者MainView的默认缩放
|
||||
//faceRectTransform.anchoredPosition = Vector2.zero; // 或者MainView的默认位置
|
||||
foreach (var viewConfig in viewConfigs)
|
||||
{
|
||||
viewConfig.viewPanel.SetActive(false);
|
||||
@@ -91,15 +100,13 @@ public class EyeTransitionManager : MonoBehaviour
|
||||
|
||||
if (!viewConfigDictionary.TryGetValue(viewState, out ViewConfig config)) return;
|
||||
|
||||
//faceRectTransform.localScale = config.viewScale;
|
||||
//faceRectTransform.anchoredPosition = config.viewPosition;
|
||||
|
||||
foreach (var viewConfig in viewConfigs)
|
||||
{
|
||||
viewConfig.viewPanel.SetActive(viewConfig.viewState == viewState);
|
||||
}
|
||||
}
|
||||
|
||||
// Yarn 命令,开始视图过渡
|
||||
[YarnCommand("start_transition")]
|
||||
public IEnumerator StartTransitionCoroutine(string targetViewStateName)
|
||||
{
|
||||
@@ -115,20 +122,37 @@ public class EyeTransitionManager : MonoBehaviour
|
||||
{
|
||||
yield return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Yarn 命令,设置视图的可用性
|
||||
[YarnCommand("set_view_availability")]
|
||||
public void SetViewAvailability(string viewStateName, bool isAvailable)
|
||||
{
|
||||
ViewState viewState;
|
||||
if (!Enum.TryParse(viewStateName, out viewState))
|
||||
{
|
||||
Debug.LogError("Invalid ViewState name: " + viewStateName);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!viewConfigDictionary.TryGetValue(viewState, out ViewConfig config)) return;
|
||||
|
||||
// 更新视图的可用性和激活按钮的可用性
|
||||
config.isAvailable = isAvailable;
|
||||
config.activateButton.interactable = isAvailable;
|
||||
}
|
||||
|
||||
// 开始视图过渡
|
||||
private void StartTransition(ViewState targetViewState)
|
||||
{
|
||||
// 如果正在进行视图过渡,或者目标视图是当前视图,或者 MemoryProcess 正在处理,就不进行视图过渡
|
||||
if (isTransitioning || currentViewState == targetViewState || (memoryProcess != null && memoryProcess.IsProcessing()))
|
||||
{
|
||||
Debug.LogWarning("Transition is currently not allowed. Please wait until the current process is finished.");
|
||||
return;
|
||||
}
|
||||
|
||||
// 开始视图过渡
|
||||
isTransitioning = true;
|
||||
|
||||
if (targetViewState == ViewState.MainView)
|
||||
@@ -150,10 +174,6 @@ public class EyeTransitionManager : MonoBehaviour
|
||||
// 开始淡出黑屏
|
||||
zoomOutSequence.Append(blackScreenImage.DOFade(0f, zoomDuration).OnComplete(() => blackScreenImage.gameObject.SetActive(false)));
|
||||
|
||||
// 在淡出黑屏到一半时开始 Zoom Out
|
||||
//zoomOutSequence.Insert(zoomDuration / 2, faceRectTransform.DOAnchorPos(Vector2.zero, zoomDuration).SetEase(Ease.OutCubic));
|
||||
//zoomOutSequence.Insert(zoomDuration / 2, faceRectTransform.DOScale(Vector2.one, zoomDuration).SetEase(Ease.OutCubic));
|
||||
|
||||
// 在整个动画完成后更新视图状态
|
||||
zoomOutSequence.OnComplete(() =>
|
||||
{
|
||||
@@ -167,8 +187,6 @@ public class EyeTransitionManager : MonoBehaviour
|
||||
|
||||
// Zoom In 的时候,开始 Zoom
|
||||
Sequence zoomInSequence = DOTween.Sequence();
|
||||
//zoomInSequence.Append(faceRectTransform.DOAnchorPos(targetConfig.viewPosition, zoomDuration).SetEase(Ease.OutCubic));
|
||||
//zoomInSequence.Join(faceRectTransform.DOScale(targetConfig.viewScale, zoomDuration).SetEase(Ease.OutCubic));
|
||||
|
||||
// 在 Zoom 到一半时开始黑屏过渡
|
||||
zoomInSequence.Insert(zoomDuration / 2, blackScreenImage.DOFade(1f, zoomDuration / 2).OnStart(() => blackScreenImage.gameObject.SetActive(true)));
|
||||
@@ -186,6 +204,7 @@ public class EyeTransitionManager : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
// 从黑屏淡出
|
||||
private void FadeFromBlack(TweenCallback onComplete)
|
||||
{
|
||||
blackScreenImage.DOFade(0f, 1f).OnComplete(() =>
|
||||
@@ -194,11 +213,10 @@ public class EyeTransitionManager : MonoBehaviour
|
||||
onComplete?.Invoke();
|
||||
});
|
||||
}
|
||||
|
||||
// 请求更改视图
|
||||
public void RequestViewChange(ViewState targetViewState)
|
||||
{
|
||||
//OnViewChangeRequested?.Invoke(targetViewState);
|
||||
StartTransition(targetViewState);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -7654,7 +7654,7 @@ GameObject:
|
||||
- component: {fileID: 863689911}
|
||||
- component: {fileID: 863689912}
|
||||
m_Layer: 0
|
||||
m_Name: Line
|
||||
m_Name: MemoryToEyeLine
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
@@ -7837,7 +7837,7 @@ MonoBehaviour:
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
startTransform: {fileID: 1887941706}
|
||||
endTransform: {fileID: 19183080}
|
||||
endTransform: {fileID: 590852442}
|
||||
--- !u!1 &881978916
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -9025,14 +9025,17 @@ MonoBehaviour:
|
||||
activateButton: {fileID: 1887941707}
|
||||
returnToMainViewButton: {fileID: 1700390218}
|
||||
viewState: 1
|
||||
isAvailable: 1
|
||||
- viewPanel: {fileID: 1294333830}
|
||||
activateButton: {fileID: 19183081}
|
||||
returnToMainViewButton: {fileID: 2126911511}
|
||||
viewState: 2
|
||||
isAvailable: 1
|
||||
- viewPanel: {fileID: 1882925196}
|
||||
activateButton: {fileID: 590852443}
|
||||
returnToMainViewButton: {fileID: 254003903}
|
||||
viewState: 3
|
||||
isAvailable: 1
|
||||
--- !u!4 &1102365682
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -9602,7 +9605,7 @@ MonoBehaviour:
|
||||
m_FallbackScreenDPI: 96
|
||||
m_DefaultSpriteDPI: 96
|
||||
m_DynamicPixelsPerUnit: 1
|
||||
m_PresetInfoIsWorld: 0
|
||||
m_PresetInfoIsWorld: 1
|
||||
--- !u!223 &1141076861
|
||||
Canvas:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -9747,8 +9750,7 @@ MonoBehaviour:
|
||||
m_Script: {fileID: 11500000, guid: 11d7356c830440f48bbd0208dde62749, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
interactiveLineSegmentPrefab: {fileID: 0}
|
||||
visualLineSegmentPrefab: {fileID: 0}
|
||||
visualLineSegmentPrefab: {fileID: 3614166255594274803, guid: 094e209d31320554891f54b63c125b31, type: 3}
|
||||
--- !u!4 &1182811777
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -14622,7 +14624,7 @@ MonoBehaviour:
|
||||
m_FallbackScreenDPI: 96
|
||||
m_DefaultSpriteDPI: 96
|
||||
m_DynamicPixelsPerUnit: 1
|
||||
m_PresetInfoIsWorld: 0
|
||||
m_PresetInfoIsWorld: 1
|
||||
--- !u!223 &1652508980
|
||||
Canvas:
|
||||
m_ObjectHideFlags: 0
|
||||
|
||||
Binary file not shown.
@@ -1233,7 +1233,7 @@ MonoBehaviour:
|
||||
m_Script: {fileID: 11500000, guid: 18a3ec3914131d44199ae33902edf159, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
runMode: 1
|
||||
runMode: 0
|
||||
firstTalkSO: {fileID: 11400000, guid: bd44f6c25aa17a4408e172d16b903176, type: 2}
|
||||
clinicScene: ClinicScene
|
||||
testYarnProject: OptionTest
|
||||
|
||||
@@ -9,14 +9,14 @@ public class Socket : MonoBehaviour, ISocket
|
||||
{
|
||||
if (IsAvailable)
|
||||
{
|
||||
// Here you can add the functionality that will be executed when a plug is inserted
|
||||
|
||||
IsAvailable = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void RemovePlug(Plug plug)
|
||||
{
|
||||
// Here you can add the functionality that will be executed when a plug is removed
|
||||
|
||||
IsAvailable = true;
|
||||
}
|
||||
public Vector2 GetPosition()
|
||||
|
||||
Reference in New Issue
Block a user