CreativeRoom.cs 50 KB

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