245 lines
6.2 KiB
C#
245 lines
6.2 KiB
C#
using cfg.ShowCfg;
|
|
using Sirenix.OdinInspector;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.Playables;
|
|
|
|
/// <summary>
|
|
/// 演出组件
|
|
/// </summary>
|
|
public class ShowComponent : MonoBehaviour
|
|
{
|
|
#region 外部序列化字段
|
|
/// <summary>
|
|
/// 演出场景类型
|
|
/// </summary>
|
|
[LabelText("演出场景类型")]
|
|
[SerializeField]
|
|
private E_ShowSceneType showSceneType;
|
|
|
|
/// <summary>
|
|
/// 角色根节点
|
|
/// </summary>
|
|
[LabelText("角色根节点")]
|
|
[SerializeField]
|
|
private Transform tsCharacterRoot;
|
|
|
|
/// <summary>
|
|
/// 道具根节点
|
|
/// </summary>
|
|
[LabelText("道具根节点")]
|
|
[SerializeField]
|
|
private Transform tsItemRoot;
|
|
|
|
/// <summary>
|
|
/// 收集演出点根节点
|
|
/// </summary>
|
|
[LabelText("收集演出点的根节点")]
|
|
[SerializeField]
|
|
private Transform tsCollectRoot;
|
|
|
|
/// <summary>
|
|
/// 角色演出点根节点
|
|
/// </summary>
|
|
[LabelText("角色演出点根节点")]
|
|
[SerializeField]
|
|
private Transform tsCharacterShowPointRoot;
|
|
|
|
/// <summary>
|
|
/// 道具演出点根节点
|
|
/// </summary>
|
|
[LabelText("道具演出点根节点")]
|
|
[SerializeField]
|
|
private Transform tsItemShowPointRoot;
|
|
|
|
/// <summary>
|
|
/// 最大抽取角色数量
|
|
/// </summary>
|
|
[LabelText("最大抽取角色数")]
|
|
[SerializeField]
|
|
private int characterMaxCount = 20;
|
|
|
|
/// <summary>
|
|
/// 是否忽略看板娘
|
|
/// </summary>
|
|
[LabelText("是否忽略看板娘")]
|
|
[SerializeField]
|
|
private bool IsIgnoreKanbanban;
|
|
|
|
/// <summary>
|
|
/// 相机Timeline
|
|
/// </summary>
|
|
[LabelText("相机PlayableDirector")]
|
|
[SerializeField]
|
|
private PlayableDirector cameraPlayable;
|
|
#endregion
|
|
|
|
/// <summary>
|
|
/// 固定演出列表
|
|
/// </summary>
|
|
[LabelText("固定演出列表"), Indent]
|
|
public List<FixedShow> listFixedShow;
|
|
|
|
/// <summary>
|
|
/// 相机动画回调
|
|
/// </summary>
|
|
public Action CameraAction;
|
|
|
|
/// <summary>
|
|
/// 可以抽取的角色最大数量
|
|
/// </summary>
|
|
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; } }
|
|
|
|
/// <summary>
|
|
/// 角色演出点根节点
|
|
/// </summary>
|
|
public Transform TsShowPointRoot
|
|
{
|
|
get { return tsCharacterShowPointRoot; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// 道具演出点根节点
|
|
/// </summary>
|
|
public Transform TsItemShowPointRoot
|
|
{
|
|
get { return tsItemShowPointRoot; }
|
|
}
|
|
|
|
public Transform TsCharacterRoot
|
|
{
|
|
get { return tsCharacterRoot; }
|
|
}
|
|
|
|
public Transform TsItemRoot
|
|
{
|
|
get { return tsItemRoot; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// 相机动画播放完成
|
|
/// </summary>
|
|
public void OnPlayCameraAnimStop()
|
|
{
|
|
CameraAction?.Invoke();
|
|
CameraAction = null;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取角色演出点
|
|
/// </summary>
|
|
/// <param name="list"></param>
|
|
public void GetCharacterShowPoint(ref List<Transform> 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));
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取道具演出点
|
|
/// </summary>
|
|
/// <param name="list"></param>
|
|
public void GetItemShowPoint(ref List<Transform> 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));
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 收集演出点
|
|
/// </summary>
|
|
[Button("收集演出点")]
|
|
public void CollectShowPoint()
|
|
{
|
|
if (tsCharacterShowPointRoot == null)
|
|
{
|
|
Debug.LogError("角色演出点为空");
|
|
return;
|
|
}
|
|
|
|
if (tsItemShowPointRoot == null)
|
|
{
|
|
Debug.LogError("道具演出点为空");
|
|
return;
|
|
}
|
|
|
|
#region 先清除原有演出点
|
|
|
|
Transform[] tsShowPoints = tsCharacterShowPointRoot.GetComponentsInChildren<Transform>();
|
|
foreach (Transform ts in tsShowPoints)
|
|
{
|
|
if (ts == tsCharacterShowPointRoot)
|
|
continue;
|
|
|
|
DestroyImmediate(ts.gameObject);
|
|
}
|
|
|
|
tsShowPoints = tsItemShowPointRoot.GetComponentsInChildren<Transform>();
|
|
foreach (Transform ts in tsShowPoints)
|
|
{
|
|
if (ts == tsItemShowPointRoot)
|
|
continue;
|
|
|
|
DestroyImmediate(ts.gameObject);
|
|
}
|
|
#endregion
|
|
|
|
ShowPoint[] showPoints = tsCollectRoot.GetComponentsInChildren<ShowPoint>();
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
} |