using System;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Rendering;
using UnityEngine.UI;

namespace MyRoomCustom
{
	public class CreativeRoom : MonoBehaviour
	{
		public int mapSizeX
		{
			get
			{
				return this.m_MapSizeX;
			}
			set
			{
				this.m_MapSizeX = Mathf.Clamp(value, 1, 32);
			}
		}

		public int mapSizeZ
		{
			get
			{
				return this.m_MapSizeZ;
			}
			set
			{
				this.m_MapSizeZ = Mathf.Clamp(value, 1, 32);
			}
		}

		public int mapSizeY
		{
			get
			{
				return this.m_MapSizeY;
			}
			set
			{
				this.m_MapSizeY = Mathf.Clamp(value, 2, 16);
			}
		}

		public float unitSize
		{
			get
			{
				return this.m_UnitSize;
			}
			set
			{
				this.m_UnitSize = Mathf.Clamp(value, 0.25f, 1f);
				CreativeRoomUIObjectSettings creativeRoomUIObjSetting = this.m_Manager.creativeRoomUIObjSetting;
				if (creativeRoomUIObjSetting)
				{
					creativeRoomUIObjSetting.snapValuePosition = this.m_UnitSize * 0.5f;
				}
				CreativeRoomUIPlacementMaid creativeRoomUIMaid = this.m_Manager.creativeRoomUIMaid;
				if (creativeRoomUIMaid)
				{
					creativeRoomUIMaid.snapValuePosition = this.m_UnitSize * 0.5f;
				}
			}
		}

		private static GameObject prefabUnit
		{
			get
			{
				if (CreativeRoom.m_PrefabUnit == null)
				{
					CreativeRoom.m_PrefabUnit = GameObject.CreatePrimitive(PrimitiveType.Quad);
					CreativeRoom.m_PrefabUnit.AddComponent<Rigidbody>().isKinematic = true;
					Renderer component = CreativeRoom.m_PrefabUnit.GetComponent<Renderer>();
					component.reflectionProbeUsage = ReflectionProbeUsage.Off;
					component.shadowCastingMode = ShadowCastingMode.Off;
					component.receiveShadows = false;
					CreativeRoom.m_PrefabUnit.gameObject.SetActive(false);
				}
				return CreativeRoom.m_PrefabUnit;
			}
		}

		private static Transform parentTileObject
		{
			get
			{
				if (CreativeRoom.m_ParentTileObject == null)
				{
					CreativeRoom.m_ParentTileObject = new GameObject("Parent Tile Object");
				}
				return CreativeRoom.m_ParentTileObject.transform;
			}
		}

		private static GameObject parentCombineMeshObject
		{
			get
			{
				if (CreativeRoom.m_ParentCombineMeshObject == null)
				{
					CreativeRoom.m_ParentCombineMeshObject = new GameObject("Combine Mesh Object Parent");
				}
				return CreativeRoom.m_ParentCombineMeshObject;
			}
		}

		private void Start()
		{
			if (CreativeRoom.m_MatDefaultColor == null)
			{
				CreativeRoom.m_MatDefaultColor = new Material(Shader.Find("CM3D2/RoomPanel"));
				CreativeRoom.m_MatDefaultColor.SetColor("_Color", Color.white);
				CreativeRoom.m_MatDefaultColor.SetColor("_ShadowColor", Color.black);
			}
			if (CreativeRoom.m_MatHighlightColor == null)
			{
				CreativeRoom.m_MatHighlightColor = new Material(Shader.Find("CM3D2/RoomPanel"));
				CreativeRoom.m_MatHighlightColor.SetColor("_Color", new Color(1f, 0.75f, 1f, 1f));
				CreativeRoom.m_MatHighlightColor.SetColor("_ShadowColor", Color.black);
			}
			if (CreativeRoom.m_MatDisableColor == null)
			{
				CreativeRoom.m_MatDisableColor = new Material(Shader.Find("CM3D2/RoomPanel"));
				CreativeRoom.m_MatDisableColor.SetColor("_Color", Color.white * 0.25f);
				CreativeRoom.m_MatDisableColor.SetColor("_ShadowColor", Color.black);
			}
			if (CreativeRoom.m_MatSelectColor == null)
			{
				CreativeRoom.m_MatSelectColor = new Material(Shader.Find("CM3D2/RoomPanelSelect"));
			}
			this.m_MaterialPropertyBlock = new MaterialPropertyBlock();
			this.m_MaterialPropertyBlock.SetColor("_Color", new Color(0.5f, 1f, 1f, 1f));
			CreativeRoom.LoadAllTextures();
			Renderer component = CreativeRoom.prefabUnit.GetComponent<Renderer>();
			if (component && CreativeRoom.m_Materials != null && CreativeRoom.m_Materials.Count > 0)
			{
				component.sharedMaterial = CreativeRoom.m_Materials[0];
			}
			this.SetUpInputArea();
			this.OnUpdateMap();
			this.InvokeAllPanels(false, false, false, false, false, true, delegate(CreativeRoom.TileObject floorPanel)
			{
				this.AddEventQuad(floorPanel, new Action<BaseEventData, CreativeRoom.TileObject>(this.EventPointerEnter), new Action<BaseEventData, CreativeRoom.TileObject>(this.EventPointerExit), new Action<BaseEventData, CreativeRoom.TileObject>(this.EventPointerClick));
			}, delegate(CreativeRoom.TileObject otherPanel)
			{
				this.RemoveEventQuad(otherPanel);
			});
			this.CreateMaterialButton(0);
		}

		private void SetUpInputArea()
		{
			this.m_UIInputRoomSizeX.contentType = InputField.ContentType.IntegerNumber;
			this.m_UIInputRoomSizeY.contentType = InputField.ContentType.IntegerNumber;
			this.m_UIInputRoomSizeZ.contentType = InputField.ContentType.IntegerNumber;
			this.m_UIInputUnitScale.contentType = InputField.ContentType.DecimalNumber;
			this.m_UIInputRoomSizeX.text = this.mapSizeX.ToString();
			this.m_UIInputRoomSizeY.text = this.mapSizeY.ToString();
			this.m_UIInputRoomSizeZ.text = this.mapSizeZ.ToString();
			this.m_UIInputUnitScale.text = this.unitSize.ToString();
			this.m_UIInputRoomSizeX.onValueChanged.AddListener(delegate(string str)
			{
				int num;
				if (int.TryParse(str, out num))
				{
					if (num == this.mapSizeX)
					{
						return;
					}
					this.mapSizeX = num;
					this.m_UISliderRoomSizeX.value = (float)this.mapSizeX;
				}
			});
			this.m_UIInputRoomSizeY.onValueChanged.AddListener(delegate(string str)
			{
				int num;
				if (int.TryParse(str, out num))
				{
					if (num == this.mapSizeY)
					{
						return;
					}
					this.mapSizeY = num;
					this.m_UISliderRoomSizeY.value = (float)this.mapSizeY;
				}
			});
			this.m_UIInputRoomSizeZ.onValueChanged.AddListener(delegate(string str)
			{
				int num;
				if (int.TryParse(str, out num))
				{
					if (num == this.mapSizeZ)
					{
						return;
					}
					this.mapSizeZ = num;
					this.m_UISliderRoomSizeZ.value = (float)this.mapSizeZ;
				}
			});
			this.m_UIInputUnitScale.onValueChanged.AddListener(delegate(string str)
			{
				float num;
				if (float.TryParse(str, out num))
				{
					if (Mathf.Approximately(this.unitSize, num))
					{
						return;
					}
					this.unitSize = num;
					this.m_UISliderUnitScale.value = this.unitSize;
				}
			});
			this.m_UIInputRoomSizeX.onEndEdit.AddListener(delegate(string str)
			{
				this.m_UIInputRoomSizeX.text = this.mapSizeX.ToString();
			});
			this.m_UIInputRoomSizeY.onEndEdit.AddListener(delegate(string str)
			{
				this.m_UIInputRoomSizeY.text = this.mapSizeY.ToString();
			});
			this.m_UIInputRoomSizeZ.onEndEdit.AddListener(delegate(string str)
			{
				this.m_UIInputRoomSizeZ.text = this.mapSizeZ.ToString();
			});
			this.m_UIInputUnitScale.onEndEdit.AddListener(delegate(string str)
			{
				this.m_UIInputUnitScale.text = this.unitSize.ToString();
			});
		}

