Beispiel #1
0
        public override void OnGUI()
        {
            //inouts
            layout.Par(20); output.DrawIcon(layout);
            layout.Par(5);

            //preview texture
            layout.margin = 4;
                        #if UNITY_EDITOR
            int  previewSize  = 70;
            int  controlsSize = (int)layout.field.width - previewSize - 10;
            Rect oldCursor    = layout.cursor;
            if (preview == null)
            {
                if (previewMatrix != null)
                {
                    preview = previewMatrix.SimpleToTexture();
                }
                else
                {
                    preview = Extensions.ColorTexture(2, 2, Color.black);
                }
            }
            layout.Par(previewSize + 3); layout.Inset(controlsSize);
            layout.Icon(preview, layout.Inset(previewSize + 4));
            layout.cursor = oldCursor;

            //preview params
            layout.Par(); if (layout.Button("Browse", rect: layout.Inset(controlsSize)))
            {
                ImportRaw(); layout.change = true;
            }
            layout.Par(); if (layout.Button("Refresh", rect: layout.Inset(controlsSize)))
            {
                ImportRaw(texturePath); layout.change = true;
            }
            layout.Par(40); layout.Label("Square gray 16bit RAW, PC byte order", layout.Inset(controlsSize), helpbox: true, fontSize: 9);
                        #endif

            layout.fieldSize = 0.62f;
            layout.Field(ref intensity, "Intensity");
            layout.Field(ref scale, "Scale");
            layout.Field(ref offset, "Offset");
            layout.Toggle(ref tile, "Tile");
        }
Beispiel #2
0
			public void Preview ()
			{
				#if UNITY_EDITOR 
				if (Event.current == null || Event.current.type != EventType.Repaint) return;
					
				//clearing preview if prevew generator is off (or non-map)
				if (MapMagic.instance.previewOutput==null || MapMagic.instance.previewOutput.type!=Generator.InoutType.Map)
				{
					if (terrain.materialTemplate != null && terrain.materialTemplate.shader.name == "MapMagic/TerrainPreviewFirstPass")
					{
						terrain.materialType = MapMagic.ToUnityTerrMatType(MapMagic.instance.terrainMaterialType);
						terrain.materialTemplate = previewBackupMaterial;

						previewBackupMaterial = null;
						lastPreviewedMatrix = null;

						UnityEditor.SceneView.RepaintAll();
					}
				}
						
				if (MapMagic.instance.previewOutput!=null && MapMagic.instance.previewOutput.type == Generator.InoutType.Map)
				{
					//loading preview material from terrain (or creating new)
					Material previewMat = null;
					if (terrain.materialTemplate!=null && terrain.materialTemplate.shader.name=="MapMagic/TerrainPreviewFirstPass") previewMat = terrain.materialTemplate;
					if (previewMat == null) 
					{
						Shader previewShader = Shader.Find("MapMagic/TerrainPreviewFirstPass");
						previewMat = new Material(previewShader);

						previewBackupMaterial = terrain.materialTemplate;
						terrain.materialTemplate = previewMat;
						terrain.materialType = Terrain.MaterialType.Custom;
						
						UnityEditor.SceneView.RepaintAll();
					}

					//loading matrix
					Matrix matrix = MapMagic.instance.previewOutput.GetObject<Matrix>(this);

					//refreshing preview texture
					if (matrix != lastPreviewedMatrix)
					{
						Texture2D tex = null;
						
						//populate
						if (matrix != null) 
						{
							tex = new Texture2D(matrix.rect.size.x, matrix.rect.size.z);
			 
							Color[] line = new Color[matrix.rect.size.z];
							for (int x=0; x<matrix.rect.size.x; x++)
							{
								for (int z=0; z<matrix.rect.size.z; z++)
								{
									float val = matrix[x+matrix.rect.offset.x, z+matrix.rect.offset.z];
									line[z] = new Color(val, val, val);
								}
								tex.SetPixels(x,0,1,line.Length,line);
							}
						}
						else //in case the output is not generated
						{
							tex = Extensions.ColorTexture(2,2,Color.gray);
						}

						//apply
						tex.Apply();
						previewMat.SetTexture("_Preview", tex);
						if (MapMagic.instance.guiDebug) Debug.Log("Preview Applied");

						lastPreviewedMatrix = matrix;

						UnityEditor.SceneView.RepaintAll();
					}
				}

				//spatial hash
				if (MapMagic.instance.previewOutput!=null && MapMagic.instance.previewOutput.type == Generator.InoutType.Objects)
				{
					float pixelSize = 1f * MapMagic.instance.terrainSize / MapMagic.instance.resolution;
					
					SpatialHash objs = MapMagic.instance.previewOutput.GetObject<SpatialHash>(this);

					if (objs != null)
					{
						int objsCount = objs.Count;
						foreach (SpatialObject obj in objs)
						{
							float terrainHeight = 0;
							if (heights != null) terrainHeight = heights.GetInterpolated(obj.pos.x, obj.pos.y);
							Vector3 pos = new Vector3(obj.pos.x*pixelSize, (obj.height+terrainHeight)*MapMagic.instance.terrainHeight, obj.pos.y*pixelSize);
							pos += MapMagic.instance.transform.position;

							UnityEditor.Handles.color = new Color(1,1,1,1);
							UnityEditor.Handles.DrawLine(pos+new Vector3(obj.size/2f,0,0), pos-new Vector3(obj.size/2f,0,0));
							UnityEditor.Handles.DrawLine(pos+new Vector3(0,0,obj.size/2f), pos-new Vector3(0,0,obj.size/2f));

							if (objsCount < 100)
							{
								Vector3 oldPoint = pos;
								foreach (Vector3 point in pos.CircleAround(obj.size/2f, 12, true))
								{
									UnityEditor.Handles.DrawLine(oldPoint,point);
									oldPoint = point;
								}
							}

							UnityEditor.Handles.color = new Color(1,1,1,0.15f); 
							UnityEditor.Handles.DrawLine(new Vector3(pos.x, 0, pos.z), new Vector3(pos.x, MapMagic.instance.terrainHeight, pos.z));
						}
					}
				}

				#endif
			}
