ArtCatalog.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. using System;
  2. using System.Collections.Generic;
  3. using TMPro;
  4. using UnityEngine;
  5. namespace BuffaloSiege
  6. {
  7. [Serializable] public class ArtEntry {public string id;public Sprite sprite;public Vector4 padding;}
  8. [Serializable] public class EnemyAnimation
  9. {
  10. public string id;public Sprite[] frames;public float framesPerSecond=10;
  11. public Sprite Frame(float elapsed,int phase=0)
  12. {
  13. if(frames==null||frames.Length==0)return null;
  14. int index=(Mathf.FloorToInt(Mathf.Max(0,elapsed)*framesPerSecond)+Mathf.Abs(phase))%frames.Length;
  15. return frames[index];
  16. }
  17. }
  18. [CreateAssetMenu(menuName="Buffalo Siege/Style A Theme")]
  19. public class ArtCatalog:ScriptableObject
  20. {
  21. public ArtEntry[] entries;public TMP_FontAsset brand,serif,body;public GameObject buttonPrefab,panelPrefab,textPrefab;
  22. public EnemyAnimation[] enemyAnimations=Array.Empty<EnemyAnimation>();
  23. public Vector2 referenceResolution=new Vector2(750,1334);
  24. public Color cream=new Color32(255,240,191,255),gold=new Color32(243,198,107,255),plum=new Color32(53,33,50,255),ink=new Color32(33,19,26,255);
  25. Dictionary<string,Sprite> cache;
  26. public Sprite Get(string id){if(cache==null){cache=new Dictionary<string,Sprite>();foreach(var e in entries)cache[e.id]=e.sprite;}return cache.TryGetValue(id,out var sprite)?sprite:null;}
  27. public Sprite EnemyFrame(int type,float elapsed,int phase=0)
  28. {
  29. string id=GameData.Enemies[type].Id;
  30. foreach(var animation in enemyAnimations)if(animation.id==id)return animation.Frame(elapsed,phase)??Get("enemy."+id);
  31. return Get("enemy."+id);
  32. }
  33. void OnEnable(){cache=null;}
  34. void OnValidate(){cache=null;}
  35. }
  36. }