コード例 #1
0
    public void Execute(Player player)
    {
        textSS.enabled = false;
        IdlePlayerState idleState = new IdlePlayerState();

        idleState.Enter(player);
    }
コード例 #2
0
 public void Execute(Player player)
 {
     if (Physics2D.Raycast(rbPlayer.transform.position, Vector2.down, 0.5f))
     {
         IdlePlayerState idleState = new IdlePlayerState();
         idleState.Enter(player);
     }
 }
コード例 #3
0
        public void Awake()
        {
            distToGround = GetComponent <BoxCollider2D>().bounds.extents.y;
            //Debug.Log("Awake start");
            _stateMachine = new StateMachine();

            var idle     = new IdlePlayerState(this, _rigidbody2D);
            var move     = new MovePlayerState(this, _rigidbody2D, _animator);
            var attack   = new AttackPlayerState(this, _animator);
            var jump     = new JumpPlayerState(this, _rigidbody2D, _animator);
            var airborne = new AirbornePlayerState(this, _rigidbody2D, _animator);
            var death    = new DeathPlayerState(this);

            At(idle, move, isMoving());
            At(move, idle, isIdle());

            At(idle, jump, isJumping());
            At(move, jump, isJumping());

            At(jump, airborne, isJumping());

            At(airborne, idle, isGrounded());
            At(airborne, move, isGrounded());

            At(idle, attack, isAttacking());
            At(jump, attack, isAttacking());
            At(airborne, attack, isAttacking());
            At(move, attack, isAttacking());

            At(attack, idle, isIdle());
            At(attack, move, isMoving());
            At(attack, airborne, isAirborne());

            At(idle, death, isDead());
            At(jump, death, isDead());
            At(airborne, death, isDead());
            At(move, death, isDead());

            At(death, idle, isAlive());

            Func <bool> isIdle() => () => MoveVal == 0 && Physics2D.Raycast(transform.position, Vector2.down, distToGround + 0.05f, _jumpLayerMask);
            Func <bool> isMoving() => () => MoveVal != 0 && !Jumped && Physics2D.Raycast(transform.position, Vector2.down, distToGround + 0.05f, _jumpLayerMask);
            Func <bool> isJumping() => () => Jumped;
            Func <bool> isGrounded() => () => Physics2D.Raycast(transform.position, Vector2.down, distToGround + 0.05f, _jumpLayerMask);
            Func <bool> isAirborne() => () => !Physics2D.Raycast(transform.position, Vector2.down, distToGround + 0.05f, _jumpLayerMask);
            Func <bool> isAttacking() => () => Attacked;
            Func <bool> isDead() => () => health <= 0;
            Func <bool> isAlive() => () => health > 0;

            void At(IState from, IState to, Func <bool> condition) => _stateMachine.AddTransition(from, to, condition);

            //Debug.Log("Awake end");

            _stateMachine.SetState(idle);
        }
コード例 #4
0
    public void Execute(Player player)
    {
        IdlePlayerState idleState = new IdlePlayerState();

        idleState.Enter(player);
    }
コード例 #5
0
        protected override void link()
        {
            base.link();

            var controlsType = this.PlayerId.GetPlayerKeyedType(typeof(PlayerControls <>));

            playerControls = Scope.ServiceProvider.GetService(controlsType) as PlayerControls;

            rigidBody = Owner.getElement(RigidBodyName) as RigidBody;
            if (rigidBody == null)
            {
                blacklist("Cannot find player rigid body '{0}'", RigidBodyName);
            }

            node = Owner.getElement(NodeName) as SceneNodeElement;
            if (node == null)
            {
                blacklist("Cannot find player node '{0}'");
            }
            entity = node.getNodeObject(EntityName) as Entity;
            if (entity == null)
            {
                blacklist("Cannot find entity '{0}' on node '{1}'", EntityName, NodeName);
            }

            runBase = entity.getAnimationState(RunBaseAnimationName);
            if (runBase == null)
            {
                blacklist("Cannot find animation for run base '{0}' on entity '{1}'", RunBaseAnimationName, EntityName);
            }

            runTop = entity.getAnimationState(RunTopAnimationName);
            if (runTop == null)
            {
                blacklist("Cannot find animation for run top '{0}' on entity '{1}'", RunTopAnimationName, EntityName);
            }

            idleBase = entity.getAnimationState(IdleBaseAnimationName);
            if (idleBase == null)
            {
                blacklist("Cannot find animation for idle base '{0}' on entity '{1}'", IdleBaseAnimationName, EntityName);
            }

            idleTop = entity.getAnimationState(IdleTopAnimationName);
            if (idleTop == null)
            {
                blacklist("Cannot find animation for idle top '{0}' on entity '{1}'", IdleTopAnimationName, EntityName);
            }

            jumpStart = entity.getAnimationState(JumpStartAnimationName);
            if (jumpStart == null)
            {
                blacklist("Cannot find animation for jump start '{0}' on entity '{1}'", JumpStartAnimationName, EntityName);
            }

            jumpLoop = entity.getAnimationState(JumpLoopAnimationName);
            if (jumpLoop == null)
            {
                blacklist("Cannot find animation for jump loop '{0}' on entity '{1}'", JumpLoopAnimationName, EntityName);
            }

            jumpEnd = entity.getAnimationState(JumpLoopAnimationName);
            if (jumpEnd == null)
            {
                blacklist("Cannot find animation for jump end '{0}' on entity '{1}'", JumpEndAnimationName, EntityName);
            }

            groundRayCenter = new ClosestRayResultCallback(Owner.Translation, Owner.Translation + Vector3.Down);
            groundRayCenter.CollisionFilterMask = ~2;

            groundRayFront = new ClosestRayResultCallback(Owner.Translation + frontRearRayOffset, Owner.Translation + Vector3.Down);
            groundRayFront.CollisionFilterMask = ~2;

            groundRayRear = new ClosestRayResultCallback(Owner.Translation - frontRearRayOffset, Owner.Translation + Vector3.Down);
            groundRayRear.CollisionFilterMask = ~2;

            rigidBody.Scene.Tick += Scene_Tick;

            runningState = new RunningPlayerState();
            runningState.link(this);

            idleState = new IdlePlayerState();
            idleState.link(this);

            jumpUpState = new JumpUpPlayerState();
            jumpUpState.link(this);

            fallingState = new FallingPlayerState();
            fallingState.link(this);

            CurrentState = idleState;

            addToDebugDrawing();
        }