using UnityEngine; using Mono; using System.Collections.Generic; using AniType = Mono.AnimationData.AnimationType; using FairyGUI; using CommonLang; namespace ET.Client { [ChildOf(typeof(ModelViewComponent))] public class UnitRenderComponet : Entity, IAwake, IUpdate, IDestroy { public static readonly AnimatorCommand CMDIdle = new AnimatorCommand(AniType.Idle, true); public static readonly AnimatorCommand CMDRun = new AnimatorCommand(AniType.Run, true); public static readonly AnimatorCommand CMDDead = new AnimatorCommand(AniType.Dead); //buff产生的特效. public HashMap BuffEffects = new(); //指令队列 public List Commands = new (); public GameObject GameObject { get; set; } public AnimationData AniData; public AnimatorCommand DoingCmd; public GComponent HeadBar; public Transform TransHeadInfo; public Transform TransChest; public Transform TransFoot; //TODO: 获得模型绑定部件,如不存在返回Root public Transform GetBindPart(string partName) { if(partName == "chest") { if (TransChest == null) { TransChest = GameObject.transform.Find("BindPart/" + partName); } if (TransChest != null) { return TransChest; } else { Log.Error($"NotFound part({partName}) @{GameObject.name}"); } } else if (partName == "foot") { if (TransFoot == null) { TransFoot = GameObject.transform.Find("BindPart/" + partName); } if (TransFoot != null) { return TransFoot; } else { Log.Error($"NotFound part({partName}) @{GameObject.name}"); } } else { if(!partName.Contains('/')) { partName = "BindPart/" + partName; } var trans = GameObject.transform.Find(partName); if(trans != null) { return trans; } else { Log.Error($"NotFound part({partName}) @{GameObject.name}"); } } return GameObject.transform; } //重复回收利用的component,在下次使用前需要reset public void Reset() { GameObject = null; AniData = null; DoingCmd = null; HeadBar = null; TransHeadInfo = null; TransChest = null; TransFoot = null; Commands.Clear(); BuffEffects.Clear(); } } //TODO: 支持ObjectPool public class AnimatorCommand { public AniType Type; public float Duration = -1f; public float Speed = 1.0f; public uint GroupId = 0; public bool Loop = false; public AnimatorCommand(AniType type, bool loop = false) { this.Type = type; this.Loop = loop; } public bool IsSkillCmd() { return Type >= AniType.Skill0 && Type < AniType.SkillMax; } } }