NewN_UAVPlane/Assets/Zion/Scripts/Adam/DragController.cs

69 lines
1.7 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;
}
DragManager.Instance.AddObj(model);
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
{
}
}
}