using cfg.ShowCfg; using Sirenix.OdinInspector; using System; using System.Collections.Generic; using UnityEngine; using UnityEngine.Playables; /// /// 演出组件 /// public class ShowComponent : MonoBehaviour { #region 外部序列化字段 /// /// 演出场景类型 /// [LabelText("演出场景类型")] [SerializeField] private E_ShowSceneType showSceneType; /// /// 角色根节点 /// [LabelText("角色根节点")] [SerializeField] private Transform tsCharacterRoot; /// /// 道具根节点 /// [LabelText("道具根节点")] [SerializeField] private Transform tsItemRoot; /// /// 收集演出点根节点 /// [LabelText("收集演出点的根节点")] [SerializeField] private Transform tsCollectRoot; /// /// 角色演出点根节点 /// [LabelText("角色演出点根节点")] [SerializeField] private Transform tsCharacterShowPointRoot; /// /// 道具演出点根节点 /// [LabelText("道具演出点根节点")] [SerializeField] private Transform tsItemShowPointRoot; /// /// 最大抽取角色数量 /// [LabelText("最大抽取角色数")] [SerializeField] private int characterMaxCount = 20; /// /// 是否忽略看板娘 /// [LabelText("是否忽略看板娘")] [SerializeField] private bool IsIgnoreKanbanban; /// /// 相机Timeline /// [LabelText("相机PlayableDirector")] [SerializeField] private PlayableDirector cameraPlayable; #endregion /// /// 固定演出列表 /// [LabelText("固定演出列表"), Indent] public List listFixedShow; /// /// 相机动画回调 /// public Action CameraAction; /// /// 可以抽取的角色最大数量 /// public int CharacterMaxCount { get { return characterMaxCount; } } public bool IsIgnoreKanban { get { return IsIgnoreKanbanban; } } public E_ShowSceneType ShowSceneTyp { get { return showSceneType; } } public PlayableDirector CameraPlayable { get { return cameraPlayable; } } /// /// 角色演出点根节点 /// public Transform TsShowPointRoot { get { return tsCharacterShowPointRoot; } } /// /// 道具演出点根节点 /// public Transform TsItemShowPointRoot { get { return tsItemShowPointRoot; } } public Transform TsCharacterRoot { get { return tsCharacterRoot; } } public Transform TsItemRoot { get { return tsItemRoot; } } /// /// 相机动画播放完成 /// public void OnPlayCameraAnimStop() { CameraAction?.Invoke(); CameraAction = null; } /// /// 获取角色演出点 /// /// public void GetCharacterShowPoint(ref List list) { list.Clear(); if (tsCharacterShowPointRoot is null) return; list = new(tsCharacterShowPointRoot.childCount); for (int i = 0; i < tsCharacterShowPointRoot.childCount; ++i) { list.Add(tsCharacterShowPointRoot.GetChild(i)); } } /// /// 获取道具演出点 /// /// public void GetItemShowPoint(ref List list) { list.Clear(); if (tsItemShowPointRoot is null) return; list = new(tsItemShowPointRoot.childCount); for (int i = 0; i < tsItemShowPointRoot.childCount; ++i) { list.Add(tsItemShowPointRoot.GetChild(i)); } } /// /// 收集演出点 /// [Button("收集演出点")] public void CollectShowPoint() { if (tsCharacterShowPointRoot == null) { Debug.LogError("角色演出点为空"); return; } if (tsItemShowPointRoot == null) { Debug.LogError("道具演出点为空"); return; } #region 先清除原有演出点 Transform[] tsShowPoints = tsCharacterShowPointRoot.GetComponentsInChildren(); foreach (Transform ts in tsShowPoints) { if (ts == tsCharacterShowPointRoot) continue; DestroyImmediate(ts.gameObject); } tsShowPoints = tsItemShowPointRoot.GetComponentsInChildren(); foreach (Transform ts in tsShowPoints) { if (ts == tsItemShowPointRoot) continue; DestroyImmediate(ts.gameObject); } #endregion ShowPoint[] showPoints = tsCollectRoot.GetComponentsInChildren(); int characterIndex = 0; int itemIndex = 0; foreach (ShowPoint showPoint in showPoints) { switch (showPoint.ShowPointType) { case E_ShowPointType.Character: { GameObject go = new($"{characterIndex++:D3}_{showPoint.Name}"); go.transform.SetPositionAndRotation(showPoint.gameObject.transform.position, showPoint.gameObject.transform.rotation); go.transform.parent = tsCharacterShowPointRoot; } break; case E_ShowPointType.Item: { GameObject go = new($"{itemIndex++:D3}_{showPoint.Name}"); go.transform.SetPositionAndRotation(showPoint.gameObject.transform.position, showPoint.gameObject.transform.rotation); go.transform.parent = tsItemShowPointRoot; } break; default: { Debug.LogError("未处理类型"); } break; } } } }