| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- using UnityEngine;
- using System.Collections;
- using System.Security;
- public class SpawnCfgGroup : SpawnCfg
- {
- [HideInInspector]
- public int GroupId;
- [FriendlyName("需要触发器")]
- public bool bTriggerSpawn;
- private Color GroupColor = new Color(0.8f, 0.1f, 0.1f, 0.8f);
- private SpawnCfg[] drawPoints = null;
- private bool bSpawned = false;
- protected override void Start()
- {
- SpawnCfg next = nextPoint;
- #if UNITY_EDITOR
- int nTmp = 0;
- #endif
- while (next)
- {
- mSpawnCfgList.Add(next);
- next.onAllDeadEvt += this.onSpawnPointAllDead;
- next = next.nextPoint;
- #if UNITY_EDITOR
- if (++nTmp > 100)
- {
- DebugHelper.LogError("超过100个,tm死循环了吧!!");
- break;
- }
- #endif
- }
- base.Start();
- }
- public override void UpdateLogic(float delta)
- {
- if (!isStartup)
- {
- return;
- }
- }
- public override void Stop()
- {
- base.Stop();
- mSpawnedList.Clear();
- }
- protected override void DecSpawnPointOver()
- {
- base.DecSpawnPointOver();
- }
- public override void Startup()
- {
- if (!bTriggerSpawn && !isStartup)
- {
- base.Startup();
- }
- }
- public void TriggerStartUp()
- {
- if (!isStartup)
- {
- base.Startup();
- }
- }
- private SpawnCfg[] FindChildrenPoints()
- {
- return GetComponentsInChildren<SpawnCfg>(); // parent always the 1st
- }
- protected void onSpawnPointAllDead(SpawnCfg inSpawnPoint)
- {
- if (mSpawnCfgList.Contains(inSpawnPoint))
- {
- DecSpawnPointOver();
- }
- }
- void OnDrawGizmos()
- {
- Gizmos.color = GroupColor;
- Gizmos.DrawSphere(transform.position, 0.3f);
- drawPoints = FindChildrenPoints();
- if (drawPoints != null && drawPoints.Length > 0)
- {
- Gizmos.color = GroupColor;
- for (int i = 0; i < drawPoints.Length - 1; ++i)
- {
- var Start = drawPoints[0].gameObject.transform.position;
- var End = drawPoints[i + 1].gameObject.transform.position;
- var direction = (End - Start).normalized;
- var Length = Vector3.Distance(End, Start) - drawPoints[i + 1].radius - drawPoints[0].radius;
- Start = Start + direction * drawPoints[0].radius;
- End = Start + direction * Length;
- Gizmos.DrawLine(Start, End);
- drawPoints[i + 1].PointColor = GroupColor;
- }
- // draw start icon
- Gizmos.DrawIcon(
- new Vector3(drawPoints[0].transform.position.x,
- drawPoints[0].transform.position.y + drawPoints[0].radius * 3.0f,
- drawPoints[0].transform.position.z
- ),
- "StartPoint",
- true
- );
- }
- }
- }
|