InvokeInterval.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class InvokeInterval : BaseBehaviour
  5. {
  6. private void GetEffectSettingsComponent(Transform tr)
  7. {
  8. Transform parent = tr.parent;
  9. if (parent != null)
  10. {
  11. this.effectSettings = parent.GetComponentInChildren<EffectSettings>();
  12. if (this.effectSettings == null)
  13. {
  14. this.GetEffectSettingsComponent(parent.transform);
  15. }
  16. }
  17. }
  18. private void Start()
  19. {
  20. this.GetEffectSettingsComponent(base.transform);
  21. this.goInstances = new List<GameObject>();
  22. this.count = (int)(this.Duration / this.Interval);
  23. for (int i = 0; i < this.count; i++)
  24. {
  25. GameObject gameObject = UnityEngine.Object.Instantiate<GameObject>(this.GO, base.transform.position, default(Quaternion));
  26. gameObject.transform.parent = base.transform;
  27. EffectSettings component = gameObject.GetComponent<EffectSettings>();
  28. component.Target = this.effectSettings.Target;
  29. component.IsHomingMove = this.effectSettings.IsHomingMove;
  30. component.MoveDistance = this.effectSettings.MoveDistance;
  31. component.MoveSpeed = this.effectSettings.MoveSpeed;
  32. component.CollisionEnter += delegate(object n, CollisionInfo e)
  33. {
  34. this.effectSettings.OnCollisionHandler(e);
  35. };
  36. component.ColliderRadius = this.effectSettings.ColliderRadius;
  37. component.EffectRadius = this.effectSettings.EffectRadius;
  38. component.EffectDeactivated += this.effectSettings_EffectDeactivated;
  39. this.goInstances.Add(gameObject);
  40. gameObject.SetActive(false);
  41. }
  42. this.InvokeAll();
  43. this.isInitialized = true;
  44. }
  45. private void InvokeAll()
  46. {
  47. for (int i = 0; i < this.count; i++)
  48. {
  49. base.Invoke("InvokeInstance", (float)i * this.Interval);
  50. }
  51. }
  52. private void InvokeInstance()
  53. {
  54. this.goInstances[this.goIndexActivate].SetActive(true);
  55. this.goInstances[this.goIndexActivate].GetComponentInChildren<EnemyBulletLaucher>().attacker = this.attacker;
  56. if (this.goIndexActivate >= this.goInstances.Count - 1)
  57. {
  58. this.goIndexActivate = 0;
  59. }
  60. else
  61. {
  62. this.goIndexActivate++;
  63. }
  64. }
  65. private void effectSettings_EffectDeactivated(object sender, EventArgs e)
  66. {
  67. EffectSettings effectSettings = sender as EffectSettings;
  68. effectSettings.transform.position = base.transform.position;
  69. if (this.goIndexDeactivate >= this.count - 1)
  70. {
  71. this.effectSettings.Deactivate();
  72. this.goIndexDeactivate = 0;
  73. }
  74. else
  75. {
  76. this.goIndexDeactivate++;
  77. }
  78. }
  79. private void OnEnable()
  80. {
  81. if (this.isInitialized)
  82. {
  83. this.InvokeAll();
  84. }
  85. }
  86. private void OnDisable()
  87. {
  88. }
  89. public GameObject GO;
  90. public float Interval = 0.3f;
  91. public float Duration = 3f;
  92. private List<GameObject> goInstances;
  93. private EffectSettings effectSettings;
  94. private int goIndexActivate;
  95. private int goIndexDeactivate;
  96. private bool isInitialized;
  97. private int count;
  98. public Transform attacker;
  99. }