12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703 |
- 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);
- CreativeRoom.m_PrefabUnit.layer = LayerMask.NameToLayer("Terrain");
- }
- 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;
- }
- }
- }
|