| 1234567891011121314151617181920212223242526 |
- using UnityEngine;
- namespace HexaCrazy
- {
- [CreateAssetMenu(menuName="Hexa Crazy/Level Database")]
- public sealed class LevelDatabase : ScriptableObject
- {
- public LevelSpec[] levels;
- [System.Serializable] private sealed class LevelFile { public LevelSpec[] levels; }
- public static LevelDatabase LoadDefault()
- {
- var text = Resources.Load<TextAsset>("level-data");
- if (text == null) throw new System.InvalidOperationException("Missing level-data.json");
- var data = JsonUtility.FromJson<LevelFile>(text.text);
- if (data?.levels == null || data.levels.Length != 60)
- throw new System.InvalidOperationException("Expected 60 levels in level-data.json");
- var database = CreateInstance<LevelDatabase>();
- database.hideFlags = HideFlags.DontSave;
- database.levels = data.levels;
- return database;
- }
- public LevelSpec Get(int mode,int level) => levels[mode*20+Mathf.Clamp(level-1,0,19)];
- public static readonly string[] ModeNames = { "CLASSIC SORT", "TIME RUSH", "HIVE LOCK" };
- public static readonly string[] ItemNames = { "HAMMER", "SWAP", "BONUS", "UNLOCK" };
- public static readonly int[] Prices = { 800, 500, 1200, 1500 };
- }
- }
|