using AX.MessageSystem; using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class NAVSelectCarItem : MonoBehaviour { public Toggle Toggle; public Text Text; public Button Button; public GameObject SelectCar; public static List SelectCarItem = new List(); // Use this for initialization void Start() { SelectCarItem.Add(this); Toggle.onValueChanged.AddListener(Change); Button.onClick.AddListener(Delete); MessageDispatcher.AddListener("RemoveSelectCar", RemoveSelectCar); MessageDispatcher.AddListener("DeleteObj", DeleteObj); } private void DeleteObj(IMessage message) { var obj = message.Data as GameObject; if (SelectCar == obj) { Delete(); } } private void RemoveSelectCar(IMessage message) { var obj = message.Data as GameObject; if (SelectCar == obj) { Toggle.isOn = false; } } private void Delete() { MultiSelectNAV.GetInstance.RemoveSelectCar(SelectCar); SelectCarItem.Remove(this); Destroy(gameObject); } private void Change(bool arg0) { if (arg0) MultiSelectNAV.GetInstance.AddSelectCar(SelectCar); else MultiSelectNAV.GetInstance.RemoveSelectCar(SelectCar); } private void OnDisable() { MessageDispatcher.RemoveListener("RemoveSelectCar", RemoveSelectCar); MessageDispatcher.RemoveListener("DeleteObj", DeleteObj); SelectCarItem.Remove(this); Destroy(gameObject); } }