142 lines
4.3 KiB
C#
142 lines
4.3 KiB
C#
using AdamSync;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.Events;
|
|
using UnityEngine.Networking;
|
|
using static InterfaceManager;
|
|
|
|
public class Backpack : MonoBehaviour
|
|
{
|
|
public UnityEvent oneClickEvent;//unity事件
|
|
public UnityEvent doubleClickEvent;//unity事件
|
|
public float time;
|
|
public float lascktime;
|
|
public float itemtime = 0.2f;
|
|
public int count;
|
|
public bool isCount = true;
|
|
|
|
public Mastermanagement mastermanagement;
|
|
public string Id;//设备的
|
|
public string wrjid;//无人机id
|
|
void Start()
|
|
{
|
|
|
|
}
|
|
|
|
|
|
void Update()
|
|
{
|
|
if (GlobalFlag.isStartRehearsing) return;
|
|
if (Input.GetMouseButtonDown(1))
|
|
{
|
|
time = 0.2f;
|
|
if (Time.realtimeSinceStartup - lascktime < itemtime)
|
|
{
|
|
count = 2;
|
|
}
|
|
else
|
|
{
|
|
count = 1;
|
|
}
|
|
}
|
|
if (Input.GetMouseButtonUp(1))
|
|
{
|
|
isCount = false;
|
|
lascktime = Time.realtimeSinceStartup;
|
|
}
|
|
if (!isCount)
|
|
{
|
|
time -= Time.deltaTime;
|
|
if (time <= 0)
|
|
{
|
|
if (count == 2)
|
|
{
|
|
OnRay();
|
|
doubleClickEvent?.Invoke();
|
|
}
|
|
else
|
|
{
|
|
oneClickEvent?.Invoke();
|
|
}
|
|
isCount = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void OnRay()
|
|
{
|
|
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
|
|
RaycastHit hit;
|
|
if (Physics.Raycast(ray, out hit, 1000))
|
|
{
|
|
if (hit.collider.gameObject.tag == "AttackTarget")
|
|
{
|
|
EquipmentCommon eTemp = hit.collider.gameObject.GetComponent<EquipmentCommon>();
|
|
if (eTemp != null)
|
|
{
|
|
if (eTemp.isPlayer)
|
|
{
|
|
mastermanagement.Onobj(hit.collider.gameObject);
|
|
mastermanagement.Remove(hit.collider.gameObject);
|
|
Id = hit.collider.gameObject.GetComponent<EquipmentCommon>().deviceID;
|
|
Deletedevice();
|
|
}
|
|
}
|
|
}
|
|
if (hit.collider.gameObject.tag == "WRJ")
|
|
{
|
|
EquipmentCommon eTemp = hit.collider.gameObject.GetComponent<EquipmentCommon>();
|
|
if (eTemp != null)
|
|
{
|
|
if (hit.collider.gameObject.GetComponent<EquipmentCommon>().isPlayer)
|
|
{
|
|
wrjid = hit.collider.gameObject.GetComponent<EquipmentCommon>().deviceID;
|
|
mastermanagement.Remove(hit.collider.gameObject);
|
|
DragManager.Instance.RemoveObj(hit.collider.gameObject);
|
|
Deletedevice1();
|
|
Destroy(hit.collider.gameObject);
|
|
DroneViewDisplay.Instance.DistroyUI(eTemp.deviceID);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void Deletedevice()
|
|
{
|
|
if (string.IsNullOrEmpty(Id))
|
|
{
|
|
return;
|
|
}
|
|
string nowData = string.Format("{0},{1}", "SetToBeDestroyedTwo", Id);
|
|
//_ = SyncCreateRoom.SendMessageAsync(string.Format("send2room {0}", nowData));
|
|
MQTTManager.instance.SendData(MQTTManager.instance.SetToBeDestroyedTwo, nowData);
|
|
WWWForm headers = new WWWForm();
|
|
headers.AddField("id", Id);
|
|
StartCoroutine(PostString(Url_Deletepracticedevicedetail, headers, data =>
|
|
{
|
|
Id = null;
|
|
Debug.Log(data);
|
|
}));
|
|
}
|
|
private void Deletedevice1()
|
|
{
|
|
if (string.IsNullOrEmpty(wrjid))
|
|
{
|
|
return;
|
|
}
|
|
string nowData = string.Format("{0},{1}", "SetToBeDestroyedTwo", wrjid);
|
|
//_ = SyncCreateRoom.SendMessageAsync(string.Format("send2room {0}", nowData));
|
|
MQTTManager.instance.SendData(MQTTManager.instance.SetToBeDestroyedTwo, nowData);
|
|
WWWForm headers = new WWWForm();
|
|
headers.AddField("id", wrjid);
|
|
StartCoroutine(PostString(Url_Deletepracticedevicedetail, headers, data =>
|
|
{
|
|
wrjid = null;
|
|
Debug.Log(data);
|
|
}));
|
|
}
|
|
}
|