CreativeRoomManager.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692
  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 float cameraFOV
  40. {
  41. set
  42. {
  43. if (value != this.m_CamerauGUI.fieldOfView)
  44. {
  45. this.m_CamerauGUI.fieldOfView = value;
  46. }
  47. }
  48. }
  49. private float cameraOrthographicSize
  50. {
  51. set
  52. {
  53. if (value != this.m_CamerauGUI.orthographicSize)
  54. {
  55. this.m_CamerauGUI.orthographicSize = value;
  56. }
  57. }
  58. }
  59. private bool cameraOrthographic
  60. {
  61. set
  62. {
  63. if (value != this.m_CamerauGUI.orthographic)
  64. {
  65. this.m_CamerauGUI.orthographic = value;
  66. }
  67. }
  68. }
  69. private Rect cameraRect
  70. {
  71. set
  72. {
  73. if (value != this.m_CamerauGUI.rect)
  74. {
  75. this.m_CamerauGUI.rect = value;
  76. }
  77. }
  78. }
  79. private void Awake()
  80. {
  81. Camera camera = GameMain.Instance.MainCamera.camera;
  82. this.m_MainCamera = camera;
  83. GameObject gameObject = new GameObject("[CreativeRoom]Camera (Input Module)");
  84. this.m_CamerauGUI = gameObject.AddComponent<Camera>();
  85. this.m_CamerauGUI.clearFlags = CameraClearFlags.Nothing;
  86. this.m_CamerauGUI.useOcclusionCulling = false;
  87. this.m_CamerauGUI.enabled = false;
  88. this.m_CamerauGUI.allowHDR = false;
  89. this.m_CamerauGUI.allowMSAA = false;
  90. this.m_CamerauGUI.gameObject.AddComponent<PhysicsRaycaster>();
  91. Transform transform = camera.transform;
  92. gameObject.transform.SetParent(transform, false);
  93. gameObject.transform.localPosition = Vector3.zero;
  94. gameObject.transform.localEulerAngles = Vector3.zero;
  95. gameObject.transform.localScale = Vector3.one;
  96. this.cameraFOV = camera.fieldOfView;
  97. this.cameraOrthographic = camera.orthographic;
  98. this.cameraOrthographicSize = camera.orthographicSize;
  99. this.cameraRect = camera.pixelRect;
  100. CharacterMgr characterMgr = GameMain.Instance.CharacterMgr;
  101. for (int i = 0; i < characterMgr.GetMaidCount(); i++)
  102. {
  103. if (characterMgr.GetMaid(i) != null)
  104. {
  105. characterMgr.GetMaid(i).Visible = false;
  106. }
  107. }
  108. }
  109. private void Start()
  110. {
  111. if (!this.m_PtrCreativeRoom)
  112. {
  113. this.m_PtrCreativeRoom = UnityEngine.Object.FindObjectOfType<CreativeRoom>();
  114. }
  115. if (!this.m_PtrCreativeRoomUIObjectSettings)
  116. {
  117. this.m_PtrCreativeRoomUIObjectSettings = UnityEngine.Object.FindObjectOfType<CreativeRoomUIObjectSettings>();
  118. }
  119. if (!this.m_PtrCreativeRoomUIPlacementMaid)
  120. {
  121. this.m_PtrCreativeRoomUIPlacementMaid = UnityEngine.Object.FindObjectOfType<CreativeRoomUIPlacementMaid>();
  122. }
  123. this.GetTagBackup();
  124. GameMain.Instance.BgMgr.DeleteBg();
  125. GameMain.Instance.SoundMgr.PlayBGM(this.m_MusicName + ".ogg", 0.5f, true);
  126. GameMain.Instance.MainCamera.Reset(CameraMain.CameraType.Target, true);
  127. GameMain.Instance.MainCamera.SetTargetPos(new Vector3(0f, 1.8f, 0f), true);
  128. GameMain.Instance.MainCamera.SetDistance(7f, true);
  129. GameMain.Instance.MainCamera.SetAroundAngle(new Vector2(45f, 20f), true);
  130. GameMain.Instance.MainCamera.FadeIn(0.5f, false, null, true, true, default(Color));
  131. if (!uGUITutorialPanel.IsOpened())
  132. {
  133. uGUITutorialPanel.OpenTutorial("SceneCreativeRoom", null, false);
  134. }
  135. }
  136. private void Update()
  137. {
  138. GameMain.VRDeviceType vrdeviceTypeID = GameMain.Instance.VRDeviceTypeID;
  139. if (vrdeviceTypeID != GameMain.VRDeviceType.RIFT_TOUCH && vrdeviceTypeID != GameMain.VRDeviceType.VIVE)
  140. {
  141. this.cameraFOV = this.m_MainCamera.fieldOfView;
  142. this.cameraOrthographic = this.m_MainCamera.orthographic;
  143. this.cameraOrthographicSize = this.m_MainCamera.orthographicSize;
  144. this.cameraRect = this.m_MainCamera.pixelRect;
  145. }
  146. }
  147. public CreativeRoomManager.CreativeRoomHeader Save(int number)
  148. {
  149. string text = UTY.gameProjectPath + "\\";
  150. text += "MyRoom\\";
  151. string text2 = "Room_";
  152. text2 += number.ToString("000");
  153. text2 += ".room";
  154. if (!Directory.Exists(text))
  155. {
  156. Directory.CreateDirectory(text);
  157. }
  158. MemoryStream memoryStream = new MemoryStream();
  159. BinaryWriter binaryWriter = new BinaryWriter(memoryStream);
  160. string text3 = DateTime.Now.ToString("yyyyMMddHHmm");
  161. CreativeRoomManager.CreativeRoomHeader creativeRoomHeader = this.GetSaveDataHeader(number);
  162. if (creativeRoomHeader != null)
  163. {
  164. binaryWriter.Write("COM3D2_MY_ROOM");
  165. binaryWriter.Write("2");
  166. binaryWriter.Write(creativeRoomHeader.comment);
  167. binaryWriter.Write(text3);
  168. string value = creativeRoomHeader.guid;
  169. if (string.IsNullOrEmpty(value))
  170. {
  171. value = Guid.NewGuid().ToString();
  172. }
  173. binaryWriter.Write(value);
  174. creativeRoomHeader.lastWriteTime = text3;
  175. }
  176. else
  177. {
  178. binaryWriter.Write("COM3D2_MY_ROOM");
  179. binaryWriter.Write("2");
  180. binaryWriter.Write(string.Empty);
  181. binaryWriter.Write(text3);
  182. string text4 = Guid.NewGuid().ToString();
  183. binaryWriter.Write(text4);
  184. creativeRoomHeader = new CreativeRoomManager.CreativeRoomHeader();
  185. creativeRoomHeader.guid = text4;
  186. creativeRoomHeader.comment = string.Empty;
  187. creativeRoomHeader.lastWriteTime = text3;
  188. }
  189. this.m_PtrCreativeRoom.SavePanelData(binaryWriter);
  190. this.m_PtrCreativeRoomUIObjectSettings.SaveDeployObjectData(binaryWriter);
  191. File.WriteAllBytes(text + text2, memoryStream.ToArray());
  192. memoryStream.Close();
  193. memoryStream.Dispose();
  194. return creativeRoomHeader;
  195. }
  196. public void Load(int number)
  197. {
  198. string text = UTY.gameProjectPath + "\\";
  199. text += "MyRoom\\";
  200. if (!Directory.Exists(text))
  201. {
  202. Directory.CreateDirectory(text);
  203. }
  204. string text2 = text + "Room_" + number.ToString("000");
  205. if (File.Exists(text2 + ".save"))
  206. {
  207. text2 += ".save";
  208. }
  209. else
  210. {
  211. if (!File.Exists(text2 + ".room"))
  212. {
  213. Debug.LogWarning(string.Format("[CreativeRoomManager]{0}\u3000のセーブファイルが見つかりませんでした", text2));
  214. return;
  215. }
  216. text2 += ".room";
  217. }
  218. FileStream fileStream = new FileStream(text2, FileMode.Open);
  219. byte[] buffer = new byte[fileStream.Length];
  220. fileStream.Read(buffer, 0, (int)fileStream.Length);
  221. fileStream.Close();
  222. fileStream.Dispose();
  223. BinaryReader binaryReader = new BinaryReader(new MemoryStream(buffer));
  224. string a = binaryReader.ReadString();
  225. int num = 0;
  226. if (a != "COM3D2_MY_ROOM")
  227. {
  228. binaryReader.BaseStream.Seek(0L, SeekOrigin.Begin);
  229. }
  230. else if (!int.TryParse(binaryReader.ReadString(), out num))
  231. {
  232. string message = "[自室カスタム]セーブデータのヘッダーが不正です\n" + text2;
  233. Debug.LogError(message);
  234. NDebug.Assert(message, false);
  235. }
  236. binaryReader.ReadString();
  237. binaryReader.ReadString();
  238. if (num >= 1)
  239. {
  240. binaryReader.ReadString();
  241. }
  242. this.m_PtrCreativeRoom.LoadPanelData(binaryReader);
  243. this.m_PtrCreativeRoomUIObjectSettings.LoadDeployObjectData(binaryReader);
  244. this.m_PtrCreativeRoomUIObjectSettings.SetDeploymentObjectGizmoEnable(false);
  245. binaryReader.Close();
  246. }
  247. public CreativeRoomManager.CreativeRoomHeader GetSaveDataHeader(int number)
  248. {
  249. return this.GetSaveDataHeader(number.ToString("000"));
  250. }
  251. public CreativeRoomManager.CreativeRoomHeader GetSaveDataHeader(string number)
  252. {
  253. string str = UTY.gameProjectPath + "\\";
  254. str += "MyRoom\\";
  255. string text = "Room_" + number;
  256. if (File.Exists(str + text + ".save"))
  257. {
  258. text += ".save";
  259. }
  260. else
  261. {
  262. text += ".room";
  263. }
  264. if (!File.Exists(str + text))
  265. {
  266. return null;
  267. }
  268. FileStream fileStream = new FileStream(str + text, FileMode.Open);
  269. byte[] buffer = new byte[fileStream.Length];
  270. fileStream.Read(buffer, 0, (int)fileStream.Length);
  271. fileStream.Close();
  272. fileStream.Dispose();
  273. BinaryReader binaryReader = new BinaryReader(new MemoryStream(buffer));
  274. CreativeRoomManager.CreativeRoomHeader creativeRoomHeader = new CreativeRoomManager.CreativeRoomHeader();
  275. string a = binaryReader.ReadString();
  276. int num = 0;
  277. if (a != "COM3D2_MY_ROOM")
  278. {
  279. binaryReader.BaseStream.Seek(0L, SeekOrigin.Begin);
  280. }
  281. else if (!int.TryParse(binaryReader.ReadString(), out num))
  282. {
  283. string message = "[自室カスタム]セーブデータのヘッダーが不正です\n" + text;
  284. Debug.LogError(message);
  285. NDebug.Assert(message, false);
  286. }
  287. creativeRoomHeader.comment = binaryReader.ReadString();
  288. creativeRoomHeader.lastWriteTime = binaryReader.ReadString();
  289. if (num >= 1)
  290. {
  291. creativeRoomHeader.guid = binaryReader.ReadString();
  292. }
  293. creativeRoomHeader.headerSize = binaryReader.BaseStream.Position;
  294. binaryReader.Close();
  295. return creativeRoomHeader;
  296. }
  297. public void SaveComment(int number, string comment)
  298. {
  299. this.SaveComment(number.ToString("000"), comment);
  300. }
  301. public void SaveComment(string number, string comment)
  302. {
  303. CreativeRoomManager.CreativeRoomHeader saveDataHeader = this.GetSaveDataHeader(number);
  304. if (saveDataHeader == null)
  305. {
  306. return;
  307. }
  308. string str = UTY.gameProjectPath + "\\";
  309. str += "MyRoom\\";
  310. string path = str + "Room_" + number + ".room";
  311. FileStream fileStream = new FileStream(path, FileMode.Open);
  312. byte[] array = new byte[fileStream.Length];
  313. fileStream.Read(array, 0, (int)fileStream.Length);
  314. fileStream.Close();
  315. fileStream.Dispose();
  316. MemoryStream memoryStream = new MemoryStream();
  317. BinaryWriter binaryWriter = new BinaryWriter(memoryStream);
  318. int num = (int)saveDataHeader.headerSize;
  319. binaryWriter.Write("COM3D2_MY_ROOM");
  320. binaryWriter.Write("2");
  321. binaryWriter.Write(comment);
  322. binaryWriter.Write(saveDataHeader.lastWriteTime);
  323. if (string.IsNullOrEmpty(saveDataHeader.guid))
  324. {
  325. saveDataHeader.guid = Guid.NewGuid().ToString();
  326. }
  327. binaryWriter.Write(saveDataHeader.guid);
  328. binaryWriter.Write(array, num, array.Length - num);
  329. File.WriteAllBytes(path, memoryStream.ToArray());
  330. memoryStream.Close();
  331. memoryStream.Dispose();
  332. Debug.Log("セーブデータ" + number + "番:ヘッダーを保存");
  333. }
  334. public string DateTimeParse(string strDate)
  335. {
  336. return DateTime.ParseExact(strDate, "yyyyMMddHHmm", null).ToString("yyyy.MM.dd HH:mm");
  337. }
  338. private void GetTagBackup()
  339. {
  340. Dictionary<string, string> tag_backup = GameMain.Instance.ScriptMgr.adv_kag.tag_backup;
  341. string a;
  342. if (tag_backup != null && tag_backup.TryGetValue("name", out a) && a == "SceneCreativeRoom")
  343. {
  344. if (!tag_backup.TryGetValue("label", out this.m_strScriptReturnLabel))
  345. {
  346. Debug.LogFormat("スクリプトからの引数「{0}」がありませんでした", new object[]
  347. {
  348. "label"
  349. });
  350. }
  351. }
  352. }
  353. public void Exit()
  354. {
  355. if (!GameMain.Instance.SysDlg.IsDecided)
  356. {
  357. return;
  358. }
  359. GameMain.Instance.SysDlg.ShowFromLanguageTerm("ScenePhotoMode/セーブしていないデータは失われます。終了しますか?", null, SystemDialog.TYPE.YES_NO, delegate
  360. {
  361. if (string.IsNullOrEmpty(this.m_strScriptReturnLabel))
  362. {
  363. Debug.Log("シーン終了時に飛ぶラベルがありませんでした");
  364. return;
  365. }
  366. GameMain.Instance.MainCamera.FadeOut(0.5f, false, delegate
  367. {
  368. GameMain.Instance.SoundMgr.StopBGM(1f);
  369. PlacementData.Clear();
  370. TextureData.Clear();
  371. uGUIUtility.SetActiveEventSystem(true);
  372. ScriptManager scriptMgr = GameMain.Instance.ScriptMgr;
  373. scriptMgr.adv_kag.JumpLabel(this.m_strScriptReturnLabel);
  374. scriptMgr.adv_kag.Exec();
  375. }, true, default(Color));
  376. GameMain.Instance.SysDlg.Close();
  377. }, delegate
  378. {
  379. GameMain.Instance.SysDlg.Close();
  380. uGUIUtility.SetActiveEventSystem(true);
  381. });
  382. uGUIUtility.SetActiveEventSystem(false);
  383. }
  384. private void OnDestroy()
  385. {
  386. if (this.m_CamerauGUI)
  387. {
  388. UnityEngine.Object.Destroy(this.m_CamerauGUI.gameObject);
  389. }
  390. }
  391. private static StringDictionary cachedSaveDataDic
  392. {
  393. get
  394. {
  395. if (CreativeRoomManager.m_CachedSaveDataDic == null)
  396. {
  397. CreativeRoomManager.m_CachedSaveDataDic = new StringDictionary();
  398. string text = UTY.gameProjectPath + "\\";
  399. text += "MyRoom\\";
  400. if (Directory.Exists(text))
  401. {
  402. string[] files = Directory.GetFiles(text, "*.room");
  403. for (int i = 0; i < files.Length; i++)
  404. {
  405. CreativeRoomManager.CreativeRoomHeader creativeRoomHeader;
  406. CreativeRoomManager.DeserializeHeader(files[i], out creativeRoomHeader);
  407. CreativeRoomManager.m_CachedSaveDataDic[creativeRoomHeader.guid] = files[i];
  408. }
  409. }
  410. }
  411. return CreativeRoomManager.m_CachedSaveDataDic;
  412. }
  413. }
  414. public static Dictionary<string, string> GetSaveDataDic()
  415. {
  416. CreativeRoomManager.UpdateSaveDataGUID();
  417. if (CreativeRoomManager.m_CachedSaveDataDic != null)
  418. {
  419. CreativeRoomManager.m_CachedSaveDataDic.Clear();
  420. }
  421. CreativeRoomManager.m_CachedSaveDataDic = new StringDictionary();
  422. string text = UTY.gameProjectPath + "\\";
  423. text += "MyRoom\\";
  424. Dictionary<string, string> dictionary = null;
  425. if (Directory.Exists(text))
  426. {
  427. dictionary = new Dictionary<string, string>();
  428. string[] files = Directory.GetFiles(text, "*.room");
  429. for (int i = 0; i < files.Length; i++)
  430. {
  431. CreativeRoomManager.CreativeRoomHeader creativeRoomHeader;
  432. CreativeRoomManager.DeserializeHeader(files[i], out creativeRoomHeader);
  433. string text2 = string.Empty;
  434. if (string.IsNullOrEmpty(creativeRoomHeader.comment))
  435. {
  436. text2 = "自室カスタム" + i.ToString("000");
  437. }
  438. else
  439. {
  440. int num = 10;
  441. text2 = creativeRoomHeader.comment;
  442. if (text2.Length > num)
  443. {
  444. text2 = text2.Substring(0, num - 1) + "…";
  445. }
  446. }
  447. dictionary.Add(creativeRoomHeader.guid, text2);
  448. CreativeRoomManager.m_CachedSaveDataDic[creativeRoomHeader.guid] = files[i];
  449. }
  450. }
  451. return dictionary;
  452. }
  453. private static void UpdateSaveDataGUID()
  454. {
  455. string text = UTY.gameProjectPath + "\\";
  456. text += "MyRoom\\";
  457. if (Directory.Exists(text))
  458. {
  459. SortedDictionary<string, KeyValuePair<FileInfo, CreativeRoomManager.CreativeRoomHeader>> sortedDictionary = new SortedDictionary<string, KeyValuePair<FileInfo, CreativeRoomManager.CreativeRoomHeader>>();
  460. string[] files = Directory.GetFiles(text, "*.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. }