c1_unity/Assets/Scripts/Component/Helper/TimelineHelper.cs
2023-04-03 11:04:31 +08:00

117 lines
2.9 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace BF
{
[System.Serializable]
public struct TimelineEventItem
{
public string eventName;
public uint eventHash;
public double eventTime;
}
[ExecuteInEditMode]
[DisallowMultipleComponent]
public class TimelineHelper : MonoBehaviour
{
public List<GameObjectInfo> prefabList = new List<GameObjectInfo>();
public double duration;
[SerializeField, Delayed]
public List<TimelineEventItem> timelineEventList = new List<TimelineEventItem>();
public GameObject GetGameObjectByName(string name)
{
int count = prefabList.Count;
for (int i = 0; i < count; i++)
{
if (prefabList[i].name == name)
{
return prefabList[i].gameObject;
}
}
return null;
}
public int GetListCount()
{
return prefabList.Count;
}
public int GetObjectTypeByIndex(int index)
{
if (index >= 0 && index < prefabList.Count)
{
return prefabList[index].objectType;
}
return 0;
}
public uint GetHashNameByIndex(int index)
{
if (index >= 0 && index < prefabList.Count)
{
return prefabList[index].hashName;
}
return 0;
}
public GameObject GetGameObjectByIndex(int index)
{
if (index >= 0 && index < prefabList.Count)
{
return prefabList[index].gameObject;
}
else if (index < 0)
{
return this.gameObject;
}
return null;
}
public int GetRootPrefabIndex()
{
int index = -1;
for (int i = 0; i < prefabList.Count; i++)
{
if (prefabList[i].gameObject == this.gameObject)
{
index = i;
break;
}
}
return index;
}
public int GetEventListCount()
{
return timelineEventList.Count;
}
public uint GetEventHashNameByIndex(int index)
{
if (index >= 0 && index < timelineEventList.Count)
{
return timelineEventList[index].eventHash;
}
return 0;
}
public double GetEventTimeByIndex(int index)
{
if (index >= 0 && index < timelineEventList.Count)
{
return timelineEventList[index].eventTime;
}
return 0;
}
void OnDestroy()
{
prefabList.Clear();
prefabList = null;
}
}
}