コード例 #1
0
 public void Start()
 {
     energyGauge = GetComponentsInChildren <TextMeshProUGUI>()[1];
     if (GameObject.FindGameObjectWithTag(Tags.PLAYER).GetComponentInChildren <JetpackState>() == null)
     {
         this.enabled = false;
         Debug.LogWarning("No jetpack found");
     }
     else
     {
         jetpack = GameObject.FindGameObjectWithTag(Tags.PLAYER).GetComponentInChildren <JetpackState>();
     }
 }
コード例 #2
0
        public void Awake()
        {
            sprite       = GetComponent <SpriteRenderer>();
            actorPhysics = GetComponent <IActorPhysics>();
            if (!animator)
            {
                animator = GetComponent <Animator>();
                if (!animator)
                {
                    Debug.LogWarning("No animator found for " + gameObject.name);
                }
            }

            actionStateLookup   = new Dictionary <ActionStateType, IActionState>();
            movementStateLookup = new Dictionary <MovementStateType, IMovementState>();

            if (!standingState)
            {
                standingState = GetComponentInChildren <StandingState>();
            }
            if (standingState)
            {
                standingState.SetActor(this);
                movementStateLookup.Add(MovementStateType.STANDING, standingState);
            }

            if (!duckingState)
            {
                duckingState = GetComponentInChildren <KneelingState>();
            }
            if (duckingState)
            {
                duckingState.SetActor(this);
                movementStateLookup.Add(MovementStateType.KNEELING, duckingState);
            }

            if (!walkingState)
            {
                walkingState = GetComponentInChildren <WalkingState>();
            }
            if (walkingState)
            {
                walkingState.SetActor(this);
                movementStateLookup.Add(MovementStateType.WALKING, walkingState);
            }

            if (stairsState)
            {
                stairsState.SetActor(this);
                movementStateLookup.Add(MovementStateType.STAIRS, stairsState);
            }

            if (!airbornState)
            {
                airbornState = GetComponentInChildren <FallingState>();
            }
            if (airbornState)
            {
                airbornState.SetActor(this);
                movementStateLookup.Add(MovementStateType.FALLING, airbornState);
            }

            if (!jetpackState)
            {
                jetpackState = GetComponentInChildren <JetpackState>();
            }
            if (jetpackState)
            {
                jetpackState.SetActor(this);
                movementStateLookup.Add(MovementStateType.JETPACK, jetpackState);
            }

            elevatorState = GetComponentInChildren <ElevatorState>();
            if (elevatorState)
            {
                elevatorState.SetActor(this);
                movementStateLookup.Add(MovementStateType.ELEVATOR, elevatorState);
                actionStateLookup.Add(ActionStateType.ELEVATOR, elevatorState);
            }



            NoActionState awaitingState = new NoActionState();

            awaitingState.SetActor(this);
            actionStateLookup.Add(ActionStateType.AWAITING_ACTION, awaitingState);

            if (!shootingState)
            {
                shootingState = GetComponentInChildren <ShootingState>();
            }
            if (shootingState)
            {
                shootingState.SetActor(this);
                actionStateLookup.Add(ActionStateType.SHOOT, shootingState);
            }

            currentMovementState = MovementStateType.FALLING;
            movementState        = airbornState;
            currentActionState   = ActionStateType.AWAITING_ACTION;
            actionState          = actionStateLookup[ActionStateType.AWAITING_ACTION];
        }