using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.UI; //============================================================ //支持中文,文件使用UTF-8编码 //@author #AUTHOR# //@create #CREATEDATE# //@company #COMPANY# // //@description:给生成设备添加的脚本 //============================================================ public class DeviceItem : MonoBehaviour { public DeviceManager deviceManager; public int startIndex; public int volume; public DragTest1 oriPrefab; // Use this for initialization public MeshRenderer _mesh = null; public void Init(DeviceManager _deviceManager, int _startIndex, int _volume, DragTest1 _dtPrefab) { BoxCollider boxCollider = GetComponent(); if (!boxCollider) { if (gameObject.GetComponent() != null) { _mesh = gameObject.GetComponent(); } else { _mesh = transform.GetChild(0).GetComponent(); } if (_mesh != null) { var initrot = transform.rotation; transform.rotation = Quaternion.identity; var bounds = _mesh.bounds; var a = transform.gameObject.AddComponent(); a.isTrigger = false; a.center = bounds.center - transform.position; a.size = bounds.size; transform.rotation = initrot; } } if (!gameObject.GetComponent()) gameObject.AddComponent(); //gameObject.AddComponent(); deviceManager = _deviceManager; startIndex = _startIndex; volume = _volume; oriPrefab = _dtPrefab; } //private void OnMouseDown() //{ // if (!EventSystem.current.IsPointerOverGameObject()) // { // Vector3 pos = Input.mousePosition; // deviceManager.SetMenuValue(pos, this, oriPrefab); // } //} public void OnselfClick() { if (!EventSystem.current.IsPointerOverGameObject()) { Vector3 pos = Input.mousePosition; deviceManager.SetMenuValue(pos, this, oriPrefab); } } }