修改状态机bug
This commit is contained in:
parent
cbf6cde0b0
commit
378ebcde83
@ -254,27 +254,30 @@ public class ActionHelper
|
||||
/// <returns></returns>
|
||||
public static ICondition GetCondition(XMLTool.ActionItem condition)
|
||||
{
|
||||
switch (condition.Type)
|
||||
if (condition!=null)
|
||||
{
|
||||
case "And":
|
||||
case "Or":
|
||||
var group = ConditionGroup.Allocate(condition.Type);
|
||||
foreach (var item in condition.SubActions)
|
||||
{
|
||||
group.AddCondition(GetCondition(item));
|
||||
}
|
||||
return group;
|
||||
case "UIClick":
|
||||
return UIClickCondition.Allocate(condition.Value);
|
||||
case "ObjClick":
|
||||
var dict = (XMLTool.DictionaryCondition)condition;
|
||||
return ObjClickCondition.Allocate(dict.Value, dict.args);
|
||||
case "Input":
|
||||
return InputCondition.Allocate(condition.Value);
|
||||
case "Var":
|
||||
return VarCondition.Allocate(condition.Name, condition.Value);
|
||||
case "StrEvent":
|
||||
return StrEventCondition.Allocate(condition.Value);
|
||||
switch (condition.Type)
|
||||
{
|
||||
case "And":
|
||||
case "Or":
|
||||
var group = ConditionGroup.Allocate(condition.Type);
|
||||
foreach (var item in condition.SubActions)
|
||||
{
|
||||
group.AddCondition(GetCondition(item));
|
||||
}
|
||||
return group;
|
||||
case "UIClick":
|
||||
return UIClickCondition.Allocate(condition.Value);
|
||||
case "ObjClick":
|
||||
var dict = (XMLTool.DictionaryCondition)condition;
|
||||
return ObjClickCondition.Allocate(dict.Value, dict.args);
|
||||
case "Input":
|
||||
return InputCondition.Allocate(condition.Value);
|
||||
case "Var":
|
||||
return VarCondition.Allocate(condition.Name, condition.Value);
|
||||
case "StrEvent":
|
||||
return StrEventCondition.Allocate(condition.Value);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -48,31 +48,22 @@ public class StateMachineController : MonoSingleton<StateMachineController>
|
||||
{
|
||||
firstState = state.Key;
|
||||
}
|
||||
IAction enterAct = null;
|
||||
IAction exitAct = null;
|
||||
|
||||
|
||||
fsm.State(state.Key).OnEnter(() =>
|
||||
var vfState = new VfState();
|
||||
vfState.OnEnter(() =>
|
||||
{
|
||||
if (state.Value.Enter != null)
|
||||
{
|
||||
enterAct = ActionHelper.GetActionAndSub(state.Value.Enter.Action);
|
||||
enterAct?.Start(this);
|
||||
}
|
||||
|
||||
vfState.enterAct = ActionHelper.GetActionAndSub(state.Value.Enter?.Action);
|
||||
vfState.enterAct?.Start(this);
|
||||
}).OnExit(() =>
|
||||
{
|
||||
if (enterAct != null)
|
||||
if (vfState.enterAct != null)
|
||||
{
|
||||
enterAct.Deinit();
|
||||
vfState.enterAct.Deinit();
|
||||
}
|
||||
if (state.Value.Exit != null)
|
||||
{
|
||||
exitAct = ActionHelper.GetActionAndSub(state.Value.Exit.Action);
|
||||
exitAct?.Start(this);
|
||||
vfState.exitAct = ActionHelper.GetActionAndSub(state.Value.Exit?.Action);
|
||||
vfState.exitAct?.Start(this);
|
||||
|
||||
}
|
||||
});
|
||||
fsm.AddState(state.Key, vfState);
|
||||
}
|
||||
foreach (var transision in item.Value.Transisions)
|
||||
{
|
||||
@ -84,7 +75,7 @@ public class StateMachineController : MonoSingleton<StateMachineController>
|
||||
}
|
||||
fsmInfo.fsm = fsm;
|
||||
fsmInfo.fsm.StartState(firstState);
|
||||
if (FSMDitc.ContainsKey(item.Key)==false)
|
||||
if (FSMDitc.ContainsKey(item.Key) == false)
|
||||
{
|
||||
FSMDitc.Add(item.Key, fsmInfo);
|
||||
}
|
||||
@ -102,14 +93,19 @@ public class StateMachineController : MonoSingleton<StateMachineController>
|
||||
{
|
||||
foreach (var item in FSMDitc)
|
||||
{
|
||||
var curState = item.Value.fsm.CurrentStateId;
|
||||
foreach (var trans in item.Value.transisions)
|
||||
VfState state = item.Value.fsm.CurrentState as VfState;
|
||||
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
|
||||
guid: 6d7f9813c337725468c8739dba68c439
|
||||
guid: 8b474fbd8dd5f4c49b70b10f5328d67e
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
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;
|
||||
gameObject.GetComponent<SpriteRenderer>().sortingOrder = data.order;
|
||||
TypeEventSystem.Global.Register<OnPoint3DQuestionDestroy>(OnObjDestroy).UnRegisterWhenGameObjectDestroyed(gameObject);
|
||||
|
||||
}
|
||||
|
||||
@ -4,6 +4,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
using UnityEngine;
|
||||
using static UnityEngine.Rendering.DebugUI;
|
||||
namespace XMLTool
|
||||
{
|
||||
public class AppData
|
||||
@ -88,6 +89,7 @@ namespace XMLTool
|
||||
public Vector3 rotate;
|
||||
public Vector3 scale;
|
||||
public float rotateSpeed;
|
||||
public int order = 1;
|
||||
public string clickEvent;
|
||||
}
|
||||
public List<Data> datas = new List<Data>();
|
||||
@ -1093,6 +1095,12 @@ namespace XMLTool
|
||||
data.scale = Utility.GetVector3FromStrArray(item.Attribute("scale")?.Value);
|
||||
}
|
||||
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;
|
||||
act.datas.Add(data);
|
||||
}
|
||||
@ -1146,6 +1154,10 @@ namespace XMLTool
|
||||
|
||||
public static Condition ParseCondition(XElement action)
|
||||
{
|
||||
if (action == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
Condition newAction = null;
|
||||
string type = action.Attribute("type")?.Value;
|
||||
switch (type)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user