Beispiel #3
0
        public override void OnGUI(GeneratorsAsset gens)
        {
                        #if RTP
            if (rtp == null)
            {
                rtp = MapMagic.instance.GetComponent <ReliefTerrain>();
            }
            if (renderer == null)
            {
                renderer = MapMagic.instance.GetComponent <MeshRenderer>();
            }

            //wrong material and settings warnings
            if (MapMagic.instance.copyComponents)
            {
                layout.Par(42);
                layout.Label("Copy Component should be turned off to prevent copying RTP to chunks.", rect: layout.Inset(0.8f), helpbox: true);
                if (layout.Button("Fix", rect: layout.Inset(0.2f)))
                {
                    MapMagic.instance.copyComponents = false;
                }
            }

            if (rtp == null)
            {
                layout.Par(42);
                layout.Label("Could not find Relief Terrain component on MapMagic object.", rect: layout.Inset(0.8f), helpbox: true);
                if (layout.Button("Fix", rect: layout.Inset(0.2f)))
                {
                    renderer = MapMagic.instance.gameObject.GetComponent <MeshRenderer>();
                    if (renderer == null)
                    {
                        renderer = MapMagic.instance.gameObject.AddComponent <MeshRenderer>();
                    }
                    renderer.enabled = false;
                    rtp = MapMagic.instance.gameObject.AddComponent <ReliefTerrain>();

                    //if (MapMagic.instance.gameObject.GetComponent<InstantUpdater>()==null) MapMagic.instance.gameObject.AddComponent<InstantUpdater>();

                    //filling empty splats
                    Texture2D emptyTex = Extensions.ColorTexture(4, 4, new Color(0.5f, 0.5f, 0.5f, 1f));
                    emptyTex.name = "Empty";
                    rtp.globalSettingsHolder.splats = new Texture2D[] { emptyTex, emptyTex, emptyTex, emptyTex };
                }
            }

            if (MapMagic.instance.terrainMaterialType != Terrain.MaterialType.Custom)
            {
                layout.Par(30);
                layout.Label("Material Type is not switched to Custom.", rect: layout.Inset(0.8f), helpbox: true);
                if (layout.Button("Fix", rect: layout.Inset(0.2f)))
                {
                    MapMagic.instance.terrainMaterialType = Terrain.MaterialType.Custom;
                    foreach (Chunk tw in MapMagic.instance.chunks.All())
                    {
                        tw.SetSettings();
                    }
                }
            }

            if (MapMagic.instance.assignCustomTerrainMaterial)
            {
                layout.Par(30);
                layout.Label("Assign Custom Material is turned on.", rect: layout.Inset(0.8f), helpbox: true);
                if (layout.Button("Fix", rect: layout.Inset(0.2f)))
                {
                    MapMagic.instance.assignCustomTerrainMaterial = false;
                }
            }

            if (MapMagic.instance.GetComponent <InstantUpdater>() == null)
            {
                layout.Par(52);
                layout.Label("Use Instant Updater component to apply RTP changes to all the terrains.", rect: layout.Inset(0.8f), helpbox: true);
                if (layout.Button("Fix", rect: layout.Inset(0.2f)))
                {
                    MapMagic.instance.gameObject.AddComponent <InstantUpdater>();
                }
            }

            /*if (!MapMagic.instance.materialTemplateMode)
             * {
             *      layout.Par(30);
             *      layout.Label("Material Template Mode is off.", rect:layout.Inset(0.8f), helpbox:true);
             *      if (layout.Button("Fix",rect:layout.Inset(0.2f))) MapMagic.instance.materialTemplateMode = true;
             * }*/

            /*if ((renderer != null) &&
             *      (renderer.sharedMaterial == null || !renderer.sharedMaterial.shader.name.Contains("ReliefTerrain")))
             * {
             *      layout.Par(50);
             *      layout.Label("No Relief Terrain material is assigned as Custom Material in Terrain Settings.", rect:layout.Inset(0.8f), helpbox:true);
             *      if (layout.Button("Fix",rect:layout.Inset(0.2f)))
             *      {
             *              //if (renderer.sharedMaterial == null)
             *              //{
             *                      Shader shader = Shader.Find("Relief Pack/ReliefTerrain-FirstPass");
             *                      if (shader != null) renderer.sharedMaterial = new Material(shader);
             *                      else Debug.Log ("MapMagic: Could not find Relief Pack/ReliefTerrain-FirstPass shader. Make sure RTP is installed or switch material type to Standard.");
             *              //}
             *              MapMagic.instance.customTerrainMaterial = renderer.sharedMaterial;
             *              foreach (Chunk tw in MapMagic.instance.chunks.All()) tw.SetSettings();
             *      }
             * }*/

            if (rtp == null)
            {
                return;
            }

            bool doubleLayer = false;
            for (int i = 0; i < baseLayers.Length; i++)
            {
                for (int j = 0; j < baseLayers.Length; j++)
                {
                    if (i == j)
                    {
                        continue;
                    }
                    if (baseLayers[i].index == baseLayers[j].index)
                    {
                        doubleLayer = true;
                    }
                }
            }
            if (doubleLayer)
            {
                layout.Par(30);
                layout.Label("Seems that multiple layers use the same splat index.", rect: layout.Inset(0.8f), helpbox: true);
                if (layout.Button("Fix", rect: layout.Inset(0.2f)))
                {
                    ResetLayers(baseLayers.Length);
                }
            }


            //refreshing layers from rtp
            Texture2D[] splats = rtp.globalSettingsHolder.splats;
            if (baseLayers.Length != splats.Length)
            {
                ResetLayers(splats.Length);
            }

            //drawing layers
            layout.margin = 20; layout.rightMargin = 20; layout.fieldSize = 1f;
            for (int i = baseLayers.Length - 1; i >= 0; i--)
            {
                //if (baseLayers[i] == null)
                //baseLayers[i] = new Layer();

                if (layout.DrawWithBackground(OnLayerGUI, active:i == selected, num:i, frameDisabled:false))
                {
                    selected = i;
                }
            }

            layout.Par(3); layout.Par();
            //layout.DrawArrayAdd(ref baseLayers, ref selected, layout.Inset(0.25f));
            //layout.DrawArrayRemove(ref baseLayers, ref selected, layout.Inset(0.25f));
            layout.DrawArrayUp(ref baseLayers, ref selected, layout.Inset(0.25f), reverseOrder: true);
            layout.DrawArrayDown(ref baseLayers, ref selected, layout.Inset(0.25f), reverseOrder: true);

            layout.margin = 3; layout.rightMargin = 3;
            layout.Par(64); layout.Label("Use Relief Terrain component to set layer properties. \"Refresh All\" in RTP settings might be required.", rect: layout.Inset(), helpbox: true);
                        #else
            layout.margin      = 5;
            layout.rightMargin = 5;

            layout.Par(45);
            layout.Label("Cannot find Relief Terrain plugin. Restart Unity if you have just installed it.", rect: layout.Inset(), helpbox: true);
                        #endif
        }
Beispiel #4
0
			public void ClearSplats () //same as SplatOutput.Clear
			{
				terrain.terrainData.splatPrototypes = new SplatPrototype[] { new SplatPrototype() { texture = Extensions.ColorTexture(2,2,new Color(0.5f, 0.5f, 0.5f, 0f)) } };

				float[,,] emptySplats = new float[16,16,1];
				for (int x=0; x<16; x++)
					for (int z=0; z<16; z++)
						emptySplats[z,x,0] = 1;

				terrain.terrainData.alphamapResolution = 16;
				terrain.terrainData.SetAlphamaps(0,0,emptySplats);

				if (MapMagic.instance.guiDebug) Debug.Log("Splats Cleared");
			}