147 lines
3.5 KiB
C#
147 lines
3.5 KiB
C#
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<ShowPoint> lstShowPoint;
|
||
|
||
int currentShowIndex = -1;
|
||
|
||
public string ShowPointFileName;
|
||
|
||
int index;
|
||
public void ShowPanel(int index)
|
||
{
|
||
this.index = index;
|
||
if (lstShowPoint == null)
|
||
{
|
||
StartCoroutine(DataLoader<ShowPoint>.LoadDataList(ShowPointFileName, Show));
|
||
}
|
||
else
|
||
{
|
||
Show();
|
||
}
|
||
}
|
||
|
||
void Show()
|
||
{
|
||
if (lstShowPoint == null)
|
||
{
|
||
lstShowPoint = DataLoader<ShowPoint>.DataList;
|
||
}
|
||
|
||
if (objShowPointEx.activeSelf && index == currentShowIndex)
|
||
{
|
||
return;
|
||
}
|
||
|
||
objShowPointEx.SetActive(true);
|
||
BaseController.CanControl = false;
|
||
|
||
if (currentShowIndex != index)
|
||
{
|
||
tranParent.GetComponent<RectTransform>().anchoredPosition = Vector2.zero;
|
||
|
||
// <20>Ƴ<EFBFBD><C6B3>ɵ<EFBFBD>չʾ<D5B9><CABE><EFBFBD>б<EFBFBD>
|
||
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;
|
||
// <20><><EFBFBD>ݼ<EFBFBD><DDBC>ؽ<EFBFBD><D8BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݸ<EFBFBD><DDB8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӿ<EFBFBD><D3BF>Ƶ<EFBFBD><C6B5><EFBFBD><EFBFBD><EFBFBD>
|
||
foreach (var info in result)
|
||
{
|
||
tmpObj = Instantiate(preBtnShowPoint, tranParent);
|
||
tmpObj.name = "SP_" + info.ObjectID;
|
||
tmpObj.GetComponentInChildren<Text>().text = info.Title;
|
||
tmpBtn = tmpObj.GetComponent<Button>();
|
||
tmpBtn.onClick.AddListener(
|
||
delegate ()
|
||
{
|
||
BtnShowPointClick(info);
|
||
}
|
||
);
|
||
tmpBtn.transform.gameObject.AddComponent<ShowPointInfo>();
|
||
}
|
||
|
||
for (int i = 0; i < 6; i++)
|
||
{
|
||
GameObject obj = GameObject.Find("Button" + i);
|
||
Image img = obj.GetComponent<Image>();
|
||
if (i == index)
|
||
img.color = Color.white;
|
||
else
|
||
img.color = new Color(1f, 1f, 1f, 0.2f);
|
||
}
|
||
}
|
||
|
||
currentShowIndex = index;
|
||
}
|
||
|
||
public void HidePanel()
|
||
{
|
||
objShowPointEx.SetActive(false);
|
||
BtnController.Instance.SetCanControlDelay();
|
||
// BaseController.CanControl = true;
|
||
}
|
||
}
|