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.
142 lines
3.7 KiB
142 lines
3.7 KiB
using UnityEngine.EventSystems;
|
|
using UnityEngine;
|
|
using System;
|
|
using UnityEngine.UI;
|
|
|
|
public enum SheBeiType
|
|
{
|
|
设备,
|
|
注入器,
|
|
开机棒,
|
|
受启棒,
|
|
}
|
|
|
|
public class DragItemH : MonoBehaviour, IPointerDownHandler, IDragHandler, IPointerUpHandler
|
|
{
|
|
public SheBeiType SheBeiType;
|
|
|
|
private Vector2 resetPos;
|
|
private CheckDarg[] checkDargs;
|
|
public int type;
|
|
public string id;
|
|
public string SheBeiHao;
|
|
public string Name;
|
|
public string jsonData;
|
|
|
|
public Text NameText;
|
|
|
|
[HideInInspector]
|
|
[Header("插孔位置")]
|
|
public Vector3 ChaKongPos;
|
|
[Header("插入设备模型路径")]
|
|
public string ChaRuItemPath;
|
|
|
|
|
|
private GameObject ChaRuItem;
|
|
|
|
[SerializeField]
|
|
private Transform ResetAear;
|
|
[SerializeField]
|
|
private Transform DargAear;
|
|
|
|
private bool CanDarg = true;
|
|
|
|
|
|
|
|
public void Init()
|
|
{
|
|
ResetAear = this.transform.parent;
|
|
DargAear = GameObject.FindGameObjectWithTag("DargAear").transform;
|
|
//resetPos = this.transform.GetComponent<RectTransform>().position;
|
|
|
|
ChaRuItem = GameObject.Instantiate(Resources.Load<GameObject>(ChaRuItemPath));
|
|
ChaRuItem.SetActive(false);
|
|
NameText = transform.GetChild(0).GetComponent<Text>();
|
|
NameText.text = Name;
|
|
////获取设备信息
|
|
//GameManager.Instance.GetItemType(this, false);
|
|
}
|
|
|
|
|
|
public void OnDrag(PointerEventData eventData)
|
|
{
|
|
if (!CanDarg) return;
|
|
this.transform.SetParent(DargAear);
|
|
this.transform.GetComponent<RectTransform>().position = Input.mousePosition;
|
|
|
|
|
|
}
|
|
|
|
internal void ResetPos()
|
|
{
|
|
this.transform.SetParent(ResetAear);
|
|
CanDarg = true;
|
|
this.gameObject.SetActive(true);
|
|
this.Hide3DItem();
|
|
this.GetComponent<RectTransform>().localPosition= resetPos;
|
|
// this.transform.position = Vector3.zero;
|
|
this.ChaKongPos = Vector3.zero;
|
|
|
|
//GameManager.Instance.PostMessage(this.type, this.ID);
|
|
}
|
|
|
|
public void OnPointerDown(PointerEventData eventData)
|
|
{
|
|
resetPos = this.transform.localPosition;
|
|
}
|
|
|
|
public void OnPointerUp(PointerEventData eventData)
|
|
{
|
|
if (!CanDarg) return;
|
|
//写放入检测框方法
|
|
checkDargs = GameObject.FindObjectsOfType<CheckDarg>();
|
|
for (int i = 0; i < checkDargs.Length; i++)
|
|
{
|
|
if (Vector2.Distance(this.transform.position, checkDargs[i].transform.position)<30f)
|
|
{
|
|
if (checkDargs[i].isEmpty == false||this.SheBeiType!= checkDargs[i].ChaKongType)
|
|
{
|
|
break;
|
|
}
|
|
this.transform.position = checkDargs[i].transform.position;
|
|
this.ChaKongPos = checkDargs[i].ChaKongPos;
|
|
checkDargs[i].dragItem = this;
|
|
checkDargs[i].isEmpty = false;
|
|
|
|
this.CanDarg = false;
|
|
this.gameObject.SetActive(false);
|
|
//显示插入设备3D可视化
|
|
this.Show3DItem();
|
|
GameManager.Instance.GetItemType(this);
|
|
//GameManager.Instance.SendItemData();
|
|
return;
|
|
}
|
|
|
|
}
|
|
this.transform.SetParent(ResetAear);
|
|
this.transform.GetComponent<RectTransform>().localPosition = resetPos;
|
|
|
|
}
|
|
|
|
|
|
public void Show3DItem()
|
|
{
|
|
if (ChaRuItem != null)
|
|
{
|
|
ChaRuItem.SetActive(true);
|
|
ChaRuItem.transform.position = ChaKongPos;
|
|
}
|
|
}
|
|
|
|
public void Hide3DItem()
|
|
{
|
|
if (ChaRuItem != null)
|
|
{
|
|
ChaRuItem.SetActive(false);
|
|
ChaRuItem.transform.position = Vector3.zero;
|
|
}
|
|
}
|
|
}
|
|
|
|
|