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.
269 lines
9.5 KiB
269 lines
9.5 KiB
using UnityEngine; |
|
using AX.MessageSystem; |
|
using System; |
|
using UnityEngine.SceneManagement; |
|
using AX.TrackRecord; |
|
using System.Collections.Generic; |
|
/// <summary> |
|
/// 挂载在所有预制体上 |
|
/// </summary> |
|
public class CengID : MonoBehaviour { |
|
public int cengID = 0; |
|
public string NEI = "0"; |
|
public BuildType CengIDBuildType ; |
|
public string hitTag; |
|
void Awake() |
|
{ |
|
MessageDispatcher.AddListener("SELECTFLOOR_EVENT", SelectFloor); |
|
MessageDispatcher.AddListener("SetCengID", SetCengID); |
|
MessageDispatcher.AddListener("SetArrow", SetArrow); |
|
MessageDispatcher.AddListener("MoveUpFloor", MoveUpFloor); |
|
MessageDispatcher.AddListener("MoveDownFloor", MoveDownFloor); |
|
|
|
} |
|
void Start() |
|
{ |
|
if( (MySceneManager.GetActiveScene().name.Contains("2") && (gameObject.layer == 26 || gameObject.layer == 25)) || |
|
(!MySceneManager.GetActiveScene().name.Contains("2") && (gameObject.layer == 26)) && |
|
CengIDBuildType!= BuildType.None && !gameObject.name.Contains("XHS") && |
|
!gameObject.name.Contains("LT") && !gameObject.name.Contains("LouTi"))// |
|
{ |
|
CengIDManager.Instance.AddItemToDict(gameObject); |
|
} |
|
} |
|
private void SetCengID(IMessage message) |
|
{ |
|
if ((string)message.Sender == gameObject.name) |
|
{ |
|
var build = (BuildItem)message.Data; |
|
|
|
//给cengID赋值,几种方式 |
|
//1.点击的物体身上都有cengID属性,直接获取即可 |
|
//2.根据点击物体的名字,解析出cengID,然后赋值 |
|
|
|
//要求被点击的物体身上有CengID脚本,并赋值CengID(建筑类手动赋值) |
|
cengID = build.floor; |
|
CengIDBuildType = build.buildType; |
|
//string ShiNeiCengName = hitObj.transform.parent.gameObject.name; |
|
//string ShiNeiCengNumStr; |
|
//int ShiNeiCengNum = 0; |
|
//if (ShiNeiCengName.IndexOf("nei") >= 0) |
|
//{ |
|
// ShiNeiCengNumStr = ShiNeiCengName.Substring(3); |
|
// if (ShiNeiCengNumStr.IndexOf("-") >= 0) |
|
// { |
|
// string ShiNei = ShiNeiCengNumStr.Substring(1); |
|
// ShiNeiCengNum = -(int.Parse(ShiNei)); |
|
// obj.GetComponent<CengID>().cengID = ShiNeiCengNum; |
|
// } |
|
// else |
|
// { |
|
// ShiNeiCengNum = int.Parse(ShiNeiCengNumStr); |
|
// obj.GetComponent<CengID>().cengID = ShiNeiCengNum; |
|
// } |
|
//} |
|
//else if (ShiNeiCengName.IndexOf("pxiangfangyuan") >= 0) |
|
//{ |
|
// obj.GetComponent<CengID>().cengID = hit.transform.gameObject.GetComponent<CengID>().cengID; |
|
//} |
|
|
|
} |
|
} |
|
|
|
void OnDestroy() |
|
{ |
|
MessageDispatcher.RemoveListener("SELECTFLOOR_EVENT", SelectFloor); |
|
MessageDispatcher.RemoveListener("SetCengID", SetCengID); |
|
MessageDispatcher.RemoveListener("SetArrow", SetArrow); |
|
MessageDispatcher.RemoveListener("MoveUpFloor", MoveUpFloor); |
|
MessageDispatcher.RemoveListener("MoveDownFloor", MoveDownFloor); |
|
|
|
} |
|
|
|
private void SelectFloor(IMessage message) |
|
{ |
|
//if (!SceneManager.GetActiveScene().name.Equals("2")|| !SceneManager.GetActiveScene().name.Equals("3")) |
|
//{ |
|
// if (0 == cengID)//室外物体,不参与隐藏 //底下建筑除外 |
|
// return; |
|
//} |
|
//InputManager.Instance_.ClearSelectedCharacters(); |
|
if (CengIDBuildType == (BuildType)message.Sender) |
|
{ |
|
if (cengID <= (int)message.Data )//选中层及以下物体显示,以上物体隐藏 |
|
{ |
|
gameObject.SetActive(true); |
|
if (ExamInfoHelpClass.applicationMode == ExamInfoHelpClass.ApplicationMode.PATHFINDING |
|
&& gameObject.name.Contains("xiaofangyuan") && !gameObject.name.Contains("drawline")) |
|
{ |
|
gameObject.GetComponent<UnityEngine.AI.NavMeshAgent>().enabled = true; |
|
} |
|
//*********** 给超高层添加每层楼的楼层显示 (qyy)******** |
|
if (name.Contains("_Floor")) |
|
{ |
|
if (cengID == (int)message.Data) |
|
{ |
|
if (transform.parent.Find("info(Clone)")) return; |
|
//将需要的TextMesh实例化出来 |
|
GameObject textMesh = Instantiate(Resources.Load("Prefabs/info") as GameObject, transform.parent); |
|
textMesh.GetComponentInChildren<TextMesh>().text = NEI; |
|
if (cengID>37&&cengID<85) |
|
{ |
|
textMesh.transform.localEulerAngles = new Vector3(180,0,0); |
|
} |
|
} |
|
else { |
|
if (transform.parent.Find("info(Clone)")) |
|
{ |
|
Destroy(transform.parent.Find("info(Clone)").gameObject); |
|
} |
|
} |
|
} |
|
//****************************************** |
|
|
|
} |
|
else |
|
{ |
|
|
|
if (InputManager.Instance_.GetSelectedCharacters().Contains(gameObject)) |
|
{ |
|
gameObject.SetActive(true); |
|
return; |
|
} |
|
if (gameObject.layer != 25 && gameObject.layer != 29) |
|
{ |
|
gameObject.SetActive(false); |
|
//LineamentEvent.gameobj = null; |
|
//MessageDispatcher.SendMessage("SelectControl", (object)""); |
|
} |
|
if (MySceneManager.GetActiveScene().name.Equals("1"))//处理城市综合体-1层和-2层搂空问题 |
|
{ |
|
if (gameObject.name.Contains("XHSFSS")) |
|
{ |
|
gameObject.SetActive(true); |
|
} |
|
} |
|
|
|
} |
|
} |
|
} |
|
|
|
private List<int> lostCeng = new List<int>() { 0,4,13,14,24,34,44,54,64,74};//缺失楼层的链表 |
|
/// <summary> |
|
/// 设置上下夹攻的箭头 |
|
/// </summary> |
|
/// <param name="msg"></param> |
|
private void SetArrow(IMessage msg) |
|
{ |
|
if (gameObject.layer != 26) return; |
|
List<int> cengList = (List<int>)msg.Data; |
|
if (cengList == null) return; |
|
if (cengList.Count == 0) return; |
|
if (!cengList.Contains(cengID)) return; |
|
if (cengID == 0) return; |
|
if (!transform.parent.name.Contains("nei")) return; |
|
|
|
int cengNow =int.Parse(transform.parent.name.Split('i')[1]); |
|
int cengShang, cengXia; |
|
Transform transShang = null; |
|
Transform transXia = null; |
|
|
|
cengShang = cengNow + 1; |
|
cengXia = cengNow - 1; |
|
|
|
CheckXia(ref cengXia); |
|
CheckShang(ref cengShang); |
|
|
|
if (cengNow == 47)//47,48层分开处理,因为他们不在同一父物体下 |
|
{ |
|
transShang = transform.parent.parent.parent.GetChild(1).GetChild(0); |
|
} |
|
else if (cengNow == 48) |
|
{ |
|
transXia = transform.parent.parent.parent.GetChild(0).GetChild(transform.parent.parent.parent.GetChild(0).childCount-1); |
|
} |
|
|
|
for (int i = 0; i < transform.parent.parent.childCount; i++) |
|
{ |
|
Transform transChild = transform.parent.parent.GetChild(i); |
|
if (!transChild.name.Contains("nei")) |
|
{ |
|
continue; |
|
} |
|
|
|
if (transChild.name.Equals("nei"+cengShang.ToString())) |
|
{ |
|
transShang = transChild; |
|
} |
|
else if (transChild.name.Contains("nei" + cengXia.ToString())) |
|
{ |
|
transXia = transChild; |
|
} |
|
} |
|
|
|
|
|
if (transShang!=null) |
|
{ |
|
UPAndDownAttack.Instance.InsDowanArrow(transShang,transform.parent);//上层,实例化朝下箭头 |
|
} |
|
|
|
if (transXia!=null) |
|
{ |
|
UPAndDownAttack.Instance.InsUpArrow(transXia,transform.parent);//下层,实例化朝上箭头 |
|
} |
|
} |
|
|
|
bool posHasChange; |
|
Vector3 orignPos = Vector3.one; |
|
/// <summary> |
|
/// 点击上下合击,物体移动 |
|
/// </summary> |
|
/// <param name="msg"></param> |
|
private void MoveUpFloor(IMessage msg) |
|
{ |
|
if (!gameObject.activeInHierarchy) return; |
|
if (posHasChange) return; |
|
|
|
posHasChange = true; |
|
orignPos = transform.localPosition; |
|
if (transform.parent&&transform.parent.parent&&transform.parent.parent.name.Contains("AllParent")) |
|
{ |
|
if (cengID > (int)msg.Data) |
|
{ |
|
transform.localPosition = new Vector3(transform.localPosition.x, transform.localPosition.y + 20, transform.localPosition.z); |
|
} |
|
else if (cengID < (int)msg.Data) |
|
{ |
|
transform.localPosition = new Vector3(transform.localPosition.x, transform.localPosition.y - 20, transform.localPosition.z); |
|
} |
|
} |
|
} |
|
|
|
private void MoveDownFloor(IMessage msg) |
|
{ |
|
if (!gameObject.activeInHierarchy) return; |
|
if (!posHasChange) return; |
|
posHasChange = false; |
|
transform.localPosition = orignPos; |
|
} |
|
|
|
|
|
void CheckXia(ref int cengID) |
|
{ |
|
if (lostCeng.Contains(cengID)) |
|
{ |
|
cengID -= 1; |
|
CheckXia(ref cengID); |
|
} |
|
} |
|
|
|
void CheckShang(ref int cengID) |
|
{ |
|
if (lostCeng.Contains(cengID)) |
|
{ |
|
cengID += 1; |
|
CheckShang(ref cengID); |
|
} |
|
} |
|
|
|
}
|
|
|