123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232 |
- 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.enabledIDList.Count;
- }
- }
- public static bool Contains(int id)
- {
- PlacementData.CreateData();
- return PlacementData.enabledIDList.Contains(id);
- }
- public static PlacementData.Data GetData(int id)
- {
- PlacementData.CreateData();
- NDebug.Assert(PlacementData.basicDatas.ContainsKey(id), "自室カスタム.配置物\nID[" + id + "]のデータは存在しません");
- return PlacementData.basicDatas[id];
- }
- public static List<PlacementData.Data> GetAllDatas(bool onlyEnabled)
- {
- PlacementData.CreateData();
- List<PlacementData.Data> list = new List<PlacementData.Data>();
- foreach (KeyValuePair<int, PlacementData.Data> keyValuePair in PlacementData.basicDatas)
- {
- if (!onlyEnabled || PlacementData.enabledIDList.Contains(keyValuePair.Key))
- {
- list.Add(keyValuePair.Value);
- }
- }
- return list;
- }
- public static List<PlacementData.Data> GetDatas(Func<PlacementData.Data, bool> customCheckFunction)
- {
- PlacementData.CreateData();
- List<PlacementData.Data> list = new List<PlacementData.Data>();
- foreach (int key in PlacementData.enabledIDList)
- {
- PlacementData.Data data = PlacementData.basicDatas[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()
- {
- if (PlacementData.enabledIDList != null)
- {
- return;
- }
- PlacementData.CreateCategoryData();
- PlacementData.basicDatas = new Dictionary<int, PlacementData.Data>();
- PlacementData.enabledIDList = new HashSet<int>();
- CsvCommonIdManager.ReadEnabledIdList(CsvCommonIdManager.FileSystemType.Normal, true, "my_room_placement_obj_enabled_list", ref PlacementData.enabledIDList);
- using (AFileBase afileBase = GameUty.FileSystem.FileOpen("my_room_placement_obj_list.nei"))
- {
- using (CsvParser csvParser = new CsvParser())
- {
- bool condition = csvParser.Open(afileBase);
- NDebug.Assert(condition, "my_room_placement_obj_list\nopen failed.");
- foreach (int num in PlacementData.enabledIDList)
- {
- PlacementData.Data value = new PlacementData.Data(num, csvParser);
- PlacementData.basicDatas.Add(num, value);
- }
- }
- }
- }
- 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.enabledIDList != null)
- {
- PlacementData.enabledIDList = null;
- }
- if (PlacementData.basicDatas != null)
- {
- PlacementData.basicDatas = null;
- }
- if (PlacementData.categoryIdManager != null)
- {
- PlacementData.categoryIdManager = null;
- }
- }
- private const string csvTopCommonName = "my_room_placement_obj";
- private const string typeNameForErrorLog = "自室カスタム.配置物";
- private static CsvCommonIdManager categoryIdManager;
- private static HashSet<int> enabledIDList;
- 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 string drawNameTerm
- {
- get
- {
- return "SceneCreativeRoom/オブジェクト/" + this.ID.ToString();
- }
- }
- public readonly int ID;
- public readonly string drawName;
- public readonly string resourceName;
- public readonly string assetName;
- public readonly int categoryID;
- public readonly string thumbnailName;
- }
- }
- }
|