4using System.Collections.Generic;
19 public const string settingsPath =
"Assets/Resources/ItemIDsSettings.asset";
20 public List<ItemID> itemIds;
22 internal static ItemIDsSettings GetOrCreateSettings()
24 var settings = AssetDatabase.LoadAssetAtPath<ItemIDsSettings>(settingsPath);
28 settings = CreateInstance<ItemIDsSettings>();
29 settings.itemIds =
new List<ItemID>();
31 var names = Enum.GetNames(typeof(ItemID));
33 for (
int i = 0; i < names.Length; i++)
35 settings.itemIds.Add(
new ItemID() {name = names[i],
id = (int) Enum.Parse<
int>(names[i])});
38 CheckOrCreateAssetsPath(settingsPath);
39 AssetDatabase.CreateAsset(settings, settingsPath);
40 AssetDatabase.SaveAssets();
46 private static void CheckOrCreateAssetsPath(
string path)
48 var splitedArray = path.Split(
'/');
49 string currentPath = splitedArray[0];
51 for (
int i = 1; i < splitedArray.Length; i++)
53 if (!splitedArray[i].Contains(
"."))
55 if (!AssetDatabase.IsValidFolder(currentPath +
"/" + splitedArray[i]))
57 AssetDatabase.CreateFolder(currentPath, splitedArray[i]);
60 currentPath +=
"/" + splitedArray[i];
65 internal static SerializedObject GetSerializedSettings()
67 return new SerializedObject(GetOrCreateSettings());