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().huoPaoControllerList = huoPaoCtrls; } DragManager.Instance.AddObj(model);//把对应模型传入链表 //DragManager.Instance.Addobj1(model);// //model.GetComponent().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 { } } }