CreativeRoom.cs 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using I2.Loc;
  5. using UnityEngine;
  6. using UnityEngine.EventSystems;
  7. using UnityEngine.Rendering;
  8. using UnityEngine.UI;
  9. using wf;
  10. namespace MyRoomCustom
  11. {
  12. public class CreativeRoom : MonoBehaviour
  13. {
  14. public int mapSizeX
  15. {
  16. get
  17. {
  18. return this.m_MapSizeX;
  19. }
  20. set
  21. {
  22. this.m_MapSizeX = Mathf.Clamp(value, 1, 32);
  23. }
  24. }
  25. public int mapSizeZ
  26. {
  27. get
  28. {
  29. return this.m_MapSizeZ;
  30. }
  31. set
  32. {
  33. this.m_MapSizeZ = Mathf.Clamp(value, 1, 32);
  34. }
  35. }
  36. public int mapSizeY
  37. {
  38. get
  39. {
  40. return this.m_MapSizeY;
  41. }
  42. set
  43. {
  44. this.m_MapSizeY = Mathf.Clamp(value, 2, 16);
  45. }
  46. }
  47. public float unitSize
  48. {
  49. get
  50. {
  51. return this.m_UnitSize;
  52. }
  53. set
  54. {
  55. this.m_UnitSize = Mathf.Clamp(value, 0.25f, 1f);
  56. CreativeRoomUIObjectSettings creativeRoomUIObjSetting = this.m_Manager.creativeRoomUIObjSetting;
  57. if (creativeRoomUIObjSetting)
  58. {
  59. creativeRoomUIObjSetting.snapValuePosition = this.m_UnitSize * 0.5f;
  60. }
  61. CreativeRoomUIPlacementMaid creativeRoomUIMaid = this.m_Manager.creativeRoomUIMaid;
  62. if (creativeRoomUIMaid)
  63. {
  64. creativeRoomUIMaid.snapValuePosition = this.m_UnitSize * 0.5f;
  65. }
  66. }
  67. }
  68. private static GameObject prefabUnit
  69. {
  70. get
  71. {
  72. if (CreativeRoom.m_PrefabUnit == null)
  73. {
  74. CreativeRoom.m_PrefabUnit = GameObject.CreatePrimitive(PrimitiveType.Quad);
  75. CreativeRoom.m_PrefabUnit.AddComponent<Rigidbody>().isKinematic = true;
  76. Renderer component = CreativeRoom.m_PrefabUnit.GetComponent<Renderer>();
  77. component.reflectionProbeUsage = ReflectionProbeUsage.Off;
  78. component.shadowCastingMode = ShadowCastingMode.Off;
  79. component.receiveShadows = false;
  80. CreativeRoom.m_PrefabUnit.gameObject.SetActive(false);
  81. CreativeRoom.m_PrefabUnit.layer = LayerMask.NameToLayer("Terrain");
  82. }
  83. return CreativeRoom.m_PrefabUnit;
  84. }
  85. }
  86. private static Transform parentTileObject
  87. {
  88. get
  89. {
  90. if (CreativeRoom.m_ParentTileObject == null)
  91. {
  92. CreativeRoom.m_ParentTileObject = new GameObject("Parent Tile Object");
  93. }
  94. return CreativeRoom.m_ParentTileObject.transform;
  95. }
  96. }
  97. private static GameObject parentCombineMeshObject
  98. {
  99. get
  100. {
  101. if (CreativeRoom.m_ParentCombineMeshObject == null)
  102. {
  103. CreativeRoom.m_ParentCombineMeshObject = new GameObject("Combine Mesh Object Parent");
  104. }
  105. return CreativeRoom.m_ParentCombineMeshObject;
  106. }
  107. }
  108. private void Start()
  109. {
  110. if (CreativeRoom.m_MatDefaultColor == null)
  111. {
  112. CreativeRoom.m_MatDefaultColor = new Material(Shader.Find("CM3D2/RoomPanel"));
  113. CreativeRoom.m_MatDefaultColor.SetColor("_Color", Color.white);
  114. CreativeRoom.m_MatDefaultColor.SetColor("_ShadowColor", Color.black);
  115. }
  116. if (CreativeRoom.m_MatHighlightColor == null)
  117. {
  118. CreativeRoom.m_MatHighlightColor = new Material(Shader.Find("CM3D2/RoomPanel"));
  119. CreativeRoom.m_MatHighlightColor.SetColor("_Color", new Color(1f, 0.75f, 1f, 1f));
  120. CreativeRoom.m_MatHighlightColor.SetColor("_ShadowColor", Color.black);
  121. }
  122. if (CreativeRoom.m_MatDisableColor == null)
  123. {
  124. CreativeRoom.m_MatDisableColor = new Material(Shader.Find("CM3D2/RoomPanel"));
  125. CreativeRoom.m_MatDisableColor.SetColor("_Color", Color.white * 0.25f);
  126. CreativeRoom.m_MatDisableColor.SetColor("_ShadowColor", Color.black);
  127. }
  128. if (CreativeRoom.m_MatSelectColor == null)
  129. {
  130. CreativeRoom.m_MatSelectColor = new Material(Shader.Find("CM3D2/RoomPanelSelect"));
  131. }
  132. this.m_MaterialPropertyBlock = new MaterialPropertyBlock();
  133. this.m_MaterialPropertyBlock.SetColor("_Color", new Color(0.5f, 1f, 1f, 1f));
  134. CreativeRoom.LoadAllTextures();
  135. Renderer component = CreativeRoom.prefabUnit.GetComponent<Renderer>();
  136. if (component && CreativeRoom.m_Materials != null && CreativeRoom.m_Materials.Count > 0)
  137. {
  138. component.sharedMaterial = CreativeRoom.m_Materials[0];
  139. }
  140. this.SetUpInputArea();
  141. this.OnUpdateMap();
  142. this.InvokeAllPanels(false, false, false, false, false, true, delegate(CreativeRoom.TileObject floorPanel)
  143. {
  144. this.AddEventQuad(floorPanel, new Action<BaseEventData, CreativeRoom.TileObject>(this.EventPointerEnter), new Action<BaseEventData, CreativeRoom.TileObject>(this.EventPointerExit), new Action<BaseEventData, CreativeRoom.TileObject>(this.EventPointerClick));
  145. }, delegate(CreativeRoom.TileObject otherPanel)
  146. {
  147. this.RemoveEventQuad(otherPanel);
  148. });
  149. this.CreateMaterialButton(0);
  150. }
  151. private void SetUpInputArea()
  152. {
  153. this.m_UIInputRoomSizeX.contentType = InputField.ContentType.IntegerNumber;
  154. this.m_UIInputRoomSizeY.contentType = InputField.ContentType.IntegerNumber;
  155. this.m_UIInputRoomSizeZ.contentType = InputField.ContentType.IntegerNumber;
  156. this.m_UIInputUnitScale.contentType = InputField.ContentType.DecimalNumber;
  157. this.m_UIInputRoomSizeX.text = this.mapSizeX.ToString();
  158. this.m_UIInputRoomSizeY.text = this.mapSizeY.ToString();
  159. this.m_UIInputRoomSizeZ.text = this.mapSizeZ.ToString();
  160. this.m_UIInputUnitScale.text = this.unitSize.ToString();
  161. this.m_UIInputRoomSizeX.onValueChanged.AddListener(delegate(string str)
  162. {
  163. int num;
  164. if (int.TryParse(str, out num))
  165. {
  166. if (num == this.mapSizeX)
  167. {
  168. return;
  169. }
  170. this.mapSizeX = num;
  171. this.m_UISliderRoomSizeX.value = (float)this.mapSizeX;
  172. }
  173. });
  174. this.m_UIInputRoomSizeY.onValueChanged.AddListener(delegate(string str)
  175. {
  176. int num;
  177. if (int.TryParse(str, out num))
  178. {
  179. if (num == this.mapSizeY)
  180. {
  181. return;
  182. }
  183. this.mapSizeY = num;
  184. this.m_UISliderRoomSizeY.value = (float)this.mapSizeY;
  185. }
  186. });
  187. this.m_UIInputRoomSizeZ.onValueChanged.AddListener(delegate(string str)
  188. {
  189. int num;
  190. if (int.TryParse(str, out num))
  191. {
  192. if (num == this.mapSizeZ)
  193. {
  194. return;
  195. }
  196. this.mapSizeZ = num;
  197. this.m_UISliderRoomSizeZ.value = (float)this.mapSizeZ;
  198. }
  199. });
  200. this.m_UIInputUnitScale.onValueChanged.AddListener(delegate(string str)
  201. {
  202. float num;
  203. if (float.TryParse(str, out num))
  204. {
  205. if (Mathf.Approximately(this.unitSize, num))
  206. {
  207. return;
  208. }
  209. this.unitSize = num;
  210. this.m_UISliderUnitScale.value = this.unitSize;
  211. }
  212. });
  213. this.m_UIInputRoomSizeX.onEndEdit.AddListener(delegate(string str)
  214. {
  215. this.m_UIInputRoomSizeX.text = this.mapSizeX.ToString();
  216. });
  217. this.m_UIInputRoomSizeY.onEndEdit.AddListener(delegate(string str)
  218. {
  219. this.m_UIInputRoomSizeY.text = this.mapSizeY.ToString();
  220. });
  221. this.m_UIInputRoomSizeZ.onEndEdit.AddListener(delegate(string str)
  222. {
  223. this.m_UIInputRoomSizeZ.text = this.mapSizeZ.ToString();
  224. });
  225. this.m_UIInputUnitScale.onEndEdit.AddListener(delegate(string str)
  226. {
  227. this.m_UIInputUnitScale.text = this.unitSize.ToString();
  228. });
  229. }
  230. public void OnUpdateMap()
  231. {
  232. this.SetFloorArraySize(this.mapSizeX, this.mapSizeY, this.mapSizeZ);
  233. CreativeRoom.OnUpdateMapWall(this.m_FloorArray, this.unitSize);
  234. this.InvokeAllPanels(false, false, false, false, false, true, delegate(CreativeRoom.TileObject floorPanel)
  235. {
  236. this.AddEventQuad(floorPanel, new Action<BaseEventData, CreativeRoom.TileObject>(this.EventPointerEnter), new Action<BaseEventData, CreativeRoom.TileObject>(this.EventPointerExit), new Action<BaseEventData, CreativeRoom.TileObject>(this.EventPointerClick));
  237. if (floorPanel.type == CreativeRoom.TileType.TempEnable)
  238. {
  239. this.SetPanelType(floorPanel, CreativeRoom.TileType.Enable);
  240. }
  241. else if (floorPanel.type == CreativeRoom.TileType.TempSelect)
  242. {
  243. this.SetPanelType(floorPanel, CreativeRoom.TileType.Select);
  244. }
  245. }, delegate(CreativeRoom.TileObject otherPanel)
  246. {
  247. this.RemoveEventQuad(otherPanel);
  248. if (otherPanel.type == CreativeRoom.TileType.Enable)
  249. {
  250. this.SetPanelType(otherPanel, CreativeRoom.TileType.TempEnable);
  251. }
  252. else if (otherPanel.type == CreativeRoom.TileType.Select)
  253. {
  254. this.SetPanelType(otherPanel, CreativeRoom.TileType.TempSelect);
  255. }
  256. });
  257. this.InvokeAllPanels(true, true, true, true, true, true, delegate(CreativeRoom.TileObject tileObject)
  258. {
  259. this.SetPanelType(tileObject, tileObject.type);
  260. }, null);
  261. this.UpdateRoomSizeText();
  262. if (CreativeRoom.m_CombineMeshObjectArray != null)
  263. {
  264. for (int i = 0; i < CreativeRoom.m_CombineMeshObjectArray.Count; i++)
  265. {
  266. if (CreativeRoom.m_CombineMeshObjectArray[i].activeSelf)
  267. {
  268. CreativeRoom.m_CombineMeshObjectArray[i].SetActive(false);
  269. }
  270. }
  271. }
  272. }
  273. private static void OnUpdateMapWall(List<List<List<CreativeRoom.TileData>>> floorArray, float unitSize)
  274. {
  275. for (int i = 0; i < floorArray.Count; i++)
  276. {
  277. for (int j = 0; j < floorArray[i].Count; j++)
  278. {
  279. for (int k = 0; k < floorArray[i][j].Count; k++)
  280. {
  281. CreativeRoom.TileData tileData = CreativeRoom.GetTileData(floorArray, i, j, k);
  282. if (tileData != null)
  283. {
  284. CreativeRoom.TileData tileData2 = CreativeRoom.GetTileData(floorArray, i, 0, k);
  285. CreativeRoom.TileData tileData3 = CreativeRoom.GetTileData(floorArray, i, j - 1, k);
  286. tileData.enableDown = (tileData.down.type == CreativeRoom.TileType.Enable && tileData3 == null);
  287. tileData3 = CreativeRoom.GetTileData(floorArray, i + 1, 0, k);
  288. tileData.enableRight = (tileData2.down.type != CreativeRoom.TileType.Disable && (tileData3 == null || tileData3.down.type == CreativeRoom.TileType.Disable));
  289. tileData3 = CreativeRoom.GetTileData(floorArray, i - 1, 0, k);
  290. tileData.enableLeft = (tileData2.down.type != CreativeRoom.TileType.Disable && (tileData3 == null || tileData3.down.type == CreativeRoom.TileType.Disable));
  291. tileData3 = CreativeRoom.GetTileData(floorArray, i, 0, k + 1);
  292. tileData.enableFront = (tileData2.down.type != CreativeRoom.TileType.Disable && (tileData3 == null || tileData3.down.type == CreativeRoom.TileType.Disable));
  293. tileData3 = CreativeRoom.GetTileData(floorArray, i, 0, k - 1);
  294. tileData.enableBack = (tileData2.down.type != CreativeRoom.TileType.Disable && (tileData3 == null || tileData3.down.type == CreativeRoom.TileType.Disable));
  295. tileData3 = CreativeRoom.GetTileData(floorArray, i, j + 1, k);
  296. tileData.enableUp = (tileData2.down.type != CreativeRoom.TileType.Disable && tileData3 == null);
  297. }
  298. }
  299. }
  300. }
  301. for (int l = 0; l < floorArray.Count; l++)
  302. {
  303. for (int m = 0; m < floorArray[l].Count; m++)
  304. {
  305. for (int n = 0; n < floorArray[l][m].Count; n++)
  306. {
  307. if (CreativeRoom.GetTileData(floorArray, l, m, n) != null)
  308. {
  309. CreativeRoom.CreateSixPanel(floorArray, l, m, n, unitSize);
  310. }
  311. }
  312. }
  313. }
  314. }
  315. private static void CreateSixPanel(List<List<List<CreativeRoom.TileData>>> floorArray, int x, int y, int z, float unitSize)
  316. {
  317. CreativeRoom.TileData tileData = CreativeRoom.GetTileData(floorArray, x, y, z);
  318. if (tileData == null)
  319. {
  320. return;
  321. }
  322. Transform parentTileObject = CreativeRoom.parentTileObject;
  323. if (tileData.enableRight)
  324. {
  325. GameObject gameObject = tileData.right.gameObject;
  326. if (gameObject == null)
  327. {
  328. gameObject = CreativeRoom.CreatePanel(parentTileObject);
  329. tileData.right.type = CreativeRoom.TileType.Enable;
  330. }
  331. if (!gameObject.activeSelf)
  332. {
  333. gameObject.SetActive(true);
  334. }
  335. Transform transform = gameObject.transform;
  336. transform.position = new Vector3((float)x + 0.5f, (float)y + 0.5f, (float)z) * unitSize;
  337. transform.rotation = Quaternion.AngleAxis(90f, Vector3.up);
  338. transform.localScale = Vector3.one * unitSize;
  339. tileData.right.gameObject = gameObject;
  340. }
  341. else
  342. {
  343. if (tileData.right.gameObject)
  344. {
  345. UnityEngine.Object.Destroy(tileData.right.gameObject);
  346. }
  347. tileData.right.Reset();
  348. }
  349. if (tileData.enableLeft)
  350. {
  351. GameObject gameObject2 = tileData.left.gameObject;
  352. if (gameObject2 == null)
  353. {
  354. gameObject2 = CreativeRoom.CreatePanel(parentTileObject);
  355. tileData.left.type = CreativeRoom.TileType.Enable;
  356. }
  357. if (!gameObject2.activeSelf)
  358. {
  359. gameObject2.SetActive(true);
  360. }
  361. Transform transform2 = gameObject2.transform;
  362. transform2.position = new Vector3((float)x - 0.5f, (float)y + 0.5f, (float)z) * unitSize;
  363. transform2.rotation = Quaternion.AngleAxis(-90f, Vector3.up);
  364. transform2.localScale = Vector3.one * unitSize;
  365. tileData.left.gameObject = gameObject2;
  366. }
  367. else
  368. {
  369. if (tileData.left.gameObject)
  370. {
  371. UnityEngine.Object.Destroy(tileData.left.gameObject);
  372. }
  373. tileData.left.Reset();
  374. }
  375. if (tileData.enableUp)
  376. {
  377. GameObject gameObject3 = tileData.up.gameObject;
  378. if (gameObject3 == null)
  379. {
  380. gameObject3 = CreativeRoom.CreatePanel(parentTileObject);
  381. tileData.up.type = CreativeRoom.TileType.Enable;
  382. }
  383. if (!gameObject3.activeSelf)
  384. {
  385. gameObject3.SetActive(true);
  386. }
  387. Transform transform3 = gameObject3.transform;
  388. transform3.position = new Vector3((float)x, (float)y + 1f, (float)z) * unitSize;
  389. transform3.rotation = Quaternion.AngleAxis(-90f, Vector3.right);
  390. transform3.localScale = Vector3.one * unitSize;
  391. tileData.up.gameObject = gameObject3;
  392. }
  393. else
  394. {
  395. if (tileData.up.gameObject)
  396. {
  397. UnityEngine.Object.Destroy(tileData.up.gameObject);
  398. }
  399. tileData.up.Reset();
  400. }
  401. if (tileData.enableDown || y == 0)
  402. {
  403. GameObject gameObject4 = tileData.down.gameObject;
  404. if (gameObject4 == null)
  405. {
  406. gameObject4 = CreativeRoom.CreatePanel(parentTileObject);
  407. if (tileData.enableDown)
  408. {
  409. tileData.down.type = CreativeRoom.TileType.Enable;
  410. }
  411. }
  412. if (!gameObject4.activeSelf)
  413. {
  414. gameObject4.SetActive(true);
  415. }
  416. Transform transform4 = gameObject4.transform;
  417. transform4.position = new Vector3((float)x, (float)y, (float)z) * unitSize;
  418. transform4.rotation = Quaternion.AngleAxis(90f, Vector3.right);
  419. transform4.localScale = Vector3.one * unitSize;
  420. tileData.down.gameObject = gameObject4;
  421. }
  422. else
  423. {
  424. if (tileData.down.gameObject)
  425. {
  426. UnityEngine.Object.Destroy(tileData.down.gameObject);
  427. }
  428. tileData.down.Reset();
  429. }
  430. if (tileData.enableFront)
  431. {
  432. GameObject gameObject5 = tileData.front.gameObject;
  433. if (gameObject5 == null)
  434. {
  435. gameObject5 = CreativeRoom.CreatePanel(parentTileObject);
  436. tileData.front.type = CreativeRoom.TileType.Enable;
  437. }
  438. if (!gameObject5.activeSelf)
  439. {
  440. gameObject5.SetActive(true);
  441. }
  442. Transform transform5 = gameObject5.transform;
  443. transform5.position = new Vector3((float)x, (float)y + 0.5f, (float)z + 0.5f) * unitSize;
  444. transform5.rotation = Quaternion.AngleAxis(0f, Vector3.up);
  445. transform5.localScale = Vector3.one * unitSize;
  446. tileData.front.gameObject = gameObject5;
  447. }
  448. else
  449. {
  450. if (tileData.front.gameObject)
  451. {
  452. UnityEngine.Object.Destroy(tileData.front.gameObject);
  453. }
  454. tileData.front.Reset();
  455. }
  456. if (tileData.enableBack)
  457. {
  458. GameObject gameObject6 = tileData.back.gameObject;
  459. if (gameObject6 == null)
  460. {
  461. gameObject6 = CreativeRoom.CreatePanel(parentTileObject);
  462. tileData.back.type = CreativeRoom.TileType.Enable;
  463. }
  464. if (!gameObject6.activeSelf)
  465. {
  466. gameObject6.SetActive(true);
  467. }
  468. Transform transform6 = gameObject6.transform;
  469. transform6.position = new Vector3((float)x, (float)y + 0.5f, (float)z - 0.5f) * unitSize;
  470. transform6.rotation = Quaternion.AngleAxis(180f, Vector3.up);
  471. transform6.localScale = Vector3.one * unitSize;
  472. tileData.back.gameObject = gameObject6;
  473. }
  474. else
  475. {
  476. if (tileData.back.gameObject)
  477. {
  478. UnityEngine.Object.Destroy(tileData.back.gameObject);
  479. }
  480. tileData.back.Reset();
  481. }
  482. }
  483. private static GameObject CreatePanel(Transform parent)
  484. {
  485. GameObject gameObject = UnityEngine.Object.Instantiate<GameObject>(CreativeRoom.prefabUnit);
  486. Transform transform = gameObject.transform;
  487. if (!gameObject.activeSelf)
  488. {
  489. gameObject.SetActive(true);
  490. }
  491. if (parent != null)
  492. {
  493. transform.SetParent(parent, false);
  494. }
  495. return gameObject;
  496. }
  497. public void SetMapSizeX(float x)
  498. {
  499. if (!this.m_UIInputRoomSizeX.isFocused)
  500. {
  501. this.m_UIInputRoomSizeX.text = ((int)x).ToString();
  502. }
  503. this.mapSizeX = (int)x;
  504. this.OnUpdateMap();
  505. this.InvokeAllPanels(false, false, false, false, false, true, delegate(CreativeRoom.TileObject floorPanel)
  506. {
  507. this.AddEventQuad(floorPanel, new Action<BaseEventData, CreativeRoom.TileObject>(this.EventPointerEnter), new Action<BaseEventData, CreativeRoom.TileObject>(this.EventPointerExit), new Action<BaseEventData, CreativeRoom.TileObject>(this.EventPointerClick));
  508. }, delegate(CreativeRoom.TileObject otherPanel)
  509. {
  510. this.RemoveEventQuad(otherPanel);
  511. });
  512. }
  513. public void SetMapSizeZ(float z)
  514. {
  515. if (!this.m_UIInputRoomSizeZ.isFocused)
  516. {
  517. this.m_UIInputRoomSizeZ.text = ((int)z).ToString();
  518. }
  519. this.mapSizeZ = (int)z;
  520. this.OnUpdateMap();
  521. this.InvokeAllPanels(false, false, false, false, false, true, delegate(CreativeRoom.TileObject floorPanel)
  522. {
  523. this.AddEventQuad(floorPanel, new Action<BaseEventData, CreativeRoom.TileObject>(this.EventPointerEnter), new Action<BaseEventData, CreativeRoom.TileObject>(this.EventPointerExit), new Action<BaseEventData, CreativeRoom.TileObject>(this.EventPointerClick));
  524. }, delegate(CreativeRoom.TileObject otherPanel)
  525. {
  526. this.RemoveEventQuad(otherPanel);
  527. });
  528. }
  529. public void SetMapSizeY(float y)
  530. {
  531. if (!this.m_UIInputRoomSizeY.isFocused)
  532. {
  533. this.m_UIInputRoomSizeY.text = ((int)y).ToString();
  534. }
  535. this.mapSizeY = (int)y;
  536. this.OnUpdateMap();
  537. this.InvokeAllPanels(false, false, false, false, false, true, delegate(CreativeRoom.TileObject floorPanel)
  538. {
  539. this.AddEventQuad(floorPanel, new Action<BaseEventData, CreativeRoom.TileObject>(this.EventPointerEnter), new Action<BaseEventData, CreativeRoom.TileObject>(this.EventPointerExit), new Action<BaseEventData, CreativeRoom.TileObject>(this.EventPointerClick));
  540. }, delegate(CreativeRoom.TileObject otherPanel)
  541. {
  542. this.RemoveEventQuad(otherPanel);
  543. });
  544. }
  545. public void SetUnitSize(float size)
  546. {
  547. size = Mathf.Round(size * 20f);
  548. size *= 0.05f;
  549. this.m_UISliderUnitScale.value = size;
  550. if (!this.m_UIInputUnitScale.isFocused)
  551. {
  552. this.m_UIInputUnitScale.text = size.ToString();
  553. }
  554. this.unitSize = size;
  555. this.OnUpdateMap();
  556. this.InvokeAllPanels(false, false, false, false, false, true, delegate(CreativeRoom.TileObject floorPanel)
  557. {
  558. this.AddEventQuad(floorPanel, new Action<BaseEventData, CreativeRoom.TileObject>(this.EventPointerEnter), new Action<BaseEventData, CreativeRoom.TileObject>(this.EventPointerExit), new Action<BaseEventData, CreativeRoom.TileObject>(this.EventPointerClick));
  559. }, delegate(CreativeRoom.TileObject otherPanel)
  560. {
  561. this.RemoveEventQuad(otherPanel);
  562. });
  563. }
  564. private void UpdateRoomSizeText()
  565. {
  566. if (!Product.supportMultiLanguage)
  567. {
  568. this.m_UITextRoomSizeX.text = "横幅:" + string.Format("{0:#0.##}", (float)this.mapSizeX * this.unitSize) + "m";
  569. this.m_UITextRoomSizeZ.text = "奥行:" + string.Format("{0:#0.##}", (float)this.mapSizeZ * this.unitSize) + "m";
  570. this.m_UITextRoomSizeY.text = "高さ:" + string.Format("{0:#0.##}", (float)this.mapSizeY * this.unitSize) + "m";
  571. }
  572. else
  573. {
  574. Localize component = this.m_UITextRoomSizeX.GetComponent<Localize>();
  575. if (component != null)
  576. {
  577. component.TermSuffix = ":" + string.Format("{0:#0.##}", (float)this.mapSizeX * this.unitSize) + "m";
  578. Utility.SetLocalizeTerm(component, "SceneCreativeRoom/横幅", false);
  579. }
  580. component = this.m_UITextRoomSizeZ.GetComponent<Localize>();
  581. if (component != null)
  582. {
  583. component.TermSuffix = ":" + string.Format("{0:#0.##}", (float)this.mapSizeZ * this.unitSize) + "m";
  584. Utility.SetLocalizeTerm(component, "SceneCreativeRoom/奥行", false);
  585. }
  586. component = this.m_UITextRoomSizeY.GetComponent<Localize>();
  587. if (component != null)
  588. {
  589. component.TermSuffix = ":" + string.Format("{0:#0.##}", (float)this.mapSizeY * this.unitSize) + "m";
  590. Utility.SetLocalizeTerm(component, "SceneCreativeRoom/高さ", false);
  591. }
  592. }
  593. }
  594. private void AddEventQuad(CreativeRoom.TileObject Obj, Action<BaseEventData, CreativeRoom.TileObject> pointerEnter, Action<BaseEventData, CreativeRoom.TileObject> pointerExit, Action<BaseEventData, CreativeRoom.TileObject> pointerClick)
  595. {
  596. if (Obj.gameObject == null)
  597. {
  598. return;
  599. }
  600. CreativeRoom.MouseEvent mouseEvent = Obj.eventTrigger;
  601. if (mouseEvent == null)
  602. {
  603. mouseEvent = (Obj.eventTrigger = Obj.gameObject.AddComponent<CreativeRoom.MouseEvent>());
  604. }
  605. if (pointerEnter != null)
  606. {
  607. mouseEvent.onPointerEnter = delegate(PointerEventData data)
  608. {
  609. pointerEnter(data, Obj);
  610. };
  611. }
  612. if (pointerExit != null)
  613. {
  614. mouseEvent.onPointerExit = delegate(PointerEventData data)
  615. {
  616. pointerExit(data, Obj);
  617. };
  618. }
  619. if (pointerClick != null)
  620. {
  621. mouseEvent.onPointerClick = delegate(PointerEventData data)
  622. {
  623. pointerClick(data, Obj);
  624. };
  625. }
  626. mouseEvent.onPointerDown = delegate(PointerEventData data)
  627. {
  628. this.m_IsDraggingSelect = true;
  629. };
  630. mouseEvent.onPointerUp = delegate(PointerEventData data)
  631. {
  632. this.m_IsDraggingSelect = false;
  633. };
  634. }
  635. private void EventPointerEnter(BaseEventData eventData, CreativeRoom.TileObject Obj)
  636. {
  637. Renderer componentInChildren = Obj.gameObject.GetComponentInChildren<Renderer>();
  638. if (componentInChildren == null)
  639. {
  640. return;
  641. }
  642. componentInChildren.material = CreativeRoom.m_MatHighlightColor;
  643. this.m_MaterialPropertyBlock.SetTexture("_MainTex", CreativeRoom.m_Materials[Obj.matID].mainTexture);
  644. componentInChildren.SetPropertyBlock(this.m_MaterialPropertyBlock);
  645. }
  646. private void EventPointerExit(BaseEventData eventData, CreativeRoom.TileObject Obj)
  647. {
  648. Renderer componentInChildren = Obj.gameObject.GetComponentInChildren<Renderer>();
  649. if (componentInChildren == null)
  650. {
  651. return;
  652. }
  653. this.SetPanelType(Obj, Obj.type);
  654. }
  655. private void EventPointerEnterDrag(BaseEventData eventData, CreativeRoom.TileObject Obj)
  656. {
  657. if (!this.m_IsDraggingSelect)
  658. {
  659. return;
  660. }
  661. if (!NInput.GetMouseButton(0))
  662. {
  663. return;
  664. }
  665. Renderer componentInChildren = Obj.gameObject.GetComponentInChildren<Renderer>();
  666. if (componentInChildren == null)
  667. {
  668. return;
  669. }
  670. if (Obj.type == CreativeRoom.TileType.Enable)
  671. {
  672. this.SetPanelType(Obj, CreativeRoom.TileType.Select);
  673. }
  674. }
  675. private void EventPointerClick(BaseEventData eventData, CreativeRoom.TileObject Obj)
  676. {
  677. if (!NInput.GetMouseButtonUp(0))
  678. {
  679. return;
  680. }
  681. Renderer componentInChildren = Obj.gameObject.GetComponentInChildren<Renderer>();
  682. if (componentInChildren == null)
  683. {
  684. return;
  685. }
  686. if (Obj.type == CreativeRoom.TileType.Enable)
  687. {
  688. this.SetPanelType(Obj, CreativeRoom.TileType.Disable);
  689. }
  690. else if (Obj.type == CreativeRoom.TileType.Disable)
  691. {
  692. this.SetPanelType(Obj, CreativeRoom.TileType.Enable);
  693. }
  694. }
  695. private void EventPointerClickSelect(BaseEventData eventData, CreativeRoom.TileObject Obj)
  696. {
  697. Renderer componentInChildren = Obj.gameObject.GetComponentInChildren<Renderer>();
  698. if (componentInChildren == null)
  699. {
  700. return;
  701. }
  702. if (!NInput.GetMouseButtonUp(0))
  703. {
  704. return;
  705. }
  706. if (Obj.type == CreativeRoom.TileType.Enable)
  707. {
  708. this.SetPanelType(Obj, CreativeRoom.TileType.Select);
  709. }
  710. else if (Obj.type == CreativeRoom.TileType.Select)
  711. {
  712. this.SetPanelType(Obj, CreativeRoom.TileType.Enable);
  713. }
  714. }
  715. private void RemoveEventQuad(CreativeRoom.TileObject Obj)
  716. {
  717. if (Obj.gameObject == null)
  718. {
  719. return;
  720. }
  721. CreativeRoom.MouseEvent eventTrigger = Obj.eventTrigger;
  722. if (eventTrigger == null)
  723. {
  724. return;
  725. }
  726. eventTrigger.onPointerEnter = null;
  727. eventTrigger.onPointerExit = null;
  728. eventTrigger.onPointerClick = null;
  729. eventTrigger.onPointerDown = null;
  730. eventTrigger.onPointerUp = null;
  731. }
  732. private static CreativeRoom.TileData GetTileData(List<List<List<CreativeRoom.TileData>>> floorArray, int x, int y, int z)
  733. {
  734. if (floorArray.Count <= x || x < 0)
  735. {
  736. return null;
  737. }
  738. if (floorArray[x].Count <= y || y < 0)
  739. {
  740. return null;
  741. }
  742. if (floorArray[x][y].Count <= z || z < 0)
  743. {
  744. return null;
  745. }
  746. return floorArray[x][y][z];
  747. }
  748. private void SetFloorArraySize(int x, int y, int z)
  749. {
  750. List<List<List<CreativeRoom.TileData>>> list = new List<List<List<CreativeRoom.TileData>>>();
  751. for (int i = 0; i < x; i++)
  752. {
  753. List<List<CreativeRoom.TileData>> list2 = new List<List<CreativeRoom.TileData>>();
  754. for (int j = 0; j < y; j++)
  755. {
  756. List<CreativeRoom.TileData> list3 = new List<CreativeRoom.TileData>();
  757. for (int k = 0; k < z; k++)
  758. {
  759. if (i < this.m_FloorArray.Count && j < this.m_FloorArray[i].Count && k < this.m_FloorArray[i][j].Count)
  760. {
  761. list3.Add(this.m_FloorArray[i][j][k]);
  762. }
  763. else
  764. {
  765. list3.Add(new CreativeRoom.TileData());
  766. }
  767. }
  768. list2.Add(list3);
  769. }
  770. list.Add(list2);
  771. }
  772. for (int l = 0; l < this.m_FloorArray.Count; l++)
  773. {
  774. for (int m = 0; m < this.m_FloorArray[l].Count; m++)
  775. {
  776. for (int n = 0; n < this.m_FloorArray[l][m].Count; n++)
  777. {
  778. if (l >= x || m >= y || n >= z)
  779. {
  780. CreativeRoom.DestroyTileObject(this.m_FloorArray[l][m][n]);
  781. }
  782. }
  783. }
  784. }
  785. this.m_FloorArray = list;
  786. }
  787. private static void DestroyTileObject(CreativeRoom.TileData data)
  788. {
  789. UnityEngine.Object.Destroy(data.right.gameObject);
  790. UnityEngine.Object.Destroy(data.left.gameObject);
  791. UnityEngine.Object.Destroy(data.up.gameObject);
  792. UnityEngine.Object.Destroy(data.down.gameObject);
  793. UnityEngine.Object.Destroy(data.front.gameObject);
  794. UnityEngine.Object.Destroy(data.back.gameObject);
  795. }
  796. private static void GetAllPanels(List<List<List<CreativeRoom.TileData>>> floorArray, out List<CreativeRoom.TileObject> floorPanels, out List<CreativeRoom.TileObject> otherPanels, bool right, bool left, bool front, bool back, bool up, bool down)
  797. {
  798. floorPanels = new List<CreativeRoom.TileObject>();
  799. otherPanels = new List<CreativeRoom.TileObject>();
  800. for (int i = 0; i < floorArray.Count; i++)
  801. {
  802. for (int j = 0; j < floorArray[i].Count; j++)
  803. {
  804. for (int k = 0; k < floorArray[i][j].Count; k++)
  805. {
  806. if (right)
  807. {
  808. floorPanels.Add(floorArray[i][j][k].right);
  809. }
  810. else
  811. {
  812. otherPanels.Add(floorArray[i][j][k].right);
  813. }
  814. if (left)
  815. {
  816. floorPanels.Add(floorArray[i][j][k].left);
  817. }
  818. else
  819. {
  820. otherPanels.Add(floorArray[i][j][k].left);
  821. }
  822. if (front)
  823. {
  824. floorPanels.Add(floorArray[i][j][k].front);
  825. }
  826. else
  827. {
  828. otherPanels.Add(floorArray[i][j][k].front);
  829. }
  830. if (back)
  831. {
  832. floorPanels.Add(floorArray[i][j][k].back);
  833. }
  834. else
  835. {
  836. otherPanels.Add(floorArray[i][j][k].back);
  837. }
  838. if (up)
  839. {
  840. floorPanels.Add(floorArray[i][j][k].up);
  841. }
  842. else
  843. {
  844. otherPanels.Add(floorArray[i][j][k].up);
  845. }
  846. if (down)
  847. {
  848. floorPanels.Add(floorArray[i][j][k].down);
  849. }
  850. else
  851. {
  852. otherPanels.Add(floorArray[i][j][k].down);
  853. }
  854. }
  855. }
  856. }
  857. }
  858. private void InvokeAllPanels(bool right, bool left, bool front, bool back, bool up, bool down, Action<CreativeRoom.TileObject> floorPanelsFunc, Action<CreativeRoom.TileObject> otherPanelsFunc)
  859. {
  860. List<CreativeRoom.TileObject> list;
  861. List<CreativeRoom.TileObject> list2;
  862. CreativeRoom.GetAllPanels(this.m_FloorArray, out list, out list2, right, left, front, back, up, down);
  863. if (floorPanelsFunc != null)
  864. {
  865. for (int i = 0; i < list.Count; i++)
  866. {
  867. if (list[i] != null)
  868. {
  869. floorPanelsFunc(list[i]);
  870. }
  871. }
  872. }
  873. if (otherPanelsFunc != null)
  874. {
  875. for (int j = 0; j < list2.Count; j++)
  876. {
  877. if (list2[j] != null)
  878. {
  879. otherPanelsFunc(list2[j]);
  880. }
  881. }
  882. }
  883. }
  884. public void CheckFloorPanel()
  885. {
  886. this.InvokeAllPanels(false, false, false, false, false, true, delegate(CreativeRoom.TileObject panel)
  887. {
  888. this.AddEventQuad(panel, delegate(BaseEventData eventData, CreativeRoom.TileObject Obj)
  889. {
  890. this.EventPointerEnter(eventData, Obj);
  891. this.EventPointerEnterDrag(eventData, Obj);
  892. }, new Action<BaseEventData, CreativeRoom.TileObject>(this.EventPointerExit), new Action<BaseEventData, CreativeRoom.TileObject>(this.EventPointerClickSelect));
  893. if (panel.type == CreativeRoom.TileType.TempSelect)
  894. {
  895. this.SetPanelType(panel, CreativeRoom.TileType.Select);
  896. }
  897. else if (panel.type == CreativeRoom.TileType.TempEnable)
  898. {
  899. this.SetPanelType(panel, CreativeRoom.TileType.Enable);
  900. }
  901. }, delegate(CreativeRoom.TileObject panel)
  902. {
  903. this.RemoveEventQuad(panel);
  904. if (panel.type == CreativeRoom.TileType.Select)
  905. {
  906. this.SetPanelType(panel, CreativeRoom.TileType.TempSelect);
  907. }
  908. else if (panel.type == CreativeRoom.TileType.Enable)
  909. {
  910. this.SetPanelType(panel, CreativeRoom.TileType.TempEnable);
  911. }
  912. });
  913. }
  914. public void CheckWallPanel()
  915. {
  916. this.InvokeAllPanels(true, true, true, true, false, false, delegate(CreativeRoom.TileObject panel)
  917. {
  918. this.AddEventQuad(panel, delegate(BaseEventData eventData, CreativeRoom.TileObject Obj)
  919. {
  920. this.EventPointerEnter(eventData, Obj);
  921. this.EventPointerEnterDrag(eventData, Obj);
  922. }, new Action<BaseEventData, CreativeRoom.TileObject>(this.EventPointerExit), new Action<BaseEventData, CreativeRoom.TileObject>(this.EventPointerClickSelect));
  923. if (panel.type == CreativeRoom.TileType.TempSelect)
  924. {
  925. this.SetPanelType(panel, CreativeRoom.TileType.Select);
  926. }
  927. else if (panel.type == CreativeRoom.TileType.TempEnable)
  928. {
  929. this.SetPanelType(panel, CreativeRoom.TileType.Enable);
  930. }
  931. }, delegate(CreativeRoom.TileObject panel)
  932. {
  933. this.RemoveEventQuad(panel);
  934. if (panel.type == CreativeRoom.TileType.Select)
  935. {
  936. this.SetPanelType(panel, CreativeRoom.TileType.TempSelect);
  937. }
  938. else if (panel.type == CreativeRoom.TileType.Enable)
  939. {
  940. this.SetPanelType(panel, CreativeRoom.TileType.TempEnable);
  941. }
  942. });
  943. }
  944. public void CheckCeilPanel()
  945. {
  946. this.InvokeAllPanels(false, false, false, false, true, false, delegate(CreativeRoom.TileObject panel)
  947. {
  948. this.AddEventQuad(panel, delegate(BaseEventData eventData, CreativeRoom.TileObject Obj)
  949. {
  950. this.EventPointerEnter(eventData, Obj);
  951. this.EventPointerEnterDrag(eventData, Obj);
  952. }, new Action<BaseEventData, CreativeRoom.TileObject>(this.EventPointerExit), new Action<BaseEventData, CreativeRoom.TileObject>(this.EventPointerClickSelect));
  953. if (panel.type == CreativeRoom.TileType.TempSelect)
  954. {
  955. this.SetPanelType(panel, CreativeRoom.TileType.Select);
  956. }
  957. else if (panel.type == CreativeRoom.TileType.TempEnable)
  958. {
  959. this.SetPanelType(panel, CreativeRoom.TileType.Enable);
  960. }
  961. }, delegate(CreativeRoom.TileObject panel)
  962. {
  963. this.RemoveEventQuad(panel);
  964. if (panel.type == CreativeRoom.TileType.Select)
  965. {
  966. this.SetPanelType(panel, CreativeRoom.TileType.TempSelect);
  967. }
  968. else if (panel.type == CreativeRoom.TileType.Enable)
  969. {
  970. this.SetPanelType(panel, CreativeRoom.TileType.TempEnable);
  971. }
  972. });
  973. }
  974. public void SelectAllFloorPanel()
  975. {
  976. this.InvokeAllPanels(false, false, false, false, false, true, delegate(CreativeRoom.TileObject panel)
  977. {
  978. if (panel.type == CreativeRoom.TileType.Enable)
  979. {
  980. this.SetPanelType(panel, CreativeRoom.TileType.Select);
  981. }
  982. }, null);
  983. this.CheckFloorPanel();
  984. }
  985. public void SelectAllWallPanel()
  986. {
  987. this.InvokeAllPanels(true, true, true, true, false, false, delegate(CreativeRoom.TileObject panel)
  988. {
  989. if (panel.type == CreativeRoom.TileType.Enable)
  990. {
  991. this.SetPanelType(panel, CreativeRoom.TileType.Select);
  992. }
  993. }, null);
  994. this.CheckWallPanel();
  995. }
  996. public void SelectAllCeilPanel()
  997. {
  998. this.InvokeAllPanels(false, false, false, false, true, false, delegate(CreativeRoom.TileObject panel)
  999. {
  1000. if (panel.type == CreativeRoom.TileType.Enable)
  1001. {
  1002. this.SetPanelType(panel, CreativeRoom.TileType.Select);
  1003. }
  1004. }, null);
  1005. this.CheckCeilPanel();
  1006. }
  1007. public void DeselectAllFloorPanel()
  1008. {
  1009. this.InvokeAllPanels(false, false, false, false, false, true, delegate(CreativeRoom.TileObject panel)
  1010. {
  1011. if (panel.type == CreativeRoom.TileType.Select)
  1012. {
  1013. this.SetPanelType(panel, CreativeRoom.TileType.Enable);
  1014. }
  1015. }, null);
  1016. this.CheckFloorPanel();
  1017. }
  1018. public void DeselectAllWallPanel()
  1019. {
  1020. this.InvokeAllPanels(true, true, true, true, false, false, delegate(CreativeRoom.TileObject panel)
  1021. {
  1022. if (panel.type == CreativeRoom.TileType.Select)
  1023. {
  1024. this.SetPanelType(panel, CreativeRoom.TileType.Enable);
  1025. }
  1026. }, null);
  1027. this.CheckWallPanel();
  1028. }
  1029. public void DeselectAllCeilPanel()
  1030. {
  1031. this.InvokeAllPanels(false, false, false, false, true, false, delegate(CreativeRoom.TileObject panel)
  1032. {
  1033. if (panel.type == CreativeRoom.TileType.Select)
  1034. {
  1035. this.SetPanelType(panel, CreativeRoom.TileType.Enable);
  1036. }
  1037. }, null);
  1038. this.CheckCeilPanel();
  1039. }
  1040. private void SetPanelType(CreativeRoom.TileObject Obj, CreativeRoom.TileType type)
  1041. {
  1042. if (Obj.gameObject == null)
  1043. {
  1044. return;
  1045. }
  1046. Obj.type = type;
  1047. Renderer componentInChildren = Obj.gameObject.GetComponentInChildren<Renderer>();
  1048. if (type == CreativeRoom.TileType.Disable)
  1049. {
  1050. componentInChildren.SetPropertyBlock(null);
  1051. componentInChildren.material = CreativeRoom.m_MatDisableColor;
  1052. }
  1053. else if (type == CreativeRoom.TileType.Select)
  1054. {
  1055. componentInChildren.material = CreativeRoom.m_MatSelectColor;
  1056. this.m_MaterialPropertyBlock.SetTexture("_MainTex", CreativeRoom.m_Materials[Obj.matID].mainTexture);
  1057. componentInChildren.SetPropertyBlock(this.m_MaterialPropertyBlock);
  1058. }
  1059. else if (type == CreativeRoom.TileType.Enable)
  1060. {
  1061. componentInChildren.SetPropertyBlock(null);
  1062. if (Obj.matID >= 0)
  1063. {
  1064. componentInChildren.material = CreativeRoom.m_Materials[Obj.matID];
  1065. }
  1066. else
  1067. {
  1068. componentInChildren.material = CreativeRoom.m_MatDefaultColor;
  1069. }
  1070. }
  1071. else if (type == CreativeRoom.TileType.TempSelect)
  1072. {
  1073. componentInChildren.SetPropertyBlock(null);
  1074. if (Obj.matID >= 0)
  1075. {
  1076. componentInChildren.material = CreativeRoom.m_Materials[Obj.matID];
  1077. }
  1078. else
  1079. {
  1080. componentInChildren.material = CreativeRoom.m_MatDefaultColor;
  1081. }
  1082. }
  1083. else if (type == CreativeRoom.TileType.TempEnable)
  1084. {
  1085. componentInChildren.SetPropertyBlock(null);
  1086. if (Obj.matID >= 0)
  1087. {
  1088. componentInChildren.material = CreativeRoom.m_Materials[Obj.matID];
  1089. }
  1090. else
  1091. {
  1092. componentInChildren.material = CreativeRoom.m_MatDefaultColor;
  1093. }
  1094. }
  1095. }
  1096. private static void LoadAllTextures()
  1097. {
  1098. if (CreativeRoom.m_Materials != null && CreativeRoom.m_Materials.Count > 0)
  1099. {
  1100. return;
  1101. }
  1102. CreativeRoom.m_Materials = new List<Material>();
  1103. List<TextureData.Data> allDatas = TextureData.GetAllDatas(true);
  1104. Material material = new Material(Shader.Find("CM3D2/RoomPanel"));
  1105. material.SetColor("_Color", Color.white);
  1106. material.SetColor("_ShadowColor", Color.black);
  1107. for (int i = 0; i < allDatas.Count; i++)
  1108. {
  1109. Texture texture = Resources.Load<Texture>("SceneCreativeRoom/Debug/Textures/" + allDatas[i].resourceName);
  1110. if (texture == null)
  1111. {
  1112. Debug.LogWarningFormat("テクスチャ「{0}」が見つからない", new object[]
  1113. {
  1114. allDatas[i].resourceName
  1115. });
  1116. }
  1117. else
  1118. {
  1119. Material material2 = new Material(material);
  1120. material2.mainTexture = texture;
  1121. CreativeRoom.m_Materials.Add(material2);
  1122. }
  1123. }
  1124. UnityEngine.Object.Destroy(material);
  1125. }
  1126. public void CreateMaterialButton(int AddIndex)
  1127. {
  1128. int count = CreativeRoom.m_Materials.Count;
  1129. this.m_UIParentTextureButtons.Show<Button>(count, delegate(int index, Button button)
  1130. {
  1131. RawImage component = button.GetComponent<RawImage>();
  1132. component.texture = CreativeRoom.m_Materials[index].mainTexture;
  1133. button.onClick.AddListener(delegate()
  1134. {
  1135. this.ButtonEvent_SetPanelsMaterial(index);
  1136. });
  1137. });
  1138. uGUIScrollRect componentInParent = this.m_UIParentTextureButtons.GetComponentInParent<uGUIScrollRect>();
  1139. if (componentInParent != null)
  1140. {
  1141. componentInParent.verticalNormalizedPosition = 1f;
  1142. }
  1143. }
  1144. private void ButtonEvent_SetPanelsMaterial(int index)
  1145. {
  1146. if (CreativeRoom.m_Materials.Count <= index)
  1147. {
  1148. return;
  1149. }
  1150. if (index < 0)
  1151. {
  1152. return;
  1153. }
  1154. Material material = CreativeRoom.m_Materials[index];
  1155. this.InvokeAllPanels(true, true, true, true, true, true, delegate(CreativeRoom.TileObject panel)
  1156. {
  1157. if (panel.type != CreativeRoom.TileType.Select)
  1158. {
  1159. return;
  1160. }
  1161. panel.matID = index;
  1162. this.SetPanelType(panel, CreativeRoom.TileType.Select);
  1163. }, null);
  1164. }
  1165. public void CombinePanelMesh()
  1166. {
  1167. this.OnUpdateMap();
  1168. CreativeRoom.CombinePanelMesh(this.m_FloorArray);
  1169. }
  1170. private static void CombinePanelMesh(List<List<List<CreativeRoom.TileData>>> floorArray)
  1171. {
  1172. List<CreativeRoom.TileObject> list;
  1173. List<CreativeRoom.TileObject> list2;
  1174. CreativeRoom.GetAllPanels(floorArray, out list, out list2, true, true, true, true, true, true);
  1175. List<CreativeRoom.TileObject> list3 = new List<CreativeRoom.TileObject>();
  1176. for (int i = 0; i < list.Count; i++)
  1177. {
  1178. if (!(list[i].gameObject == null))
  1179. {
  1180. list[i].gameObject.SetActive(false);
  1181. if (list[i].type != CreativeRoom.TileType.Disable)
  1182. {
  1183. list3.Add(list[i]);
  1184. }
  1185. }
  1186. }
  1187. Dictionary<Material, List<CombineInstance>> dictionary = new Dictionary<Material, List<CombineInstance>>();
  1188. for (int j = 0; j < list3.Count; j++)
  1189. {
  1190. if (CreativeRoom.m_Materials.Count > list3[j].matID)
  1191. {
  1192. Material material;
  1193. if (list3[j].matID < 0)
  1194. {
  1195. material = list3[j].gameObject.GetComponent<Renderer>().sharedMaterial;
  1196. }
  1197. else
  1198. {
  1199. material = CreativeRoom.m_Materials[list3[j].matID];
  1200. }
  1201. if (!(material == null))
  1202. {
  1203. if (!dictionary.ContainsKey(material))
  1204. {
  1205. dictionary.Add(material, new List<CombineInstance>());
  1206. }
  1207. List<CombineInstance> list4 = dictionary[material];
  1208. list4.Add(new CombineInstance
  1209. {
  1210. transform = list3[j].gameObject.transform.localToWorldMatrix,
  1211. mesh = list3[j].gameObject.GetComponent<MeshFilter>().sharedMesh
  1212. });
  1213. }
  1214. }
  1215. }
  1216. if (CreativeRoom.m_CombineMeshObjectArray == null)
  1217. {
  1218. CreativeRoom.m_CombineMeshObjectArray = new List<GameObject>();
  1219. }
  1220. for (int k = 0; k < CreativeRoom.m_CombineMeshObjectArray.Count; k++)
  1221. {
  1222. CreativeRoom.m_CombineMeshObjectArray[k].SetActive(false);
  1223. }
  1224. GameObject parentCombineMeshObject = CreativeRoom.parentCombineMeshObject;
  1225. List<Material> list5 = new List<Material>(dictionary.Keys);
  1226. List<List<CombineInstance>> list6 = new List<List<CombineInstance>>(dictionary.Values);
  1227. for (int l = 0; l < list5.Count; l++)
  1228. {
  1229. GameObject gameObject;
  1230. MeshFilter meshFilter;
  1231. MeshRenderer meshRenderer;
  1232. if (CreativeRoom.m_CombineMeshObjectArray.Count > l)
  1233. {
  1234. gameObject = CreativeRoom.m_CombineMeshObjectArray[l];
  1235. meshFilter = gameObject.GetComponent<MeshFilter>();
  1236. meshRenderer = gameObject.GetComponent<MeshRenderer>();
  1237. gameObject.SetActive(true);
  1238. UnityEngine.Object.Destroy(meshFilter.sharedMesh);
  1239. }
  1240. else
  1241. {
  1242. gameObject = new GameObject();
  1243. meshFilter = gameObject.AddComponent<MeshFilter>();
  1244. meshRenderer = gameObject.AddComponent<MeshRenderer>();
  1245. CreativeRoom.m_CombineMeshObjectArray.Add(gameObject);
  1246. gameObject.transform.SetParent(parentCombineMeshObject.transform);
  1247. }
  1248. gameObject.name = "Combine Mesh [" + list5[l].name + "]";
  1249. Mesh mesh = new Mesh();
  1250. mesh.CombineMeshes(list6[l].ToArray());
  1251. meshFilter.sharedMesh = mesh;
  1252. meshRenderer.sharedMaterial = list5[l];
  1253. meshRenderer.receiveShadows = true;
  1254. meshRenderer.shadowCastingMode = ShadowCastingMode.Off;
  1255. }
  1256. for (int m = CreativeRoom.m_CombineMeshObjectArray.Count - 1; m >= 0; m--)
  1257. {
  1258. if (list5.Count <= m)
  1259. {
  1260. UnityEngine.Object.Destroy(CreativeRoom.m_CombineMeshObjectArray[m]);
  1261. CreativeRoom.m_CombineMeshObjectArray.Remove(CreativeRoom.m_CombineMeshObjectArray[m]);
  1262. }
  1263. }
  1264. }
  1265. public void SavePanelData(BinaryWriter binary)
  1266. {
  1267. CreativeRoom.CombinePanelMesh(this.m_FloorArray);
  1268. int count = this.m_FloorArray.Count;
  1269. int count2 = this.m_FloorArray[0].Count;
  1270. int count3 = this.m_FloorArray[0][0].Count;
  1271. binary.Write(count);
  1272. binary.Write(count2);
  1273. binary.Write(count3);
  1274. binary.Write(this.unitSize);
  1275. for (int i = 0; i < count; i++)
  1276. {
  1277. for (int j = 0; j < count2; j++)
  1278. {
  1279. for (int k = 0; k < count3; k++)
  1280. {
  1281. CreativeRoom.TileData tileData = CreativeRoom.GetTileData(this.m_FloorArray, i, j, k);
  1282. if (tileData != null)
  1283. {
  1284. for (int l = 0; l < 6; l++)
  1285. {
  1286. binary.Write((!(tileData[l].gameObject == null) && tileData[l].type != CreativeRoom.TileType.Disable) ? tileData[l].matID.ToString() : "-1");
  1287. }
  1288. }
  1289. }
  1290. }
  1291. }
  1292. }
  1293. public void LoadPanelData(BinaryReader brRead)
  1294. {
  1295. int num = brRead.ReadInt32();
  1296. int num2 = brRead.ReadInt32();
  1297. int num3 = brRead.ReadInt32();
  1298. float num4 = brRead.ReadSingle();
  1299. this.m_UISliderRoomSizeX.value = (float)num;
  1300. this.m_UISliderRoomSizeY.value = (float)num2;
  1301. this.m_UISliderRoomSizeZ.value = (float)num3;
  1302. this.m_UISliderUnitScale.value = num4;
  1303. this.mapSizeX = num;
  1304. this.mapSizeY = num2;
  1305. this.mapSizeZ = num3;
  1306. this.unitSize = num4;
  1307. List<List<List<CreativeRoom.TileData>>> list = new List<List<List<CreativeRoom.TileData>>>();
  1308. for (int i = 0; i < num; i++)
  1309. {
  1310. List<List<CreativeRoom.TileData>> list2 = new List<List<CreativeRoom.TileData>>();
  1311. for (int j = 0; j < num2; j++)
  1312. {
  1313. List<CreativeRoom.TileData> list3 = new List<CreativeRoom.TileData>();
  1314. for (int k = 0; k < num3; k++)
  1315. {
  1316. CreativeRoom.TileData tileData;
  1317. if (i < this.m_FloorArray.Count && j < this.m_FloorArray[i].Count && k < this.m_FloorArray[i][j].Count)
  1318. {
  1319. tileData = this.m_FloorArray[i][j][k];
  1320. }
  1321. else
  1322. {
  1323. tileData = new CreativeRoom.TileData();
  1324. }
  1325. for (int l = 0; l < 6; l++)
  1326. {
  1327. tileData[l].matID = int.Parse(brRead.ReadString());
  1328. tileData[l].type = ((tileData[l].matID >= 0) ? CreativeRoom.TileType.Enable : CreativeRoom.TileType.Disable);
  1329. tileData[l].matID = ((tileData[l].matID >= 0) ? tileData[l].matID : 0);
  1330. }
  1331. list3.Add(tileData);
  1332. }
  1333. list2.Add(list3);
  1334. }
  1335. list.Add(list2);
  1336. }
  1337. this.m_FloorArray = list;
  1338. this.OnUpdateMap();
  1339. CreativeRoom.CombinePanelMesh(this.m_FloorArray);
  1340. }
  1341. public static GameObject Load(BinaryReader brRead)
  1342. {
  1343. int num = brRead.ReadInt32();
  1344. int num2 = brRead.ReadInt32();
  1345. int num3 = brRead.ReadInt32();
  1346. float unitSize = brRead.ReadSingle();
  1347. List<List<List<CreativeRoom.TileData>>> list = new List<List<List<CreativeRoom.TileData>>>();
  1348. for (int i = 0; i < num; i++)
  1349. {
  1350. List<List<CreativeRoom.TileData>> list2 = new List<List<CreativeRoom.TileData>>();
  1351. for (int j = 0; j < num2; j++)
  1352. {
  1353. List<CreativeRoom.TileData> list3 = new List<CreativeRoom.TileData>();
  1354. for (int k = 0; k < num3; k++)
  1355. {
  1356. CreativeRoom.TileData tileData = new CreativeRoom.TileData();
  1357. for (int l = 0; l < 6; l++)
  1358. {
  1359. tileData[l].matID = int.Parse(brRead.ReadString());
  1360. tileData[l].type = ((tileData[l].matID >= 0) ? CreativeRoom.TileType.Enable : CreativeRoom.TileType.Disable);
  1361. tileData[l].matID = ((tileData[l].matID >= 0) ? tileData[l].matID : 0);
  1362. }
  1363. list3.Add(tileData);
  1364. }
  1365. list2.Add(list3);
  1366. }
  1367. list.Add(list2);
  1368. }
  1369. CreativeRoom.LoadAllTextures();
  1370. CreativeRoom.OnUpdateMapWall(list, unitSize);
  1371. CreativeRoom.CombinePanelMesh(list);
  1372. if (CreativeRoom.m_ParentTileObject != null)
  1373. {
  1374. UnityEngine.Object.Destroy(CreativeRoom.m_ParentTileObject);
  1375. }
  1376. UnityEngine.Object.Destroy(CreativeRoom.m_PrefabUnit);
  1377. CreativeRoom.m_CombineMeshObjectArray = null;
  1378. GameObject parentCombineMeshObject = CreativeRoom.m_ParentCombineMeshObject;
  1379. CreativeRoom.m_ParentCombineMeshObject = null;
  1380. return parentCombineMeshObject;
  1381. }
  1382. private void OnDestroy()
  1383. {
  1384. GameObject parentCombineMeshObject = CreativeRoom.m_ParentCombineMeshObject;
  1385. if (parentCombineMeshObject != null)
  1386. {
  1387. UnityEngine.Object.Destroy(parentCombineMeshObject);
  1388. }
  1389. CreativeRoom.m_CombineMeshObjectArray = null;
  1390. for (int i = 0; i < this.m_FloorArray.Count; i++)
  1391. {
  1392. for (int j = 0; j < this.m_FloorArray[i].Count; j++)
  1393. {
  1394. for (int k = 0; k < this.m_FloorArray[i][j].Count; k++)
  1395. {
  1396. CreativeRoom.DestroyTileObject(this.m_FloorArray[i][j][k]);
  1397. }
  1398. }
  1399. }
  1400. if (CreativeRoom.m_PrefabUnit != null)
  1401. {
  1402. UnityEngine.Object.Destroy(CreativeRoom.m_PrefabUnit);
  1403. }
  1404. if (CreativeRoom.m_ParentTileObject != null)
  1405. {
  1406. UnityEngine.Object.Destroy(CreativeRoom.m_ParentTileObject);
  1407. }
  1408. UnityEngine.Object.Destroy(CreativeRoom.m_MatDefaultColor);
  1409. UnityEngine.Object.Destroy(CreativeRoom.m_MatHighlightColor);
  1410. UnityEngine.Object.Destroy(CreativeRoom.m_MatSelectColor);
  1411. UnityEngine.Object.Destroy(CreativeRoom.m_MatDisableColor);
  1412. for (int l = 0; l < CreativeRoom.m_Materials.Count; l++)
  1413. {
  1414. UnityEngine.Object.Destroy(CreativeRoom.m_Materials[l]);
  1415. }
  1416. CreativeRoom.m_Materials = null;
  1417. }
  1418. private int m_MapSizeX = 1;
  1419. private int m_MapSizeZ = 1;
  1420. private int m_MapSizeY = 2;
  1421. private float m_UnitSize = 1f;
  1422. [SerializeField]
  1423. private CreativeRoomManager m_Manager;
  1424. private static GameObject m_PrefabUnit;
  1425. private static GameObject m_ParentTileObject;
  1426. private static GameObject m_ParentCombineMeshObject;
  1427. [SerializeField]
  1428. [Tooltip("親オブジェクト:テクスチャ一覧を表示しているUIオブジェクト")]
  1429. private uGUIListViewer m_UIParentTextureButtons;
  1430. [SerializeField]
  1431. [Tooltip("テキスト:部屋の大きさを表示するUI")]
  1432. private Text m_UITextRoomSizeX;
  1433. [SerializeField]
  1434. [Tooltip("テキスト:部屋の大きさを表示するUI")]
  1435. private Text m_UITextRoomSizeY;
  1436. [SerializeField]
  1437. [Tooltip("テキスト:部屋の大きさを表示するUI")]
  1438. private Text m_UITextRoomSizeZ;
  1439. [SerializeField]
  1440. [Tooltip("スライダー:部屋の大きさを変更するスライダー")]
  1441. private Slider m_UISliderRoomSizeX;
  1442. [SerializeField]
  1443. [Tooltip("スライダー:部屋の大きさを変更するスライダー")]
  1444. private Slider m_UISliderRoomSizeY;
  1445. [SerializeField]
  1446. [Tooltip("スライダー:部屋の大きさを変更するスライダー")]
  1447. private Slider m_UISliderRoomSizeZ;
  1448. [SerializeField]
  1449. [Tooltip("スライダー:ユニット一つあたりの大きさを変更するスライダー")]
  1450. private Slider m_UISliderUnitScale;
  1451. [SerializeField]
  1452. private InputField m_UIInputRoomSizeX;
  1453. [SerializeField]
  1454. private InputField m_UIInputRoomSizeY;
  1455. [SerializeField]
  1456. private InputField m_UIInputRoomSizeZ;
  1457. [SerializeField]
  1458. private InputField m_UIInputUnitScale;
  1459. private static Material m_MatDefaultColor;
  1460. private static Material m_MatHighlightColor;
  1461. private static Material m_MatDisableColor;
  1462. private static Material m_MatSelectColor;
  1463. private List<List<List<CreativeRoom.TileData>>> m_FloorArray = new List<List<List<CreativeRoom.TileData>>>();
  1464. private static List<Material> m_Materials = new List<Material>();
  1465. private int m_PageIndexTexture;
  1466. private bool m_IsDraggingSelect;
  1467. private static List<GameObject> m_CombineMeshObjectArray = new List<GameObject>();
  1468. private MaterialPropertyBlock m_MaterialPropertyBlock;
  1469. public enum TileType
  1470. {
  1471. Enable,
  1472. TempEnable,
  1473. Disable,
  1474. Select,
  1475. TempSelect
  1476. }
  1477. private class TileData
  1478. {
  1479. public TileData()
  1480. {
  1481. this.right = new CreativeRoom.TileObject(CreativeRoom.TileType.Enable, null);
  1482. this.left = new CreativeRoom.TileObject(CreativeRoom.TileType.Enable, null);
  1483. this.up = new CreativeRoom.TileObject(CreativeRoom.TileType.Enable, null);
  1484. this.down = new CreativeRoom.TileObject(CreativeRoom.TileType.Enable, null);
  1485. this.front = new CreativeRoom.TileObject(CreativeRoom.TileType.Enable, null);
  1486. this.back = new CreativeRoom.TileObject(CreativeRoom.TileType.Enable, null);
  1487. this.enableRight = false;
  1488. this.enableLeft = false;
  1489. this.enableUp = false;
  1490. this.enableDown = false;
  1491. this.enableFront = false;
  1492. this.enableBack = false;
  1493. }
  1494. public CreativeRoom.TileObject this[int i]
  1495. {
  1496. get
  1497. {
  1498. switch (i)
  1499. {
  1500. case 0:
  1501. return this.right;
  1502. case 1:
  1503. return this.left;
  1504. case 2:
  1505. return this.up;
  1506. case 3:
  1507. return this.down;
  1508. case 4:
  1509. return this.front;
  1510. case 5:
  1511. return this.back;
  1512. default:
  1513. return null;
  1514. }
  1515. }
  1516. set
  1517. {
  1518. switch (i)
  1519. {
  1520. case 0:
  1521. this.right = value;
  1522. break;
  1523. case 1:
  1524. this.left = value;
  1525. break;
  1526. case 2:
  1527. this.up = value;
  1528. break;
  1529. case 3:
  1530. this.down = value;
  1531. break;
  1532. case 4:
  1533. this.front = value;
  1534. break;
  1535. case 5:
  1536. this.back = value;
  1537. break;
  1538. }
  1539. }
  1540. }
  1541. public CreativeRoom.TileObject right;
  1542. public CreativeRoom.TileObject left;
  1543. public CreativeRoom.TileObject up;
  1544. public CreativeRoom.TileObject down;
  1545. public CreativeRoom.TileObject front;
  1546. public CreativeRoom.TileObject back;
  1547. public bool enableRight;
  1548. public bool enableLeft;
  1549. public bool enableUp;
  1550. public bool enableDown;
  1551. public bool enableFront;
  1552. public bool enableBack;
  1553. }
  1554. private class TileObject
  1555. {
  1556. public TileObject(CreativeRoom.TileType tileType, GameObject obj)
  1557. {
  1558. this.gameObject = obj;
  1559. this.eventTrigger = null;
  1560. this.type = tileType;
  1561. this.matID = 0;
  1562. }
  1563. public void Reset()
  1564. {
  1565. UnityEngine.Object.Destroy(this.eventTrigger);
  1566. UnityEngine.Object.Destroy(this.gameObject);
  1567. this.gameObject = null;
  1568. this.matID = 0;
  1569. }
  1570. public GameObject gameObject;
  1571. public CreativeRoom.MouseEvent eventTrigger;
  1572. public CreativeRoom.TileType type;
  1573. public int matID;
  1574. }
  1575. private class MouseEvent : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, IPointerClickHandler, IPointerDownHandler, IPointerUpHandler, IEventSystemHandler
  1576. {
  1577. public void OnPointerEnter(PointerEventData data)
  1578. {
  1579. if (this.onPointerEnter != null)
  1580. {
  1581. this.onPointerEnter(data);
  1582. }
  1583. }
  1584. public void OnPointerExit(PointerEventData data)
  1585. {
  1586. if (this.onPointerExit != null)
  1587. {
  1588. this.onPointerExit(data);
  1589. }
  1590. }
  1591. public void OnPointerClick(PointerEventData data)
  1592. {
  1593. if (this.onPointerClick != null)
  1594. {
  1595. this.onPointerClick(data);
  1596. }
  1597. }
  1598. public void OnPointerDown(PointerEventData data)
  1599. {
  1600. if (this.onPointerDown != null)
  1601. {
  1602. this.onPointerDown(data);
  1603. }
  1604. }
  1605. public void OnPointerUp(PointerEventData data)
  1606. {
  1607. if (this.onPointerUp != null)
  1608. {
  1609. this.onPointerUp(data);
  1610. }
  1611. }
  1612. public Action<PointerEventData> onPointerEnter;
  1613. public Action<PointerEventData> onPointerExit;
  1614. public Action<PointerEventData> onPointerClick;
  1615. public Action<PointerEventData> onPointerDown;
  1616. public Action<PointerEventData> onPointerUp;
  1617. }
  1618. }
  1619. }