		public void OnUpdateMap()
		{
			this.SetFloorArraySize(this.mapSizeX, this.mapSizeY, this.mapSizeZ);
			CreativeRoom.OnUpdateMapWall(this.m_FloorArray, this.unitSize);
			this.InvokeAllPanels(false, false, false, false, false, true, delegate(CreativeRoom.TileObject floorPanel)
			{
				this.AddEventQuad(floorPanel, new Action<BaseEventData, CreativeRoom.TileObject>(this.EventPointerEnter), new Action<BaseEventData, CreativeRoom.TileObject>(this.EventPointerExit), new Action<BaseEventData, CreativeRoom.TileObject>(this.EventPointerClick));
				if (floorPanel.type == CreativeRoom.TileType.TempEnable)
				{
					this.SetPanelType(floorPanel, CreativeRoom.TileType.Enable);
				}
				else if (floorPanel.type == CreativeRoom.TileType.TempSelect)
				{
					this.SetPanelType(floorPanel, CreativeRoom.TileType.Select);
				}
			}, delegate(CreativeRoom.TileObject otherPanel)
			{
				this.RemoveEventQuad(otherPanel);
				if (otherPanel.type == CreativeRoom.TileType.Enable)
				{
					this.SetPanelType(otherPanel, CreativeRoom.TileType.TempEnable);
				}
				else if (otherPanel.type == CreativeRoom.TileType.Select)
				{
					this.SetPanelType(otherPanel, CreativeRoom.TileType.TempSelect);
				}
			});
			this.InvokeAllPanels(true, true, true, true, true, true, delegate(CreativeRoom.TileObject tileObject)
			{
				this.SetPanelType(tileObject, tileObject.type);
			}, null);
			this.UpdateRoomSizeText();
			if (CreativeRoom.m_CombineMeshObjectArray != null)
			{
				for (int i = 0; i < CreativeRoom.m_CombineMeshObjectArray.Count; i++)
				{
					if (CreativeRoom.m_CombineMeshObjectArray[i].activeSelf)
					{
						CreativeRoom.m_CombineMeshObjectArray[i].SetActive(false);
					}
				}
			}
		}

		private static void OnUpdateMapWall(List<List<List<CreativeRoom.TileData>>> floorArray, float unitSize)
		{
			for (int i = 0; i < floorArray.Count; i++)
			{
				for (int j = 0; j < floorArray[i].Count; j++)
				{
					for (int k = 0; k < floorArray[i][j].Count; k++)
					{
						CreativeRoom.TileData tileData = CreativeRoom.GetTileData(floorArray, i, j, k);
						if (tileData != null)
						{
							CreativeRoom.TileData tileData2 = CreativeRoom.GetTileData(floorArray, i, 0, k);
							CreativeRoom.TileData tileData3 = CreativeRoom.GetTileData(floorArray, i, j - 1, k);
							tileData.enableDown = (tileData.down.type == CreativeRoom.TileType.Enable && tileData3 == null);
							tileData3 = CreativeRoom.GetTileData(floorArray, i + 1, 0, k);
							tileData.enableRight = (tileData2.down.type != CreativeRoom.TileType.Disable && (tileData3 == null || tileData3.down.type == CreativeRoom.TileType.Disable));
							tileData3 = CreativeRoom.GetTileData(floorArray, i - 1, 0, k);
							tileData.enableLeft = (tileData2.down.type != CreativeRoom.TileType.Disable && (tileData3 == null || tileData3.down.type == CreativeRoom.TileType.Disable));
							tileData3 = CreativeRoom.GetTileData(floorArray, i, 0, k + 1);
							tileData.enableFront = (tileData2.down.type != CreativeRoom.TileType.Disable && (tileData3 == null || tileData3.down.type == CreativeRoom.TileType.Disable));
							tileData3 = CreativeRoom.GetTileData(floorArray, i, 0, k - 1);
							tileData.enableBack = (tileData2.down.type != CreativeRoom.TileType.Disable && (tileData3 == null || tileData3.down.type == CreativeRoom.TileType.Disable));
							tileData3 = CreativeRoom.GetTileData(floorArray, i, j + 1, k);
							tileData.enableUp = (tileData2.down.type != CreativeRoom.TileType.Disable && tileData3 == null);
						}
					}
				}
			}
			for (int l = 0; l < floorArray.Count; l++)
			{
				for (int m = 0; m < floorArray[l].Count; m++)
				{
					for (int n = 0; n < floorArray[l][m].Count; n++)
					{
						if (CreativeRoom.GetTileData(floorArray, l, m, n) != null)
						{
							CreativeRoom.CreateSixPanel(floorArray, l, m, n, unitSize);
						}
					}
				}
			}
		}

