CreativeRoomManager.cs 22 KB

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