天津23维预案
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.
 
 
 
 
 
 

293 lines
12 KiB

using UnityEngine;
using System.Collections;
using System;
using UnityEngine.EventSystems;
using UnityEngine.UI;
using AX.MessageSystem;
/// <summary>
/// 1、鼠标通过射线点击对应的UI,实现实例化灾情物体
/// 2、挂载在Canvas下DomeView下DisasterButtonPicture;
/// 3、核心方法:GetObj();
/// </summary>
public class InstantiationDisaster : MonoBehaviour
{
public static InstantiationDisaster Instance;
public LayerMask m_layerMask = -1;
private LayerMask ground_layerMask = -1;
public LayerMask yg_layerMask = -1;
public LayerMask fire_layerMask = -1;
[HideInInspector]
public Vector3 Pos1_late = new Vector3(0, 0, 0);//第一碰撞点原来的位置
[HideInInspector]
public Vector3 Pos2_late = new Vector3(0, 0, 0);//第二碰撞点原来的位置
private GameObject XieLou;
private RaycastHit hit;
private GameObject DisasterGrid;
private LayerMask indoor_layerMask = -1;//室内层
DateTime t1, t2;
[HideInInspector]
public string DisasterName;
void Awake()
{
if (Instance == null)
{
Instance = this;
}
MessageDispatcher.AddListener("ResettingButton", ResettingButton);
MessageDispatcher.AddListener("InstantiateButton", GetObj);
if (ExamInfoHelpClass.applicationMode == ExamInfoHelpClass.ApplicationMode.SANDTABLE)
{
this.transform.Find("ScrollRect/DisasterGrid/PoChaiDian").gameObject.SetActive(false);
}
#region 查找灾情按钮对象
//XieLou = GameObject.Find("DomeView/BroweMenu/DisasterButtonPicture/ScrollRect/DisasterGrid").transform.FindChild("Fluvio").gameObject;
DisasterGrid = GameObject.Find("DomeView/BroweMenu/DisasterButtonPicture/ScrollRect").transform.Find("DisasterGrid").gameObject;
indoor_layerMask = 1 << 29 | 1 << 25 | 1 << 26;
ground_layerMask = 1 << 25 | 1 << 26;
#endregion
HideOilParticle();
}
void OnDestroy()
{
MessageDispatcher.RemoveListener("ResettingButton", ResettingButton);
MessageDispatcher.RemoveListener("InstantiateButton", GetObj);
Wounded.wounded1Index = 0;
PCD.pcdIndex = 0;
Wounded.wounded1Index = 0;
Fire.fireIndex = 0;
DangerGoods.wxpIndex = 0;
ZWD.zwdIndex = 0;
InsiDe.insiderIndex = 0;
YGXL.ygxlIndex = 0;
}
//重置方法
public void ResettingButton(IMessage message)
{
foreach (Transform child in DisasterGrid.transform)
{
if (child.gameObject.GetComponent<Button>().interactable == true)
{
child.Find("Image").gameObject.SetActive(false);
}
}
DisasterName = "";
}
void Update()
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit, Mathf.Infinity, indoor_layerMask))
{
if (hit.collider.name.Equals("VoidWall"))
{
return;
}
}
if (Physics.Raycast(ray, out hit, Mathf.Infinity, LayerMask.GetMask("shineiFloor")) && Input.GetMouseButtonDown(0) && !EventSystem.current.IsPointerOverGameObject())
{//实例化烟雾
//if (DisasterName == null)
// return;
if (DisasterName.Equals("Smog"))
{
Smog smog = new Smog(Resources.Load<GameObject>("Prefabs/ZQPrefab/Smog"), GameObject.Find("psmog"), DisasterGrid, Smog.SmogIndex, hit, 0.7f);
smog.InstatiateItem("中队名" + "-" + "smog" + "-" + "smog" + "-");
}
//室内烟1(qyy)
if (DisasterName.Equals("Shineiyan1"))
{
ShiNeiYan1 shineiyan1 = new ShiNeiYan1(Resources.Load<GameObject>("Prefabs/ZQPrefab/ny1"), GameObject.Find("pShineiyan1"), DisasterGrid, ShiNeiYan1.ShiNeiYan1Index, hit, 0.7f);
shineiyan1.InstatiateItem("中队名" + "-" + "Shineiyan1" + "-" + "ny1" + "-");
}
//室内烟2(qyy)
if (DisasterName.Equals("Shineiyan2"))
{
ShiNeiYan2 shineiyan2 = new ShiNeiYan2(Resources.Load<GameObject>("Prefabs/ZQPrefab/ny2"), GameObject.Find("pShineiyan2"), DisasterGrid, ShiNeiYan2.ShiNeiYan2Index, hit, 0.7f);
shineiyan2.InstatiateItem("中队名" + "-" + "Shineiyan2" + "-" + "ny2" + "-");
}
//室内火(qyy)
if (DisasterName.Equals("Shineihuo"))
{
Shineihuo shineihuo = new Shineihuo(Resources.Load<GameObject>("Prefabs/ZQPrefab/snh"), GameObject.Find("pShineihuo"), DisasterGrid, Shineihuo.ShineihuoIndex, hit, 0.7f);
shineihuo.InstatiateItem("中队名" + "-" + "Shineihuo" + "-" + "snh" + "-");
}
}
if (Physics.Raycast(ray, out hit, Mathf.Infinity, m_layerMask) && Input.GetMouseButtonDown(0) && !EventSystem.current.IsPointerOverGameObject())
{
if (InstantiationCar.Instance.isCarSelect)
{
return;
}
if (DisasterName == null)
return;
//伤员
if (DisasterName.Equals("ShangYuan2"))
{
Wounded wounded = new Wounded(Resources.Load<GameObject>("Prefabs/ZQPrefab/sy1"), GameObject.Find("pshangyuan1"), DisasterGrid, Wounded.wounded1Index, hit, 0.1f);
wounded.InstatiateItem("中队名" + "-" + "shangyuan1" + "-" + "sy1" + "-");
}
//破拆点
else if (DisasterName.Equals("PoChaiDian"))
{
PCD wounded = new PCD(Resources.Load<GameObject>("Prefabs/ZQPrefab/pcd"), GameObject.Find("ppochaidian"), DisasterGrid, PCD.pcdIndex, hit, 1.1f);
wounded.InstatiateItem("中队名" + "-" + "pochaidian" + "-" + "pcd" + "-");
}
//伤员倒
else if (DisasterName.Equals("ShangYuan"))
{
Wounded wounded = new Wounded(Resources.Load<GameObject>("Prefabs/ZQPrefab/sy2"), GameObject.Find("pshangyuan2"), DisasterGrid, Wounded.wounded1Index, hit, 1f);
wounded.InstatiateItem("中队名" + "-" + "shangyuan2" + "-" + "sy2" + "-");
}
//火
//else if (DisasterName.Equals("Huo"))
//{
// Fire fire = new Fire(Resources.Load<GameObject>("Prefabs/ZQPrefab/fire"), GameObject.Find("pfire"), DisasterGrid, Fire.fireIndex, hit, 0.7f);
// fire.InstatiateItem("中队名" + "-" + "fire" + "-" + "fire" + "-");
//}
//危险品
else if (DisasterName.Equals("WeiXianPin"))
{
DangerGoods wxp = new DangerGoods(Resources.Load<GameObject>("Prefabs/ZQPrefab/wxp"), GameObject.Find("pweixianpin"), DisasterGrid, DangerGoods.wxpIndex, hit, 1.1f);
wxp.InstatiateItem("中队名" + "-" + "weixianpin" + "-" + "wxp" + "-");
}
//杂物堆
else if (DisasterName.Equals("ZaWuDui"))
{
ZWD zwd = new ZWD(Resources.Load<GameObject>("Prefabs/ZQPrefab/zwd"), GameObject.Find("pzawudui"), DisasterGrid, ZWD.zwdIndex, hit, 0.5f);
zwd.InstatiateItem("中队名" + "-" + "zawudui" + "-" + "zwd" + "-");
}
}
//单独写火层
if (Physics.Raycast(ray, out hit, Mathf.Infinity, fire_layerMask) && Input.GetMouseButtonDown(0) && !EventSystem.current.IsPointerOverGameObject())
{
if (InstantiationCar.Instance.isCarSelect)
{
return;
}
if (DisasterName == null)
return;
if (DisasterName.Equals("Huo"))
{
Fire fire = new Fire(Resources.Load<GameObject>("Prefabs/ZQPrefab/fire"), GameObject.Find("pfire"), DisasterGrid, Fire.fireIndex, hit, 0.7f);
fire.InstatiateItem("中队名" + "-" + "fire" + "-" + "fire" + "-");
}
}
if (Input.GetMouseButtonDown(0) && Physics.Raycast(ray, out hit, Mathf.Infinity, ground_layerMask) && Input.GetMouseButtonDown(0) && !EventSystem.current.IsPointerOverGameObject())
{
if (hit.collider.gameObject.layer == 26)
return;
//知情人
if (DisasterName.Equals("ZhiQingRen"))
{
InsiDe.insiderIndex = 0;
if (!GameObject.Find("中队名" + "-" + "zhiqingren" + "-" + "zqr" + "-0"))
{
GameObject obj = GameObject.Find("pzhiqingren");
foreach (Transform child in obj.transform)
{
if (child.name.Contains("zqr"))
{
MessageDispatcher.SendMessage("Operatinghints", (object)"知情人已经存在");
return;
}
}
InsiDe inside = new InsiDe(Resources.Load<GameObject>("Prefabs/ZQPrefab/zqr"), GameObject.Find("pzhiqingren"), DisasterGrid, InsiDe.insiderIndex, hit, 1f);
inside.InstatiateItem("中队名" + "-" + "zhiqingren" + "-" + "zqr" + "-");
}
else
{
MessageDispatcher.SendMessage("Operatinghints", (object)"知情人已经存在");
}
}
}
//if (MySceneManager.GetActiveScene().name.Equals("5"))
//{
// XieLou.SetActive(true);
//}
//else
//{
// XieLou.SetActive(false);
//}
if (Input.GetMouseButtonDown(0) && Physics.Raycast(ray, out hit, Mathf.Infinity, yg_layerMask) && Input.GetMouseButtonDown(0) && !EventSystem.current.IsPointerOverGameObject())
{
//泄漏
if (DisasterName.Equals("Fluvio"))
{
YGXL ygxl = new YGXL(Resources.Load<GameObject>("Prefabs/ZQPrefab/Fluvio"), GameObject.Find("pFluvio"), DisasterGrid, YGXL.ygxlIndex, hit, 0.5f);
ygxl.InstatiateItem("中队名" + "-" + "Fluvio" + "-" + "Fluvio" + "-");
}
else if (DisasterName.Equals("splash"))
{
Splash splash = new Splash(Resources.Load<GameObject>("Prefabs/ZQPrefab/Splash"), GameObject.Find("psplash"), DisasterGrid, Splash.SplashIndex, hit, 0.7f);
splash.InstatiateItem("中队名" + "-" + "splash" + "-" + "splash" + "-");
}
else if (DisasterName.Equals("guanTiFire"))
{
GuanTiFire fire = new GuanTiFire(Resources.Load<GameObject>("Prefabs/ZQPrefab/GuanTiFire"), GameObject.Find("pguanTiFire"), DisasterGrid, GuanTiFire.GuanTiFireIndex, hit, 0.7f);
fire.InstatiateItem("中队名" + "-" + "guanTiFire" + "-" + "guanTiFire" + "-");
}
}
if (Physics.Raycast(ray, out hit, Mathf.Infinity,LayerMask.GetMask("dimian")) && Input.GetMouseButtonDown(0) && !EventSystem.current.IsPointerOverGameObject())
{
if (DisasterName == null)
return;
if (DisasterName.Equals("diMianFire"))
{
DiMianFire fire = new DiMianFire(Resources.Load<GameObject>("Prefabs/ZQPrefab/DiMianFire"), GameObject.Find("pdiMianFire"), DisasterGrid, DiMianFire.DiMianFireIndex, hit, 0.7f);
fire.InstatiateItem("中队名" + "-" + "diMianFire" + "-" + "diMianFire" + "-");
Debug.Log("DiMianFire");
}
}
}
public void GetObj(IMessage message)
{
if (gameObject.name.Contains(message.Sender.ToString()))
{
MessageDispatcher.SendMessage("ResettingButton");
var obj = (GameObject)message.Data;
obj.transform.Find("Image").gameObject.SetActive(true);
DisasterName = obj.name;
}
}
/// <summary>
/// 只有在石油场景才显示油罐泄露的四种灾情
/// </summary>
void HideOilParticle()
{
if (MySceneManager.GetActiveScene().name!="5")
{
BaseTool[] childArray = transform.GetComponentsInChildren<BaseTool>();
foreach (BaseTool baseTool in childArray)
{
if (baseTool.name.Contains("splash") || baseTool.name.Contains("guanTiFire") || baseTool.name.Contains("diMianFire"))
{
baseTool.gameObject.SetActive(false);
}
}
}
}
}