		private static void CreateSixPanel(List<List<List<CreativeRoom.TileData>>> floorArray, int x, int y, int z, float unitSize)
		{
			CreativeRoom.TileData tileData = CreativeRoom.GetTileData(floorArray, x, y, z);
			if (tileData == null)
			{
				return;
			}
			Transform parentTileObject = CreativeRoom.parentTileObject;
			if (tileData.enableRight)
			{
				GameObject gameObject = tileData.right.gameObject;
				if (gameObject == null)
				{
					gameObject = CreativeRoom.CreatePanel(parentTileObject);
					tileData.right.type = CreativeRoom.TileType.Enable;
				}
				if (!gameObject.activeSelf)
				{
					gameObject.SetActive(true);
				}
				Transform transform = gameObject.transform;
				transform.position = new Vector3((float)x + 0.5f, (float)y + 0.5f, (float)z) * unitSize;
				transform.rotation = Quaternion.AngleAxis(90f, Vector3.up);
				transform.localScale = Vector3.one * unitSize;
				tileData.right.gameObject = gameObject;
			}
			else
			{
				if (tileData.right.gameObject)
				{
					UnityEngine.Object.Destroy(tileData.right.gameObject);
				}
				tileData.right.Reset();
			}
			if (tileData.enableLeft)
			{
				GameObject gameObject2 = tileData.left.gameObject;
				if (gameObject2 == null)
				{
					gameObject2 = CreativeRoom.CreatePanel(parentTileObject);
					tileData.left.type = CreativeRoom.TileType.Enable;
				}
				if (!gameObject2.activeSelf)
				{
					gameObject2.SetActive(true);
				}
				Transform transform2 = gameObject2.transform;
				transform2.position = new Vector3((float)x - 0.5f, (float)y + 0.5f, (float)z) * unitSize;
				transform2.rotation = Quaternion.AngleAxis(-90f, Vector3.up);
				transform2.localScale = Vector3.one * unitSize;
				tileData.left.gameObject = gameObject2;
			}
			else
			{
				if (tileData.left.gameObject)
				{
					UnityEngine.Object.Destroy(tileData.left.gameObject);
				}
				tileData.left.Reset();
			}
			if (tileData.enableUp)
			{
				GameObject gameObject3 = tileData.up.gameObject;
				if (gameObject3 == null)
				{
					gameObject3 = CreativeRoom.CreatePanel(parentTileObject);
					tileData.up.type = CreativeRoom.TileType.Enable;
				}
				if (!gameObject3.activeSelf)
				{
					gameObject3.SetActive(true);
				}
				Transform transform3 = gameObject3.transform;
				transform3.position = new Vector3((float)x, (float)y + 1f, (float)z) * unitSize;
				transform3.rotation = Quaternion.AngleAxis(-90f, Vector3.right);
				transform3.localScale = Vector3.one * unitSize;
				tileData.up.gameObject = gameObject3;
			}
			else
			{
				if (tileData.up.gameObject)
				{
					UnityEngine.Object.Destroy(tileData.up.gameObject);
				}
				tileData.up.Reset();
			}
			if (tileData.enableDown || y == 0)
			{
				GameObject gameObject4 = tileData.down.gameObject;
				if (gameObject4 == null)
				{
					gameObject4 = CreativeRoom.CreatePanel(parentTileObject);
					if (tileData.enableDown)
					{
						tileData.down.type = CreativeRoom.TileType.Enable;
					}
				}
				if (!gameObject4.activeSelf)
				{
					gameObject4.SetActive(true);
				}
				Transform transform4 = gameObject4.transform;
				transform4.position = new Vector3((float)x, (float)y, (float)z) * unitSize;
				transform4.rotation = Quaternion.AngleAxis(90f, Vector3.right);
				transform4.localScale = Vector3.one * unitSize;
				tileData.down.gameObject = gameObject4;
			}
			else
			{
				if (tileData.down.gameObject)
				{
					UnityEngine.Object.Destroy(tileData.down.gameObject);
				}
				tileData.down.Reset();
			}
			if (tileData.enableFront)
			{
				GameObject gameObject5 = tileData.front.gameObject;
				if (gameObject5 == null)
				{
					gameObject5 = CreativeRoom.CreatePanel(parentTileObject);
					tileData.front.type = CreativeRoom.TileType.Enable;
				}
				if (!gameObject5.activeSelf)
				{
					gameObject5.SetActive(true);
				}
				Transform transform5 = gameObject5.transform;
				transform5.position = new Vector3((float)x, (float)y + 0.5f, (float)z + 0.5f) * unitSize;
				transform5.rotation = Quaternion.AngleAxis(0f, Vector3.up);
				transform5.localScale = Vector3.one * unitSize;
				tileData.front.gameObject = gameObject5;
			}
			else
			{
				if (tileData.front.gameObject)
				{
					UnityEngine.Object.Destroy(tileData.front.gameObject);
				}
				tileData.front.Reset();
			}
			if (tileData.enableBack)
			{
				GameObject gameObject6 = tileData.back.gameObject;
				if (gameObject6 == null)
				{
					gameObject6 = CreativeRoom.CreatePanel(parentTileObject);
					tileData.back.type = CreativeRoom.TileType.Enable;
				}
				if (!gameObject6.activeSelf)
				{
					gameObject6.SetActive(true);
				}
				Transform transform6 = gameObject6.transform;
				transform6.position = new Vector3((float)x, (float)y + 0.5f, (float)z - 0.5f) * unitSize;
				transform6.rotation = Quaternion.AngleAxis(180f, Vector3.up);
				transform6.localScale = Vector3.one * unitSize;
				tileData.back.gameObject = gameObject6;
			}
			else
			{
				if (tileData.back.gameObject)
				{
					UnityEngine.Object.Destroy(tileData.back.gameObject);
				}
				tileData.back.Reset();
			}
		}

		private static GameObject CreatePanel(Transform parent)
		{
			GameObject gameObject = UnityEngine.Object.Instantiate<GameObject>(CreativeRoom.prefabUnit);
			Transform transform = gameObject.transform;
			if (!gameObject.activeSelf)
			{
				gameObject.SetActive(true);
			}
			if (parent != null)
			{
				transform.SetParent(parent, false);
			}
			return gameObject;
		}

		public void SetMapSizeX(float x)
		{
			if (!this.m_UIInputRoomSizeX.isFocused)
			{
				this.m_UIInputRoomSizeX.text = ((int)x).ToString();
			}
			this.mapSizeX = (int)x;
			this.OnUpdateMap();
			this.InvokeAllPanels(false, false, false, false, false, true, delegate(CreativeRoom.TileObject floorPanel)
			{
				this.AddEventQuad(floorPanel, new Action<BaseEventData, CreativeRoom.TileObject>(this.EventPointerEnter), new Action<BaseEventData, CreativeRoom.TileObject>(this.EventPointerExit), new Action<BaseEventData, CreativeRoom.TileObject>(this.EventPointerClick));
			}, delegate(CreativeRoom.TileObject otherPanel)
			{
				this.RemoveEventQuad(otherPanel);
			});
		}

		public void SetMapSizeZ(float z)
		{
			if (!this.m_UIInputRoomSizeZ.isFocused)
			{
				this.m_UIInputRoomSizeZ.text = ((int)z).ToString();
			}
			this.mapSizeZ = (int)z;
			this.OnUpdateMap();
			this.InvokeAllPanels(false, false, false, false, false, true, delegate(CreativeRoom.TileObject floorPanel)
			{
				this.AddEventQuad(floorPanel, new Action<BaseEventData, CreativeRoom.TileObject>(this.EventPointerEnter), new Action<BaseEventData, CreativeRoom.TileObject>(this.EventPointerExit), new Action<BaseEventData, CreativeRoom.TileObject>(this.EventPointerClick));
			}, delegate(CreativeRoom.TileObject otherPanel)
			{
				this.RemoveEventQuad(otherPanel);
			});
		}

		public void SetMapSizeY(float y)
		{
			if (!this.m_UIInputRoomSizeY.isFocused)
			{
				this.m_UIInputRoomSizeY.text = ((int)y).ToString();
			}
			this.mapSizeY = (int)y;
			this.OnUpdateMap();
			this.InvokeAllPanels(false, false, false, false, false, true, delegate(CreativeRoom.TileObject floorPanel)
			{
				this.AddEventQuad(floorPanel, new Action<BaseEventData, CreativeRoom.TileObject>(this.EventPointerEnter), new Action<BaseEventData, CreativeRoom.TileObject>(this.EventPointerExit), new Action<BaseEventData, CreativeRoom.TileObject>(this.EventPointerClick));
			}, delegate(CreativeRoom.TileObject otherPanel)
			{
				this.RemoveEventQuad(otherPanel);
			});
		}

		public void SetUnitSize(float size)
		{
			size = Mathf.Round(size * 20f);
			size *= 0.05f;
			this.m_UISliderUnitScale.value = size;
			if (!this.m_UIInputUnitScale.isFocused)
			{
				this.m_UIInputUnitScale.text = size.ToString();
			}
			this.unitSize = size;
			this.OnUpdateMap();
			this.InvokeAllPanels(false, false, false, false, false, true, delegate(CreativeRoom.TileObject floorPanel)
			{
				this.AddEventQuad(floorPanel, new Action<BaseEventData, CreativeRoom.TileObject>(this.EventPointerEnter), new Action<BaseEventData, CreativeRoom.TileObject>(this.EventPointerExit), new Action<BaseEventData, CreativeRoom.TileObject>(this.EventPointerClick));
			}, delegate(CreativeRoom.TileObject otherPanel)
			{
				this.RemoveEventQuad(otherPanel);
			});
		}

