Esempio n. 1
0
			public void OnBeforeSerialize () 
			{ 
				if (mapMagic is MapMagic) serializedMM_mapMagic = (MapMagic)mapMagic;
				#if VOXELAND
				if (mapMagic is Voxeland5.Voxeland) serializedMM_voxeland = (Voxeland5.Voxeland)mapMagic;
				#endif
			}
Esempio n. 2
0
		private void OnEnable ()
		{
			//finding mapmagic object if window is empty (has no gens)
			if (gens==null)
			{
				MapMagic mm = GameObject.FindObjectOfType<MapMagic>();
				if (mm!=null)
				{
					mapMagic = mm;
					gensBiomeHierarchy.Clear();
					gensBiomeHierarchy.Add(mm.gens);
				}

				#if VOXELAND
				else
				{
					Voxeland5.Voxeland voxeland = GameObject.FindObjectOfType<Voxeland5.Voxeland>();
					if (voxeland!=null)
					{
						mapMagic = voxeland;
						gensBiomeHierarchy.Clear();
						if (voxeland.data!=null && voxeland.data.generator!=null && voxeland.data.generator.mapMagicGens!=null) 
							gensBiomeHierarchy.Add(voxeland.data.generator.mapMagicGens);
					}
				}

				#endif
			}

			instance = this;
		}
Esempio n. 3
0
        public override void OnGUI(GeneratorsAsset gens)
        {
                        #if VOXELAND
            //voxeland = MapMagic.instance.GetComponent("Voxeland");

            //refreshing voxeland blocks information
            if (voxeland == null)
            {
                voxeland = GameObject.FindObjectOfType <Voxeland5.Voxeland>();
            }

            //creating layers
            if (voxeland != null)
            {
                int layersCount = voxeland.grassTypes.array.Length;
                if (layersCount != layers.Length)
                {
                    for (int i = layersCount; i < layers.Length; i++)
                    {
                        layers[i].input.Unlink();
                    }
                    ArrayTools.Resize(ref layers, layersCount);
                }
                for (int i = 0; i < layers.Length; i++)
                {
                    if (layers[i] == null)
                    {
                        layers[i] = new Layer();
                    }
                }
            }

            if (layers.Length == 0)
            {
                layout.Par(32);
                layout.Label("Voxeland terrain has no Grass Block types", rect: layout.Inset(), helpbox: true);
            }

            //drawing layers
            layout.Par(1); layout.Label("Temp", rect: layout.Inset());           //needed to reset label bold style
            layout.margin = 10; layout.rightMargin = 10;
            for (int i = layers.Length - 1; i >= 0; i--)
            {
                layout.DrawLayer(OnLayerGUI, ref selected, i);
            }
                        #endif
        }
Esempio n. 4
0
        public override void OnGUI(GeneratorsAsset gens)
        {
                        #if VOXELAND
            //voxeland = MapMagic.instance.GetComponent("Voxeland");

            //refreshing voxeland blocks information
            if (voxeland == null)
            {
                voxeland = GameObject.FindObjectOfType <Voxeland5.Voxeland>();
            }

            //gathering block names
            if (voxeland != null)
            {
                int namesCount = voxeland.landTypes.array.Length + 2;
                if (blockNames == null || blockNames.Length != namesCount)
                {
                    blockNames = new string[namesCount];
                }
                for (int i = 0; i < voxeland.landTypes.array.Length; i++)
                {
                    blockNames[i] = voxeland.landTypes.array[i].name;
                }
                blockNames[namesCount - 1] = "Empty";
            }

            //drawing layers
            layout.Par(1); layout.Label("Temp", rect: layout.Inset());           //needed to reset label bold style
            layout.margin = 10; layout.rightMargin = 10;
            for (int i = layers.Length - 1; i >= 0; i--)
            {
                layout.DrawLayer(OnLayerGUI, ref selected, i);
            }

            layout.Par(3); layout.Par();
            layout.DrawArrayAdd(ref layers, ref selected, layout.Inset(0.15f), reverse: true, createElement: () => new Layer());
            layout.DrawArrayRemove(ref layers, ref selected, layout.Inset(0.15f), reverse: true);
            layout.DrawArrayDown(ref layers, ref selected, layout.Inset(0.15f), dispUp: true);
            layout.DrawArrayUp(ref layers, ref selected, layout.Inset(0.15f), dispDown: true);

            layout.Par(5);
                        #endif
        }
