UnitRenderComponet.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. using UnityEngine;
  2. using Mono;
  3. using System.Collections.Generic;
  4. using AnimationType = 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(AnimationType.Idle, true);
  13. public static readonly AnimatorCommand CMDRun = new AnimatorCommand(AnimationType.Run, true);
  14. public static readonly AnimatorCommand CMDDead = new AnimatorCommand(AnimationType.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 GProgressBar HPBar;
  25. public GTextField NameBar;
  26. public Transform TransHeadInfo;
  27. public Transform TransChest;
  28. public Transform TransFoot;
  29. public int Vip = 0;
  30. //TODO: 获得模型绑定部件,如不存在返回Root
  31. public Transform GetBindPart(string partName)
  32. {
  33. if(partName == "chest")
  34. {
  35. if (TransChest == null)
  36. {
  37. TransChest = GameObject.transform.Find("BindPart/" + partName);
  38. }
  39. if (TransChest != null)
  40. {
  41. return TransChest;
  42. }
  43. else
  44. {
  45. Log.Error($"NotFound part({partName}) @{GameObject.name}");
  46. }
  47. }
  48. else if (partName == "foot")
  49. {
  50. if (TransFoot == null)
  51. {
  52. TransFoot = GameObject.transform.Find("BindPart/" + partName);
  53. }
  54. if (TransFoot != null)
  55. {
  56. return TransFoot;
  57. }
  58. else
  59. {
  60. Log.Error($"NotFound part({partName}) @{GameObject.name}");
  61. }
  62. }
  63. else
  64. {
  65. if(!partName.Contains('/'))
  66. {
  67. partName = "BindPart/" + partName;
  68. }
  69. var trans = GameObject.transform.Find(partName);
  70. if(trans != null)
  71. {
  72. return trans;
  73. }
  74. else
  75. {
  76. Log.Error($"NotFound part({partName}) @{GameObject.name}");
  77. }
  78. }
  79. return GameObject.transform;
  80. }
  81. //重复回收利用的component,在下次使用前需要reset
  82. public void Reset()
  83. {
  84. FrozenComponent = null;
  85. GameObject = null;
  86. AniData = null;
  87. DoingCmd = null;
  88. HeadBar = null;
  89. TransHeadInfo = null;
  90. TransChest = null;
  91. TransFoot = null;
  92. Commands.Clear();
  93. BuffEffects.Clear();
  94. Vip = 0;
  95. }
  96. }
  97. //TODO: 支持ObjectPool
  98. public class AnimatorCommand
  99. {
  100. public AnimationType Type;
  101. public float Duration = -1f;
  102. public float Speed = 1.0f;
  103. public uint GroupId = 0;
  104. public bool Loop = false;
  105. public AnimatorCommand(AnimationType type, bool loop = false)
  106. {
  107. this.Type = type;
  108. this.Loop = loop;
  109. }
  110. public bool IsSkillCmd()
  111. {
  112. return Type >= AnimationType.Skill0 && Type < AnimationType.SkillMax;
  113. }
  114. }
  115. }