增加距离判断
This commit is contained in:
parent
1fca93283a
commit
1a10ee747d
@ -342,6 +342,11 @@ public class ActionHelper
|
|||||||
var dict = (XMLTool.DictionaryCondition)condition;
|
var dict = (XMLTool.DictionaryCondition)condition;
|
||||||
return HasDeviceCondition.Allocate(dict.args);
|
return HasDeviceCondition.Allocate(dict.args);
|
||||||
}
|
}
|
||||||
|
case "Distance":
|
||||||
|
{
|
||||||
|
var dict = (XMLTool.DictionaryCondition)condition;
|
||||||
|
return DistanceCondition.Allocate(condition.Value, dict.args);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
95
Assets/Scripts/Conditions/DistanceCondition.cs
Normal file
95
Assets/Scripts/Conditions/DistanceCondition.cs
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.EventSystems;
|
||||||
|
|
||||||
|
namespace QFramework
|
||||||
|
{
|
||||||
|
public class DistanceCondition : ICondition
|
||||||
|
{
|
||||||
|
|
||||||
|
private static SimpleObjectPool<DistanceCondition> mSimpleObjectPool =
|
||||||
|
new SimpleObjectPool<DistanceCondition>(() => new DistanceCondition(), null, 10);
|
||||||
|
|
||||||
|
private DistanceCondition() { }
|
||||||
|
public GameObject obj = null;
|
||||||
|
float value = 0;
|
||||||
|
Vector3 targetPos = Vector3.zero;
|
||||||
|
bool ignoreY = false;
|
||||||
|
public static DistanceCondition Allocate(string value, Dictionary<string, string> datas)
|
||||||
|
{
|
||||||
|
var conditionAction = mSimpleObjectPool.Allocate();
|
||||||
|
conditionAction.ActionID = ActionKit.ID_GENERATOR++;
|
||||||
|
conditionAction.Deinited = false;
|
||||||
|
conditionAction.Reset();
|
||||||
|
float.TryParse(value, out conditionAction.value);
|
||||||
|
if (datas.ContainsKey("targetPos"))
|
||||||
|
{
|
||||||
|
conditionAction.targetPos = Utility.GetVector3FromStrArray(datas["targetPos"]);
|
||||||
|
}
|
||||||
|
if (datas.ContainsKey("ignoreY"))
|
||||||
|
{
|
||||||
|
if (bool.TryParse(datas["ignoreY"], out conditionAction.ignoreY) == false)
|
||||||
|
{
|
||||||
|
conditionAction.ignoreY = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return conditionAction;
|
||||||
|
}
|
||||||
|
public bool Check()
|
||||||
|
{
|
||||||
|
|
||||||
|
Vector3 self = FreeCameraController.instance.transform.position;
|
||||||
|
if (ignoreY)
|
||||||
|
{
|
||||||
|
self.y = targetPos.y;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Vector3.Distance(self, targetPos) <= value;
|
||||||
|
}
|
||||||
|
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;
|
||||||
|
mSimpleObjectPool.Recycle(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Reset()
|
||||||
|
{
|
||||||
|
Paused = false;
|
||||||
|
Status = ActionStatus.NotStart;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class DistanceConditionExtension
|
||||||
|
{
|
||||||
|
public static ISequence DistanceCondition(this ISequence self, string value,Dictionary<string,string> datas)
|
||||||
|
{
|
||||||
|
return self.Append(QFramework.DistanceCondition.Allocate(value, datas));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Assets/Scripts/Conditions/DistanceCondition.cs.meta
Normal file
11
Assets/Scripts/Conditions/DistanceCondition.cs.meta
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: c8bdcde7925b9534494a18a7b803043e
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -1819,6 +1819,22 @@ namespace XMLTool
|
|||||||
newAction = act;
|
newAction = act;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case "Distance":
|
||||||
|
{
|
||||||
|
var act = new DictionaryCondition();
|
||||||
|
XAttribute targetPos = action.Attribute("targetPos");
|
||||||
|
if (targetPos != null)
|
||||||
|
{
|
||||||
|
act.args.Add("targetPos", targetPos.Value);
|
||||||
|
}
|
||||||
|
XAttribute ignoreY = action.Attribute("ignoreY");
|
||||||
|
if (ignoreY != null)
|
||||||
|
{
|
||||||
|
act.args.Add("ignoreY", ignoreY.Value);
|
||||||
|
}
|
||||||
|
newAction = act;
|
||||||
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
newAction = new Condition();
|
newAction = new Condition();
|
||||||
break;
|
break;
|
||||||
|
|||||||
@ -35,14 +35,14 @@
|
|||||||
<State name="状态2">
|
<State name="状态2">
|
||||||
<Enter>
|
<Enter>
|
||||||
<Action type="Sequence">
|
<Action type="Sequence">
|
||||||
<!--<Action type="Log" value="11111"></Action>-->
|
<Action type="Log" value="11111"></Action>
|
||||||
</Action>
|
</Action>
|
||||||
</Enter>
|
</Enter>
|
||||||
</State>
|
</State>
|
||||||
<Transision from="状态1" to="状态2">
|
<Transision from="状态1" to="状态2">
|
||||||
<Condition type="And">
|
<Condition type="And">
|
||||||
<Condition type="HasDevice" deviceName="LeiGu" count="1"></Condition>
|
<Condition type="HasDevice" deviceName="LeiGu" count="1"></Condition>
|
||||||
<Condition type="HasDevice" deviceName="Qiu" count="1"></Condition>
|
<Condition type="Distance" value="5" targetPos="0,0,0" ignoreY="false"></Condition>
|
||||||
</Condition>
|
</Condition>
|
||||||
</Transision>
|
</Transision>
|
||||||
</FSM>
|
</FSM>
|
||||||
|
|||||||
@ -176,6 +176,11 @@
|
|||||||
|
|
||||||
<!--身上是否存有某个道具 count默认为1 可以判断数量 如:身上有某个道具20个-->
|
<!--身上是否存有某个道具 count默认为1 可以判断数量 如:身上有某个道具20个-->
|
||||||
<Condition type="HasDevice" deviceName="道具名" count="1"></Condition>
|
<Condition type="HasDevice" deviceName="道具名" count="1"></Condition>
|
||||||
|
|
||||||
|
<!--判断是否距离某个点 在某个范围内 ignoreY 是否忽略Y方向的距离-->
|
||||||
|
<Condition type="Distance" value="10" targetPos="0,0,0" ignoreY="false"></Condition>
|
||||||
|
|
||||||
|
|
||||||
<!--画线 途径点使用|分割 lineScale 可以调整x轴向和y轴线上的线的粗细-->
|
<!--画线 途径点使用|分割 lineScale 可以调整x轴向和y轴线上的线的粗细-->
|
||||||
<Action type="Line" name="红线" value="-4.030808,2.689521,-1.768913|-3.759371,2.694512,-1.247592" color="255,0,0,255" width="0.05" lineScale="10,0.5"></Action>
|
<Action type="Line" name="红线" value="-4.030808,2.689521,-1.768913|-3.759371,2.694512,-1.247592" color="255,0,0,255" width="0.05" lineScale="10,0.5"></Action>
|
||||||
<!--相机锁定 是否可以移动 isMove 是否可以旋转镜头 isRotate-->
|
<!--相机锁定 是否可以移动 isMove 是否可以旋转镜头 isRotate-->
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user