新增长按功能
This commit is contained in:
parent
53beb1ec4e
commit
c9529a1216
@ -269,8 +269,15 @@ public class ActionHelper
|
||||
case "UIClick":
|
||||
return UIClickCondition.Allocate(condition.Value);
|
||||
case "ObjClick":
|
||||
{
|
||||
var dict = (XMLTool.DictionaryCondition)condition;
|
||||
return ObjClickCondition.Allocate(dict.Value, dict.args);
|
||||
}
|
||||
case "ObjClickLong":
|
||||
{
|
||||
var dict = (XMLTool.DictionaryCondition)condition;
|
||||
return ObjClickLongCondition.Allocate(dict.Value, dict.args);
|
||||
}
|
||||
case "Input":
|
||||
return InputCondition.Allocate(condition.Value);
|
||||
case "Var":
|
||||
|
||||
146
Assets/Scripts/Conditions/ObjClickLongCondition.cs
Normal file
146
Assets/Scripts/Conditions/ObjClickLongCondition.cs
Normal file
@ -0,0 +1,146 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace QFramework
|
||||
{
|
||||
public class ObjClickLongCondition : ICondition
|
||||
{
|
||||
|
||||
private static SimpleObjectPool<ObjClickLongCondition> mSimpleObjectPool =
|
||||
new SimpleObjectPool<ObjClickLongCondition>(() => new ObjClickLongCondition(), null, 10);
|
||||
|
||||
private ObjClickLongCondition() { }
|
||||
public GameObject obj = null;
|
||||
string path;
|
||||
string deviceName;
|
||||
float time;
|
||||
float curTime;
|
||||
bool isDown = false;
|
||||
public static ObjClickLongCondition Allocate(string path, Dictionary<string, string> datas)
|
||||
{
|
||||
var conditionAction = mSimpleObjectPool.Allocate();
|
||||
conditionAction.ActionID = ActionKit.ID_GENERATOR++;
|
||||
conditionAction.Deinited = false;
|
||||
conditionAction.Reset();
|
||||
conditionAction.path = path;
|
||||
conditionAction.deviceName = datas.ContainsKey("deviceName") ? datas["deviceName"] : null;
|
||||
if (datas.ContainsKey("time"))
|
||||
{
|
||||
float.TryParse(datas["time"], out conditionAction.time);
|
||||
}
|
||||
return conditionAction;
|
||||
}
|
||||
public bool Check()
|
||||
{
|
||||
if (obj == null)
|
||||
{
|
||||
if (string.IsNullOrEmpty(deviceName))
|
||||
{
|
||||
obj = Utility.FindObj(path);
|
||||
}
|
||||
else
|
||||
{
|
||||
obj = DeviceController.Instance.GetDeviceObj(deviceName);
|
||||
if (obj == null)
|
||||
{
|
||||
Debug.LogError($"没有找到 path:{path} deviceName:{deviceName}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 检测鼠标左键按下
|
||||
if (Input.GetMouseButtonDown(0))
|
||||
{
|
||||
OnMouseDown();
|
||||
}
|
||||
|
||||
// 检测鼠标左键松开
|
||||
if (Input.GetMouseButtonUp(0))
|
||||
{
|
||||
OnMouseUp();
|
||||
}
|
||||
|
||||
if (isDown && EventSystem.current.IsPointerOverGameObject() == false)
|
||||
{
|
||||
Vector3 mousePos = Input.mousePosition;
|
||||
Ray ray = Camera.main.ScreenPointToRay(mousePos);
|
||||
RaycastHit hit;
|
||||
if (Physics.Raycast(ray, out hit))
|
||||
{
|
||||
if (obj == hit.collider.gameObject)
|
||||
{
|
||||
curTime -= Time.deltaTime;
|
||||
if (curTime <= 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void OnMouseDown()
|
||||
{
|
||||
curTime = this.time;
|
||||
isDown = true;
|
||||
}
|
||||
|
||||
public void OnMouseUp()
|
||||
{
|
||||
isDown = false;
|
||||
}
|
||||
|
||||
|
||||
public bool Paused { get; set; }
|
||||
public bool Deinited { get; set; }
|
||||
public ulong ActionID { get; set; }
|
||||
public ActionStatus Status { get; set; }
|
||||
public void OnStart()
|
||||
{
|
||||
}
|
||||
|
||||
public void OnExecute(float dt)
|
||||
{
|
||||
if (Check())
|
||||
{
|
||||
this.Finish();
|
||||
}
|
||||
}
|
||||
|
||||
public void OnFinish()
|
||||
{
|
||||
}
|
||||
|
||||
public void Deinit()
|
||||
{
|
||||
if (!Deinited)
|
||||
{
|
||||
Deinited = true;
|
||||
obj = null;
|
||||
path = null;
|
||||
mSimpleObjectPool.Recycle(this);
|
||||
}
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
curTime = 0;
|
||||
Paused = false;
|
||||
Status = ActionStatus.NotStart;
|
||||
}
|
||||
}
|
||||
|
||||
//public static class ObjClickLongConditionExtension
|
||||
//{
|
||||
// public static ISequence ObjClickLongCondition(this ISequence self, string uipath)
|
||||
// {
|
||||
// return self.Append(QFramework.ObjClickLongCondition.Allocate(uipath));
|
||||
// }
|
||||
//}
|
||||
}
|
||||
3
Assets/Scripts/Conditions/ObjClickLongCondition.cs.meta
Normal file
3
Assets/Scripts/Conditions/ObjClickLongCondition.cs.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 297e67e3bc7868a4cae6623426c359b9
|
||||
timeCreated: 1647673104
|
||||
@ -1163,6 +1163,7 @@ namespace XMLTool
|
||||
switch (type)
|
||||
{
|
||||
case "ObjClick":
|
||||
{
|
||||
var act = new DictionaryCondition();
|
||||
|
||||
XAttribute deviceName = action.Attribute("deviceName");
|
||||
@ -1176,6 +1177,23 @@ namespace XMLTool
|
||||
act.args.Add("isRight", isRight.Value);
|
||||
}
|
||||
newAction = act;
|
||||
}
|
||||
break;
|
||||
case "ObjClickLong":
|
||||
{
|
||||
var act = new DictionaryCondition();
|
||||
XAttribute deviceName = action.Attribute("deviceName");
|
||||
if (deviceName != null)
|
||||
{
|
||||
act.args.Add("deviceName", deviceName.Value);
|
||||
}
|
||||
XAttribute time = action.Attribute("time");
|
||||
if (time != null)
|
||||
{
|
||||
act.args.Add("time", time.Value);
|
||||
}
|
||||
newAction = act;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
newAction = new Condition();
|
||||
|
||||
@ -104,8 +104,11 @@
|
||||
|
||||
<!--判断UI点击-->
|
||||
<Condition type="UIClick" value="UI路径 可以使用快捷键Ctrl+Q获取"></Condition>
|
||||
<!--判断物体点击 isRight = true 则点击到目标物体 才算满足 false 则点击了其他物体就满足 常用于错误的点击-->
|
||||
<Condition type="ObjClick" value="物体路径 可以使用快捷键Ctrl+Q获取" isRight="true"></Condition>
|
||||
<!--判断物体点击 支持deviceName isRight = true 则点击到目标物体 才算满足 false 则点击了其他物体就满足 常用于错误的点击-->
|
||||
<Condition type="ObjClick" deviceName="设备名" value="物体路径 可以使用快捷键Ctrl+Q获取" isRight="true"></Condition>
|
||||
<!--判断物体点击(长按) time为长按时间(秒)-->
|
||||
<Condition type="ObjClickLong" deviceName="设备名" value="物体路径 可以使用快捷键Ctrl+Q获取" time="3"></Condition>
|
||||
|
||||
<!--判断键盘输入 这里的value对应的是KeyCode枚举-->
|
||||
<Condition type="Input" value="A"></Condition>
|
||||
<!--判断变量名i是否等于1-->
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user