본문 바로가기
유니티/코기엔진

2-3. Character Ability Class (코기엔진)

by 메타버스월드 2021. 1. 30.
반응형

- CharacterAbility.cs

이 클래스를 확장함으로써 게임에서 필요한 새로운 능력을 만들 수 있습니다.

 

  • Initialization: 이름에서 알 수 있듯이 기본 클래스는 캐릭터 또는 씬의 일부를 가져와 아이들의 능력에 정기적으로 유용합니다. 카메라, CorgiController 구성 요소, 입력 관리자 등과 같은 것. 자식 능력은 일반적으로 추가 구성 요소를 가져 오거나 변수 (점프 수 등)를 초기화하는 데 이것을 사용합니다.
  • Animation methods : InitializeAnimatorParameters 및 UpdateAnimator : 첫 번째를 사용하여 애니메이션 매개 변수를 등록하고 두 번째를 사용하여 업데이트합니다. 이는 성능 문제를 야기하는 모든 프레임의 각 매개 변수의 존재를 확인하지 않도록 두 단계로 수행됩니다.
  • HandleInput : 관련 버튼 및 축의 상태를 확인하는 각 기능으로 재정의됩니다. 특정 버튼을 눌렀다 놓으면이 메서드는 능력의 다른 메서드를 호출합니다.
  • Early / Process / Late Process 능력 : 이러한 메서드는 각 업데이트에서 상태 머신에 의해 호출됩니다.
  • Reset : 캐릭터가 죽으면이 메서드가 호출됩니다. 카운터 등을 재설정하는 데 유용합니다.
  • Sfx 재생 / 중지 : 능력 소리를 트리거하는 데 사용되는 방법입니다. 기본적으로 각 능력에는 3 개의 소리가 있습니다 (검사자의 능력에 따라 정의 됨) : 시작시, 사용 중, 중지시 하나씩. 물론 이들 중 하나만 사용하거나 사용하지 않을 수 있습니다. 자신 만의 능력을 만드는 경우 이러한 메서드를 호출하여 사운드를 트리거해야합니다.

 

 

이 클래스를 확장하려면 아래 코드를 복사해서 사용하세요.

using UnityEngine;
using System.Collections;
using MoreMountains.Tools;

namespace MoreMountains.CorgiEngine // you might want to use your own namespace here
{
    /// <summary>
    /// TODO_DESCRIPTION
    /// </summary>
    [AddComponentMenu("Corgi Engine/Character/Abilities/TODO_REPLACE_WITH_ABILITY_NAME")]
    public class TODO_NEW_ABILITY_NAME : CharacterAbility
    {
        /// This method is only used to display a helpbox text
        /// at the beginning of the ability's inspector
        public override string HelpBoxText() { return "TODO_HELPBOX_TEXT."; }

        [Header("TODO_HEADER")]
        /// declare your parameters here
        public float randomParameter = 4f;
        public bool randomBool;

        // Animation parameters
        protected const string _todoParameterName = "TODO";
        protected int _todoAnimationParameter;

        /// <summary>
        /// Here you should initialize our parameters
        /// </summary>
        protected override void Initialization()
        {
            base.Initialization();
            randomBool = false;
        }

        /// <summary>
        /// Every frame, we check if we're crouched and if we still should be
        /// </summary>
        public override void ProcessAbility()
        {
            base.ProcessAbility();
        }

        /// <summary>
        /// Called at the start of the ability's cycle, this is where you'll check for input
        /// </summary>
        protected override void HandleInput()
        {
            // here as an example we check if we're pressing down
            // on our main stick/direction pad/keyboard
            if (_inputManager.PrimaryMovement.y < -_inputManager.Threshold.y)
            {
                DoSomething();
            }
        }

        /// <summary>
        /// If we're pressing down, we check for a few conditions to see if we can perform our action
        /// </summary>
        protected virtual void DoSomething()
        {
            // if the ability is not permitted
            if (!AbilityPermitted
                // or if we're not in our normal stance
                || (_condition.CurrentState != CharacterStates.CharacterConditions.Normal)
                // or if we're grounded
                || (!_controller.State.IsGrounded)
                // or if we're gripping
                || (_movement.CurrentState == CharacterStates.MovementStates.Gripping))
            {
                // we do nothing and exit
                return;
            }

            // if we're still here, we display a text log in the console
            MMDebug.DebugLogTime("We're doing something yay!");
        }

        /// <summary>
        /// Adds required animator parameters to the animator parameters list if they exist
        /// </summary>
        protected override void InitializeAnimatorParameters()
        {
            RegisterAnimatorParameter(_todoParameterName, AnimatorControllerParameterType.Bool, out _todoAnimationParameter);
        }

        /// <summary>
        /// At the end of the ability's cycle,
        /// we send our current crouching and crawling states to the animator
        /// </summary>
        public override void UpdateAnimator()
        {
            MMAnimatorExtensions.UpdateAnimatorBool(_animator, _todoAnimationParameter, (_movement.CurrentState == CharacterStates.MovementStates.Crouching), _character._animatorParameters);
        }
    }
}

 

 

 

 

반응형

댓글