using System; using UnityEngine; namespace BulletHellTemplate.Core.FSM { /// /// Eight-way animation set. Designers only need to assign Forward; /// all others are optional.
/// Order (reference only): N(Fwd), NE, E(Right), SE, S(Back), SW, W(Left), NW. ///
[Serializable] public struct DirectionalAnimSet { [Header("Required")] public AnimClipData Forward; // North [Header("Optional")] public AnimClipData ForwardRight; // North-East public AnimClipData Right; // East public AnimClipData BackRight; // South-East public AnimClipData Back; // South public AnimClipData BackLeft; // South-West public AnimClipData Left; // West public AnimClipData ForwardLeft; // North-West /// /// Returns the appropriate clip for .
/// Falls back to when the specific clip is null. ///
public AnimClipData GetClip(Vector2 dir) { // Default to Forward when standing still if (dir.sqrMagnitude < 0.01f) return Forward; float angle = (Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg + 360f + 22.5f) % 360f; int idx = (int)(angle / 45f); return idx switch { 0 => ForwardRight.Clip ? ForwardRight : Forward, 1 => Right.Clip ? Right : Forward, 2 => BackRight.Clip ? BackRight : Forward, 3 => Back.Clip ? Back : Forward, 4 => BackLeft.Clip ? BackLeft : Forward, 5 => Left.Clip ? Left : Forward, 6 => ForwardLeft.Clip ? ForwardLeft : Forward, _ => Forward, // 7 == Forward (N) }; } public string GetStateName(Vector2 dir, string prefix) { string suffix = "N"; // default if (dir.sqrMagnitude >= 0.01f) { float angle = (Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg + 360f + 22.5f) % 360f; suffix = ((int)(angle / 45f)) switch { 0 => "NE", 1 => "E", 2 => "SE", 3 => "S", 4 => "SW", 5 => "W", 6 => "NW", _ => "N", }; } return $"{prefix}_{suffix}"; } } }