73 lines
2.1 KiB
C#
73 lines
2.1 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
using UnityEngine.UI;
|
|
using static UnityEngine.GraphicsBuffer;
|
|
|
|
public class DragController : MonoBehaviour, IBeginDragHandler, IEndDragHandler, IDragHandler
|
|
{
|
|
public GameObject prefabItem;
|
|
public GameObject model;
|
|
public HuoPaoController[] huoPaoCtrls;
|
|
public Text modelname_text;
|
|
public bool isDragWRJ = true;
|
|
|
|
public void OnBeginDrag(PointerEventData eventData)
|
|
{
|
|
if (model == null)
|
|
{
|
|
model = Instantiate(prefabItem);
|
|
//Debug.Log(prefabItem.name);
|
|
//Debug.Log(model.name);
|
|
}
|
|
|
|
}
|
|
|
|
public void OnDrag(PointerEventData eventData)
|
|
{
|
|
if (model != null)
|
|
{
|
|
OnRay(model);
|
|
}
|
|
}
|
|
|
|
public void OnEndDrag(PointerEventData eventData)
|
|
{
|
|
if (model != null)
|
|
{
|
|
if (isDragWRJ)
|
|
{
|
|
//for (int i = 0; i < huoPaoCtrls.Length; i++)
|
|
//{
|
|
// huoPaoCtrls[i].wrjs.Add(model);
|
|
//}
|
|
//model.GetComponent<WRJController>().huoPaoControllerList = huoPaoCtrls;
|
|
}
|
|
if (DragManager.Instance != null)
|
|
{
|
|
DragManager.Instance.AddObj(model);//把对应模型传入链表
|
|
//DragManager.Instance.Addobj1(model);//
|
|
//model.GetComponent<Modeldata>().SetPos();//重新获取该模型的位置的值
|
|
DragManager.Instance.Addtext(modelname_text.text);//把对应名字存入链表
|
|
}
|
|
model = null;
|
|
}
|
|
}
|
|
|
|
private void OnRay(GameObject target)
|
|
{
|
|
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
|
|
RaycastHit hitInfo;
|
|
if (Physics.Raycast(ray, out hitInfo, 1000, 1 << 8))
|
|
{
|
|
Debug.Log("daadad");
|
|
target.transform.localPosition = hitInfo.point;
|
|
}
|
|
else
|
|
{
|
|
|
|
}
|
|
}
|
|
}
|