89 lines
2.3 KiB
C#
89 lines
2.3 KiB
C#
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<BoxCollider>();
|
||
if (!boxCollider)
|
||
{
|
||
if (gameObject.GetComponent<MeshRenderer>() != null)
|
||
{
|
||
_mesh = gameObject.GetComponent<MeshRenderer>();
|
||
}
|
||
else
|
||
{
|
||
_mesh = transform.GetChild(0).GetComponent<MeshRenderer>();
|
||
}
|
||
if (_mesh != null)
|
||
{
|
||
var initrot = transform.rotation;
|
||
transform.rotation = Quaternion.identity;
|
||
|
||
var bounds = _mesh.bounds;
|
||
var a = transform.gameObject.AddComponent<BoxCollider>();
|
||
a.isTrigger = false;
|
||
a.center = bounds.center - transform.position;
|
||
|
||
a.size = bounds.size;
|
||
|
||
transform.rotation = initrot;
|
||
}
|
||
|
||
|
||
|
||
}
|
||
if (!gameObject.GetComponent<ClickEvent>())
|
||
gameObject.AddComponent<ClickEvent>();
|
||
|
||
//gameObject.AddComponent<BoxCollider>();
|
||
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);
|
||
}
|
||
}
|
||
}
|