CreativeRoom.cs 50 KB

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