using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.UI; public class CreateXHS : MonoBehaviour { /// /// 创建消火栓 /// private RaycastHit hit;//射线 public LayerMask ground_layerMask = -1; public static CreateXHS instance = null; private Toggle toggle; void Awake () { if (instance == null) { instance = this; } } private void Start() { toggle = this.GetComponent(); toggle.onValueChanged.AddListener(ChangeValue); } public void ChangeValue(bool flag) { if (flag) { ControlInstance = true; } else { ControlInstance = false; } } bool ControlInstance = false; public List XHSList = new List(); void Update() { if (ControlInstance) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit, Mathf.Infinity, ground_layerMask) && Input.GetMouseButtonDown(0) && !EventSystem.current.IsPointerOverGameObject()) { GameObject xhs = Instantiate(Resources.Load("Prefabs/ToolPrefab/XHSScene")); xhs.transform.parent = GameObject.Find("AllParent/pXhs").transform; xhs.transform.localPosition = hit.point+new Vector3(0,0.5f,0); xhs.transform.localScale = new Vector3(1.8f, 1.8f, 1.8f); xhs.GetComponent().cengID = hit.transform.GetComponent().cengID; xhs.GetComponent().CengIDBuildType = hit.transform.GetComponent().CengIDBuildType; string Now = System.DateTime.Now.Year.ToString() + System.DateTime.Now.Month.ToString() + System.DateTime.Now.Day.ToString() + System.DateTime.Now.Hour.ToString() + System.DateTime.Now.Minute.ToString() + System.DateTime.Now.Second.ToString()+ System.DateTime.Now.Millisecond.ToString(); xhs.name = "XHSScene" + Now; XHSList.Add(xhs); } } } }