天津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.
 
 
 
 
 
 

205 lines
7.5 KiB

using UnityEngine;
using System.Collections;
using System;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using AX.MessageSystem;
/// <summary>
/// 1、鼠标通过射线点击对应的UI,实现实例化人员栏物体
/// 2、挂载在Canvas下DomeView下StaffButtonPicture;
/// 3、核心方法:GetObj();
/// </summary>
public class InstantiationStaff : MonoBehaviour {
public static InstantiationStaff Instance;
private LayerMask ground_layerMask = -1;//地面层
private LayerMask indoor_layerMask = -1;//室内层
DateTime t1, t2;
private int delta_millisecond = 400;
public string XFYName;
private GameObject XFYGrid;
private RaycastHit hit;//射线
public int zdfNum = 0;
private int bhfNum = 0;
private int fhfNum = 0;
private int grfNum = 0;
private int jyfNum = 0;
private int Num = 0;
[HideInInspector]
public bool isboolStaff = false;
[HideInInspector]
public string TopName = "";
private InputField ForceNameInput;
void Awake()
{
if (Instance == null)
{
Instance = this;
}
XFYGrid= GameObject.Find("DomeView/BroweMenu/StaffButtonPicture/ScrollRect").transform.Find("StaffGrid").gameObject;
ForceNameInput = GameObject.Find("Canvas"). transform.Find("TeamNameWin").transform.Find("InputField").gameObject.GetComponent<InputField>();
MessageDispatcher.AddListener("ResetTheScene", ResettingInformation);
MessageDispatcher.AddListener("ResettingButton", ResettingButton);
MessageDispatcher.AddListener("InstantiateButton", GetObj);
indoor_layerMask = 1 << 29 | 1 << 25 | 1 << 26;
ground_layerMask = 1 << 25 | 1 << 26;
}
void ResettingButton(IMessage message)
{
foreach (Transform child in XFYGrid.transform)
{
if (child.gameObject.GetComponent<Button>().interactable == true)
{
child.Find("Image").gameObject.SetActive(false);
}
}
XFYName = "";
}
public void GetObj(IMessage message)
{
if (gameObject.name.Contains(message.Sender.ToString()))
{
MessageDispatcher.SendMessage("ResettingButton");
t2 = DateTime.Now;
if (t2 - t1 < new TimeSpan(0, 0, 0, 0, delta_millisecond))//防止一次单击被检测到多次
return;
var obj = (GameObject)message.Data;
obj.transform.Find("Image").gameObject.SetActive(true);
XFYName = obj.name;
t1 = t2;
}
}
void OnDestroy()
{
MessageDispatcher.RemoveListener("ResetTheScene", ResettingInformation);
MessageDispatcher.RemoveListener("ResettingButton", ResettingButton);
MessageDispatcher.RemoveListener("InstantiateButton", GetObj);
NormalStaff.staffIndex = 0;
}
void ResettingInformation(IMessage message)
{
zdfNum = 0;
bhfNum = 0;
fhfNum = 0;
grfNum = 0;
jyfNum = 0;
isboolStaff = false;
}
// Update is called once per frame
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, ground_layerMask) && Input.GetMouseButtonDown(0) && !EventSystem.current.IsPointerOverGameObject())
{
if (InstantiationCar.Instance.isCarSelect)
{
return;
}
//if (isboolStaff)
//{
// TopName = EditForceName.JudgeName+"-" + "高喷车" + "-" + Num;
//}
if (XFYName==null)
{
return;
}
//战斗服
if ( XFYName.Equals("zdf"))
{
zdfNum++;
if (isboolStaff)
{
TopName = EditForceName.Instance.JudgeName + "-" + "战斗服" + "-" + zdfNum;
}
else
{
TopName = "战斗服" + "-" + zdfNum;
}
string Name = "中队名" + "-" + "xiaofangyuan" + "-" + "zdf" + "-";
NormalStaff xfy = new NormalStaff(Resources.Load<GameObject>("Prefabs/xiaofangyuan/zdf"), GameObject.Find("pxiaofangyuan"), null, NormalStaff.staffIndex, hit, 0f);
xfy.InstatiateItem(Name, TopName);
}
//避火服
else if ( XFYName.Equals("bhf"))
{
bhfNum++;
if (isboolStaff)
{
TopName = EditForceName.Instance.JudgeName + "-" + "避火服" + "-" + bhfNum;
}
else
{
TopName = "避火服" + "-" + bhfNum;
}
string Name = "中队名" + "-" + "xiaofangyuan" + "-" + "bhf" + "-";
NormalStaff xfy = new NormalStaff(Resources.Load<GameObject>("Prefabs/xiaofangyuan/bhf"), GameObject.Find("pxiaofangyuan"), null, NormalStaff.staffIndex, hit, 0f);
xfy.InstatiateItem(Name, TopName);
}
//防化服
else if ( XFYName.Equals("fhf"))
{
fhfNum++;
if (isboolStaff)
{
TopName = EditForceName.Instance.JudgeName + "-" + "防化服" + "-" + fhfNum;
}
else
{
TopName = "防化服" + "-" + fhfNum;
}
string Name = "中队名" + "-" + "xiaofangyuan" + "-" + "fhf" + "-";
NormalStaff xfy = new NormalStaff(Resources.Load<GameObject>("Prefabs/xiaofangyuan/fhf"), GameObject.Find("pxiaofangyuan"), null, NormalStaff.staffIndex, hit, 0f);
xfy.InstatiateItem(Name, TopName);
}
//隔热服
else if ( XFYName.Equals("grf"))
{
grfNum++;
if (isboolStaff)
{
TopName = EditForceName.Instance.JudgeName + "-" + "隔热服" + "-" + grfNum;
}
else
{
TopName = "隔热服" + "-" + grfNum;
}
string Name = "中队名" + "-" + "xiaofangyuan" + "-" + "grf" + "-";
NormalStaff xfy = new NormalStaff(Resources.Load<GameObject>("Prefabs/xiaofangyuan/grf"), GameObject.Find("pxiaofangyuan"), null, NormalStaff.staffIndex, hit, 0f);
xfy.InstatiateItem(Name, TopName);
}
//救援服
else if (XFYName.Equals("jyf"))
{
jyfNum++;
if (isboolStaff)
{
TopName = EditForceName.Instance.JudgeName + "-" + "救援服" + "-" + jyfNum;
}
else
{
TopName = "救援服" + "-" + jyfNum;
}
string Name = "中队名" + "-" + "xiaofangyuan" + "-" + "jyf" + "-";
NormalStaff xfy = new NormalStaff(Resources.Load<GameObject>("Prefabs/xiaofangyuan/jyf"), GameObject.Find("pxiaofangyuan"), null, NormalStaff.staffIndex, hit, 0f);
xfy.InstatiateItem(Name,TopName);
}
}
}
}