扩展objclick 支持反向判断

This commit is contained in:
shenjianxing 2025-01-02 14:45:55 +08:00
parent ed940235af
commit f5846b0919
3 changed files with 21 additions and 3 deletions

View File

@ -16,6 +16,7 @@ namespace QFramework
public GameObject obj = null; public GameObject obj = null;
string path; string path;
string deviceName; string deviceName;
bool isRight;
public static ObjClickCondition Allocate(string path, Dictionary<string, string> datas) public static ObjClickCondition Allocate(string path, Dictionary<string, string> datas)
{ {
var conditionAction = mSimpleObjectPool.Allocate(); var conditionAction = mSimpleObjectPool.Allocate();
@ -24,6 +25,11 @@ namespace QFramework
conditionAction.Reset(); conditionAction.Reset();
conditionAction.path = path; conditionAction.path = path;
conditionAction.deviceName = datas.ContainsKey("deviceName") ? datas["deviceName"] : null; conditionAction.deviceName = datas.ContainsKey("deviceName") ? datas["deviceName"] : null;
conditionAction.isRight = true;
if (datas.ContainsKey("isRight"))
{
bool.TryParse(datas["isRight"], out conditionAction.isRight);
}
return conditionAction; return conditionAction;
} }
public bool Check() public bool Check()
@ -45,9 +51,16 @@ namespace QFramework
Ray ray = Camera.main.ScreenPointToRay(mousePos); Ray ray = Camera.main.ScreenPointToRay(mousePos);
RaycastHit hit; RaycastHit hit;
if (Physics.Raycast(ray, out hit)) if (Physics.Raycast(ray, out hit))
{
if (isRight)
{ {
return obj == hit.collider.gameObject; return obj == hit.collider.gameObject;
} }
else
{
return obj != hit.collider.gameObject;
}
}
} }
return false; return false;
} }

View File

@ -1049,6 +1049,11 @@ namespace XMLTool
{ {
act.args.Add("deviceName", deviceName.Value); act.args.Add("deviceName", deviceName.Value);
} }
XAttribute isRight = action.Attribute("isRight");
if (isRight != null)
{
act.args.Add("isRight", isRight.Value);
}
newAction = act; newAction = act;
break; break;
default: default:

View File

@ -79,8 +79,8 @@
<!--判断UI点击--> <!--判断UI点击-->
<Condition type="UIClick" value="UI路径 可以使用快捷键Ctrl+Q获取"></Condition> <Condition type="UIClick" value="UI路径 可以使用快捷键Ctrl+Q获取"></Condition>
<!--判断物体点击--> <!--判断物体点击 isRight = true 则点击到目标物体 才算满足 false 则点击了其他物体就满足 常用于错误的点击-->
<Condition type="ObjClick" value="物体路径 可以使用快捷键Ctrl+Q获取"></Condition> <Condition type="ObjClick" value="物体路径 可以使用快捷键Ctrl+Q获取" isRight="true"></Condition>
<!--判断键盘输入--> <!--判断键盘输入-->
<Condition type="Input" value="A"></Condition> <Condition type="Input" value="A"></Condition>
<!--判断变量名i是否等于1--> <!--判断变量名i是否等于1-->