You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
199 lines
6.6 KiB
199 lines
6.6 KiB
4 years ago
|
using System;
|
||
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using UnityEngine;
|
||
|
using AX.MessageSystem;
|
||
|
using UnityEngine.UI;
|
||
|
using System.Linq;
|
||
|
|
||
|
public struct FloorData
|
||
|
{
|
||
|
public string buildNum;//楼号
|
||
|
public int floorNum;//层号
|
||
|
public int interlayerNum;//夹层号,0表示不是夹层,1表示第一个夹层
|
||
|
public bool isOn;
|
||
|
}
|
||
|
public class UIFloor : BaseToggle
|
||
|
{
|
||
|
//楼层切换UI,发送楼层切换消息
|
||
|
public string buildNum;//楼号
|
||
|
public int floorNum;//层号
|
||
|
public int interlayerNum;//夹层号,0表示不是夹层,1表示第一个夹层
|
||
|
public List<Transform> MyChildFloors = new List<Transform>();//所含楼层
|
||
|
public FloorsPanelManager floorsPanelManager;
|
||
|
public Text MyText;
|
||
|
public GameObject HasChild;//显示该建筑(区域)下的所有楼层
|
||
|
public Transform MyTarget;
|
||
|
private CameraManager cameraManager;
|
||
|
private float FollowCameraDistance = 100f;
|
||
|
|
||
|
public override void RespondFun(bool isOn)
|
||
|
{
|
||
|
var group = GetComponent<Toggle>().group;
|
||
|
var anyIsOn = group.AnyTogglesOn();
|
||
|
var data = new FloorData { buildNum = buildNum, floorNum = floorNum, interlayerNum = interlayerNum, isOn = isOn };
|
||
|
if ((anyIsOn && isOn) || !anyIsOn)
|
||
|
{
|
||
|
GlobalVariable.CurrentFloor = data;
|
||
|
MessageDispatcher.SendMessage("FloorNumChanged", data);
|
||
|
}
|
||
|
if (isOn)
|
||
|
{
|
||
|
if (MyChildFloors.Count > 0)
|
||
|
{
|
||
|
// Camera.main.GetComponent<CameraManager>().SetCameraWhileSetFloor(MyTarget.position);
|
||
|
foreach (var item in MyChildFloors)
|
||
|
{
|
||
|
item.gameObject.SetActive(true);
|
||
|
}
|
||
|
}
|
||
|
ShowFloor(data);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
if (MyChildFloors.Count > 0)
|
||
|
{
|
||
|
foreach (var item in MyChildFloors)
|
||
|
{
|
||
|
if (item.GetComponent<Toggle>().isOn)
|
||
|
{
|
||
|
item.GetComponent<Toggle>().isOn = false;
|
||
|
}
|
||
|
item.gameObject.SetActive(false);
|
||
|
}
|
||
|
}
|
||
|
HideFloor();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private void HideFloor()
|
||
|
{
|
||
|
foreach (var item in floorsPanelManager.AllNei)
|
||
|
{
|
||
|
item.gameObject.SetActive(true);
|
||
|
}
|
||
|
foreach (var item in floorsPanelManager.AllWai)
|
||
|
{
|
||
|
item.gameObject.SetActive(true);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private void ShowFloor(FloorData data)
|
||
|
{
|
||
|
if (Mathf.Abs(data.floorNum) > 0)
|
||
|
{
|
||
|
foreach (var item in floorsPanelManager.AllWai)
|
||
|
{
|
||
|
if (item.buildNum == data.buildNum && item.floorNum > data.floorNum && Mathf.Abs(item.floorNum) > 0)
|
||
|
{
|
||
|
item.gameObject.SetActive(false);
|
||
|
}
|
||
|
if (item.buildNum == data.buildNum && item.floorNum == data.floorNum && item.interlayerNum > data.interlayerNum && Mathf.Abs(item.floorNum) > 0)
|
||
|
{
|
||
|
item.gameObject.SetActive(false);
|
||
|
}
|
||
|
}
|
||
|
foreach (var item in floorsPanelManager.AllNei)
|
||
|
{
|
||
|
if (item.buildNum == data.buildNum && item.floorNum > data.floorNum && Mathf.Abs(item.floorNum) > 0)
|
||
|
{
|
||
|
item.gameObject.SetActive(false);
|
||
|
}
|
||
|
if (item.buildNum == data.buildNum && item.floorNum == data.floorNum && item.interlayerNum > data.interlayerNum && Mathf.Abs(item.floorNum) > 0)
|
||
|
{
|
||
|
item.gameObject.SetActive(false);
|
||
|
}
|
||
|
|
||
|
}
|
||
|
}
|
||
|
if (MyTarget != null && floorNum == 0)//镜头拉近
|
||
|
{
|
||
|
cameraManager.CameraFollowTarget(MyTarget.position, FollowCameraDistance);
|
||
|
}
|
||
|
if (ReplaySetting.PlayStatus == PlayStatus.isEditor && RecordManager.Instance.recordStatus == RecordStatus.normal)
|
||
|
{
|
||
|
AddRecordUIFloor(data);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private void AddRecordUIFloor(FloorData data)
|
||
|
{
|
||
|
var eventData = new EventData();
|
||
|
eventData.time = RecordManager.Instance.RecordTimer;
|
||
|
eventData.cloneObjType = CloneObjType.None;
|
||
|
eventData.eventType = RecordEventType.UIFloor;
|
||
|
eventData.json = JsonUtility.ToJson(data);
|
||
|
|
||
|
RecordManager.Instance.jsonData.eventDataList.Add(eventData);
|
||
|
}
|
||
|
|
||
|
void Start()
|
||
|
{
|
||
|
MessageDispatcher.AddListener("ToChangeFloor", changeFloor);
|
||
|
//MessageDispatcher.AddListener("ReplayFrame", ReplayFrameUIFloor);
|
||
|
//MessageDispatcher.AddListener("ReplayEvent", ReplayUIFloor);
|
||
|
cameraManager = Camera.main.GetComponent<CameraManager>();
|
||
|
}
|
||
|
|
||
|
private void ReplayUIFloor(IMessage obj)
|
||
|
{
|
||
|
var eventData = (EventData)obj.Data;
|
||
|
if (eventData.eventType == RecordEventType.UIFloor)
|
||
|
{
|
||
|
FloorData data = JsonUtility.FromJson<FloorData>(eventData.json);
|
||
|
Setting(data);
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
private void Setting(FloorData data)
|
||
|
{
|
||
|
foreach (Transform item in floorsPanelManager.FloorBtnsParentPanel)
|
||
|
{
|
||
|
if (item.gameObject.activeSelf && item.GetComponent<Toggle>().isOn)
|
||
|
item.GetComponent<Toggle>().isOn = false;
|
||
|
}
|
||
|
if (data.buildNum == buildNum && data.floorNum == floorNum && data.interlayerNum == interlayerNum)
|
||
|
{
|
||
|
if (data.isOn)
|
||
|
{
|
||
|
if (Mathf.Abs(data.floorNum) > 0)
|
||
|
{
|
||
|
GetComponentInParent<Toggle>().isOn = true;
|
||
|
GetComponent<Toggle>().isOn = true;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
GetComponent<Toggle>().isOn = true;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private void ReplayFrameUIFloor(IMessage obj)
|
||
|
{
|
||
|
var objectData = (ObjectData)obj.Data;
|
||
|
if (objectData.cloneObjType == CloneObjType.UIFloor)
|
||
|
{
|
||
|
FloorData data = JsonUtility.FromJson<FloorData>(objectData.json);
|
||
|
Setting(data);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public override void OnDestroy()
|
||
|
{
|
||
|
base.OnDestroy();
|
||
|
MessageDispatcher.RemoveListener("ToChangeFloor", changeFloor);
|
||
|
//MessageDispatcher.RemoveListener("ReplayFrame", ReplayFrameUIFloor);
|
||
|
//MessageDispatcher.RemoveListener("ReplayEvent", ReplayUIFloor);
|
||
|
}
|
||
|
private void changeFloor(IMessage msg)
|
||
|
{
|
||
|
var data = (FloorData)msg.Data;
|
||
|
if (data.buildNum == buildNum && data.floorNum == floorNum && data.interlayerNum == interlayerNum)
|
||
|
{
|
||
|
GetComponent<Toggle>().isOn = true;
|
||
|
}
|
||
|
}
|
||
|
}
|