Ejemplo n.º 1
0
    private static string GenerateCharacterSpriteFullIdentifier(string spriteName,
                                                                string stateIdentifier,
                                                                GameCharacterController.FacingDirection direction,
                                                                int index = -1)
    {
        string directionIdentifier;

        switch (direction)
        {
        case GameCharacterController.FacingDirection.Down:
            directionIdentifier = "d";
            break;

        case GameCharacterController.FacingDirection.Left:
            directionIdentifier = "l";
            break;

        case GameCharacterController.FacingDirection.Up:
            directionIdentifier = "u";
            break;

        default:
            Debug.LogWarning($"Invalid direction facing ({direction})");
            directionIdentifier = "l";
            break;
        }

        return(spriteName + '_' + stateIdentifier + '_' + directionIdentifier + (index == -1 ? "" : '_' + index.ToString()));
    }
Ejemplo n.º 2
0
        /// <summary>
        /// Get the position one step in a direction from another position
        /// </summary>
        public static Vector2Int GetPositionInDirection(Vector2Int startPosition, GameCharacterController.FacingDirection direction)
        {
            Vector2Int offset;

            switch (direction)
            {
            case GameCharacterController.FacingDirection.Up:
                offset = Vector2Int.up;
                break;

            case GameCharacterController.FacingDirection.Down:
                offset = -Vector2Int.up;
                break;

            case GameCharacterController.FacingDirection.Left:
                offset = -Vector2Int.right;
                break;

            case GameCharacterController.FacingDirection.Right:
                offset = Vector2Int.right;
                break;

            default:
                Debug.LogWarning($"Invalid directionFacing was found ({direction})");
                offset = Vector2Int.up;
                break;
            }

            return(startPosition + offset);
        }
Ejemplo n.º 3
0
    /// <summary>
    /// Gets a sprite referenced by a state identifier and a FacingDirection direction. The full identifier will then be formed from these parameters
    /// </summary>
    /// /// <param name="flipSprite">Whether the sprite should be flipped once returned</param>
    /// <param name="spriteName">The name of the sprite</param>
    /// <param name="stateIdentifier">The name of the state that is being requested (eg. "neutral")</param>
    /// <param name="direction">The direction of sprite to request</param>
    /// <param name="index">The index of the sprite to request</param>
    /// <returns>The sprite as specified if found, otherwise null</returns>
    public static Sprite GetCharacterSprite(out bool flipSprite,
                                            string spriteName,
                                            string stateIdentifier,
                                            GameCharacterController.FacingDirection direction,
                                            int index = -1)
    {
        string identifier = GenerateCharacterSpriteFullIdentifier(spriteName,
                                                                  stateIdentifier,
                                                                  direction == GameCharacterController.FacingDirection.Right ? GameCharacterController.FacingDirection.Left : direction,
                                                                  index);

        flipSprite = direction == GameCharacterController.FacingDirection.Right;

        return(GetSprite(SpriteType.Character,
                         identifier));
    }
Ejemplo n.º 4
0
        /// <summary>
        /// Gets the positions in a direction from provided position
        /// </summary>
        public static Vector2Int[] GetPositionsInDirection(Vector2Int startPosition, GameCharacterController.FacingDirection direction, ushort count)
        {
            if (count == 0)
            {
                return(new Vector2Int[0]);
            }

            Vector2Int[] positions = new Vector2Int[count];

            positions[0] = GetPositionInDirection(startPosition, direction);

            for (int i = 1; i < count; i++)
            {
                positions[i] = GetPositionInDirection(positions[i - 1], direction);
            }

            return(positions);
        }