		private void UpdateRoomSizeText()
		{
			this.m_UITextRoomSizeX.text = "横幅：" + string.Format("{0:#0.##}", (float)this.mapSizeX * this.unitSize) + "m";
			this.m_UITextRoomSizeZ.text = "奥行：" + string.Format("{0:#0.##}", (float)this.mapSizeZ * this.unitSize) + "m";
			this.m_UITextRoomSizeY.text = "高さ：" + string.Format("{0:#0.##}", (float)this.mapSizeY * this.unitSize) + "m";
		}

		private void AddEventQuad(CreativeRoom.TileObject Obj, Action<BaseEventData, CreativeRoom.TileObject> pointerEnter, Action<BaseEventData, CreativeRoom.TileObject> pointerExit, Action<BaseEventData, CreativeRoom.TileObject> pointerClick)
		{
			if (Obj.gameObject == null)
			{
				return;
			}
			CreativeRoom.MouseEvent mouseEvent = Obj.eventTrigger;
			if (mouseEvent == null)
			{
				mouseEvent = (Obj.eventTrigger = Obj.gameObject.AddComponent<CreativeRoom.MouseEvent>());
			}
			if (pointerEnter != null)
			{
				mouseEvent.onPointerEnter = delegate(PointerEventData data)
				{
					pointerEnter(data, Obj);
				};
			}
			if (pointerExit != null)
			{
				mouseEvent.onPointerExit = delegate(PointerEventData data)
				{
					pointerExit(data, Obj);
				};
			}
			if (pointerClick != null)
			{
				mouseEvent.onPointerClick = delegate(PointerEventData data)
				{
					pointerClick(data, Obj);
				};
			}
			mouseEvent.onPointerDown = delegate(PointerEventData data)
			{
				this.m_IsDraggingSelect = true;
			};
			mouseEvent.onPointerUp = delegate(PointerEventData data)
			{
				this.m_IsDraggingSelect = false;
			};
		}

		private void EventPointerEnter(BaseEventData eventData, CreativeRoom.TileObject Obj)
		{
			Renderer componentInChildren = Obj.gameObject.GetComponentInChildren<Renderer>();
			if (componentInChildren == null)
			{
				return;
			}
			componentInChildren.material = CreativeRoom.m_MatHighlightColor;
			this.m_MaterialPropertyBlock.SetTexture("_MainTex", CreativeRoom.m_Materials[Obj.matID].mainTexture);
			componentInChildren.SetPropertyBlock(this.m_MaterialPropertyBlock);
		}

		private void EventPointerExit(BaseEventData eventData, CreativeRoom.TileObject Obj)
		{
			Renderer componentInChildren = Obj.gameObject.GetComponentInChildren<Renderer>();
			if (componentInChildren == null)
			{
				return;
			}
			this.SetPanelType(Obj, Obj.type);
		}

		private void EventPointerEnterDrag(BaseEventData eventData, CreativeRoom.TileObject Obj)
		{
			if (!this.m_IsDraggingSelect)
			{
				return;
			}
			if (!NInput.GetMouseButton(0))
			{
				return;
			}
			Renderer componentInChildren = Obj.gameObject.GetComponentInChildren<Renderer>();
			if (componentInChildren == null)
			{
				return;
			}
			if (Obj.type == CreativeRoom.TileType.Enable)
			{
				this.SetPanelType(Obj, CreativeRoom.TileType.Select);
			}
		}

		private void EventPointerClick(BaseEventData eventData, CreativeRoom.TileObject Obj)
		{
			if (!NInput.GetMouseButtonUp(0))
			{
				return;
			}
			Renderer componentInChildren = Obj.gameObject.GetComponentInChildren<Renderer>();
			if (componentInChildren == null)
			{
				return;
			}
			if (Obj.type == CreativeRoom.TileType.Enable)
			{
				this.SetPanelType(Obj, CreativeRoom.TileType.Disable);
			}
			else if (Obj.type == CreativeRoom.TileType.Disable)
			{
				this.SetPanelType(Obj, CreativeRoom.TileType.Enable);
			}
		}

		private void EventPointerClickSelect(BaseEventData eventData, CreativeRoom.TileObject Obj)
		{
			Renderer componentInChildren = Obj.gameObject.GetComponentInChildren<Renderer>();
			if (componentInChildren == null)
			{
				return;
			}
			if (!NInput.GetMouseButtonUp(0))
			{
				return;
			}
			if (Obj.type == CreativeRoom.TileType.Enable)
			{
				this.SetPanelType(Obj, CreativeRoom.TileType.Select);
			}
			else if (Obj.type == CreativeRoom.TileType.Select)
			{
				this.SetPanelType(Obj, CreativeRoom.TileType.Enable);
			}
		}

		private void RemoveEventQuad(CreativeRoom.TileObject Obj)
		{
			if (Obj.gameObject == null)
			{
				return;
			}
			CreativeRoom.MouseEvent eventTrigger = Obj.eventTrigger;
			if (eventTrigger == null)
			{
				return;
			}
			eventTrigger.onPointerEnter = null;
			eventTrigger.onPointerExit = null;
			eventTrigger.onPointerClick = null;
			eventTrigger.onPointerDown = null;
			eventTrigger.onPointerUp = null;
		}

		private static CreativeRoom.TileData GetTileData(List<List<List<CreativeRoom.TileData>>> floorArray, int x, int y, int z)
		{
			if (floorArray.Count <= x || x < 0)
			{
				return null;
			}
			if (floorArray[x].Count <= y || y < 0)
			{
				return null;
			}
			if (floorArray[x][y].Count <= z || z < 0)
			{
				return null;
			}
			return floorArray[x][y][z];
		}

		private void SetFloorArraySize(int x, int y, int z)
		{
			List<List<List<CreativeRoom.TileData>>> list = new List<List<List<CreativeRoom.TileData>>>();
			for (int i = 0; i < x; i++)
			{
				List<List<CreativeRoom.TileData>> list2 = new List<List<CreativeRoom.TileData>>();
				for (int j = 0; j < y; j++)
				{
					List<CreativeRoom.TileData> list3 = new List<CreativeRoom.TileData>();
					for (int k = 0; k < z; k++)
					{
						if (i < this.m_FloorArray.Count && j < this.m_FloorArray[i].Count && k < this.m_FloorArray[i][j].Count)
						{
							list3.Add(this.m_FloorArray[i][j][k]);
						}
						else
						{
							list3.Add(new CreativeRoom.TileData());
						}
					}
					list2.Add(list3);
				}
				list.Add(list2);
			}
			for (int l = 0; l < this.m_FloorArray.Count; l++)
			{
				for (int m = 0; m < this.m_FloorArray[l].Count; m++)
				{
					for (int n = 0; n < this.m_FloorArray[l][m].Count; n++)
					{
						if (l >= x || m >= y || n >= z)
						{
							CreativeRoom.DestroyTileObject(this.m_FloorArray[l][m][n]);
						}
					}
				}
			}
			this.m_FloorArray = list;
		}

