Add fixed-camera tower effect preview scene
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace BumpCombat.Defense
|
||||
{
|
||||
public static class DefenseTowerArt
|
||||
{
|
||||
private const string ResourceRoot = "DefenseTowers-v1/";
|
||||
private static readonly Dictionary<string, Sprite[]> Frames = new();
|
||||
|
||||
public static ICollection<string> Keys => DefenseTowerArtDurations.Keys;
|
||||
|
||||
public static int ExpectedFrameCount(string key)
|
||||
{
|
||||
return DefenseTowerArtDurations.FrameCount(key);
|
||||
}
|
||||
|
||||
public static Sprite[] Load(string key)
|
||||
{
|
||||
if (string.IsNullOrEmpty(key))
|
||||
{
|
||||
return Array.Empty<Sprite>();
|
||||
}
|
||||
|
||||
if (!Frames.TryGetValue(key, out Sprite[] sprites))
|
||||
{
|
||||
sprites = Resources.LoadAll<Sprite>(ResourceRoot + key);
|
||||
Array.Sort(sprites, CompareFrameNames);
|
||||
Frames.Add(key, sprites);
|
||||
}
|
||||
return sprites;
|
||||
}
|
||||
|
||||
public static float FrameSeconds(string key, int frame)
|
||||
{
|
||||
return DefenseTowerArtDurations.Seconds(key, frame);
|
||||
}
|
||||
|
||||
public static string BodyKey(DefenseTowerKind kind, int tier, string motion)
|
||||
{
|
||||
string family = kind switch
|
||||
{
|
||||
DefenseTowerKind.Direct => "Fire",
|
||||
DefenseTowerKind.Summon => "Summon",
|
||||
DefenseTowerKind.Lightning => "Lightning",
|
||||
DefenseTowerKind.Cold => "Ice",
|
||||
DefenseTowerKind.Seismic => "Control",
|
||||
_ => "Support",
|
||||
};
|
||||
return $"Bodies/{family}/T{tier}-{motion}";
|
||||
}
|
||||
|
||||
private static int CompareFrameNames(Sprite left, Sprite right)
|
||||
{
|
||||
return FrameIndex(left.name).CompareTo(FrameIndex(right.name));
|
||||
}
|
||||
|
||||
private static int FrameIndex(string name)
|
||||
{
|
||||
int separator = name.LastIndexOf('_');
|
||||
return separator >= 0 && int.TryParse(name.Substring(separator + 1), out int index)
|
||||
? index : 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user