UnitRenderComponet.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. using UnityEngine;
  2. using Mono;
  3. using System.Collections.Generic;
  4. using AniType = Mono.AnimationData.AnimationType;
  5. using FairyGUI;
  6. using CommonLang;
  7. namespace ET.Client
  8. {
  9. [ChildOf(typeof(ModelViewComponent))]
  10. public class UnitRenderComponet : Entity, IAwake<GameObject>, IUpdate, IDestroy
  11. {
  12. public static readonly AnimatorCommand CMDIdle = new AnimatorCommand(AniType.Idle, true);
  13. public static readonly AnimatorCommand CMDRun = new AnimatorCommand(AniType.Run, true);
  14. public static readonly AnimatorCommand CMDDead = new AnimatorCommand(AniType.Dead);
  15. //buff产生的特效.
  16. public HashMap<string, uint> BuffEffects = new();
  17. //指令队列
  18. public List<AnimatorCommand> Commands = new ();
  19. public GameObject GameObject { get; set; }
  20. public AnimationData AniData;
  21. public IceFrozen FrozenComponent;
  22. public AnimatorCommand DoingCmd;
  23. public GComponent HeadBar;
  24. public Transform TransHeadInfo;
  25. public Transform TransChest;
  26. public Transform TransFoot;
  27. //TODO: 获得模型绑定部件,如不存在返回Root
  28. public Transform GetBindPart(string partName)
  29. {
  30. if(partName == "chest")
  31. {
  32. if (TransChest == null)
  33. {
  34. TransChest = GameObject.transform.Find("BindPart/" + partName);
  35. }
  36. if (TransChest != null)
  37. {
  38. return TransChest;
  39. }
  40. else
  41. {
  42. Log.Error($"NotFound part({partName}) @{GameObject.name}");
  43. }
  44. }
  45. else if (partName == "foot")
  46. {
  47. if (TransFoot == null)
  48. {
  49. TransFoot = GameObject.transform.Find("BindPart/" + partName);
  50. }
  51. if (TransFoot != null)
  52. {
  53. return TransFoot;
  54. }
  55. else
  56. {
  57. Log.Error($"NotFound part({partName}) @{GameObject.name}");
  58. }
  59. }
  60. else
  61. {
  62. if(!partName.Contains('/'))
  63. {
  64. partName = "BindPart/" + partName;
  65. }
  66. var trans = GameObject.transform.Find(partName);
  67. if(trans != null)
  68. {
  69. return trans;
  70. }
  71. else
  72. {
  73. Log.Error($"NotFound part({partName}) @{GameObject.name}");
  74. }
  75. }
  76. return GameObject.transform;
  77. }
  78. //重复回收利用的component,在下次使用前需要reset
  79. public void Reset()
  80. {
  81. FrozenComponent = null;
  82. GameObject = null;
  83. AniData = null;
  84. DoingCmd = null;
  85. HeadBar = null;
  86. TransHeadInfo = null;
  87. TransChest = null;
  88. TransFoot = null;
  89. Commands.Clear();
  90. BuffEffects.Clear();
  91. }
  92. }
  93. //TODO: 支持ObjectPool
  94. public class AnimatorCommand
  95. {
  96. public AniType Type;
  97. public float Duration = -1f;
  98. public float Speed = 1.0f;
  99. public uint GroupId = 0;
  100. public bool Loop = false;
  101. public AnimatorCommand(AniType type, bool loop = false)
  102. {
  103. this.Type = type;
  104. this.Loop = loop;
  105. }
  106. public bool IsSkillCmd()
  107. {
  108. return Type >= AniType.Skill0 && Type < AniType.SkillMax;
  109. }
  110. }
  111. }