A clean start for the shared repository: the Unity project (Assets, Packages, ProjectSettings), ArtSource, Docs and Tools as they stood at f3666f0 in the old local repository, with its generated prefabs and scene brought up to date. Images, audio, models and binaries go through Git LFS (.gitattributes). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
73 lines
3.1 KiB
C#
73 lines
3.1 KiB
C#
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace GrassCutter
|
|
{
|
|
/// <summary>Name-indexed references to clips, textures, fonts, meshes and materials (filled by the editor builder).</summary>
|
|
[CreateAssetMenu(menuName = "GrassCutter/AssetBank")]
|
|
public class AssetBank : ScriptableObject
|
|
{
|
|
public List<AudioClip> clips = new List<AudioClip>();
|
|
public List<Texture2D> textures = new List<Texture2D>();
|
|
public List<Font> fonts = new List<Font>();
|
|
public List<Mesh> meshes = new List<Mesh>();
|
|
public List<Material> materials = new List<Material>();
|
|
public List<GameObject> models = new List<GameObject>();
|
|
|
|
static AssetBank _inst;
|
|
Dictionary<string, AudioClip> _clips;
|
|
Dictionary<string, Texture2D> _tex;
|
|
Dictionary<string, Mesh> _meshes;
|
|
Dictionary<string, Material> _mats;
|
|
Dictionary<string, GameObject> _models;
|
|
|
|
public static AssetBank I
|
|
{
|
|
get
|
|
{
|
|
if (_inst == null)
|
|
{
|
|
_inst = Resources.Load<AssetBank>("AssetBank");
|
|
if (_inst == null) _inst = CreateInstance<AssetBank>();
|
|
_inst.Index();
|
|
}
|
|
return _inst;
|
|
}
|
|
}
|
|
|
|
void Index()
|
|
{
|
|
_clips = new Dictionary<string, AudioClip>();
|
|
foreach (var c in clips) if (c) _clips[c.name] = c;
|
|
_tex = new Dictionary<string, Texture2D>();
|
|
foreach (var t in textures) if (t) _tex[t.name] = t;
|
|
_meshes = new Dictionary<string, Mesh>();
|
|
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<string, Material>();
|
|
foreach (var m in materials) if (m) _mats[m.name] = m;
|
|
_models = new Dictionary<string, GameObject>();
|
|
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;
|
|
}
|
|
|
|
/// <summary>All clips whose name starts with prefix (e.g. "pop_0" → pop_01..pop_09).</summary>
|
|
public List<AudioClip> ClipsWithPrefix(string prefix)
|
|
{
|
|
var l = new List<AudioClip>();
|
|
foreach (var c in clips) if (c && c.name.StartsWith(prefix)) l.Add(c);
|
|
return l;
|
|
}
|
|
}
|
|
}
|