-
-
Save todorok1/e634ab54eee88f407593dd41d855557e to your computer and use it in GitHub Desktop.
シンプルRPGチュートリアル第107回 キャラクターの移動を行うクラスの基底クラス
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /// <summary> | |
| /// 引数のアニメーションの方向から移動方向を取得します。 | |
| /// </summary> | |
| /// <param name="animDirection">アニメーションの方向</param> | |
| public virtual Vector2Int GetMoveDirection(MoveAnimationDirection animDirection) | |
| { | |
| var moveDirection = Vector2Int.zero; | |
| switch (animDirection) | |
| { | |
| case MoveAnimationDirection.Front: | |
| moveDirection = Vector2Int.down; | |
| break; | |
| case MoveAnimationDirection.Right: | |
| moveDirection = Vector2Int.right; | |
| break; | |
| case MoveAnimationDirection.Back: | |
| moveDirection = Vector2Int.up; | |
| break; | |
| case MoveAnimationDirection.Left: | |
| moveDirection = Vector2Int.left; | |
| break; | |
| } | |
| return moveDirection; | |
| } | |
| /// <summary> | |
| /// キャラクターを外部から移動させます。 | |
| /// </summary> | |
| /// <param name="moveDirection">移動方向</param> | |
| /// <param name="animDirection">アニメーションの方向</param> | |
| public virtual void ForceMoveCharacter(MoveAnimationDirection direction, int steps, bool checkPostMove, ICharacterMoveCallback moveCallback) | |
| { | |
| _moveCallback = moveCallback; | |
| StartCoroutine(ForceMoveCharacterProcess(direction, steps, checkPostMove)); | |
| } | |
| /// <summary> | |
| /// キャラクターを外部から移動させます。 | |
| /// </summary> | |
| /// <param name="direction">移動方向</param> | |
| /// <param name="steps">移動するステップ数</param> | |
| /// <param name="checkPostMove">移動後の処理を確認するかどうか</param> | |
| IEnumerator ForceMoveCharacterProcess(MoveAnimationDirection direction, int steps, bool checkPostMove) | |
| { | |
| _isCheckPostMove = checkPostMove; | |
| var moveDirection = GetMoveDirection(direction); | |
| for (int i = 0; i < steps; i++) | |
| { | |
| while (_isMoving) | |
| { | |
| // キャラクターが移動中の場合は待機します。 | |
| yield return null; | |
| } | |
| // キャラクターを移動させます。 | |
| _isMovingPaused = false; | |
| MoveCharacter(moveDirection, direction); | |
| } | |
| _isCheckPostMove = true; | |
| _isMovingPaused = true; | |
| if (_moveCallback != null) | |
| { | |
| _moveCallback.OnFinishedMove(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment