FaultChoicesSceneCtrl.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using GameFramework.Event;
  6. public class FaultChoicesSceneCtrl : MonoBehaviour
  7. {
  8. public int ObjCount = 8;
  9. private GameObject[] _Objects;
  10. private void Awake()
  11. {
  12. _Objects = new GameObject[ObjCount];
  13. for (int i = 0; i < ObjCount; i++)
  14. {
  15. _Objects[i] = this.transform.GetChild(i).gameObject;
  16. _Objects[i].SetActive(false);
  17. }
  18. }
  19. void Start()
  20. {
  21. GameMain.Event.Subscribe(FaultChoicesChangeEvent.EventId, OnFaultChoicesChange);
  22. }
  23. private void OnDestroy()
  24. {
  25. if (GameMain.Event.Check(FaultChoicesChangeEvent.EventId, OnFaultChoicesChange))
  26. {
  27. GameMain.Event.Unsubscribe(FaultChoicesChangeEvent.EventId, OnFaultChoicesChange);
  28. }
  29. }
  30. private void OnFaultChoicesChange(object sender, GameEventArgs e)
  31. {
  32. FaultChoicesChangeEvent args = (FaultChoicesChangeEvent)e;
  33. foreach (var obj in _Objects)
  34. {
  35. obj.SetActive(false);
  36. }
  37. if (args.changeIndex == -1)
  38. {
  39. return;
  40. }
  41. _Objects[args.changeIndex].SetActive(true);
  42. }
  43. }