114 lines
3.2 KiB
C#
114 lines
3.2 KiB
C#
using DataModel.Model;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Reflection;
|
|
using System.Runtime.CompilerServices;
|
|
using UnityEditor;
|
|
using UnityEngine;
|
|
using UnityEngine.Events;
|
|
|
|
public class Doubleclickdelete : MonoBehaviour
|
|
{
|
|
public UnityEvent standaloneevent;
|
|
public UnityEvent doubleclickecent;
|
|
public float timer;//用来判断是否事单机还是双击
|
|
public float lasttime;//计入当前场景的时间
|
|
public int count;//用来判断点击了几下
|
|
public float interval = 0.2f;//用来判断双击间隔时间
|
|
private bool iscount = true;//用来判断的是单机还是双击
|
|
void Start()
|
|
{
|
|
|
|
}
|
|
|
|
|
|
void Update()
|
|
{
|
|
if (Input.GetMouseButtonDown(1))
|
|
{
|
|
timer = 0.2f;
|
|
if (Time.realtimeSinceStartup - lasttime < interval)
|
|
{
|
|
count = 2;
|
|
}
|
|
else
|
|
{
|
|
count = 1;
|
|
}
|
|
}
|
|
if (Input.GetMouseButtonUp(1))
|
|
{
|
|
iscount = false;
|
|
lasttime = Time.realtimeSinceStartup;
|
|
}
|
|
if (!iscount)
|
|
{
|
|
timer -= Time.deltaTime;
|
|
if (timer < 0)
|
|
{
|
|
if (count == 1)
|
|
{
|
|
|
|
standaloneevent?.Invoke();
|
|
}
|
|
else if (count == 2)
|
|
{
|
|
Deletionmodel();
|
|
doubleclickecent?.Invoke();
|
|
}
|
|
iscount = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void Deletionmodel()
|
|
{
|
|
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
|
|
RaycastHit hit;
|
|
if (Physics.Raycast(ray, out hit,1000))
|
|
{
|
|
if (hit.collider.gameObject.tag =="model")
|
|
{
|
|
if (DragManager.Instance.devices.Count > 0)
|
|
{
|
|
Scenariopage scenariopage = GetComponent<Scenariopage>();
|
|
for (int i = 0; i < DragManager.Instance.devices.Count; i++)
|
|
{
|
|
int index = i;
|
|
if (hit.collider.gameObject.name == DragManager.Instance.devices[index].name)
|
|
{
|
|
Destroy(DragManager.Instance.devices[index].gameObject);
|
|
DragManager.Instance.devices.RemoveAt(index);
|
|
if (scenariopage.properties.Count > 0)
|
|
{
|
|
Deletebutton(scenariopage, DragManager.Instance.devices[index].gameObject.name);
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
private void Deletebutton(Scenariopage scenariopage, string name)
|
|
{
|
|
|
|
for (int i = 0; i < scenariopage.properties.Count; i++)
|
|
{
|
|
int index = i;
|
|
if (scenariopage.properties[index].name == name)
|
|
{
|
|
Destroy(scenariopage.properties[index].gameObject);
|
|
scenariopage.properties.RemoveAt(index);
|
|
break;
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
}
|