223 lines
6.8 KiB
C#
223 lines
6.8 KiB
C#
using AibisDream.FixSystem;
|
|
using AibisDream.Framework;
|
|
using Cinemachine;
|
|
using UnityEngine;
|
|
using UnityEngine.Playables;
|
|
using Yarn.Unity;
|
|
using System.Collections;
|
|
using UnityEngine.Timeline;
|
|
using System.Collections.Generic;
|
|
using DG.Tweening;
|
|
using AibisDream.Utility;
|
|
|
|
namespace AibisDream
|
|
{
|
|
public class OpenSystem : MonoBehaviour
|
|
{
|
|
public DeepInClock deepInClock;
|
|
public PlayableDirector openPlayable;
|
|
public LightRoom lightRoom;
|
|
public GameObject screen;
|
|
|
|
public SpriteRenderer dreamSprite;
|
|
|
|
public BubbleSlotGroup bubbleSlotGroup;
|
|
|
|
private void Awake()
|
|
{
|
|
// 注册
|
|
FixSystemCenter.SystemDic.Register(this);
|
|
var virtualCam = transform.Find("Op Camera").GetComponent<ICinemachineCamera>();
|
|
CameraKit.Instance.RegisterCamera(CameraEnum.Op, virtualCam);
|
|
var breakCam = transform.Find("Break Camera").GetComponent<ICinemachineCamera>();
|
|
CameraKit.Instance.RegisterCamera(CameraEnum.BreakCamera, breakCam);
|
|
var dreamCam = transform.Find("Dream Camera").GetComponent<ICinemachineCamera>();
|
|
CameraKit.Instance.RegisterCamera(CameraEnum.DreamCamera, dreamCam);
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
dreamSprite.gameObject.SetActive(true);
|
|
dreamSprite.SetAlpha(0);
|
|
}
|
|
|
|
public void Update()
|
|
{
|
|
if (Input.GetKeyDown(KeyCode.K))
|
|
{
|
|
EnableClock();
|
|
}
|
|
}
|
|
|
|
public void OpenLightRoom()
|
|
{
|
|
screen.SetActive(false);
|
|
lightRoom.gameObject.SetActive(true);
|
|
}
|
|
|
|
public void EnableClock()
|
|
{
|
|
lightRoom.gameObject.SetActive(false);
|
|
deepInClock.Enable();
|
|
}
|
|
|
|
public void PlayOpenTimeline()
|
|
{
|
|
// 在播放Timeline之前绑定DialogController
|
|
BindDialogController();
|
|
//OpenAnima.SetActive(true);
|
|
openPlayable.Play();
|
|
}
|
|
|
|
public void DreamFadeIn(float time, float targetAlpha)
|
|
{
|
|
dreamSprite.DOFade(targetAlpha, time).SetEase(Ease.InOutSine);
|
|
}
|
|
|
|
public void DreamDisappear()
|
|
{
|
|
dreamSprite.gameObject.SetActive(false);
|
|
}
|
|
|
|
// 添加动态绑定方法
|
|
public void BindTimelineTarget(string trackName, Object target)
|
|
{
|
|
if (openPlayable == null) return;
|
|
|
|
var timeline = openPlayable.playableAsset as TimelineAsset;
|
|
if (timeline == null) return;
|
|
|
|
foreach (var track in timeline.GetOutputTracks())
|
|
{
|
|
if (track.name == trackName)
|
|
{
|
|
openPlayable.SetGenericBinding(track, target);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
// 添加DialogController绑定方法
|
|
private void BindDialogController()
|
|
{
|
|
if (openPlayable == null) return;
|
|
|
|
var timeline = openPlayable.playableAsset as TimelineAsset;
|
|
if (timeline == null) return;
|
|
|
|
// 遍历所有轨道
|
|
foreach (var track in timeline.GetOutputTracks())
|
|
{
|
|
// 检查轨道类型是否为Signal Track或其他需要DialogController的轨道
|
|
if (track is SignalTrack || track.name.Contains("Dialog"))
|
|
{
|
|
// 绑定DialogController实例
|
|
openPlayable.SetGenericBinding(track, DialogController.Instance);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void BindPlayToolPanel()
|
|
{
|
|
if (openPlayable == null) return;
|
|
|
|
var timeline = openPlayable.playableAsset as TimelineAsset;
|
|
if (timeline == null) return;
|
|
|
|
// 遍历所有轨道
|
|
foreach (var track in timeline.GetOutputTracks())
|
|
{
|
|
// 检查轨道类型是否为Signal Track或其他需要DialogController的轨道
|
|
if (track is SignalTrack || track.name.Contains("Fade"))
|
|
{
|
|
// 绑定DialogController实例
|
|
openPlayable.SetGenericBinding(track, UIManager.Instance.GetPanel<PlayToolPanel>());
|
|
}
|
|
}
|
|
}
|
|
|
|
// 通用的Timeline播放方法
|
|
public IEnumerator PlayTimeline(string timelinePath, Dictionary<string, Object> bindings = null)
|
|
{
|
|
// 加载Timeline资源
|
|
var timelineAsset = Resources.Load<TimelineAsset>(timelinePath);
|
|
if (timelineAsset == null)
|
|
{
|
|
Debug.LogError($"找不到Timeline资源: {timelinePath}");
|
|
yield break;
|
|
}
|
|
|
|
openPlayable.playableAsset = timelineAsset;
|
|
BindPlayToolPanel();
|
|
openPlayable.Play();
|
|
while (openPlayable.state == PlayState.Playing)
|
|
{
|
|
yield return null;
|
|
}
|
|
}
|
|
}
|
|
|
|
public static class OpenYarnCommand
|
|
{
|
|
private static OpenSystem OpenSystem => FixSystemCenter.SystemDic.Get<OpenSystem>();
|
|
|
|
[YarnCommand("enable_clock")]
|
|
public static void EnableClock()
|
|
{
|
|
OpenSystem.EnableClock();
|
|
}
|
|
|
|
[YarnCommand("open_light_room")]
|
|
public static void OpenLightRoom()
|
|
{
|
|
OpenSystem.OpenLightRoom();
|
|
}
|
|
|
|
[YarnCommand("play_open_timeline")]
|
|
public static IEnumerator RunTimeline()
|
|
{
|
|
OpenSystem.PlayOpenTimeline();
|
|
yield return null;
|
|
}
|
|
|
|
[YarnCommand("Open_play_timeline")]
|
|
public static IEnumerator PlayTimeline(string timelinePath)
|
|
{
|
|
yield return OpenSystem.PlayTimeline(timelinePath);
|
|
}
|
|
|
|
[YarnCommand("play_timeline_with_bindings")]
|
|
public static IEnumerator PlayTimelineWithBindings(string timelinePath, string[] bindingNames)
|
|
{
|
|
var bindings = new Dictionary<string, Object>();
|
|
|
|
// 解析绑定名称并查找对应物体
|
|
foreach (var bindingName in bindingNames)
|
|
{
|
|
var targetObj = GameObject.Find(bindingName);
|
|
if (targetObj != null)
|
|
{
|
|
bindings[bindingName] = targetObj;
|
|
}
|
|
else
|
|
{
|
|
Debug.LogWarning($"找不到绑定物体: {bindingName}");
|
|
}
|
|
}
|
|
|
|
yield return OpenSystem.PlayTimeline(timelinePath, bindings);
|
|
}
|
|
|
|
[YarnCommand("dream_fade_in")]
|
|
public static void DreamFadeIn(float time, float targetAlpha)
|
|
{
|
|
OpenSystem.DreamFadeIn(time, targetAlpha);
|
|
}
|
|
|
|
[YarnCommand("dream_disappear")]
|
|
public static void DreamDisappear()
|
|
{
|
|
OpenSystem.DreamDisappear();
|
|
}
|
|
}
|
|
} |