FightingSeatManager.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. namespace YLBattle
  5. {
  6. /// <summary>
  7. /// 占位管理
  8. /// </summary>
  9. public class FightingSeatManager : MonoBehaviour
  10. {
  11. /// <summary>
  12. /// 元素
  13. /// </summary>
  14. private List<Transform> mElements = new List<Transform>();
  15. /// <summary>
  16. /// 当前战斗占位模式
  17. /// 0=普通占位 1=PVP
  18. /// </summary>
  19. private int seatMode = -1;
  20. /// <summary>
  21. ///
  22. /// </summary>
  23. private int mMaxCount = 99;
  24. /// <summary>
  25. /// 当前占位根节点
  26. /// </summary>
  27. private Transform mSeatRoot = null;
  28. /// <summary>
  29. /// 当前占位根节点初始位置
  30. /// </summary>
  31. private Vector3 mOrgPosition = Vector3.zero;
  32. /// <summary>
  33. /// 实例
  34. /// </summary>
  35. public static FightingSeatManager mInstance;
  36. /// <summary>
  37. /// 获取单键
  38. /// </summary>
  39. /// <returns>单键实例</returns>
  40. public static FightingSeatManager Instance
  41. {
  42. get
  43. {
  44. if (mInstance == null)
  45. {
  46. GameObject obj = GameObject.Find("FightingManager");
  47. if (obj != null)
  48. {
  49. mInstance = obj.AddComponent<FightingSeatManager>();
  50. }
  51. }
  52. return mInstance;
  53. }
  54. }
  55. /// <summary>
  56. /// 初始化
  57. /// 卡槽管理+旋转工具+整形工具
  58. /// </summary>
  59. public void InitComponents(int mode)
  60. {
  61. this.mElements.Clear();
  62. this.mSeatRoot = BattleStaticFunc.FindTransform(transform, mode == 2 ? "PvPSeat" : "RoleSeat");
  63. this.mOrgPosition = mSeatRoot.position;
  64. for (int ei = 0; ei < mMaxCount; ei++)
  65. {
  66. Transform obj = BattleStaticFunc.FindTransform(mSeatRoot, "Seat_" + ei.ToString());
  67. if (obj != null)
  68. {
  69. mElements.Add(obj);
  70. }
  71. else
  72. {
  73. break;
  74. }
  75. }
  76. }
  77. /// <summary>
  78. /// 通过占位获得占位的Trans
  79. /// </summary>
  80. /// <param name="_seat">占位</param>
  81. /// <param name="_mode">当前战斗模式 0=普通 1=PVP</param>
  82. /// <returns></returns>
  83. public Transform GetFightingMapSeat(int _seat, int _mode = 0)
  84. {
  85. if (_mode != this.seatMode)
  86. {
  87. this.seatMode = _mode;
  88. InitComponents(this.seatMode);
  89. }
  90. if (_seat >= 0 && _seat < this.mElements.Count)
  91. {
  92. return this.mElements[_seat];
  93. }
  94. return null;
  95. }
  96. /// <summary>
  97. ///
  98. /// </summary>
  99. void Update()
  100. {
  101. if (mSeatRoot != null)
  102. {
  103. ///同步地图和占位的位置,以达到地图动画和角色共振的效果
  104. mSeatRoot.position = this.mOrgPosition + FightingMap.Instance.MapPos;
  105. }
  106. }
  107. }
  108. }