using System.Collections.Generic; using UnityEngine; namespace GrassCutter { /// Name-indexed references to clips, textures, fonts, meshes and materials (filled by the editor builder). [CreateAssetMenu(menuName = "GrassCutter/AssetBank")] public class AssetBank : ScriptableObject { public List clips = new List(); public List textures = new List(); public List fonts = new List(); public List meshes = new List(); public List materials = new List(); public List models = new List(); static AssetBank _inst; Dictionary _clips; Dictionary _tex; Dictionary _meshes; Dictionary _mats; Dictionary _models; public static AssetBank I { get { if (_inst == null) { _inst = Resources.Load("AssetBank"); if (_inst == null) _inst = CreateInstance(); _inst.Index(); } return _inst; } } void Index() { _clips = new Dictionary(); foreach (var c in clips) if (c) _clips[c.name] = c; _tex = new Dictionary(); foreach (var t in textures) if (t) _tex[t.name] = t; _meshes = new Dictionary(); foreach (var m in meshes) if (m) _meshes[m.name.EndsWith("_baked") ? m.name.Substring(0, m.name.Length - 6) : m.name] = m; _mats = new Dictionary(); foreach (var m in materials) if (m) _mats[m.name] = m; _models = new Dictionary(); foreach (var m in models) if (m) _models[m.name] = m; } public AudioClip Clip(string name) => name != null && _clips.TryGetValue(name, out var c) ? c : null; public Texture2D Tex(string name) => name != null && _tex.TryGetValue(name, out var t) ? t : null; public Mesh Mesh(string name) => name != null && _meshes.TryGetValue(name, out var m) ? m : null; public Material Mat(string name) => name != null && _mats.TryGetValue(name, out var m) ? m : null; public GameObject Model(string name) => name != null && _models.TryGetValue(name, out var m) ? m : null; public Font Font(string contains) { foreach (var f in fonts) if (f && f.name.Contains(contains)) return f; return fonts.Count > 0 ? fonts[0] : null; } /// All clips whose name starts with prefix (e.g. "pop_0" → pop_01..pop_09). public List ClipsWithPrefix(string prefix) { var l = new List(); foreach (var c in clips) if (c && c.name.StartsWith(prefix)) l.Add(c); return l; } } }