using System.Collections.Generic; using UnityEngine; #if UNITY_EDITOR using UnityEngine.Playables; using UnityEngine.Animations; #endif namespace Thousandto.Launcher.ExternalLibs { //动画列表脚本,用于存储角色身上的动作列表 public class AnimListScript : MonoBehaviour { #region//公有变量 //公用动作列表 //[System.Obsolete("这个动作列表将被NewAnimList属性给替代.", true)] public List AnimList = null; //独有动作列表 public List SelfAnimList = null; //是否保存Clip public bool IsSaveClip = true; //公用动作列表 public List NewAnimList = null; public Transform[] SlotTrans = null; //buildin数据 public GameObject[] BuildinLevel1 = null; public GameObject[] BuildinLevel2 = null; public GameObject[] BuildinLevel3 = null; //动作片段列表 private List _animClipTmpList; #endregion #region//公有函数 public List> GetAnimAssetPaths() { #if UNITY_EDITOR && !FUNCELL_LAUNCHER if (NewAnimList == null || IsSaveClip || NewAnimList == null) return null; var list = NewAnimList.ConvertAll>(x => { return new KeyValuePair(x.name, x.path); }); return list; #else return null; #endif } //获取动作列表 public List GetAnimList() { if (AnimList == null || AnimList.Count == 0) { if (_animClipTmpList == null && IsSaveClip && NewAnimList != null) { _animClipTmpList = NewAnimList.ConvertAll(x => { return x.clip; }); } return _animClipTmpList; } else { return AnimList; } } //获取动作列表 public List GetAnimListByEditor() { if (AnimList == null || AnimList.Count == 0) { if (_animClipTmpList == null && NewAnimList != null) { _animClipTmpList = NewAnimList.ConvertAll(x => { return x.clip; }); } return _animClipTmpList; } else { return AnimList; } } //获取独有动作列表 public List GetSelfAnimList() { return SelfAnimList; } //添加动作 public bool AddClip(AnimationClip clip, bool isclip = true) { if (clip == null) { return false; } if (isclip && IsSaveClip) { if (AnimList == null) { AnimList = new List(); } var idx = AnimList.FindIndex(x => { return x.name == clip.name; }); if (idx < 0) { AnimList.Add(clip); return true; } } else { if (NewAnimList == null) { NewAnimList = new List(); } var idx = NewAnimList.FindIndex(x => { return x.name == clip.name; }); if (idx < 0) { NewAnimList.Add(AnimInfo.Create(clip, IsSaveClip)); return true; } } return false; } //移除动作 public bool RemoveClip(string clipName) { if (AnimList != null) { for (int i = 0; i < AnimList.Count; ++i) { if (AnimList[i] != null && AnimList[i].name == clipName) { AnimList.RemoveAt(i); return true; } } } if (NewAnimList != null) { for (int i = 0; i < NewAnimList.Count; ++i) { if (NewAnimList[i] != null && NewAnimList[i].name == clipName) { NewAnimList.RemoveAt(i); return true; } } } return false; } //获取slot public Transform[] GetSlotTrans() { return SlotTrans; } //获取buildinlevel1 public GameObject[] GetBuildinLevel1() { return BuildinLevel1; } //获取buildinlevel2 public GameObject[] GetBuildinLevel2() { return BuildinLevel2; } //获取buildinlevel3 public GameObject[] GetBuildinLevel3() { return BuildinLevel3; } //设置buildinlevel public void SetBuildinLevel(int level) { if (BuildinLevel1 != null && BuildinLevel1.Length > 0) { for (int i = 0; i < BuildinLevel1.Length; ++i) { if (BuildinLevel1[i] != null) { BuildinLevel1[i].SetActive(level >= 1); } } } if (BuildinLevel2 != null && BuildinLevel2.Length > 0) { for (int i = 0; i < BuildinLevel2.Length; ++i) { if (BuildinLevel2[i] != null) { BuildinLevel2[i].SetActive(level >= 2); } } } if (BuildinLevel3 != null && BuildinLevel3.Length > 0) { for (int i = 0; i < BuildinLevel3.Length; ++i) { if (BuildinLevel3[i] != null) { BuildinLevel3[i].SetActive(level >= 3); } } } } #endregion #region//MonoBehaviour public void AnimTranslate(bool clip2Info) { if (clip2Info) { if (AnimList != null && AnimList.Count > 0) { if (NewAnimList == null || NewAnimList.Count == 0) { NewAnimList = AnimInfo.Convert(AnimList, IsSaveClip); } else { for (int i = 0; i < AnimList.Count; i++) { AddClip(AnimList[i]); } } AnimList = null; } } else { if (NewAnimList != null && NewAnimList.Count > 0) { if (AnimList == null || AnimList.Count == 0) { AnimList = NewAnimList.ConvertAll(x => { return x.clip; }); } else { for (int i = 0; i < AnimList.Count; i++) { AddClip(AnimList[i]); } } NewAnimList = null; } } } private void OnValidate() { AnimInfo.ChangedSaveClipFlag(NewAnimList, IsSaveClip); } #endregion } }