Encounter / Assets / Scripts / GUIHandlers / IconHandler.cs
IconHandler.cs
Raw
using System;
using UnityEngine;
using UnityEngine.UI;

/// <summary>
/// Handles the positioning and orientation of the icons in the party member GUIs
/// </summary>
public class IconHandler : MonoBehaviour
{
    public void HandleOrientation()
    {
        Sprite spriteInImage = GetComponent<Image>().sprite;
        RectTransform rectT = GetComponent<RectTransform>();
        // Some sprite icons need to be scaled or move around logically for them to look proper
        switch (spriteInImage.name)
        {
            case "AirGolemHeadShot":
                // Nothing needed
                break;
            case "FireGolemHeadShot":
                // Nothing needed
                break;
            case "IceGolemHeadShot":
                // Move the icon slightly down
                rectT.offsetMin = new Vector2(0f, -5f);
                rectT.offsetMax = new Vector2(0f, 5f);
                break;
            case "RockGolemHeadShot":
                // Move the icon slightly up and to the left
                // Adjust scale slightly
                rectT.offsetMin = new Vector2(-1.3f, 0.5f);
                rectT.offsetMax = new Vector2(1.3f, -0.5f);
                rectT.localScale = new Vector3(0.9f, 0.9f, 1f);
                break;
            case "Avatar_ref":
                // Nothing needed
                break;
            case "Phyll":
                // Nothing needed
                break;
            case "DemonicSoldierHeadShot":
                // Move the icon slightly to the left and up
                // Adjust scale slightly
                rectT.offsetMin = new Vector2(-3.8f, 5.1f);
                rectT.offsetMax = new Vector2(3.8f, -5.1f);
                rectT.localScale = new Vector3(.9f, .9f, 1f);
                break;
            default:
                throw new InvalidOperationException($"The sprite name does not align with any available logic checks, " +
                    $"please check the name indicated in HandleOrientation() and the sprite in the ally object! ({spriteInImage.name})");
        }
    }
}