using AdamThinkDevicesData; 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 string deviceID; public bool isPlayer = false; public bool isThinck = false; public WRJModel wrjModel = WRJModel.无人机; public Mastermanagement mastermanagement; void Start() { mastermanagement = GameObject.Find("Canvas").GetComponent(); } public void OnBeginDrag(PointerEventData eventData) { if (isDragWRJ) { if (DeviceManager.Instance.GetPlayerDevice() == GameManager.Instance.wrjCount) { return; } } 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 (!isThinck) { model.GetComponent().isPlayer = true; model.GetComponent().isStartRehearsing = GlobalFlag.isStartRehearsing; if (model.GetComponent()) model.GetComponent().wrjModel = wrjModel; List temp = UIBootstrap.Instance.GetListParaItemById(deviceID); model.GetComponent().FillInTheData(temp); model.name = gameObject.name; if (!isDragWRJ) { //transform.SetAsLastSibling(); //transform.localScale = Vector3.zero; model.name = gameObject.name; gameObject.SetActive(false); } mastermanagement.OnAdd(model); } if (DragManager.Instance != null) { DragManager.Instance.AddObj(model);//把对应模型传入链表 DragManager.Instance.Addtext(modelname_text.text);//把对应名字存入链表 } model = null; } } void Add() { string currentTime = System.DateTime.Now.ToString(); Debug.Log("当前时间:" + currentTime); } 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 { } } }