Esempio n. 5
0
        private static float GetTerrainHeight()
        {
            float terrainHeight = 100;

            //#if MAPMAGIC
            if (mapMagic is MapMagic)
            {
                terrainHeight = MapMagic.instance.terrainHeight;
            }
            //#endif
                        #if VOXELAND
            if (mapMagic is Voxeland5.Voxeland)
            {
                Voxeland5.Voxeland voxeland = mapMagic as Voxeland5.Voxeland;
                if (Voxeland5.Voxeland.instances.Contains(voxeland))
                {
                    terrainHeight = voxeland.data.generator.heightFactor;
                }
            }
                        #endif

            return(terrainHeight);
        }
Esempio n. 6
0
        private static float GetPixelSize()
        {
            float pixelSize = 1;             //TODO: rather clamsy here. Change when TerrainSize would be ready

            //#if MAPMAGIC
            if (mapMagic is MapMagic)
            {
                pixelSize = 1f * MapMagic.instance.terrainSize / MapMagic.instance.resolution;
            }
            //#endif
                        #if VOXELAND
            if (mapMagic is Voxeland5.Voxeland)
            {
                Voxeland5.Voxeland voxeland = mapMagic as Voxeland5.Voxeland;
                if (Voxeland5.Voxeland.instances.Contains(voxeland))
                {
                    pixelSize = voxeland.transform.localScale.x;
                }
            }
                        #endif

            return(pixelSize);
        }
Esempio n. 7
0
        public static void Clear()
        {
                        #if UNITY_EDITOR
            mapMagic         = null;
            previewGenerator = null;
            previewOutput    = null;

            drawGizmos = false;
            //PreviewWindow.CloseWindow();

            //returning materials - MM case
            if (MapMagic.instance != null)
            {
                foreach (Chunk chunk in MapMagic.instance.chunks.All())
                {
                    if (chunk.terrain == null)
                    {
                        continue;                                            //if terrain was deleted
                    }
                    //chunk.terrain.materialType = MapMagic.instance.terrainMaterialType;
                    //chunk.terrain.materialTemplate = MapMagic.instance.customTerrainMaterial;
                    chunk.SetSettings();

                    //assigning saved material
                    if (originalMaterials.ContainsKey(chunk.terrain.transform))
                    {
                        if (chunk.terrain.materialTemplate != null)
                        {
                            GameObject.DestroyImmediate(chunk.terrain.materialTemplate);                                                                 //removes custom shader textures as well. Unity does not remove them!
                        }
                        Resources.UnloadUnusedAssets();

                        chunk.terrain.materialTemplate = originalMaterials[chunk.terrain.transform];
                    }

                    //checking if material is null and switching to standard if so
                    if (chunk.terrain.materialType == Terrain.MaterialType.Custom && MapMagic.instance.assignCustomTerrainMaterial && chunk.terrain.materialTemplate == null)
                    {
                        chunk.terrain.materialType = Terrain.MaterialType.BuiltInStandard;
                    }

                    //rebuilding: bug #118
                    if (chunk.terrain.materialType == Terrain.MaterialType.Custom && !MapMagic.instance.assignCustomTerrainMaterial && chunk.terrain.materialTemplate == null)
                    {
                        MapMagic.instance.ClearResults(); MapMagic.instance.Generate(force: true);
                    }                                                                                                         //rebuilding if terrain has no material saved
                }
            }

            //returning materials - Voxeland case
                        #if VOXELAND
            if (Voxeland5.Voxeland.instances != null && Voxeland5.Voxeland.instances.Count != 0)
            {
                Voxeland5.Voxeland voxeland = Voxeland5.Voxeland.instances.Any();
                foreach (Transform tfm in voxeland.Transforms())
                {
                    MeshRenderer renderer = tfm.GetComponent <MeshRenderer>();
                    if (renderer != null)
                    {
                        renderer.sharedMaterial = voxeland.material;

                        if (originalMaterials.ContainsKey(tfm))
                        {
                            renderer.sharedMaterial = originalMaterials[tfm];
                        }
                    }
                }
            }
                        #endif

            matrices.Clear();

            /*
             * if (MapMagic.instance != null)
             *      foreach (Chunk tw in MapMagic.instance.chunks.All()) tw.SetSettings();
             #if VOXELAND
             * foreach (Voxeland5.Voxeland voxeland in Voxeland5.Voxeland.instances)
             *      voxeland.RefreshMaterials();
             #endif
             */
                        #endif
        }