SpawnCfgGroup.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Security;
  4. public class SpawnCfgGroup : SpawnCfg
  5. {
  6. [HideInInspector]
  7. public int GroupId;
  8. [FriendlyName("需要触发器")]
  9. public bool bTriggerSpawn;
  10. private Color GroupColor = new Color(0.8f, 0.1f, 0.1f, 0.8f);
  11. private SpawnCfg[] drawPoints = null;
  12. private bool bSpawned = false;
  13. protected override void Start()
  14. {
  15. SpawnCfg next = nextPoint;
  16. #if UNITY_EDITOR
  17. int nTmp = 0;
  18. #endif
  19. while (next)
  20. {
  21. mSpawnCfgList.Add(next);
  22. next.onAllDeadEvt += this.onSpawnPointAllDead;
  23. next = next.nextPoint;
  24. #if UNITY_EDITOR
  25. if (++nTmp > 100)
  26. {
  27. DebugHelper.LogError("超过100个,tm死循环了吧!!");
  28. break;
  29. }
  30. #endif
  31. }
  32. base.Start();
  33. }
  34. public override void UpdateLogic(float delta)
  35. {
  36. if (!isStartup)
  37. {
  38. return;
  39. }
  40. }
  41. public override void Stop()
  42. {
  43. base.Stop();
  44. mSpawnedList.Clear();
  45. }
  46. protected override void DecSpawnPointOver()
  47. {
  48. base.DecSpawnPointOver();
  49. }
  50. public override void Startup()
  51. {
  52. if (!bTriggerSpawn && !isStartup)
  53. {
  54. base.Startup();
  55. }
  56. }
  57. public void TriggerStartUp()
  58. {
  59. if (!isStartup)
  60. {
  61. base.Startup();
  62. }
  63. }
  64. private SpawnCfg[] FindChildrenPoints()
  65. {
  66. return GetComponentsInChildren<SpawnCfg>(); // parent always the 1st
  67. }
  68. protected void onSpawnPointAllDead(SpawnCfg inSpawnPoint)
  69. {
  70. if (mSpawnCfgList.Contains(inSpawnPoint))
  71. {
  72. DecSpawnPointOver();
  73. }
  74. }
  75. void OnDrawGizmos()
  76. {
  77. Gizmos.color = GroupColor;
  78. Gizmos.DrawSphere(transform.position, 0.3f);
  79. drawPoints = FindChildrenPoints();
  80. if (drawPoints != null && drawPoints.Length > 0)
  81. {
  82. Gizmos.color = GroupColor;
  83. for (int i = 0; i < drawPoints.Length - 1; ++i)
  84. {
  85. var Start = drawPoints[0].gameObject.transform.position;
  86. var End = drawPoints[i + 1].gameObject.transform.position;
  87. var direction = (End - Start).normalized;
  88. var Length = Vector3.Distance(End, Start) - drawPoints[i + 1].radius - drawPoints[0].radius;
  89. Start = Start + direction * drawPoints[0].radius;
  90. End = Start + direction * Length;
  91. Gizmos.DrawLine(Start, End);
  92. drawPoints[i + 1].PointColor = GroupColor;
  93. }
  94. // draw start icon
  95. Gizmos.DrawIcon(
  96. new Vector3(drawPoints[0].transform.position.x,
  97. drawPoints[0].transform.position.y + drawPoints[0].radius * 3.0f,
  98. drawPoints[0].transform.position.z
  99. ),
  100. "StartPoint",
  101. true
  102. );
  103. }
  104. }
  105. }