		private static void DestroyTileObject(CreativeRoom.TileData data)
		{
			UnityEngine.Object.Destroy(data.right.gameObject);
			UnityEngine.Object.Destroy(data.left.gameObject);
			UnityEngine.Object.Destroy(data.up.gameObject);
			UnityEngine.Object.Destroy(data.down.gameObject);
			UnityEngine.Object.Destroy(data.front.gameObject);
			UnityEngine.Object.Destroy(data.back.gameObject);
		}

		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)
		{
			floorPanels = new List<CreativeRoom.TileObject>();
			otherPanels = new List<CreativeRoom.TileObject>();
			for (int i = 0; i < floorArray.Count; i++)
			{
				for (int j = 0; j < floorArray[i].Count; j++)
				{
					for (int k = 0; k < floorArray[i][j].Count; k++)
					{
						if (right)
						{
							floorPanels.Add(floorArray[i][j][k].right);
						}
						else
						{
							otherPanels.Add(floorArray[i][j][k].right);
						}
						if (left)
						{
							floorPanels.Add(floorArray[i][j][k].left);
						}
						else
						{
							otherPanels.Add(floorArray[i][j][k].left);
						}
						if (front)
						{
							floorPanels.Add(floorArray[i][j][k].front);
						}
						else
						{
							otherPanels.Add(floorArray[i][j][k].front);
						}
						if (back)
						{
							floorPanels.Add(floorArray[i][j][k].back);
						}
						else
						{
							otherPanels.Add(floorArray[i][j][k].back);
						}
						if (up)
						{
							floorPanels.Add(floorArray[i][j][k].up);
						}
						else
						{
							otherPanels.Add(floorArray[i][j][k].up);
						}
						if (down)
						{
							floorPanels.Add(floorArray[i][j][k].down);
						}
						else
						{
							otherPanels.Add(floorArray[i][j][k].down);
						}
					}
				}
			}
		}

		private void InvokeAllPanels(bool right, bool left, bool front, bool back, bool up, bool down, Action<CreativeRoom.TileObject> floorPanelsFunc, Action<CreativeRoom.TileObject> otherPanelsFunc)
		{
			List<CreativeRoom.TileObject> list;
			List<CreativeRoom.TileObject> list2;
			CreativeRoom.GetAllPanels(this.m_FloorArray, out list, out list2, right, left, front, back, up, down);
			if (floorPanelsFunc != null)
			{
				for (int i = 0; i < list.Count; i++)
				{
					if (list[i] != null)
					{
						floorPanelsFunc(list[i]);
					}
				}
			}
			if (otherPanelsFunc != null)
			{
				for (int j = 0; j < list2.Count; j++)
				{
					if (list2[j] != null)
					{
						otherPanelsFunc(list2[j]);
					}
				}
			}
		}

		public void CheckFloorPanel()
		{
			this.InvokeAllPanels(false, false, false, false, false, true, delegate(CreativeRoom.TileObject panel)
			{
				this.AddEventQuad(panel, delegate(BaseEventData eventData, CreativeRoom.TileObject Obj)
				{
					this.EventPointerEnter(eventData, Obj);
					this.EventPointerEnterDrag(eventData, Obj);
				}, new Action<BaseEventData, CreativeRoom.TileObject>(this.EventPointerExit), new Action<BaseEventData, CreativeRoom.TileObject>(this.EventPointerClickSelect));
				if (panel.type == CreativeRoom.TileType.TempSelect)
				{
					this.SetPanelType(panel, CreativeRoom.TileType.Select);
				}
				else if (panel.type == CreativeRoom.TileType.TempEnable)
				{
					this.SetPanelType(panel, CreativeRoom.TileType.Enable);
				}
			}, delegate(CreativeRoom.TileObject panel)
			{
				this.RemoveEventQuad(panel);
				if (panel.type == CreativeRoom.TileType.Select)
				{
					this.SetPanelType(panel, CreativeRoom.TileType.TempSelect);
				}
				else if (panel.type == CreativeRoom.TileType.Enable)
				{
					this.SetPanelType(panel, CreativeRoom.TileType.TempEnable);
				}
			});
		}

		public void CheckWallPanel()
		{
			this.InvokeAllPanels(true, true, true, true, false, false, delegate(CreativeRoom.TileObject panel)
			{
				this.AddEventQuad(panel, delegate(BaseEventData eventData, CreativeRoom.TileObject Obj)
				{
					this.EventPointerEnter(eventData, Obj);
					this.EventPointerEnterDrag(eventData, Obj);
				}, new Action<BaseEventData, CreativeRoom.TileObject>(this.EventPointerExit), new Action<BaseEventData, CreativeRoom.TileObject>(this.EventPointerClickSelect));
				if (panel.type == CreativeRoom.TileType.TempSelect)
				{
					this.SetPanelType(panel, CreativeRoom.TileType.Select);
				}
				else if (panel.type == CreativeRoom.TileType.TempEnable)
				{
					this.SetPanelType(panel, CreativeRoom.TileType.Enable);
				}
			}, delegate(CreativeRoom.TileObject panel)
			{
				this.RemoveEventQuad(panel);
				if (panel.type == CreativeRoom.TileType.Select)
				{
					this.SetPanelType(panel, CreativeRoom.TileType.TempSelect);
				}
				else if (panel.type == CreativeRoom.TileType.Enable)
				{
					this.SetPanelType(panel, CreativeRoom.TileType.TempEnable);
				}
			});
		}

		public void CheckCeilPanel()
		{
			this.InvokeAllPanels(false, false, false, false, true, false, delegate(CreativeRoom.TileObject panel)
			{
				this.AddEventQuad(panel, delegate(BaseEventData eventData, CreativeRoom.TileObject Obj)
				{
					this.EventPointerEnter(eventData, Obj);
					this.EventPointerEnterDrag(eventData, Obj);
				}, new Action<BaseEventData, CreativeRoom.TileObject>(this.EventPointerExit), new Action<BaseEventData, CreativeRoom.TileObject>(this.EventPointerClickSelect));
				if (panel.type == CreativeRoom.TileType.TempSelect)
				{
					this.SetPanelType(panel, CreativeRoom.TileType.Select);
				}
				else if (panel.type == CreativeRoom.TileType.TempEnable)
				{
					this.SetPanelType(panel, CreativeRoom.TileType.Enable);
				}
			}, delegate(CreativeRoom.TileObject panel)
			{
				this.RemoveEventQuad(panel);
				if (panel.type == CreativeRoom.TileType.Select)
				{
					this.SetPanelType(panel, CreativeRoom.TileType.TempSelect);
				}
				else if (panel.type == CreativeRoom.TileType.Enable)
				{
					this.SetPanelType(panel, CreativeRoom.TileType.TempEnable);
				}
			});
		}

		public void SelectAllFloorPanel()
		{
			this.InvokeAllPanels(false, false, false, false, false, true, delegate(CreativeRoom.TileObject panel)
			{
				if (panel.type == CreativeRoom.TileType.Enable)
				{
					this.SetPanelType(panel, CreativeRoom.TileType.Select);
				}
			}, null);
			this.CheckFloorPanel();
		}

		public void SelectAllWallPanel()
		{
			this.InvokeAllPanels(true, true, true, true, false, false, delegate(CreativeRoom.TileObject panel)
			{
				if (panel.type == CreativeRoom.TileType.Enable)
				{
					this.SetPanelType(panel, CreativeRoom.TileType.Select);
				}
			}, null);
			this.CheckWallPanel();
		}

		public void SelectAllCeilPanel()
		{
			this.InvokeAllPanels(false, false, false, false, true, false, delegate(CreativeRoom.TileObject panel)
			{
				if (panel.type == CreativeRoom.TileType.Enable)
				{
					this.SetPanelType(panel, CreativeRoom.TileType.Select);
				}
			}, null);
			this.CheckCeilPanel();
		}

