修改状态机bug
This commit is contained in:
parent
cbf6cde0b0
commit
378ebcde83
@ -254,27 +254,30 @@ public class ActionHelper
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static ICondition GetCondition(XMLTool.ActionItem condition)
|
public static ICondition GetCondition(XMLTool.ActionItem condition)
|
||||||
{
|
{
|
||||||
switch (condition.Type)
|
if (condition!=null)
|
||||||
{
|
{
|
||||||
case "And":
|
switch (condition.Type)
|
||||||
case "Or":
|
{
|
||||||
var group = ConditionGroup.Allocate(condition.Type);
|
case "And":
|
||||||
foreach (var item in condition.SubActions)
|
case "Or":
|
||||||
{
|
var group = ConditionGroup.Allocate(condition.Type);
|
||||||
group.AddCondition(GetCondition(item));
|
foreach (var item in condition.SubActions)
|
||||||
}
|
{
|
||||||
return group;
|
group.AddCondition(GetCondition(item));
|
||||||
case "UIClick":
|
}
|
||||||
return UIClickCondition.Allocate(condition.Value);
|
return group;
|
||||||
case "ObjClick":
|
case "UIClick":
|
||||||
var dict = (XMLTool.DictionaryCondition)condition;
|
return UIClickCondition.Allocate(condition.Value);
|
||||||
return ObjClickCondition.Allocate(dict.Value, dict.args);
|
case "ObjClick":
|
||||||
case "Input":
|
var dict = (XMLTool.DictionaryCondition)condition;
|
||||||
return InputCondition.Allocate(condition.Value);
|
return ObjClickCondition.Allocate(dict.Value, dict.args);
|
||||||
case "Var":
|
case "Input":
|
||||||
return VarCondition.Allocate(condition.Name, condition.Value);
|
return InputCondition.Allocate(condition.Value);
|
||||||
case "StrEvent":
|
case "Var":
|
||||||
return StrEventCondition.Allocate(condition.Value);
|
return VarCondition.Allocate(condition.Name, condition.Value);
|
||||||
|
case "StrEvent":
|
||||||
|
return StrEventCondition.Allocate(condition.Value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -48,31 +48,22 @@ public class StateMachineController : MonoSingleton<StateMachineController>
|
|||||||
{
|
{
|
||||||
firstState = state.Key;
|
firstState = state.Key;
|
||||||
}
|
}
|
||||||
IAction enterAct = null;
|
var vfState = new VfState();
|
||||||
IAction exitAct = null;
|
vfState.OnEnter(() =>
|
||||||
|
|
||||||
|
|
||||||
fsm.State(state.Key).OnEnter(() =>
|
|
||||||
{
|
{
|
||||||
if (state.Value.Enter != null)
|
vfState.enterAct = ActionHelper.GetActionAndSub(state.Value.Enter?.Action);
|
||||||
{
|
vfState.enterAct?.Start(this);
|
||||||
enterAct = ActionHelper.GetActionAndSub(state.Value.Enter.Action);
|
|
||||||
enterAct?.Start(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
}).OnExit(() =>
|
}).OnExit(() =>
|
||||||
{
|
{
|
||||||
if (enterAct != null)
|
if (vfState.enterAct != null)
|
||||||
{
|
{
|
||||||
enterAct.Deinit();
|
vfState.enterAct.Deinit();
|
||||||
}
|
}
|
||||||
if (state.Value.Exit != null)
|
vfState.exitAct = ActionHelper.GetActionAndSub(state.Value.Exit?.Action);
|
||||||
{
|
vfState.exitAct?.Start(this);
|
||||||
exitAct = ActionHelper.GetActionAndSub(state.Value.Exit.Action);
|
|
||||||
exitAct?.Start(this);
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
fsm.AddState(state.Key, vfState);
|
||||||
}
|
}
|
||||||
foreach (var transision in item.Value.Transisions)
|
foreach (var transision in item.Value.Transisions)
|
||||||
{
|
{
|
||||||
@ -84,7 +75,7 @@ public class StateMachineController : MonoSingleton<StateMachineController>
|
|||||||
}
|
}
|
||||||
fsmInfo.fsm = fsm;
|
fsmInfo.fsm = fsm;
|
||||||
fsmInfo.fsm.StartState(firstState);
|
fsmInfo.fsm.StartState(firstState);
|
||||||
if (FSMDitc.ContainsKey(item.Key)==false)
|
if (FSMDitc.ContainsKey(item.Key) == false)
|
||||||
{
|
{
|
||||||
FSMDitc.Add(item.Key, fsmInfo);
|
FSMDitc.Add(item.Key, fsmInfo);
|
||||||
}
|
}
|
||||||
@ -102,14 +93,19 @@ public class StateMachineController : MonoSingleton<StateMachineController>
|
|||||||
{
|
{
|
||||||
foreach (var item in FSMDitc)
|
foreach (var item in FSMDitc)
|
||||||
{
|
{
|
||||||
var curState = item.Value.fsm.CurrentStateId;
|
VfState state = item.Value.fsm.CurrentState as VfState;
|
||||||
foreach (var trans in item.Value.transisions)
|
if (state.enterAct == null || state.enterAct.Status == ActionStatus.Finished)
|
||||||
{
|
{
|
||||||
if (trans.from == "any" || trans.from == item.Value.fsm.CurrentStateId)
|
foreach (var trans in item.Value.transisions)
|
||||||
{
|
{
|
||||||
if (trans.condition.Check())
|
if ((trans.from == "any" && trans.to != item.Value.fsm.CurrentStateId) || trans.from == item.Value.fsm.CurrentStateId)
|
||||||
{
|
{
|
||||||
item.Value.fsm.ChangeState(trans.to);
|
if (trans.condition == null || trans.condition.Check())
|
||||||
|
{
|
||||||
|
Debug.LogError(trans.from + "To:" + trans.to);
|
||||||
|
item.Value.fsm.ChangeState(trans.to);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: 6d7f9813c337725468c8739dba68c439
|
guid: 8b474fbd8dd5f4c49b70b10f5328d67e
|
||||||
folderAsset: yes
|
folderAsset: yes
|
||||||
DefaultImporter:
|
DefaultImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
8
Assets/Scripts/FSM/CustomState.meta
Normal file
8
Assets/Scripts/FSM/CustomState.meta
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 5feaaac014488434681db44e2face542
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
14
Assets/Scripts/FSM/CustomState/VfState.cs
Normal file
14
Assets/Scripts/FSM/CustomState/VfState.cs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
using QFramework;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
public class VfState : CustomState
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
public IAction enterAct = null;
|
||||||
|
public IAction exitAct = null;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
11
Assets/Scripts/FSM/CustomState/VfState.cs.meta
Normal file
11
Assets/Scripts/FSM/CustomState/VfState.cs.meta
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 0a5f77690765e1f44b3f3ac7783076fc
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -35,6 +35,7 @@ public class Point3DItem : MonoBehaviour
|
|||||||
|
|
||||||
}
|
}
|
||||||
rotSpeed = data.rotateSpeed;
|
rotSpeed = data.rotateSpeed;
|
||||||
|
gameObject.GetComponent<SpriteRenderer>().sortingOrder = data.order;
|
||||||
TypeEventSystem.Global.Register<OnPoint3DQuestionDestroy>(OnObjDestroy).UnRegisterWhenGameObjectDestroyed(gameObject);
|
TypeEventSystem.Global.Register<OnPoint3DQuestionDestroy>(OnObjDestroy).UnRegisterWhenGameObjectDestroyed(gameObject);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,6 +4,7 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Xml.Linq;
|
using System.Xml.Linq;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using static UnityEngine.Rendering.DebugUI;
|
||||||
namespace XMLTool
|
namespace XMLTool
|
||||||
{
|
{
|
||||||
public class AppData
|
public class AppData
|
||||||
@ -88,6 +89,7 @@ namespace XMLTool
|
|||||||
public Vector3 rotate;
|
public Vector3 rotate;
|
||||||
public Vector3 scale;
|
public Vector3 scale;
|
||||||
public float rotateSpeed;
|
public float rotateSpeed;
|
||||||
|
public int order = 1;
|
||||||
public string clickEvent;
|
public string clickEvent;
|
||||||
}
|
}
|
||||||
public List<Data> datas = new List<Data>();
|
public List<Data> datas = new List<Data>();
|
||||||
@ -1093,6 +1095,12 @@ namespace XMLTool
|
|||||||
data.scale = Utility.GetVector3FromStrArray(item.Attribute("scale")?.Value);
|
data.scale = Utility.GetVector3FromStrArray(item.Attribute("scale")?.Value);
|
||||||
}
|
}
|
||||||
float.TryParse(item.Attribute("rotateSpeed")?.Value, out data.rotateSpeed);
|
float.TryParse(item.Attribute("rotateSpeed")?.Value, out data.rotateSpeed);
|
||||||
|
var order = item.Attribute("order");
|
||||||
|
if (order != null)
|
||||||
|
{
|
||||||
|
int.TryParse(order.Value, out data.order);
|
||||||
|
}
|
||||||
|
|
||||||
data.clickEvent = item.Attribute("clickEvent")?.Value;
|
data.clickEvent = item.Attribute("clickEvent")?.Value;
|
||||||
act.datas.Add(data);
|
act.datas.Add(data);
|
||||||
}
|
}
|
||||||
@ -1146,6 +1154,10 @@ namespace XMLTool
|
|||||||
|
|
||||||
public static Condition ParseCondition(XElement action)
|
public static Condition ParseCondition(XElement action)
|
||||||
{
|
{
|
||||||
|
if (action == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
Condition newAction = null;
|
Condition newAction = null;
|
||||||
string type = action.Attribute("type")?.Value;
|
string type = action.Attribute("type")?.Value;
|
||||||
switch (type)
|
switch (type)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user