104 lines
3.0 KiB
C#
104 lines
3.0 KiB
C#
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 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 Awake()
|
|
{
|
|
mastermanagement = GameObject.Find("MainCanvas").GetComponent<Mastermanagement>();
|
|
}
|
|
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<EquipmentCommon>().isPlayer = true;
|
|
model.GetComponent<EquipmentCommon>().isStartRehearsing = GlobalFlag.isStartRehearsing;
|
|
if (model.GetComponent<UnmannedAerialVehicleManage>())
|
|
model.GetComponent<UnmannedAerialVehicleManage>().wrjModel = wrjModel;
|
|
List<List_paraItem> temp = UIBootstrap.Instance.GetListParaItemById(deviceID);
|
|
model.GetComponent<EquipmentCommon>().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);//把对应模型传入链表
|
|
|
|
}
|
|
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
|
|
{
|
|
|
|
}
|
|
}
|
|
}
|