		public void DeselectAllFloorPanel()
		{
			this.InvokeAllPanels(false, false, false, false, false, true, delegate(CreativeRoom.TileObject panel)
			{
				if (panel.type == CreativeRoom.TileType.Select)
				{
					this.SetPanelType(panel, CreativeRoom.TileType.Enable);
				}
			}, null);
			this.CheckFloorPanel();
		}

		public void DeselectAllWallPanel()
		{
			this.InvokeAllPanels(true, true, true, true, false, false, delegate(CreativeRoom.TileObject panel)
			{
				if (panel.type == CreativeRoom.TileType.Select)
				{
					this.SetPanelType(panel, CreativeRoom.TileType.Enable);
				}
			}, null);
			this.CheckWallPanel();
		}

		public void DeselectAllCeilPanel()
		{
			this.InvokeAllPanels(false, false, false, false, true, false, delegate(CreativeRoom.TileObject panel)
			{
				if (panel.type == CreativeRoom.TileType.Select)
				{
					this.SetPanelType(panel, CreativeRoom.TileType.Enable);
				}
			}, null);
			this.CheckCeilPanel();
		}

		private void SetPanelType(CreativeRoom.TileObject Obj, CreativeRoom.TileType type)
		{
			if (Obj.gameObject == null)
			{
				return;
			}
			Obj.type = type;
			Renderer componentInChildren = Obj.gameObject.GetComponentInChildren<Renderer>();
			if (type == CreativeRoom.TileType.Disable)
			{
				componentInChildren.SetPropertyBlock(null);
				componentInChildren.material = CreativeRoom.m_MatDisableColor;
			}
			else if (type == CreativeRoom.TileType.Select)
			{
				componentInChildren.material = CreativeRoom.m_MatSelectColor;
				this.m_MaterialPropertyBlock.SetTexture("_MainTex", CreativeRoom.m_Materials[Obj.matID].mainTexture);
				componentInChildren.SetPropertyBlock(this.m_MaterialPropertyBlock);
			}
			else if (type == CreativeRoom.TileType.Enable)
			{
				componentInChildren.SetPropertyBlock(null);
				if (Obj.matID >= 0)
				{
					componentInChildren.material = CreativeRoom.m_Materials[Obj.matID];
				}
				else
				{
					componentInChildren.material = CreativeRoom.m_MatDefaultColor;
				}
			}
			else if (type == CreativeRoom.TileType.TempSelect)
			{
				componentInChildren.SetPropertyBlock(null);
				if (Obj.matID >= 0)
				{
					componentInChildren.material = CreativeRoom.m_Materials[Obj.matID];
				}
				else
				{
					componentInChildren.material = CreativeRoom.m_MatDefaultColor;
				}
			}
			else if (type == CreativeRoom.TileType.TempEnable)
			{
				componentInChildren.SetPropertyBlock(null);
				if (Obj.matID >= 0)
				{
					componentInChildren.material = CreativeRoom.m_Materials[Obj.matID];
				}
				else
				{
					componentInChildren.material = CreativeRoom.m_MatDefaultColor;
				}
			}
		}

		private static void LoadAllTextures()
		{
			if (CreativeRoom.m_Materials != null && CreativeRoom.m_Materials.Count > 0)
			{
				return;
			}
			CreativeRoom.m_Materials = new List<Material>();
			List<TextureData.Data> allDatas = TextureData.GetAllDatas(true);
			Material material = new Material(Shader.Find("CM3D2/RoomPanel"));
			material.SetColor("_Color", Color.white);
			material.SetColor("_ShadowColor", Color.black);
			for (int i = 0; i < allDatas.Count; i++)
			{
				Texture texture = Resources.Load<Texture>("SceneCreativeRoom/Debug/Textures/" + allDatas[i].resourceName);
				if (texture == null)
				{
					Debug.LogWarningFormat("テクスチャ「{0}」が見つからない", new object[]
					{
						allDatas[i].resourceName
					});
				}
				else
				{
					Material material2 = new Material(material);
					material2.mainTexture = texture;
					CreativeRoom.m_Materials.Add(material2);
				}
			}
			UnityEngine.Object.Destroy(material);
		}

		public void CreateMaterialButton(int AddIndex)
		{
			int count = CreativeRoom.m_Materials.Count;
			this.m_UIParentTextureButtons.Show<Button>(count, delegate(int index, Button button)
			{
				RawImage component = button.GetComponent<RawImage>();
				component.texture = CreativeRoom.m_Materials[index].mainTexture;
				button.onClick.AddListener(delegate()
				{
					this.ButtonEvent_SetPanelsMaterial(index);
				});
			});
			uGUIScrollRect componentInParent = this.m_UIParentTextureButtons.GetComponentInParent<uGUIScrollRect>();
			if (componentInParent != null)
			{
				componentInParent.verticalNormalizedPosition = 1f;
			}
		}

		private void ButtonEvent_SetPanelsMaterial(int index)
		{
			if (CreativeRoom.m_Materials.Count <= index)
			{
				return;
			}
			if (index < 0)
			{
				return;
			}
			Material material = CreativeRoom.m_Materials[index];
			this.InvokeAllPanels(true, true, true, true, true, true, delegate(CreativeRoom.TileObject panel)
			{
				if (panel.type != CreativeRoom.TileType.Select)
				{
					return;
				}
				panel.matID = index;
				this.SetPanelType(panel, CreativeRoom.TileType.Select);
			}, null);
		}

		public void CombinePanelMesh()
		{
			this.OnUpdateMap();
			CreativeRoom.CombinePanelMesh(this.m_FloorArray);
		}

