internal void OnTick(SimpleFSM fsm_, float dt_, ref bool isDone_, State TransitionTarget) { const string key = "State.OnTick"; Performance.RecordProfiler(key); if (!isDone_) { Log.Assert(_OnTick != null, "{0} invalid OnTick", this); isDone_ = _OnTick(fsm_.Token[_tokenOnTick], dt_); if (isDone_) { _OnTickDone?.Invoke(fsm_.Token[_tokenOnTickDone]); ExitIfDeadEnd(fsm_, true, TransitionTarget); } else { goto end; } } if (TransitionTarget._mode == StateTransitMode.Manual || fsm_.CurrentState != TransitionTarget) { //still ticking || never auto transit || external transition happend goto end; } TransitionTarget.CheckTransition(fsm_, isDone_); end: Performance.End(key); }
internal void OnExit(SimpleFSM fsm_) { const string key = "State.OnExit"; Performance.RecordProfiler(key); _OnExit?.Invoke(fsm_.Token[_tokenOnExit]); Performance.End(key); }
public bool TryTransit(SimpleFSM fsm_, bool isDone_) { bool ret = _Condition(fsm_.Token[_token], isDone_); if (ret) { fsm_.DoTransition(this); } return(ret); }
//give OnExit a change to execute, for dead-end states internal void ExitIfDeadEnd(SimpleFSM fsm_, bool isDone_, State TransitionTarget) { if (TransitionTarget._transitions.Count == 0 && TransitionTarget._mode != StateTransitMode.Manual && fsm_.CurrentState == TransitionTarget && isDone_) { OnExit(fsm_); } }
private void CheckTransition(SimpleFSM fsm_, bool isDone_) { foreach (var trans in _transitions) { if (trans.TryTransit(fsm_, isDone_)) { return; } } }
void Start() { //Tank Settings rotSpeed = 150.0f; //Get the turret of the tank Turret = gameObject.transform.GetChild(0).transform; bulletSpawnPoint = Turret.GetChild(0).transform; simpleFSM = FindObjectOfType <SimpleFSM>(); }
internal void OnEnter(SimpleFSM fsm_, bool isDone_, State TransitionTarget) { const string key = "State.OnEnter"; Performance.RecordProfiler(key); _OnEnter?.Invoke(fsm_.Token[_tokenOnEnter]); if (TransitionTarget._mode == StateTransitMode.Immediate) { TransitionTarget.CheckTransition(fsm_, isDone_); } Performance.End(key); }
// Use this for initialization public virtual void InitialiseAISkill(CharacterStatus status, int skillIndex) { Debug.Log("initialising ai skill"); usageCount = 0; ownerStatus = status; ownerManager = status.actionManager; ownerFSM = (SimpleFSM)ownerManager; ownerTransform = status._myTransform; ownerAnimation = ownerFSM.myAnimation; skillID = skillIndex; SetupAnimations(); BasicSetup(); }
void reInit() { switch (ironGateType) { case IronGateType.Center: openAnimName = "attack"; closeAnimName = "attack2"; break; case IronGateType.Left: case IronGateType.Right: openAnimName = "attack-"; closeAnimName = "attack-2"; break; default: Debug.LogError("没有门类型" + ironGateType); break; } skeletonAnimation.state.SetAnimation(0, openAnimName, false); // 初始化状态机 add by TangJian 2017/10/31 15:20:33 fsm = new SimpleFSM(); state = "open"; fsm.SetState("opened"); fsm.AddEvent("opened", "closed", () => { return(state == "close"); }, () => { skeletonAnimation.state.SetAnimation(0, closeAnimName, false); }); fsm.AddEvent("closed", "opened", () => { return(state == "open"); }, () => { skeletonAnimation.state.SetAnimation(0, openAnimName, false); }); fsm.Begin(); }
private void Start() { fsm = this.GetComponent <SimpleFSM>(); fsm.isPatrol = true; //将此敌人添加到敌人列表中 EnemyManager.enemyList.Add(gameObject); //设置Z轴(Zspread用于保持敌人之间的空间) ZSpread = (EnemyManager.enemyList.Count - 1); Invoke("SetZSpread", .1f); //随机化值以避免同步移动 if (randomizeValues) { SetRandomValues(); } OnStart(); }
void OnEnable() { bot = target as SimpleFSM; }
protected override void Awake() { base.Awake(); _fsm = new SimpleFSM <States>(this); }
// Use this for initialization void Start() { simpleFSM = gameObject.transform.parent.GetComponent <SimpleFSM> (); }
void init() { // 初始化Collider add by TangJian 2017/10/31 15:20:16 gameObject.GetChild("Collider").Recursive((GameObject go, int depth) => { if (go.name == "Body") { body = go.GetComponent <Collider>(); } else if (go.name == "StandGround") { standGround = go.GetComponent <Collider>(); } }, 2, 4); // 初始化动画 add by TangJian 2017/10/31 15:20:25 skeletonAnimation = GetComponentInChildren <SkeletonAnimation>(); switch (ironGateType) { case IronGateType.Center: openAnimName = "attack"; closeAnimName = "attack2"; break; case IronGateType.Left: case IronGateType.Right: openAnimName = "attack-"; closeAnimName = "attack-2"; break; default: Debug.LogError("没有门类型" + ironGateType); break; } skeletonAnimation.state.Complete += (TrackEntry trackEntry) => { if (trackEntry.Animation.Name == openAnimName) { body.enabled = true; } else if (trackEntry.Animation.Name == closeAnimName) { body.enabled = false; } }; skeletonAnimation.state.SetAnimation(0, openAnimName, false); // 初始化状态机 add by TangJian 2017/10/31 15:20:33 fsm = new SimpleFSM(); state = "open"; fsm.SetState("opened"); fsm.AddEvent("opened", "closed", () => { return(state == "close"); }, () => { skeletonAnimation.state.SetAnimation(0, closeAnimName, false); }); fsm.AddEvent("closed", "opened", () => { return(state == "open"); }, () => { skeletonAnimation.state.SetAnimation(0, openAnimName, false); }); fsm.Begin(); ironGateTypeMonitor = new ValueMonitor <IronGateType>(() => { return(ironGateType); }, (IronGateType from, IronGateType to) => { reInit(); }); }