| 12345678910111213141516171819202122232425262728293031323334353637 |
- using System;
- using System.Collections.Generic;
- using TMPro;
- using UnityEngine;
- namespace BuffaloSiege
- {
- [Serializable] public class ArtEntry {public string id;public Sprite sprite;public Vector4 padding;}
- [Serializable] public class EnemyAnimation
- {
- public string id;public Sprite[] frames;public float framesPerSecond=10;
- public Sprite Frame(float elapsed,int phase=0)
- {
- if(frames==null||frames.Length==0)return null;
- int index=(Mathf.FloorToInt(Mathf.Max(0,elapsed)*framesPerSecond)+Mathf.Abs(phase))%frames.Length;
- return frames[index];
- }
- }
- [CreateAssetMenu(menuName="Buffalo Siege/Style A Theme")]
- public class ArtCatalog:ScriptableObject
- {
- public ArtEntry[] entries;public TMP_FontAsset brand,serif,body;public GameObject buttonPrefab,panelPrefab,textPrefab;
- public EnemyAnimation[] enemyAnimations=Array.Empty<EnemyAnimation>();
- public Vector2 referenceResolution=new Vector2(750,1334);
- 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);
- Dictionary<string,Sprite> cache;
- 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;}
- public Sprite EnemyFrame(int type,float elapsed,int phase=0)
- {
- string id=GameData.Enemies[type].Id;
- foreach(var animation in enemyAnimations)if(animation.id==id)return animation.Frame(elapsed,phase)??Get("enemy."+id);
- return Get("enemy."+id);
- }
- void OnEnable(){cache=null;}
- void OnValidate(){cache=null;}
- }
- }
|