UnitRenderComponet.cs 3.3 KB

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