UnitRenderComponet.cs 3.5 KB

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