123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237 |
- using System;
- using System.Collections.Generic;
- using UnityEngine;
- using wf;
- namespace MyRoomCustom
- {
- public static class PlacementData
- {
- public static int Count
- {
- get
- {
- PlacementData.CreateData();
- return PlacementData.commonIdManager.idMap.Count;
- }
- }
- public static bool Contains(int id)
- {
- PlacementData.CreateData();
- return PlacementData.commonIdManager.idMap.ContainsKey(id);
- }
- public static PlacementData.Data GetData(int id)
- {
- PlacementData.CreateData();
- NDebug.Assert(PlacementData.basicDatas.ContainsKey(id), "自室カスタム.配置物\nID[" + id + "]のデータは存在しません");
- return PlacementData.basicDatas[id];
- }
- public static bool IsEnabled(int id)
- {
- PlacementData.CreateData();
- return PlacementData.commonIdManager.enabledIdList.Contains(id);
- }
- public static List<PlacementData.Data> GetAllDatas(bool onlyEnabled)
- {
- PlacementData.CreateData();
- List<PlacementData.Data> list = new List<PlacementData.Data>();
- foreach (KeyValuePair<int, KeyValuePair<string, string>> keyValuePair in PlacementData.commonIdManager.idMap)
- {
- if (!onlyEnabled || PlacementData.commonIdManager.enabledIdList.Contains(keyValuePair.Key))
- {
- list.Add(PlacementData.basicDatas[keyValuePair.Key]);
- }
- }
- return list;
- }
- public static List<PlacementData.Data> GetDatas(Func<PlacementData.Data, bool> customCheckFunction)
- {
- PlacementData.CreateData();
- List<PlacementData.Data> list = new List<PlacementData.Data>();
- foreach (KeyValuePair<int, KeyValuePair<string, string>> keyValuePair in PlacementData.commonIdManager.idMap)
- {
- PlacementData.Data data = PlacementData.basicDatas[keyValuePair.Key];
- if (customCheckFunction(data))
- {
- list.Add(data);
- }
- }
- return list;
- }
- public static List<int> CategoryIDList
- {
- get
- {
- PlacementData.CreateCategoryData();
- return new List<int>(PlacementData.categoryIdManager.idMap.Keys);
- }
- }
- public static string GetCategoryName(int categoryID)
- {
- PlacementData.CreateCategoryData();
- NDebug.Assert(PlacementData.categoryIdManager.idMap.ContainsKey(categoryID), string.Format("カテゴリID[{0}]の情報が存在しません", categoryID));
- return PlacementData.categoryIdManager.idMap[categoryID].Key;
- }
- public static int GetCategoryID(string categoryName)
- {
- PlacementData.CreateCategoryData();
- NDebug.Assert(PlacementData.categoryIdManager.nameMap.ContainsKey(categoryName), string.Format("カテゴリ名[{0}]の情報が存在しません", categoryName));
- return PlacementData.categoryIdManager.nameMap[categoryName];
- }
- public static void CreateData()
- {
- PlacementData.CreateCategoryData();
- if (PlacementData.commonIdManager != null)
- {
- return;
- }
- PlacementData.commonIdManager = new CsvCommonIdManager("my_room_placement_obj", "自室カスタム.配置物", CsvCommonIdManager.Type.IdOnly, null);
- PlacementData.basicDatas = new Dictionary<int, PlacementData.Data>();
- string[] array = new string[]
- {
- "list"
- };
- KeyValuePair<AFileBase, CsvParser>[] array2 = new KeyValuePair<AFileBase, CsvParser>[array.Length];
- for (int i = 0; i < array2.Length; i++)
- {
- string text = "my_room_placement_obj_" + array[i] + ".nei";
- AFileBase afileBase = GameUty.FileSystem.FileOpen(text);
- CsvParser csvParser = new CsvParser();
- bool condition = csvParser.Open(afileBase);
- NDebug.Assert(condition, text + "\nopen failed.");
- array2[i] = new KeyValuePair<AFileBase, CsvParser>(afileBase, csvParser);
- }
- foreach (KeyValuePair<int, KeyValuePair<string, string>> keyValuePair in PlacementData.commonIdManager.idMap)
- {
- int key = keyValuePair.Key;
- PlacementData.Data value = new PlacementData.Data(key, array2[0].Value);
- PlacementData.basicDatas.Add(key, value);
- }
- foreach (KeyValuePair<AFileBase, CsvParser> keyValuePair2 in array2)
- {
- keyValuePair2.Value.Dispose();
- keyValuePair2.Key.Dispose();
- }
- }
- private static void CreateCategoryData()
- {
- if (PlacementData.categoryIdManager != null)
- {
- return;
- }
- PlacementData.categoryIdManager = new CsvCommonIdManager("my_room_placement_obj_category", "自室カスタム.配置物カテゴリ", CsvCommonIdManager.Type.IdAndUniqueName, (int id) => true);
- }
- public static void Clear()
- {
- if (PlacementData.commonIdManager != null)
- {
- PlacementData.commonIdManager = null;
- }
- if (PlacementData.categoryIdManager != null)
- {
- PlacementData.categoryIdManager = null;
- }
- }
- private const string csvTopCommonName = "my_room_placement_obj";
- private const string typeNameForErrorLog = "自室カスタム.配置物";
- private static CsvCommonIdManager commonIdManager;
- private static CsvCommonIdManager categoryIdManager;
- private static Dictionary<int, PlacementData.Data> basicDatas;
- public class Data
- {
- public Data(int uniqueID, CsvParser csv)
- {
- for (int i = 1; i < csv.max_cell_y; i++)
- {
- if (csv.IsCellToExistData(0, i) && csv.GetCellAsInteger(0, i) == uniqueID)
- {
- int num = 1;
- this.ID = uniqueID;
- this.drawName = csv.GetCellAsString(num++, i);
- string cellAsString = csv.GetCellAsString(num++, i);
- this.resourceName = csv.GetCellAsString(num++, i);
- this.assetName = csv.GetCellAsString(num++, i);
- this.thumbnailName = csv.GetCellAsString(num++, i);
- this.categoryID = PlacementData.GetCategoryID(cellAsString);
- }
- }
- }
- public GameObject GetPrefab()
- {
- GameObject gameObject = null;
- if (!string.IsNullOrEmpty(this.resourceName))
- {
- gameObject = Resources.Load<GameObject>("SceneCreativeRoom/Debug/Prefab/" + this.resourceName);
- }
- if (!gameObject && !string.IsNullOrEmpty(this.assetName))
- {
- gameObject = GameMain.Instance.BgMgr.CreateAssetBundle(this.assetName);
- }
- if (!gameObject)
- {
- if (!string.IsNullOrEmpty(this.resourceName))
- {
- Debug.LogWarningFormat("[Creative Room]プレハブ[{0}]が見つかりませんでした\nパス:「{1}」", new object[]
- {
- this.resourceName,
- "Assets/Resources/SceneCreativeRoom/Debug/Prefab/" + this.resourceName
- });
- }
- else if (!string.IsNullOrEmpty(this.assetName))
- {
- Debug.LogWarningFormat("[Creative Room]アセットバンドル[{0}]が見つかりませんでした", new object[]
- {
- this.assetName
- });
- }
- return null;
- }
- return gameObject;
- }
- public Texture GetThumbnail()
- {
- Texture result = null;
- if (!string.IsNullOrEmpty(this.thumbnailName))
- {
- string f_strFileName = this.thumbnailName + ".tex";
- if (GameUty.FileSystem.IsExistentFile(f_strFileName))
- {
- result = ImportCM.CreateTexture(f_strFileName);
- }
- }
- return result;
- }
- public readonly int ID;
- public readonly string drawName;
- public readonly string resourceName;
- public readonly string assetName;
- public readonly int categoryID;
- public readonly string thumbnailName;
- }
- }
- }
|