LevelDatabase.cs 1.3 KB

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