Unity/TopdownEngine

특정 Ability On/Off 하기

lipnus 2023. 1. 28. 18:52
반응형

저거에 따라서 기능을 On/Off 할 수 있다

 

Item을 통해 Ability을 켜고 끌 수 있다 (Colonel Demo)

 

줍줍

 

PickableAbility.cs

protected override void Pick(GameObject picker)
{
    if (_character == null)
    {
        return;
    }
    bool newState = (Method == Methods.Permit);
    CharacterAbility ability = _character.FindAbilityByString(AbilityTypeAsString);
    if (ability != null)
    {
        ability.PermitAbility(newState);
    }
}
ability.PermitAbility(newState);

 

 

각 Ability는 CharacterAbility를 상속함.

 

AbilityPermitted 와 추가 조건들을 더해서 AbilityAuthorized 변수가 Ability의 발현 여부를 결정

 

CharacterAbility.cs

public virtual void PermitAbility(bool abilityPermitted)
{
   AbilityPermitted = abilityPermitted;
}
public virtual bool AbilityAuthorized
{
    get
    {
        if (_character != null)
        {
            if ((BlockingMovementStates != null) && (BlockingMovementStates.Length > 0))
            {
                for (int i = 0; i < BlockingMovementStates.Length; i++)
                {
                    if (BlockingMovementStates[i] == (_character.MovementState.CurrentState))
                    {
                        return false;
                    }    
                }
            }

            if ((BlockingConditionStates != null) && (BlockingConditionStates.Length > 0))
            {
                for (int i = 0; i < BlockingConditionStates.Length; i++)
                {
                    if (BlockingConditionStates[i] == (_character.ConditionState.CurrentState))
                    {
                        return false;
                    }    
                }
            }
        }
        return AbilityPermitted;
    }
}

AbilityAuthorized

 

CharacterDash3D.cs

protected override void HandleInput()
{
    base.HandleInput();
    if (!AbilityAuthorized
        || (!Cooldown.Ready())
        || (_condition.CurrentState != CharacterStates.CharacterConditions.Normal))
    {
        return;
    }

    if (!AllowDashWhenJumping && (_movement.CurrentState == CharacterStates.MovementStates.Jumping))
    {
        return;
    }

    if (_inputManager.DashButton.State.CurrentState == MMInput.ButtonStates.ButtonDown)
    {
        DashStart();
    }
}

AbilityAuthorized

반응형