using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class CarRightButtonPanelCtrl : MonoBehaviour { public Button Button_delete; public Button Button_detail; private CarIconInstanceCtrl clickedCar; // Start is called before the first frame update void Start() { EventCenter.Instance.AddEventListener("CarRightButtonEditor", ActiveThisPanel); Button_detail.onClick.AddListener(DetailButton); Button_delete.onClick.AddListener(DeleteButton); this.gameObject.SetActive(false); } void ActiveThisPanel(CarIconInstanceCtrl carInstanceCtrl) { clickedCar = carInstanceCtrl; this.gameObject.SetActive(true); this.transform.SetSiblingIndex(this.transform.parent.childCount - 1); float parentScale = this.transform.parent.localScale.x; this.transform.localScale = new Vector3(1.0f / parentScale, 1.0f / parentScale, 1); this.GetComponent().anchoredPosition = clickedCar.GetComponent().anchoredPosition + new Vector2(60, -30) / parentScale; } void DetailButton() { EventCenter.Instance.EventTrigger("CarDetailEditor", clickedCar); this.gameObject.SetActive(false); } void DeleteButton() { EventCenter.Instance.EventTrigger("SelectCarEditor", clickedCar, false); Destroy(clickedCar.gameObject); this.gameObject.SetActive(false); } private void Update() { float parentScale = this.transform.parent.localScale.x; this.transform.localScale = new Vector3(1.0f / parentScale, 1.0f / parentScale, 1); if (!clickedCar) this.gameObject.SetActive(false); this.GetComponent().anchoredPosition = clickedCar.GetComponent().anchoredPosition + new Vector2(60, -30)/ parentScale; } //父物体隐藏时会导致本物体被隐藏 private void OnDisable() { this.gameObject.SetActive(false); } }