using System.Collections; using System.Collections.Generic; using UnityEngine; using System.Linq; using UnityEngine.UI; using UnityEngine.Events; public class ShowPointEx : MonoBehaviour { public static ShowPointEx Instance; private void Awake() { Instance = this; } public GameObject objShowPointEx; public GameObject preBtnShowPoint; public Transform tranParent; //void Update() //{ // if (Input.GetKeyDown(KeyCode.F4)) // { // if (objShowPointEx.activeSelf) // HidePanel(); // else // ShowPanel(SceneLoader.currentIndex); // } //} public void BtnCloseClick() { HidePanel(); } void OnShowPointChanged() { if (ShowPointChanged != null) { ShowPointChanged(); } } public static event UnityAction ShowPointChanged; public void BtnShowPointClick(ShowPoint info) { SceneLoader.Instance.SetCameraPosition(info); HidePanel(); Invoke("OnShowPointChanged", 0.1f); } public void BtnExClick(int index) { ShowPanel(index); } List lstShowPoint; int currentShowIndex = -1; public string ShowPointFileName; int index; public void ShowPanel(int index) { this.index = index; if (lstShowPoint == null) { StartCoroutine(DataLoader.LoadDataList(ShowPointFileName, Show)); } else { Show(); } } void Show() { if (lstShowPoint == null) { lstShowPoint = DataLoader.DataList; } if (objShowPointEx.activeSelf && index == currentShowIndex) { return; } objShowPointEx.SetActive(true); BaseController.CanControl = false; if (currentShowIndex != index) { tranParent.GetComponent().anchoredPosition = Vector2.zero; // 移除旧的展示点列表 for (int i = 0; i < tranParent.childCount; i++) { Destroy(tranParent.GetChild(i).gameObject); } var result = lstShowPoint.Where(sp => sp.ZT_Index == index); GameObject tmpObj; Button tmpBtn; // 数据加载结束后,为所有数据根据数据类型添加控制点组件 foreach (var info in result) { tmpObj = Instantiate(preBtnShowPoint, tranParent); tmpObj.name = "SP_" + info.ObjectID; tmpObj.GetComponentInChildren().text = info.Title; tmpBtn = tmpObj.GetComponent