using AX.MessageSystem;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
///
/// 克隆游戏对象信息基类
///
public class CloneGameObjInfo : BaseGameObjInfo
{
public string buildNum;//楼号
public int floorNum;//层号
public int interlayerNum;//夹层号,0表示不是夹层,1表示第一个夹层
public int Layer;
///
/// 显示or隐藏
///
public bool ShoworHidden;
public virtual void Awake()
{
ShoworHidden = true;
Layer = gameObject.layer;
}
public virtual void Start()
{
if (gameObjType != CloneObjType.StaticGameObject)
{//室内地面、消火栓等显隐由父对象统一控制,在这不用注册事件
UpdateEnabled(GlobalVariable.CurrentFloor, this);
MessageDispatcher.AddListener("FloorNumChanged", setFloorEnabled);
MessageDispatcher.AddListener("OBJ_DODISSELECT", EscCancelSelected);
}
}
public virtual void OnDestroy()
{
if (gameObjType != CloneObjType.StaticGameObject)
{
MessageDispatcher.RemoveListener("FloorNumChanged", setFloorEnabled);
MessageDispatcher.RemoveListener("OBJ_DODISSELECT", EscCancelSelected);
}
}
public virtual string GetObjectName()
{
return CloneObjName.Instance.GetCloneNameByType(gameObjType);
}
private void setFloorEnabled(IMessage msg)
{
if (SelectedObjs.selectedObj == gameObject || SelectedObjs.selectedCharacters.Contains(gameObject))
return;
UpdateEnabled(GlobalVariable.CurrentFloor, this);
}
private void EscCancelSelected(IMessage obj)
{
if (GameObjID == (long)obj.Sender)
{
UpdateEnabled(GlobalVariable.CurrentFloor, this);
}
}
public void UpdateFloorEnabled(FloorData data)
{
UpdateEnabled(data, this);
}
private static void UpdateEnabled(FloorData data, CloneGameObjInfo obj)
{
if (string.IsNullOrEmpty(obj.buildNum))//室外物体不隐藏
return;
//if (obj.floorNum == 0)
//{
// //if (!data.isOn)
// //{
// // obj.ShoworHidden = true;
// //}
// //else
// //{
// // if (data.floorNum > obj.floorNum)
// // {
// obj.ShoworHidden = true;
// // }
// // else if (data.floorNum < obj.floorNum)
// // {
// // obj.ShoworHidden = false;
// // }
// //}
//}
if (data.buildNum == obj.buildNum)
{
if (!data.isOn)
{
obj.ShoworHidden = true;
}
else
{
if (data.floorNum > obj.floorNum)
{
obj.ShoworHidden = true;
}
else if (data.floorNum < obj.floorNum)
{
obj.ShoworHidden = false;
}
else
{
if (data.interlayerNum >= obj.interlayerNum)
{
obj.ShoworHidden = true;
}
else
{
obj.ShoworHidden = false;
}
}
}
}
TransformHelper.SetRenderer(obj.gameObject, obj.ShoworHidden);
//bool myactiveInHierarchy = obj.ShoworHidden ? true : false;//如果为隐藏层则隐藏名称 否则显示
//MessageDispatcher.SendMessage(obj.gameObject.name, "CONTROL_HIDE_SHOW_HEAD_NAME", myactiveInHierarchy);
}
}