		private static void CombinePanelMesh(List<List<List<CreativeRoom.TileData>>> floorArray)
		{
			List<CreativeRoom.TileObject> list;
			List<CreativeRoom.TileObject> list2;
			CreativeRoom.GetAllPanels(floorArray, out list, out list2, true, true, true, true, true, true);
			List<CreativeRoom.TileObject> list3 = new List<CreativeRoom.TileObject>();
			for (int i = 0; i < list.Count; i++)
			{
				if (!(list[i].gameObject == null))
				{
					list[i].gameObject.SetActive(false);
					if (list[i].type != CreativeRoom.TileType.Disable)
					{
						list3.Add(list[i]);
					}
				}
			}
			Dictionary<Material, List<CombineInstance>> dictionary = new Dictionary<Material, List<CombineInstance>>();
			for (int j = 0; j < list3.Count; j++)
			{
				if (CreativeRoom.m_Materials.Count > list3[j].matID)
				{
					Material material;
					if (list3[j].matID < 0)
					{
						material = list3[j].gameObject.GetComponent<Renderer>().sharedMaterial;
					}
					else
					{
						material = CreativeRoom.m_Materials[list3[j].matID];
					}
					if (!(material == null))
					{
						if (!dictionary.ContainsKey(material))
						{
							dictionary.Add(material, new List<CombineInstance>());
						}
						List<CombineInstance> list4 = dictionary[material];
						list4.Add(new CombineInstance
						{
							transform = list3[j].gameObject.transform.localToWorldMatrix,
							mesh = list3[j].gameObject.GetComponent<MeshFilter>().sharedMesh
						});
					}
				}
			}
			if (CreativeRoom.m_CombineMeshObjectArray == null)
			{
				CreativeRoom.m_CombineMeshObjectArray = new List<GameObject>();
			}
			for (int k = 0; k < CreativeRoom.m_CombineMeshObjectArray.Count; k++)
			{
				CreativeRoom.m_CombineMeshObjectArray[k].SetActive(false);
			}
			GameObject parentCombineMeshObject = CreativeRoom.parentCombineMeshObject;
			List<Material> list5 = new List<Material>(dictionary.Keys);
			List<List<CombineInstance>> list6 = new List<List<CombineInstance>>(dictionary.Values);
			for (int l = 0; l < list5.Count; l++)
			{
				GameObject gameObject;
				MeshFilter meshFilter;
				MeshRenderer meshRenderer;
				if (CreativeRoom.m_CombineMeshObjectArray.Count > l)
				{
					gameObject = CreativeRoom.m_CombineMeshObjectArray[l];
					meshFilter = gameObject.GetComponent<MeshFilter>();
					meshRenderer = gameObject.GetComponent<MeshRenderer>();
					gameObject.SetActive(true);
					UnityEngine.Object.Destroy(meshFilter.sharedMesh);
				}
				else
				{
					gameObject = new GameObject();
					meshFilter = gameObject.AddComponent<MeshFilter>();
					meshRenderer = gameObject.AddComponent<MeshRenderer>();
					CreativeRoom.m_CombineMeshObjectArray.Add(gameObject);
					gameObject.transform.SetParent(parentCombineMeshObject.transform);
				}
				gameObject.name = "Combine Mesh [" + list5[l].name + "]";
				Mesh mesh = new Mesh();
				mesh.CombineMeshes(list6[l].ToArray());
				meshFilter.sharedMesh = mesh;
				meshRenderer.sharedMaterial = list5[l];
				meshRenderer.receiveShadows = true;
				meshRenderer.shadowCastingMode = ShadowCastingMode.Off;
			}
			for (int m = CreativeRoom.m_CombineMeshObjectArray.Count - 1; m >= 0; m--)
			{
				if (list5.Count <= m)
				{
					UnityEngine.Object.Destroy(CreativeRoom.m_CombineMeshObjectArray[m]);
					CreativeRoom.m_CombineMeshObjectArray.Remove(CreativeRoom.m_CombineMeshObjectArray[m]);
				}
			}
		}

		public void SavePanelData(BinaryWriter binary)
		{
			CreativeRoom.CombinePanelMesh(this.m_FloorArray);
			int count = this.m_FloorArray.Count;
			int count2 = this.m_FloorArray[0].Count;
			int count3 = this.m_FloorArray[0][0].Count;
			binary.Write(count);
			binary.Write(count2);
			binary.Write(count3);
			binary.Write(this.unitSize);
			for (int i = 0; i < count; i++)
			{
				for (int j = 0; j < count2; j++)
				{
					for (int k = 0; k < count3; k++)
					{
						CreativeRoom.TileData tileData = CreativeRoom.GetTileData(this.m_FloorArray, i, j, k);
						if (tileData != null)
						{
							for (int l = 0; l < 6; l++)
							{
								binary.Write((!(tileData[l].gameObject == null) && tileData[l].type != CreativeRoom.TileType.Disable) ? tileData[l].matID.ToString() : "-1");
							}
						}
					}
				}
			}
		}

		public void LoadPanelData(BinaryReader brRead)
		{
			int num = brRead.ReadInt32();
			int num2 = brRead.ReadInt32();
			int num3 = brRead.ReadInt32();
			float num4 = brRead.ReadSingle();
			this.m_UISliderRoomSizeX.value = (float)num;
			this.m_UISliderRoomSizeY.value = (float)num2;
			this.m_UISliderRoomSizeZ.value = (float)num3;
			this.m_UISliderUnitScale.value = num4;
			this.mapSizeX = num;
			this.mapSizeY = num2;
			this.mapSizeZ = num3;
			this.unitSize = num4;
			List<List<List<CreativeRoom.TileData>>> list = new List<List<List<CreativeRoom.TileData>>>();
			for (int i = 0; i < num; i++)
			{
				List<List<CreativeRoom.TileData>> list2 = new List<List<CreativeRoom.TileData>>();
				for (int j = 0; j < num2; j++)
				{
					List<CreativeRoom.TileData> list3 = new List<CreativeRoom.TileData>();
					for (int k = 0; k < num3; k++)
					{
						CreativeRoom.TileData tileData;
						if (i < this.m_FloorArray.Count && j < this.m_FloorArray[i].Count && k < this.m_FloorArray[i][j].Count)
						{
							tileData = this.m_FloorArray[i][j][k];
						}
						else
						{
							tileData = new CreativeRoom.TileData();
						}
						for (int l = 0; l < 6; l++)
						{
							tileData[l].matID = int.Parse(brRead.ReadString());
							tileData[l].type = ((tileData[l].matID >= 0) ? CreativeRoom.TileType.Enable : CreativeRoom.TileType.Disable);
							tileData[l].matID = ((tileData[l].matID >= 0) ? tileData[l].matID : 0);
						}
						list3.Add(tileData);
					}
					list2.Add(list3);
				}
				list.Add(list2);
			}
			this.m_FloorArray = list;
			this.OnUpdateMap();
			CreativeRoom.CombinePanelMesh(this.m_FloorArray);
		}

		public static GameObject Load(BinaryReader brRead)
		{
			int num = brRead.ReadInt32();
			int num2 = brRead.ReadInt32();
			int num3 = brRead.ReadInt32();
			float unitSize = brRead.ReadSingle();
			List<List<List<CreativeRoom.TileData>>> list = new List<List<List<CreativeRoom.TileData>>>();
			for (int i = 0; i < num; i++)
			{
				List<List<CreativeRoom.TileData>> list2 = new List<List<CreativeRoom.TileData>>();
				for (int j = 0; j < num2; j++)
				{
					List<CreativeRoom.TileData> list3 = new List<CreativeRoom.TileData>();
					for (int k = 0; k < num3; k++)
					{
						CreativeRoom.TileData tileData = new CreativeRoom.TileData();
						for (int l = 0; l < 6; l++)
						{
							tileData[l].matID = int.Parse(brRead.ReadString());
							tileData[l].type = ((tileData[l].matID >= 0) ? CreativeRoom.TileType.Enable : CreativeRoom.TileType.Disable);
							tileData[l].matID = ((tileData[l].matID >= 0) ? tileData[l].matID : 0);
						}
						list3.Add(tileData);
					}
					list2.Add(list3);
				}
				list.Add(list2);
			}
			CreativeRoom.LoadAllTextures();
			CreativeRoom.OnUpdateMapWall(list, unitSize);
			CreativeRoom.CombinePanelMesh(list);
			if (CreativeRoom.m_ParentTileObject != null)
			{
				UnityEngine.Object.Destroy(CreativeRoom.m_ParentTileObject);
			}
			UnityEngine.Object.Destroy(CreativeRoom.m_PrefabUnit);
			CreativeRoom.m_CombineMeshObjectArray = null;
			GameObject parentCombineMeshObject = CreativeRoom.m_ParentCombineMeshObject;
			CreativeRoom.m_ParentCombineMeshObject = null;
			return parentCombineMeshObject;
		}

