|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
using UnityEngine.EventSystems;
|
|
|
|
using AX.MessageSystem;
|
|
|
|
using System;
|
|
|
|
|
|
|
|
public class DeviceObj : MonoBehaviour
|
|
|
|
{
|
|
|
|
public DeviceList BindData;
|
|
|
|
public DeviceType BindType;
|
|
|
|
|
|
|
|
public GameObject tParent;
|
|
|
|
public GameObject tIcon;
|
|
|
|
public GameObject tIconObj;
|
|
|
|
public bool isShow = false;
|
|
|
|
public int floorId = 0;
|
|
|
|
void Start()
|
|
|
|
{
|
|
|
|
MessageDispatcher.AddListener("DeviceMenuChanged", DeviceMenuChanged);
|
|
|
|
MessageDispatcher.AddListener("FloorChanged", FloorChanged);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void FloorChanged(IMessage obj)
|
|
|
|
{
|
|
|
|
if (DevicePanelManager.Instance.MenuType == BindType)
|
|
|
|
{
|
|
|
|
int number = (int)obj.Data;
|
|
|
|
isShow = number == floorId ? true : false;
|
|
|
|
if (tIconObj)
|
|
|
|
tIconObj.gameObject.SetActive(isShow);
|
|
|
|
gameObject.GetComponent<MeshRenderer>().enabled = isShow;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void DeviceMenuChanged(IMessage obj)
|
|
|
|
{
|
|
|
|
KeyValuePair<DeviceType, bool> data = (KeyValuePair<DeviceType, bool>)obj.Data;
|
|
|
|
if (data.Key == BindType)
|
|
|
|
{
|
|
|
|
isShow = data.Value;
|
|
|
|
if (tIconObj)
|
|
|
|
tIconObj.gameObject.SetActive(isShow);
|
|
|
|
gameObject.GetComponent<MeshRenderer>().enabled = isShow;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
isShow = false;
|
|
|
|
if (tIconObj)
|
|
|
|
tIconObj.gameObject.SetActive(isShow);
|
|
|
|
gameObject.GetComponent<MeshRenderer>().enabled = isShow;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private void OnDestroy()
|
|
|
|
{
|
|
|
|
MessageDispatcher.RemoveListener("DeviceMenuChanged", DeviceMenuChanged);
|
|
|
|
MessageDispatcher.RemoveListener("FloorChanged", FloorChanged);
|
|
|
|
}
|
|
|
|
private void Update()
|
|
|
|
{
|
|
|
|
if (Input.GetKeyDown(KeyCode.Delete))
|
|
|
|
{
|
|
|
|
if (DevicePanelManager.Instance.NowClickObject == this)
|
|
|
|
{
|
|
|
|
DeviceObjManager.Instance.DelObj(name);
|
|
|
|
if (tIconObj)
|
|
|
|
{
|
|
|
|
Destroy(tIconObj);
|
|
|
|
}
|
|
|
|
Destroy(gameObject);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (GetComponent<DeviceLumos>())
|
|
|
|
{
|
|
|
|
if (DevicePanelManager.Instance.NowClickObject != this)
|
|
|
|
{
|
|
|
|
Destroy(GetComponent<DeviceLumos>());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//if (BindType == DevicePanelManager.Instance.MenuType)
|
|
|
|
//{
|
|
|
|
// if (!isShow)
|
|
|
|
// isShow = true;
|
|
|
|
//}
|
|
|
|
//else
|
|
|
|
//{
|
|
|
|
// if (isShow)
|
|
|
|
// isShow = false;
|
|
|
|
//}
|
|
|
|
}
|
|
|
|
private void OnMouseDown()
|
|
|
|
{
|
|
|
|
if (EventSystem.current.IsPointerOverGameObject())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
DevicePanelManager.Instance.ShowBindList(BindType, this);
|
|
|
|
}
|
|
|
|
public void ShowList()
|
|
|
|
{
|
|
|
|
if (tIconObj)
|
|
|
|
{
|
|
|
|
tIconObj.GetComponent<DeviceFollowTarget>().ViewClick();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public void CreateIcon(DeviceType type, int floorId)
|
|
|
|
{
|
|
|
|
BindType = type;
|
|
|
|
this.floorId = floorId;
|
|
|
|
if (tIconObj == null)
|
|
|
|
{
|
|
|
|
var topIconsP = GameObject.Find("Canvas").transform.Find("DeviceIconPanel");
|
|
|
|
if (!topIconsP)
|
|
|
|
{
|
|
|
|
topIconsP = Instantiate(tParent, GameObject.Find("Canvas").transform).transform;
|
|
|
|
topIconsP.name = "DeviceIconPanel";
|
|
|
|
}
|
|
|
|
topIconsP.transform.SetAsFirstSibling();
|
|
|
|
tIconObj = Instantiate(tIcon, topIconsP.transform);
|
|
|
|
tIconObj.name = name;
|
|
|
|
tIconObj.GetComponent<DeviceFollowTarget>().SetTarget(this);
|
|
|
|
}
|
|
|
|
if (DevicePanelManager.Instance.NowType == BindType)
|
|
|
|
{
|
|
|
|
isShow = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
isShow = false;
|
|
|
|
}
|
|
|
|
tIconObj.gameObject.SetActive(isShow);
|
|
|
|
gameObject.GetComponent<MeshRenderer>().enabled = isShow;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|