CreativeRoomManager.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.Specialized;
  4. using System.IO;
  5. using UnityEngine;
  6. using UnityEngine.EventSystems;
  7. namespace MyRoomCustom
  8. {
  9. public class CreativeRoomManager : MonoBehaviour
  10. {
  11. public CreativeRoom creativeRoom
  12. {
  13. get
  14. {
  15. return this.m_PtrCreativeRoom;
  16. }
  17. }
  18. public CreativeRoomUIObjectSettings creativeRoomUIObjSetting
  19. {
  20. get
  21. {
  22. return this.m_PtrCreativeRoomUIObjectSettings;
  23. }
  24. }
  25. public CreativeRoomUIPlacementMaid creativeRoomUIMaid
  26. {
  27. get
  28. {
  29. return this.m_PtrCreativeRoomUIPlacementMaid;
  30. }
  31. }
  32. private float cameraFOV
  33. {
  34. set
  35. {
  36. if (value != this.m_CamerauGUI.fieldOfView)
  37. {
  38. this.m_CamerauGUI.fieldOfView = value;
  39. }
  40. }
  41. }
  42. private float cameraOrthographicSize
  43. {
  44. set
  45. {
  46. if (value != this.m_CamerauGUI.orthographicSize)
  47. {
  48. this.m_CamerauGUI.orthographicSize = value;
  49. }
  50. }
  51. }
  52. private bool cameraOrthographic
  53. {
  54. set
  55. {
  56. if (value != this.m_CamerauGUI.orthographic)
  57. {
  58. this.m_CamerauGUI.orthographic = value;
  59. }
  60. }
  61. }
  62. private Rect cameraRect
  63. {
  64. set
  65. {
  66. if (value != this.m_CamerauGUI.rect)
  67. {
  68. this.m_CamerauGUI.rect = value;
  69. }
  70. }
  71. }
  72. private void Awake()
  73. {
  74. Camera camera = GameMain.Instance.MainCamera.camera;
  75. this.m_MainCamera = camera;
  76. GameObject gameObject = new GameObject("[CreativeRoom]Camera (Input Module)");
  77. this.m_CamerauGUI = gameObject.AddComponent<Camera>();
  78. this.m_CamerauGUI.clearFlags = CameraClearFlags.Nothing;
  79. this.m_CamerauGUI.useOcclusionCulling = false;
  80. this.m_CamerauGUI.enabled = false;
  81. this.m_CamerauGUI.gameObject.AddComponent<PhysicsRaycaster>();
  82. Transform transform = camera.transform;
  83. gameObject.transform.SetParent(transform, false);
  84. gameObject.transform.localPosition = Vector3.zero;
  85. gameObject.transform.localEulerAngles = Vector3.zero;
  86. gameObject.transform.localScale = Vector3.one;
  87. this.cameraFOV = camera.fieldOfView;
  88. this.cameraOrthographic = camera.orthographic;
  89. this.cameraOrthographicSize = camera.orthographicSize;
  90. this.cameraRect = camera.pixelRect;
  91. CharacterMgr characterMgr = GameMain.Instance.CharacterMgr;
  92. for (int i = 0; i < characterMgr.GetMaidCount(); i++)
  93. {
  94. if (characterMgr.GetMaid(i) != null)
  95. {
  96. characterMgr.GetMaid(i).Visible = false;
  97. }
  98. }
  99. }
  100. private void Start()
  101. {
  102. if (!this.m_PtrCreativeRoom)
  103. {
  104. this.m_PtrCreativeRoom = UnityEngine.Object.FindObjectOfType<CreativeRoom>();
  105. }
  106. if (!this.m_PtrCreativeRoomUIObjectSettings)
  107. {
  108. this.m_PtrCreativeRoomUIObjectSettings = UnityEngine.Object.FindObjectOfType<CreativeRoomUIObjectSettings>();
  109. }
  110. if (!this.m_PtrCreativeRoomUIPlacementMaid)
  111. {
  112. this.m_PtrCreativeRoomUIPlacementMaid = UnityEngine.Object.FindObjectOfType<CreativeRoomUIPlacementMaid>();
  113. }
  114. this.GetTagBackup();
  115. GameMain.Instance.BgMgr.DeleteBg();
  116. GameMain.Instance.SoundMgr.PlayBGM(this.m_MusicName + ".ogg", 0.5f, true);
  117. GameMain.Instance.MainCamera.Reset(CameraMain.CameraType.Target, true);
  118. GameMain.Instance.MainCamera.SetTargetPos(new Vector3(0f, 1.8f, 0f), true);
  119. GameMain.Instance.MainCamera.SetDistance(7f, true);
  120. GameMain.Instance.MainCamera.SetAroundAngle(new Vector2(45f, 20f), true);
  121. GameMain.Instance.MainCamera.FadeIn(0.5f, false, null, true, true, default(Color));
  122. if (!uGUITutorialPanel.IsOpened())
  123. {
  124. uGUITutorialPanel.OpenTutorial("SceneCreativeRoom", null, false);
  125. }
  126. }
  127. private void Update()
  128. {
  129. this.cameraFOV = this.m_MainCamera.fieldOfView;
  130. this.cameraOrthographic = this.m_MainCamera.orthographic;
  131. this.cameraOrthographicSize = this.m_MainCamera.orthographicSize;
  132. this.cameraRect = this.m_MainCamera.pixelRect;
  133. }
  134. public CreativeRoomManager.CreativeRoomHeader Save(int number)
  135. {
  136. string text = Path.GetFullPath(".\\");
  137. text += "MyRoom\\";
  138. string text2 = "Room_";
  139. text2 += number.ToString("000");
  140. text2 += ".room";
  141. if (!Directory.Exists(text))
  142. {
  143. Directory.CreateDirectory(text);
  144. }
  145. MemoryStream memoryStream = new MemoryStream();
  146. BinaryWriter binaryWriter = new BinaryWriter(memoryStream);
  147. string text3 = DateTime.Now.ToString("yyyyMMddHHmm");
  148. CreativeRoomManager.CreativeRoomHeader creativeRoomHeader = this.GetSaveDataHeader(number);
  149. if (creativeRoomHeader != null)
  150. {
  151. binaryWriter.Write("COM3D2_MY_ROOM");
  152. binaryWriter.Write("2");
  153. binaryWriter.Write(creativeRoomHeader.comment);
  154. binaryWriter.Write(text3);
  155. string value = creativeRoomHeader.guid;
  156. if (string.IsNullOrEmpty(value))
  157. {
  158. value = Guid.NewGuid().ToString();
  159. }
  160. binaryWriter.Write(value);
  161. creativeRoomHeader.lastWriteTime = text3;
  162. }
  163. else
  164. {
  165. binaryWriter.Write("COM3D2_MY_ROOM");
  166. binaryWriter.Write("2");
  167. binaryWriter.Write(string.Empty);
  168. binaryWriter.Write(text3);
  169. string text4 = Guid.NewGuid().ToString();
  170. binaryWriter.Write(text4);
  171. creativeRoomHeader = new CreativeRoomManager.CreativeRoomHeader();
  172. creativeRoomHeader.guid = text4;
  173. creativeRoomHeader.comment = string.Empty;
  174. creativeRoomHeader.lastWriteTime = text3;
  175. }
  176. this.m_PtrCreativeRoom.SavePanelData(binaryWriter);
  177. this.m_PtrCreativeRoomUIObjectSettings.SaveDeployObjectData(binaryWriter);
  178. File.WriteAllBytes(text + text2, memoryStream.ToArray());
  179. memoryStream.Close();
  180. memoryStream.Dispose();
  181. return creativeRoomHeader;
  182. }
  183. public void Load(int number)
  184. {
  185. string text = Path.GetFullPath(".\\");
  186. text += "MyRoom\\";
  187. if (!Directory.Exists(text))
  188. {
  189. Directory.CreateDirectory(text);
  190. }
  191. string text2 = text + "Room_" + number.ToString("000");
  192. if (File.Exists(text2 + ".save"))
  193. {
  194. text2 += ".save";
  195. }
  196. else
  197. {
  198. if (!File.Exists(text2 + ".room"))
  199. {
  200. Debug.LogWarning(string.Format("[CreativeRoomManager]{0}\u3000のセーブファイルが見つかりませんでした", text2));
  201. return;
  202. }
  203. text2 += ".room";
  204. }
  205. FileStream fileStream = new FileStream(text2, FileMode.Open);
  206. byte[] buffer = new byte[fileStream.Length];
  207. fileStream.Read(buffer, 0, (int)fileStream.Length);
  208. fileStream.Close();
  209. fileStream.Dispose();
  210. BinaryReader binaryReader = new BinaryReader(new MemoryStream(buffer));
  211. string a = binaryReader.ReadString();
  212. int num = 0;
  213. if (a != "COM3D2_MY_ROOM")
  214. {
  215. binaryReader.BaseStream.Seek(0L, SeekOrigin.Begin);
  216. }
  217. else if (!int.TryParse(binaryReader.ReadString(), out num))
  218. {
  219. string message = "[自室カスタム]セーブデータのヘッダーが不正です\n" + text2;
  220. Debug.LogError(message);
  221. NDebug.Assert(message, false);
  222. }
  223. binaryReader.ReadString();
  224. binaryReader.ReadString();
  225. if (num >= 1)
  226. {
  227. binaryReader.ReadString();
  228. }
  229. this.m_PtrCreativeRoom.LoadPanelData(binaryReader);
  230. this.m_PtrCreativeRoomUIObjectSettings.LoadDeployObjectData(binaryReader);
  231. this.m_PtrCreativeRoomUIObjectSettings.SetDeploymentObjectGizmoEnable(false);
  232. binaryReader.Close();
  233. }
  234. public CreativeRoomManager.CreativeRoomHeader GetSaveDataHeader(int number)
  235. {
  236. return this.GetSaveDataHeader(number.ToString("000"));
  237. }
  238. public CreativeRoomManager.CreativeRoomHeader GetSaveDataHeader(string number)
  239. {
  240. string str = Path.GetFullPath(".\\");
  241. str += "MyRoom\\";
  242. string text = "Room_" + number;
  243. if (File.Exists(str + text + ".save"))
  244. {
  245. text += ".save";
  246. }
  247. else
  248. {
  249. text += ".room";
  250. }
  251. if (!File.Exists(str + text))
  252. {
  253. return null;
  254. }
  255. FileStream fileStream = new FileStream(str + text, FileMode.Open);
  256. byte[] buffer = new byte[fileStream.Length];
  257. fileStream.Read(buffer, 0, (int)fileStream.Length);
  258. fileStream.Close();
  259. fileStream.Dispose();
  260. BinaryReader binaryReader = new BinaryReader(new MemoryStream(buffer));
  261. CreativeRoomManager.CreativeRoomHeader creativeRoomHeader = new CreativeRoomManager.CreativeRoomHeader();
  262. string a = binaryReader.ReadString();
  263. int num = 0;
  264. if (a != "COM3D2_MY_ROOM")
  265. {
  266. binaryReader.BaseStream.Seek(0L, SeekOrigin.Begin);
  267. }
  268. else if (!int.TryParse(binaryReader.ReadString(), out num))
  269. {
  270. string message = "[自室カスタム]セーブデータのヘッダーが不正です\n" + text;
  271. Debug.LogError(message);
  272. NDebug.Assert(message, false);
  273. }
  274. creativeRoomHeader.comment = binaryReader.ReadString();
  275. creativeRoomHeader.lastWriteTime = binaryReader.ReadString();
  276. if (num >= 1)
  277. {
  278. creativeRoomHeader.guid = binaryReader.ReadString();
  279. }
  280. creativeRoomHeader.headerSize = binaryReader.BaseStream.Position;
  281. binaryReader.Close();
  282. return creativeRoomHeader;
  283. }
  284. public void SaveComment(int number, string comment)
  285. {
  286. this.SaveComment(number.ToString("000"), comment);
  287. }
  288. public void SaveComment(string number, string comment)
  289. {
  290. CreativeRoomManager.CreativeRoomHeader saveDataHeader = this.GetSaveDataHeader(number);
  291. if (saveDataHeader == null)
  292. {
  293. return;
  294. }
  295. string str = Path.GetFullPath(".\\");
  296. str += "MyRoom\\";
  297. string path = str + "Room_" + number + ".room";
  298. FileStream fileStream = new FileStream(path, FileMode.Open);
  299. byte[] array = new byte[fileStream.Length];
  300. fileStream.Read(array, 0, (int)fileStream.Length);
  301. fileStream.Close();
  302. fileStream.Dispose();
  303. MemoryStream memoryStream = new MemoryStream();
  304. BinaryWriter binaryWriter = new BinaryWriter(memoryStream);
  305. int num = (int)saveDataHeader.headerSize;
  306. binaryWriter.Write("COM3D2_MY_ROOM");
  307. binaryWriter.Write("2");
  308. binaryWriter.Write(comment);
  309. binaryWriter.Write(saveDataHeader.lastWriteTime);
  310. if (string.IsNullOrEmpty(saveDataHeader.guid))
  311. {
  312. saveDataHeader.guid = Guid.NewGuid().ToString();
  313. }
  314. binaryWriter.Write(saveDataHeader.guid);
  315. binaryWriter.Write(array, num, array.Length - num);
  316. File.WriteAllBytes(path, memoryStream.ToArray());
  317. memoryStream.Close();
  318. memoryStream.Dispose();
  319. Debug.Log("セーブデータ" + number + "番:ヘッダーを保存");
  320. }
  321. public string DateTimeParse(string strDate)
  322. {
  323. return DateTime.ParseExact(strDate, "yyyyMMddHHmm", null).ToString("yyyy.MM.dd HH:mm");
  324. }
  325. private void GetTagBackup()
  326. {
  327. Dictionary<string, string> tag_backup = GameMain.Instance.ScriptMgr.adv_kag.tag_backup;
  328. string a;
  329. if (tag_backup != null && tag_backup.TryGetValue("name", out a) && a == "SceneCreativeRoom")
  330. {
  331. if (!tag_backup.TryGetValue("label", out this.m_strScriptReturnLabel))
  332. {
  333. Debug.LogFormat("スクリプトからの引数「{0}」がありませんでした", new object[]
  334. {
  335. "label"
  336. });
  337. }
  338. }
  339. }
  340. public void Exit()
  341. {
  342. if (!GameMain.Instance.SysDlg.IsDecided)
  343. {
  344. return;
  345. }
  346. GameMain.Instance.SysDlg.Show("セーブしていないデータは失われます。\n終了しますか?", SystemDialog.TYPE.YES_NO, delegate
  347. {
  348. if (string.IsNullOrEmpty(this.m_strScriptReturnLabel))
  349. {
  350. Debug.Log("シーン終了時に飛ぶラベルがありませんでした");
  351. return;
  352. }
  353. GameMain.Instance.MainCamera.FadeOut(0.5f, false, delegate
  354. {
  355. GameMain.Instance.SoundMgr.StopBGM(1f);
  356. PlacementData.Clear();
  357. TextureData.Clear();
  358. uGUIUtility.SetActiveEventSystem(true);
  359. ScriptManager scriptMgr = GameMain.Instance.ScriptMgr;
  360. scriptMgr.adv_kag.JumpLabel(this.m_strScriptReturnLabel);
  361. scriptMgr.adv_kag.Exec();
  362. }, true, default(Color));
  363. GameMain.Instance.SysDlg.Close();
  364. }, delegate
  365. {
  366. GameMain.Instance.SysDlg.Close();
  367. uGUIUtility.SetActiveEventSystem(true);
  368. });
  369. uGUIUtility.SetActiveEventSystem(false);
  370. }
  371. private void OnDestroy()
  372. {
  373. if (this.m_CamerauGUI)
  374. {
  375. UnityEngine.Object.Destroy(this.m_CamerauGUI.gameObject);
  376. }
  377. }
  378. private static StringDictionary cachedSaveDataDic
  379. {
  380. get
  381. {
  382. if (CreativeRoomManager.m_CachedSaveDataDic == null)
  383. {
  384. CreativeRoomManager.m_CachedSaveDataDic = new StringDictionary();
  385. string text = Path.GetFullPath(".\\");
  386. text += "MyRoom\\";
  387. if (Directory.Exists(text))
  388. {
  389. string[] files = Directory.GetFiles(text, "*.room");
  390. for (int i = 0; i < files.Length; i++)
  391. {
  392. CreativeRoomManager.CreativeRoomHeader creativeRoomHeader;
  393. CreativeRoomManager.DeserializeHeader(files[i], out creativeRoomHeader);
  394. CreativeRoomManager.m_CachedSaveDataDic[creativeRoomHeader.guid] = files[i];
  395. }
  396. }
  397. }
  398. return CreativeRoomManager.m_CachedSaveDataDic;
  399. }
  400. }
  401. public static Dictionary<string, string> GetSaveDataDic()
  402. {
  403. CreativeRoomManager.UpdateSaveDataGUID();
  404. if (CreativeRoomManager.m_CachedSaveDataDic != null)
  405. {
  406. CreativeRoomManager.m_CachedSaveDataDic.Clear();
  407. }
  408. CreativeRoomManager.m_CachedSaveDataDic = new StringDictionary();
  409. string text = Path.GetFullPath(".\\");
  410. text += "MyRoom\\";
  411. Dictionary<string, string> dictionary = null;
  412. if (Directory.Exists(text))
  413. {
  414. dictionary = new Dictionary<string, string>();
  415. string[] files = Directory.GetFiles(text, "*.room");
  416. for (int i = 0; i < files.Length; i++)
  417. {
  418. CreativeRoomManager.CreativeRoomHeader creativeRoomHeader;
  419. CreativeRoomManager.DeserializeHeader(files[i], out creativeRoomHeader);
  420. string text2 = string.Empty;
  421. if (string.IsNullOrEmpty(creativeRoomHeader.comment))
  422. {
  423. text2 = "自室カスタム" + i.ToString("000");
  424. }
  425. else
  426. {
  427. int num = 10;
  428. text2 = creativeRoomHeader.comment;
  429. if (text2.Length > num)
  430. {
  431. text2 = text2.Substring(0, num - 1) + "…";
  432. }
  433. }
  434. dictionary.Add(creativeRoomHeader.guid, text2);
  435. CreativeRoomManager.m_CachedSaveDataDic[creativeRoomHeader.guid] = files[i];
  436. }
  437. }
  438. return dictionary;
  439. }
  440. private static void UpdateSaveDataGUID()
  441. {
  442. string text = Path.GetFullPath(".\\");
  443. text += "MyRoom\\";
  444. if (Directory.Exists(text))
  445. {
  446. SortedDictionary<string, KeyValuePair<FileInfo, CreativeRoomManager.CreativeRoomHeader>> sortedDictionary = new SortedDictionary<string, KeyValuePair<FileInfo, CreativeRoomManager.CreativeRoomHeader>>();
  447. string[] files = Directory.GetFiles(text, "*.room");
  448. for (int i = 0; i < files.Length; i++)
  449. {
  450. CreativeRoomManager.CreativeRoomHeader creativeRoomHeader;
  451. CreativeRoomManager.DeserializeHeader(files[i], out creativeRoomHeader);
  452. FileInfo fileInfo = new FileInfo(files[i]);
  453. if (sortedDictionary.ContainsKey(creativeRoomHeader.guid))
  454. {
  455. string message = "ファイル「" + fileInfo.Name + "」の内部IDが重複しています。新しい内部IDを作成します。";
  456. Debug.LogWarning(message);
  457. KeyValuePair<FileInfo, CreativeRoomManager.CreativeRoomHeader> keyValuePair = sortedDictionary[creativeRoomHeader.guid];
  458. FileInfo key = keyValuePair.Key;
  459. CreativeRoomManager.CreativeRoomHeader value = keyValuePair.Value;
  460. CreativeRoomManager.CreativeRoomHeader creativeRoomHeader2 = (!(fileInfo.CreationTimeUtc <= key.CreationTimeUtc)) ? creativeRoomHeader : value;
  461. FileInfo info = (!(fileInfo.CreationTimeUtc <= key.CreationTimeUtc)) ? fileInfo : key;
  462. creativeRoomHeader2.guid = Guid.NewGuid().ToString();
  463. CreativeRoomManager.SerializeAndUpdateHeader(info, creativeRoomHeader2);
  464. }
  465. if (!sortedDictionary.ContainsKey(creativeRoomHeader.guid))
  466. {
  467. sortedDictionary.Add(creativeRoomHeader.guid, new KeyValuePair<FileInfo, CreativeRoomManager.CreativeRoomHeader>(fileInfo, creativeRoomHeader));
  468. }
  469. else
  470. {
  471. KeyValuePair<FileInfo, CreativeRoomManager.CreativeRoomHeader> keyValuePair2 = sortedDictionary[creativeRoomHeader.guid];
  472. sortedDictionary[creativeRoomHeader.guid] = new KeyValuePair<FileInfo, CreativeRoomManager.CreativeRoomHeader>(fileInfo, creativeRoomHeader);
  473. sortedDictionary.Add(keyValuePair2.Value.guid, new KeyValuePair<FileInfo, CreativeRoomManager.CreativeRoomHeader>(keyValuePair2.Key, keyValuePair2.Value));
  474. }
  475. }
  476. }
  477. }
  478. public static GameObject InstantiateRoom(string guid_room)
  479. {
  480. if (!CreativeRoomManager.cachedSaveDataDic.ContainsKey(guid_room))
  481. {
  482. string message = "[CreativeRoom]\u3000存在しないGUIDを読み込もうとしました";
  483. NDebug.Assert(message, false);
  484. Debug.LogError(message);
  485. }
  486. GameObject gameObject = null;
  487. string path = CreativeRoomManager.cachedSaveDataDic[guid_room];
  488. if (!File.Exists(path))
  489. {
  490. string message2 = "[CreativeRoom]\u3000存在しないファイルを読み込もうとしました";
  491. NDebug.Warning(message2);
  492. Debug.LogWarning(message2);
  493. }
  494. else
  495. {
  496. using (FileStream fileStream = new FileStream(path, FileMode.Open))
  497. {
  498. byte[] buffer = new byte[fileStream.Length];
  499. fileStream.Read(buffer, 0, (int)fileStream.Length);
  500. using (BinaryReader binaryReader = new BinaryReader(new MemoryStream(buffer)))
  501. {
  502. CreativeRoomManager.CreativeRoomHeader creativeRoomHeader;
  503. CreativeRoomManager.DeserializeHeader(binaryReader, out creativeRoomHeader);
  504. long position = binaryReader.BaseStream.Position;
  505. int num = binaryReader.ReadInt32();
  506. int num2 = binaryReader.ReadInt32();
  507. int num3 = binaryReader.ReadInt32();
  508. float num4 = binaryReader.ReadSingle();
  509. binaryReader.BaseStream.Seek(position, SeekOrigin.Begin);
  510. GameObject gameObject2 = CreativeRoom.Load(binaryReader);
  511. GameObject gameObject3 = CreativeRoomUIObjectSettings.Load(binaryReader);
  512. gameObject2.name = "Parent Room Mesh";
  513. gameObject3.name = "Parent Deployment Object";
  514. gameObject = new GameObject("部屋でーた");
  515. gameObject2.transform.SetParent(gameObject.transform, true);
  516. gameObject3.transform.SetParent(gameObject.transform, true);
  517. Vector3 localPosition = -0.5f * num4 * new Vector3((float)(num - 1), 0f, (float)(num3 - 1));
  518. gameObject2.transform.localPosition = localPosition;
  519. gameObject3.transform.localPosition = localPosition;
  520. }
  521. }
  522. }
  523. return gameObject;
  524. }
  525. public static bool IsExistSaveData(string guid_room)
  526. {
  527. return CreativeRoomManager.cachedSaveDataDic.ContainsKey(guid_room) && File.Exists(CreativeRoomManager.cachedSaveDataDic[guid_room]);
  528. }
  529. private static void FileOpen(string path, Action<BinaryReader> action)
  530. {
  531. using (FileStream fileStream = new FileStream(path, FileMode.Open))
  532. {
  533. byte[] buffer = new byte[fileStream.Length];
  534. fileStream.Read(buffer, 0, (int)fileStream.Length);
  535. using (BinaryReader binaryReader = new BinaryReader(new MemoryStream(buffer)))
  536. {
  537. action(binaryReader);
  538. }
  539. }
  540. }
  541. private static void DeserializeHeader(string path, out CreativeRoomManager.CreativeRoomHeader header)
  542. {
  543. using (FileStream fileStream = new FileStream(path, FileMode.Open))
  544. {
  545. byte[] buffer = new byte[fileStream.Length];
  546. fileStream.Read(buffer, 0, (int)fileStream.Length);
  547. using (BinaryReader binaryReader = new BinaryReader(new MemoryStream(buffer)))
  548. {
  549. CreativeRoomManager.DeserializeHeader(binaryReader, out header);
  550. }
  551. }
  552. }
  553. private static void DeserializeHeader(BinaryReader br, out CreativeRoomManager.CreativeRoomHeader header)
  554. {
  555. string a = br.ReadString();
  556. int num = 0;
  557. if (a != "COM3D2_MY_ROOM")
  558. {
  559. br.BaseStream.Seek(0L, SeekOrigin.Begin);
  560. }
  561. else if (!int.TryParse(br.ReadString(), out num))
  562. {
  563. string message = "[CreativeRoom]\u3000セーブデータのヘッダーが不正です";
  564. Debug.LogError(message);
  565. NDebug.Assert(message, false);
  566. }
  567. header = new CreativeRoomManager.CreativeRoomHeader();
  568. header.comment = br.ReadString();
  569. header.lastWriteTime = br.ReadString();
  570. if (num >= 1)
  571. {
  572. header.guid = br.ReadString();
  573. }
  574. header.headerSize = br.BaseStream.Position;
  575. }
  576. private static void SerializeAndUpdateHeader(FileInfo info, CreativeRoomManager.CreativeRoomHeader header)
  577. {
  578. CreativeRoomManager.CreativeRoomHeader creativeRoomHeader;
  579. CreativeRoomManager.DeserializeHeader(info.FullName, out creativeRoomHeader);
  580. FileStream fileStream = new FileStream(info.FullName, FileMode.Open);
  581. byte[] array = new byte[fileStream.Length];
  582. fileStream.Read(array, 0, (int)fileStream.Length);
  583. fileStream.Close();
  584. fileStream.Dispose();
  585. MemoryStream memoryStream = new MemoryStream();
  586. BinaryWriter binaryWriter = new BinaryWriter(memoryStream);
  587. int num = (int)creativeRoomHeader.headerSize;
  588. binaryWriter.Write("COM3D2_MY_ROOM");
  589. binaryWriter.Write("2");
  590. binaryWriter.Write(header.comment);
  591. binaryWriter.Write(header.lastWriteTime);
  592. binaryWriter.Write(header.guid);
  593. binaryWriter.Write(array, num, array.Length - num);
  594. File.WriteAllBytes(info.FullName, memoryStream.ToArray());
  595. memoryStream.Close();
  596. memoryStream.Dispose();
  597. Debug.Log("セーブデータ" + info.Name + ":ヘッダーを保存");
  598. }
  599. [SerializeField]
  600. private CreativeRoom m_PtrCreativeRoom;
  601. [SerializeField]
  602. private CreativeRoomUIObjectSettings m_PtrCreativeRoomUIObjectSettings;
  603. [SerializeField]
  604. private CreativeRoomUIPlacementMaid m_PtrCreativeRoomUIPlacementMaid;
  605. [SerializeField]
  606. private RectTransform m_PtrCreativeRoomUIModeChangeButtons;
  607. private Camera m_MainCamera;
  608. private Camera m_CamerauGUI;
  609. private const string STR_SAVE_DATA_PATH = "MyRoom";
  610. private const string STR_SAVE_FILE_NAME = "Room_";
  611. private const string STR_SAVE_EXT = ".room";
  612. private const string STR_SERIALIZE_VER = "2";
  613. private const string STR_HEADER = "COM3D2_MY_ROOM";
  614. public string m_MusicName = "BGM020";
  615. private string m_strScriptReturnLabel = string.Empty;
  616. private static StringDictionary m_CachedSaveDataDic;
  617. private const string STR_ROOM_NAME_DEFAULT_HEADER = "自室カスタム";
  618. private const int ROOM_NAME_MAX_COUNT = 10;
  619. private const string STR_ROOM_NAME_ELLIPSE = "…";
  620. public class CreativeRoomHeader
  621. {
  622. public string guid;
  623. public string comment;
  624. public string lastWriteTime;
  625. public long headerSize;
  626. }
  627. }
  628. }