Esempio n. 1
0
        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();
            });
        }