onEnter, onExit

Scene的 onEnter事件,也同时激活 他的layer的onEnter

Scene的 onExit事件,也同时激活 他的layer的onExit


如果layer的 onEnter和onExit重写的时候,没有调用 this._super(); 则界面能显示,但是点击按钮没反应了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
public interface IState { void Enter(); void Update(); void Exit(); } public class State<T> where T : IState { public delegate void StateAction(T state); public StateAction OnEnter; public StateAction OnUpdate; public StateAction OnExit; public void Enter(T state) { if (OnEnter != null) { OnEnter(state); } } public void Update(T state) { if (OnUpdate != null) { OnUpdate(state); } } public void Exit(T state) { if (OnExit != null) { OnExit(state); } } } public class IdleState : IState { public void Enter() { // Do idle behavior } public void Update() { // Do idle behavior } public void Exit() { // Do idle behavior } } public class WalkingState : IState { public void Enter() { // Do walking behavior } public void Update() { // Do walking behavior } public void Exit() { // Do walking behavior } } public class RunningState : IState { public void Enter() { // Do running behavior } public void Update() { // Do running behavior } public void Exit() { // Do running behavior } } public class StateMachine<T> where T : IState { private Stack<State<T>> stateStack = new Stack<State<T>>(); private T currentState; public void PushState(State<T> newState) { if (currentState != null) { currentState.Exit(); } stateStack.Push(newState); currentState = newState; currentState.Enter(currentState); } public void PopState() { if (stateStack.Count > 0) { currentState.Exit(); stateStack.Pop(); currentState = stateStack.Count > 0 ? stateStack.Peek() : null; if (currentState != null) { currentState.Enter(currentState); } } } public void Update() { if (currentState != null) { currentState.Update(currentState); } } }如何使用,请给出示例代码
最新发布
03-11

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值