		private void OnDestroy()
		{
			GameObject parentCombineMeshObject = CreativeRoom.m_ParentCombineMeshObject;
			if (parentCombineMeshObject != null)
			{
				UnityEngine.Object.Destroy(parentCombineMeshObject);
			}
			CreativeRoom.m_CombineMeshObjectArray = null;
			for (int i = 0; i < this.m_FloorArray.Count; i++)
			{
				for (int j = 0; j < this.m_FloorArray[i].Count; j++)
				{
					for (int k = 0; k < this.m_FloorArray[i][j].Count; k++)
					{
						CreativeRoom.DestroyTileObject(this.m_FloorArray[i][j][k]);
					}
				}
			}
			if (CreativeRoom.m_PrefabUnit != null)
			{
				UnityEngine.Object.Destroy(CreativeRoom.m_PrefabUnit);
			}
			if (CreativeRoom.m_ParentTileObject != null)
			{
				UnityEngine.Object.Destroy(CreativeRoom.m_ParentTileObject);
			}
			UnityEngine.Object.Destroy(CreativeRoom.m_MatDefaultColor);
			UnityEngine.Object.Destroy(CreativeRoom.m_MatHighlightColor);
			UnityEngine.Object.Destroy(CreativeRoom.m_MatSelectColor);
			UnityEngine.Object.Destroy(CreativeRoom.m_MatDisableColor);
			for (int l = 0; l < CreativeRoom.m_Materials.Count; l++)
			{
				UnityEngine.Object.Destroy(CreativeRoom.m_Materials[l]);
			}
			CreativeRoom.m_Materials = null;
		}

		private int m_MapSizeX = 1;

		private int m_MapSizeZ = 1;

		private int m_MapSizeY = 2;

		private float m_UnitSize = 1f;

		[SerializeField]
		private CreativeRoomManager m_Manager;

		private static GameObject m_PrefabUnit;

		private static GameObject m_ParentTileObject;

		private static GameObject m_ParentCombineMeshObject;

		[SerializeField]
		[Tooltip("親オブジェクト：テクスチャ一覧を表示しているUIオブジェクト")]
		private uGUIListViewer m_UIParentTextureButtons;

		[SerializeField]
		[Tooltip("テキスト：部屋の大きさを表示するUI")]
		private Text m_UITextRoomSizeX;

		[SerializeField]
		[Tooltip("テキスト：部屋の大きさを表示するUI")]
		private Text m_UITextRoomSizeY;

		[SerializeField]
		[Tooltip("テキスト：部屋の大きさを表示するUI")]
		private Text m_UITextRoomSizeZ;

		[SerializeField]
		[Tooltip("スライダー：部屋の大きさを変更するスライダー")]
		private Slider m_UISliderRoomSizeX;

		[SerializeField]
		[Tooltip("スライダー：部屋の大きさを変更するスライダー")]
		private Slider m_UISliderRoomSizeY;

		[SerializeField]
		[Tooltip("スライダー：部屋の大きさを変更するスライダー")]
		private Slider m_UISliderRoomSizeZ;

		[SerializeField]
		[Tooltip("スライダー：ユニット一つあたりの大きさを変更するスライダー")]
		private Slider m_UISliderUnitScale;

		[SerializeField]
		private InputField m_UIInputRoomSizeX;

		[SerializeField]
		private InputField m_UIInputRoomSizeY;

		[SerializeField]
		private InputField m_UIInputRoomSizeZ;

		[SerializeField]
		private InputField m_UIInputUnitScale;

		private static Material m_MatDefaultColor;

		private static Material m_MatHighlightColor;

		private static Material m_MatDisableColor;

		private static Material m_MatSelectColor;

		private List<List<List<CreativeRoom.TileData>>> m_FloorArray = new List<List<List<CreativeRoom.TileData>>>();

		private static List<Material> m_Materials = new List<Material>();

		private int m_PageIndexTexture;

		private bool m_IsDraggingSelect;

		private static List<GameObject> m_CombineMeshObjectArray = new List<GameObject>();

		private MaterialPropertyBlock m_MaterialPropertyBlock;

		public enum TileType
		{
			Enable,
			TempEnable,
			Disable,
			Select,
			TempSelect
		}

		private class TileData
		{
			public TileData()
			{
				this.right = new CreativeRoom.TileObject(CreativeRoom.TileType.Enable, null);
				this.left = new CreativeRoom.TileObject(CreativeRoom.TileType.Enable, null);
				this.up = new CreativeRoom.TileObject(CreativeRoom.TileType.Enable, null);
				this.down = new CreativeRoom.TileObject(CreativeRoom.TileType.Enable, null);
				this.front = new CreativeRoom.TileObject(CreativeRoom.TileType.Enable, null);
				this.back = new CreativeRoom.TileObject(CreativeRoom.TileType.Enable, null);
				this.enableRight = false;
				this.enableLeft = false;
				this.enableUp = false;
				this.enableDown = false;
				this.enableFront = false;
				this.enableBack = false;
			}

			public CreativeRoom.TileObject this[int i]
			{
				get
				{
					switch (i)
					{
					case 0:
						return this.right;
					case 1:
						return this.left;
					case 2:
						return this.up;
					case 3:
						return this.down;
					case 4:
						return this.front;
					case 5:
						return this.back;
					default:
						return null;
					}
				}
				set
				{
					switch (i)
					{
					case 0:
						this.right = value;
						break;
					case 1:
						this.left = value;
						break;
					case 2:
						this.up = value;
						break;
					case 3:
						this.down = value;
						break;
					case 4:
						this.front = value;
						break;
					case 5:
						this.back = value;
						break;
					}
				}
			}

			public CreativeRoom.TileObject right;

			public CreativeRoom.TileObject left;

			public CreativeRoom.TileObject up;

			public CreativeRoom.TileObject down;

			public CreativeRoom.TileObject front;

			public CreativeRoom.TileObject back;

			public bool enableRight;

			public bool enableLeft;

			public bool enableUp;

			public bool enableDown;

			public bool enableFront;

			public bool enableBack;
		}

		private class TileObject
		{
			public TileObject(CreativeRoom.TileType tileType, GameObject obj)
			{
				this.gameObject = obj;
				this.eventTrigger = null;
				this.type = tileType;
				this.matID = 0;
			}

			public void Reset()
			{
				UnityEngine.Object.Destroy(this.eventTrigger);
				UnityEngine.Object.Destroy(this.gameObject);
				this.gameObject = null;
				this.matID = 0;
			}

			public GameObject gameObject;

			public CreativeRoom.MouseEvent eventTrigger;

			public CreativeRoom.TileType type;

			public int matID;
		}

		private class MouseEvent : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, IPointerClickHandler, IPointerDownHandler, IPointerUpHandler, IEventSystemHandler
		{
			public void OnPointerEnter(PointerEventData data)
			{
				if (this.onPointerEnter != null)
				{
					this.onPointerEnter(data);
				}
			}

			public void OnPointerExit(PointerEventData data)
			{
				if (this.onPointerExit != null)
				{
					this.onPointerExit(data);
				}
			}

			public void OnPointerClick(PointerEventData data)
			{
				if (this.onPointerClick != null)
				{
					this.onPointerClick(data);
				}
			}

			public void OnPointerDown(PointerEventData data)
			{
				if (this.onPointerDown != null)
				{
					this.onPointerDown(data);
				}
			}

			public void OnPointerUp(PointerEventData data)
			{
				if (this.onPointerUp != null)
				{
					this.onPointerUp(data);
				}
			}

			public Action<PointerEventData> onPointerEnter;

			public Action<PointerEventData> onPointerExit;

			public Action<PointerEventData> onPointerClick;

			public Action<PointerEventData> onPointerDown;

			public Action<PointerEventData> onPointerUp;
		}
	}
}
