Esempio n. 1
0
        void TreesCategory()
        {
            terrain.manageTrees = UNEditorUtility.DrawHelpBox("TreeInstances Management", "Here you can manage your trees.", true, terrain.manageTrees);

            selectedPrototypes = UNEditorUtility.DrawPrototypesSelector <UNTreePrototype>(terrain.terrainData.treePrototypes, selectedPrototypes, ctrlPressed, 450, ref prototypesScrollbarPos);

            GUILayout.Space(5);

            GUILayout.BeginVertical("Box");

            if (selectedPrototypes.Count == 0) // no items selected
            {
                GUILayout.Label("No items selected", EditorStyles.centeredGreyMiniLabel);
            }
            else if (selectedPrototypes.Count > 1) // more than 1 object selected.
            {
                GUILayout.Label("Multi-Edit is not currently supported.", EditorStyles.centeredGreyMiniLabel);
            }
            else // draw the prototype edit ui.
            {
                GUILayout.Label("Pool Settings :", EditorStyles.boldLabel);

                selectedPrototypes[0].forcePoolCreation = EditorGUILayout.Toggle(new GUIContent("Force creation of this item :", "Will this item be generated in the Pool even if its not being used on the terrain"), selectedPrototypes[0].forcePoolCreation);
            }

            GUILayout.EndVertical();
        }
Esempio n. 2
0
        void PoolCategory()
        {
            UNEditorUtility.DrawHelpBox("Pool Management", "Here you can manage your items Pool.", false, false);

            terrain.PoolItemType = UNEditorUtility.DrawSelectionBox <System.Type>(new GUIContent("Pool Item Type : ", "What would be the type of the Pool ?"), PoolCache, PoolCache.Find(x => x.item == terrain.PoolItemType));
            terrain.PoolAmount   = EditorGUILayout.IntSlider("Pool Amount :", terrain.PoolAmount, 1, 100);

            GUILayout.Space(10);

            if (GUILayout.Button("Update Pool"))
            {
                terrain.CreatePool(terrain.PoolItemType);
            }
        }
Esempio n. 3
0
        void GridsCategory()
        {
            UNEditorUtility.DrawHelpBox("Grids Management", "Here you can manage your grids.", false, false);

            GUILayout.BeginHorizontal();
            GUILayout.Space(Screen.width / 5);

            int resolution = terrain.sectorResolution == 1 ? 300 : (300 / terrain.sectorResolution);

            UNEditorUtility.DrawGridPreview(terrain.sectorResolution, UNStandaloneUtility.GetUIIcon("Square"), resolution, resolution);

            GUILayout.EndHorizontal();

            GUILayout.Space(15);

            terrain.sectorResolution = EditorGUILayout.IntSlider(new GUIContent("Sector Resolution", "The resolution of the sector of the terrain, grids count = (resolution)^2"), terrain.sectorResolution, 1, Sector.resolutionLimit);
        }
Esempio n. 4
0
        public void OnGUI()
        {
            if (FoliageCore_MainManager.instance == null)
            {
                GUILayout.BeginVertical();
                GUILayout.Label("Foliage Manager Not Found!!");

                if (GUILayout.Button("Create Foliage Manager"))
                {
                    FoliageCore_MainManager.InitializeAndCreateIfNotFound();
                }
                GUILayout.EndVertical();

                return;
            }

            globalScrollPos = EditorGUILayout.BeginScrollView(globalScrollPos);

            ctrlPressed = Event.current == null ? false : Event.current.control;

            if (Event.current != null && Event.current.keyCode == KeyCode.Escape) // try to disable brush on GUI window
            {
                chosenBrushes.Clear();

                EditorUtility.SetDirty(FoliageDB.instance);
                EditorUtility.SetDirty(FoliageCore_MainManager.instance);
            }

            if (invisibleButtonStyle == null)
            {
                invisibleButtonStyle = new GUIStyle("Box");

                invisibleButtonStyle.normal.background  = null;
                invisibleButtonStyle.focused.background = null;
                invisibleButtonStyle.hover.background   = null;
                invisibleButtonStyle.active.background  = null;
            }

            FoliageCore_MainManager.instance.enabled = UNEditorUtility.DrawHelpBox(string.Format("Foliage Manager: (GUID : {0})", FoliageCore_MainManager.instance.guid), "Here you can manage and paint \nFoliage all over your scene!", true, FoliageCore_MainManager.instance.enabled); // add variable to edit.

            GUI.enabled = FoliageCore_MainManager.instance.enabled;

            DrawPaintWindow();

            GUILayout.Space(5);

            DrawPrototypesWindow();

            prototypesEditDataPos = EditorGUILayout.BeginScrollView(prototypesEditDataPos);

            GUILayout.Space(2);

            DrawPrototypesEditUI();

            GUILayout.Space(5);

            DrawGlobalSettingsUI();

            GUILayout.Space(5);

            DrawFoliageInstancesEditingUI();

            EditorGUILayout.EndScrollView();

            if (GUI.changed)
            {
                EditorUtility.SetDirty(FoliageDB.instance);
                EditorUtility.SetDirty(FoliageCore_MainManager.instance);
            }

            EditorGUILayout.EndScrollView();

            GUI.enabled = true;
        }
Esempio n. 5
0
        void DrawPrototypesEditUI()
        {
            bool canEdit = chosenPrototypes.Count == 1;

            EditorGUILayout.BeginVertical("Box", GUILayout.Width(450), GUILayout.MaxHeight(canEdit ? 215 : 35));

            FoliagePrototype prototype;

            if (chosenPrototypes.Count == 1) // render settings
            {
                prototype = chosenPrototypes[0];

                GUILayout.BeginHorizontal();
                GUILayout.Label(string.Format("Prototype: {0}({1})", prototype.name, prototype.id), EditorStyles.boldLabel);

                GUILayout.FlexibleSpace();

                prototype.enabled = GUILayout.Toggle(prototype.enabled, "") && GUI.enabled;

                GUILayout.EndHorizontal();

                GUI.enabled = prototype.enabled;

                GUILayout.Space(10);

                GUILayout.Label("Generation Settings:", EditorStyles.boldLabel);

                prototype.spread = EditorGUILayout.Slider(new GUIContent("Spread Noise:", "The randomized space between each Foliage"), prototype.spread, 0, 2);
                prototype.FoliageGenerationRadius = (FoliageGenerationRadius)EditorGUILayout.EnumPopup("Generation Radius:", prototype.FoliageGenerationRadius);

                Vector2 widthValues  = UNEditorUtility.MinMaxSlider(new GUIContent("Width Noise:", ""), prototype.minimumWidth, prototype.maximumWidth, FoliagePrototype.SIZE_MIN_VALUE, FoliagePrototype.SIZE_MAX_VALUE);
                Vector2 heightValues = UNEditorUtility.MinMaxSlider(new GUIContent("Height Noise:", ""), prototype.minimumHeight, prototype.maximumHeight, FoliagePrototype.SIZE_MIN_VALUE, FoliagePrototype.SIZE_MAX_VALUE);

                prototype.minimumWidth = widthValues.x;
                prototype.maximumWidth = widthValues.y;

                prototype.minimumHeight = heightValues.x;
                prototype.maximumHeight = heightValues.y;

                GUILayout.Space(10);

                prototype.renderingLayer = EditorGUILayout.LayerField(new GUIContent("Rendering Layer: ", "The rendering layer"), prototype.renderingLayer);
                prototype.fadeDistance   = EditorGUILayout.Slider("Fade Distance: ", prototype.fadeDistance, 0, 1000);

                GUILayout.Space(10);

                prototype.receiveShadows                = EditorGUILayout.Toggle("Receive Shadows:", prototype.receiveShadows);
                prototype.castShadows                   = EditorGUILayout.Toggle("Cast Shadows:", prototype.castShadows);
                prototype.useColorMap                   = EditorGUILayout.Toggle("Use Color Map:", prototype.useColorMap);
                prototype.maxGeneratedDensity           = EditorGUILayout.IntSlider("Max Generatable Density:", prototype.maxGeneratedDensity, 1, prototype.FoliageInstancedMeshData.MeshInstancesLimiter_Optimization_Clamp);
                prototype.meshInstancesGenerationOffset = EditorGUILayout.Vector2Field(new GUIContent("Instances Generating Offset: ", "Offset for mesh instances generation, don't change unless necessary!!"), prototype.meshInstancesGenerationOffset);

                GUILayout.Space(10);

                GUILayout.Label("Touch Bending Settings :", EditorStyles.boldLabel);

                prototype.touchBendingEnabled  = GUILayout.Toggle(prototype.touchBendingEnabled, "Touch Bending Enabled");
                prototype.touchBendingStrength = EditorGUILayout.Slider("Touch Bending Strength", prototype.touchBendingStrength, 0.01f, 5f);

                GUILayout.Space(10);

                GUILayout.Label("Individual Wind Settings :", EditorStyles.boldLabel);

                prototype.useCustomWind = EditorGUILayout.BeginToggleGroup(new GUIContent("Individual Wind", "Use Individual wind for this specific prototype (dont use the global settings)"), prototype.useCustomWind);
                prototype.customWindSettings.windBending = EditorGUILayout.Slider("Wind Bending:", prototype.customWindSettings.windBending, 0, 1);
                prototype.customWindSettings.windSpeed   = EditorGUILayout.Slider("Wind Speed:", prototype.customWindSettings.windSpeed, 0, 1);
                EditorGUILayout.EndToggleGroup();

                GUILayout.Space(10);

                prototype.useLODs = EditorGUILayout.BeginToggleGroup(new GUIContent("Use LODs", "Use Level Of Detail on the Foliage."), prototype.useLODs);
                prototype.lods    = UNEditorUtility.DrawLODsEditor(prototype.lods);
                EditorGUILayout.EndToggleGroup();

                GUILayout.Space(10);

                prototype.healthyColor = EditorGUILayout.ColorField("Healthy Color", prototype.healthyColor);
                prototype.dryColor     = EditorGUILayout.ColorField("Dry Color", prototype.dryColor);

                GUI.enabled = true;
            }
            else if (chosenPrototypes.Count > 1) // if bigger than one, lets disable editing (not supporting multi-editing)
            {
                GUILayout.Label("Multi-editing is not supported!, Please note \nthat you can still draw while multi-selecting prototypes.", EditorStyles.centeredGreyMiniLabel);
            }
            else // if zero, just write that no item is selected.
            {
                GUILayout.Label("No prototype is selected, please choose one to continue!", EditorStyles.centeredGreyMiniLabel);
            }

            GUILayout.EndVertical();
        }
Esempio n. 6
0
        void DrawPrototypesWindow()
        {
            GUILayout.BeginVertical("Box", GUILayout.Width(450));

            GUILayout.BeginHorizontal();
            GUILayout.Label("Prototypes Management:", EditorStyles.boldLabel);

            GUILayout.FlexibleSpace();

            if (chosenPrototypes.Count > 0)
            {
                if (GUILayout.Button("-", GUILayout.Width(15), GUILayout.Width(15)))
                {
                    if (EditorUtility.DisplayDialog("uNature", "Are you sure you want to delete this prototype ? \nThis cannot be undone!", "Yes", "No"))
                    {
                        for (int i = 0; i < chosenPrototypes.Count; i++)
                        {
                            FoliageDB.instance.RemovePrototype(chosenPrototypes[i]);
                        }
                        chosenPrototypes.Clear();

                        return;
                    }
                }
                if (GUILayout.Button(new GUIContent("R", "Remove the prototype density from this foliage manager.")))
                {
                    if (EditorUtility.DisplayDialog("uNature", "Are you sure you want to remove this prototype's density ? \nThis cannot be undone!", "Yes", "No"))
                    {
                        for (int i = 0; i < chosenPrototypes.Count; i++)
                        {
                            FoliageCore_MainManager.ResetGrassMap(chosenPrototypes);
                        }
                    }
                }

                if (GUILayout.Button(new GUIContent("L", "Locate the material instance of this prototype")))
                {
                    UnityEngine.Object[] selectionTargets = new UnityEngine.Object[chosenPrototypes.Count];

                    for (int i = 0; i < selectionTargets.Length; i++)
                    {
                        selectionTargets[i] = chosenPrototypes[i].FoliageInstancedMeshData.mat;
                    }

                    Selection.objects = selectionTargets;
                }
            }

            GUILayout.EndHorizontal();

            chosenPrototypes = UNEditorUtility.DrawPrototypesSelector(FoliageDB.unSortedPrototypes, chosenPrototypes, ctrlPressed, 440, ref prototypesScrollPos);

            #region Drag and drop
            DragAndDrop.visualMode = DragAndDropVisualMode.Generic;
            if (Event.current.type == EventType.DragExited)
            {
                GameObject         targetFoliagePrefab;
                Texture2D          targetFoliageTexture;
                UnityEngine.Object targetGeneric;

                bool exists = false;

                for (int i = 0; i < DragAndDrop.objectReferences.Length; i++)
                {
                    targetFoliagePrefab  = DragAndDrop.objectReferences[i] as GameObject;
                    targetFoliageTexture = DragAndDrop.objectReferences[i] as Texture2D;

                    targetGeneric = targetFoliagePrefab == null ? (UnityEngine.Object)targetFoliageTexture : targetFoliagePrefab;

                    if (targetGeneric != null)
                    {
                        for (int b = 0; b < FoliageDB.unSortedPrototypes.Count; b++)
                        {
                            if ((targetFoliagePrefab != null && targetFoliagePrefab == FoliageDB.unSortedPrototypes[b].FoliageMesh) || (targetFoliageTexture != null && targetFoliageTexture == FoliageDB.unSortedPrototypes[b].FoliageTexture))
                            {
                                Debug.LogWarning("Foliage : " + targetGeneric.name + " Already exists! Ignored!");
                                exists = true;
                                break;
                            }
                        }
                    }

                    if (exists)
                    {
                        continue;
                    }

                    if (targetFoliagePrefab != null)
                    {
                        FoliageDB.instance.AddPrototype(targetFoliagePrefab);
                    }
                    else if (targetFoliageTexture != null)
                    {
                        FoliageDB.instance.AddPrototype(targetFoliageTexture);
                    }
                }
            }
            #endregion

            GUILayout.EndVertical();
        }
Esempio n. 7
0
 void DrawNormalBrush()
 {
     chosenBrushes = UNEditorUtility.DrawPrototypesSelector(FoliageDB.instance.brushes, chosenBrushes, false, 300, ref brushesScrollPos);
 }
Esempio n. 8
0
        void DrawPaintWindow()
        {
            GUILayout.BeginVertical("Box", GUILayout.Width(450));

            GUILayout.BeginHorizontal();

            GUILayout.Label("Paint Tools:", EditorStyles.boldLabel);

            GUILayout.FlexibleSpace();

            if (GUILayout.Button("Reload Brushes"))
            {
                FoliageDB.instance.brushes = null;
            }

            GUILayout.EndHorizontal();

            GUILayout.Space(5);

            GUILayout.BeginHorizontal();

            GUILayout.BeginVertical("Box");

            string[]           paintMethodsNames = Enum.GetNames(typeof(CurrentPaintMethod));
            CurrentPaintMethod currentType;

            for (int i = 0; i < paintMethodsNames.Length; i++)
            {
                currentType = (Enum.GetValues(typeof(CurrentPaintMethod)) as CurrentPaintMethod[])[i];

                if (UNEditorUtility.DrawHighlitableButton(UNStandaloneUtility.GetUIIcon(paintMethodsNames[i]), paintMethod == currentType, GUILayout.Width(40), GUILayout.Height(40)))
                {
                    paintMethod = currentType; // select the paint method.
                }
            }

            GUILayout.EndVertical();

            GUILayout.Space(3);

            GUILayout.BeginVertical("Box", GUILayout.Height(100));

            GUILayout.Label("Paint Settings:", EditorStyles.boldLabel);

            GUILayout.Space(5);

            switch (paintMethod)
            {
            case CurrentPaintMethod.Normal_Paint:
                DrawNormalBrush();
                break;

            case CurrentPaintMethod.Spline_Paint:
                DrawSplineBrush();
                break;
            }

            GUILayout.Space(5);

            paintBrushSize = EditorGUILayout.IntSlider(new GUIContent("Paint Brush Size:", "The percentage from the brush that will be drawn"), paintBrushSize, 1, 30);
            paintDensity   = (byte)EditorGUILayout.IntSlider(new GUIContent("Paint Brush Density:", "The percentage from the brush that will be drawn"), paintDensity, 0, 15);
            instaRemove    = EditorGUILayout.Toggle(new GUIContent("Instant Remove On Shift:", "Instantely remove the grass when shift is pressed (instead of needing to put density to 0"), instaRemove);

            GUILayout.EndVertical();

            GUILayout.EndHorizontal();

            if (FoliageGrassMap.globalDirty)
            {
                GUILayout.Space(10);
                EditorGUILayout.HelpBox("Foliage hasn't been saved after painting on terrain. \nPlease save the data by clicking the save button.", MessageType.Warning);

                if (GUILayout.Button("Save Grass Maps"))
                {
                    FoliageGrassMap.SaveAllMaps();

                    EditorUtility.SetDirty(FoliageCore_MainManager.instance);

                    if (!Application.isPlaying)
                    {
                        #if UNITY_5_3_OR_NEWER
                        UnityEditor.SceneManagement.EditorSceneManager.SaveScene(UnityEngine.SceneManagement.SceneManager.GetActiveScene());
                        #else
                        EditorApplication.SaveScene();
                        #endif
                    }

                    AssetDatabase.SaveAssets();
                }
            }


            if (FoliageWorldMap.globalDirty)
            {
                GUILayout.Space(10);
                EditorGUILayout.HelpBox("World information isn't been saved. \nPlease save the data by clicking the save button or changes wont be applied.", MessageType.Warning);

                if (GUILayout.Button("Save World Map"))
                {
                    FoliageWorldMap.SaveAllMaps();

                    EditorUtility.SetDirty(FoliageCore_MainManager.instance);

                    if (!Application.isPlaying)
                    {
                        #if UNITY_5_3_OR_NEWER
                        UnityEditor.SceneManagement.EditorSceneManager.SaveScene(UnityEngine.SceneManagement.SceneManager.GetActiveScene());
                        #else
                        EditorApplication.SaveScene();
                        #endif
                    }

                    AssetDatabase.SaveAssets();
                }
            }

            GUILayout.EndVertical();
        }
Esempio n. 9
0
        /// <summary>
        /// On terrain changed.
        /// </summary>
        /// <param name="changedFlags"></param>
        protected virtual void OnTerrainChanged(int changedFlags)
        {
            TerrainChangedFlags flag = (TerrainChangedFlags)changedFlags;

            if (flag == TerrainChangedFlags.TreeInstances)
            {
                if (sector == null)
                {
                    GenerateSector(sectorResolution);
                }

                #if UNITY_EDITOR
                UNEditorUtility.StartSceneScrollbar("Fetching tree instances...", 1);
                #endif

                sector.FetchTreeInstances(true, () =>
                {
                    #if UNITY_EDITOR
                    UNSettings.Log("Trees Updated.");

                    UNEditorUtility.currentProgressIndex = 1;
                    #endif
                });
            }
            else if (flag == TerrainChangedFlags.TreePrototypesChanged)
            {
                CreatePool(PoolItemType);
            }
            else if (flag == TerrainChangedFlags.DelayedHeightmapUpdate)
            {
                if (FoliageCore_MainManager.instance == null || !updateGrassOnHeightsChange || !manageGrass)
                {
                    return;
                }

                TerrainData tData = terrain.terrainData;

                float[,] heights = tData.GetHeights(0, 0, tData.heightmapWidth, tData.heightmapHeight);
                bool changed = false;

                float cordX;
                float cordY;

                FoliageCore_MainManager manager = FoliageCore_MainManager.instance;

                int mChunkID;
                FoliageCore_Chunk      mChunk;
                FoliageManagerInstance mInstance;

                Vector3 position        = transform.position;
                Vector3 managerPosition = manager.transform.position;

                FoliageWorldMap worldMap;

                int transformedSize;

                for (int x = 0; x < tData.heightmapWidth; x++)
                {
                    for (int y = 0; y < tData.heightmapHeight; y++)
                    {
                        if (heights[y, x] != terrainData.multiThreaded_terrainHeights[y, x]) // change on cord.
                        {
                            changed = true;

                            cordX = ((x * tData.size.x) / tData.heightmapWidth) + position.x;
                            cordY = ((y * tData.size.z) / tData.heightmapHeight) + position.z;

                            mChunkID = manager.GetChunkID(cordX - managerPosition.x, cordY - managerPosition.z);

                            if (manager.CheckChunkInBounds(mChunkID))
                            {
                                mChunk = manager.sector.foliageChunks[mChunkID];

                                if (!mChunk.isFoliageInstanceAttached)
                                {
                                    continue;
                                }

                                mInstance = mChunk.GetOrCreateFoliageManagerInstance();

                                worldMap = mInstance.worldMap;

                                cordX = mInstance.TransformCord(cordX, mInstance.transform.position.x);
                                cordY = mInstance.TransformCord(cordY, mInstance.transform.position.z);

                                transformedSize = mInstance.TransformCord(2, 0);

                                worldMap.UpdateHeight_RANGE(cordX, cordY, transformedSize, transformedSize, false);

                                worldMap.SetPixels32Delayed();
                            }
                        }
                    }
                }

                if (changed)
                {
                    FoliageCore_MainManager.SaveDelayedMaps();
                }

                terrainData.multiThreaded_terrainHeights = heights;
            }
        }
Esempio n. 10
0
        void VegetationCategory()
        {
            terrain.manageGrass = UNEditorUtility.DrawHelpBox("Vegetation Management", "Here you can manage your vegetation.", true, terrain.manageGrass);

            GUILayout.Space(5);

            terrain.updateGrassOnHeightsChange = EditorGUILayout.Toggle("Update Foliage On Height Change: ", terrain.updateGrassOnHeightsChange);

            GUILayout.Space(5);

            var style = GUI.skin.GetStyle("Box");

            GUILayout.BeginVertical(style, GUILayout.MaxWidth(200));

            GUILayout.Label(terrain.terrainData.backedUpTerrainData == null ? "No Backup Found." : "You have an backup available. \nUse it to revert your changes.", EditorStyles.boldLabel);

            GUILayout.Space(15);

            GUILayout.BeginHorizontal();

            if (terrain.terrainData.backedUpTerrainData == null)
            {
                if (GUILayout.Button("Create Backup", GUILayout.MaxWidth(100), GUILayout.MaxHeight(25)))
                {
                    terrain.terrainData.Backup();
                }
            }
            else
            {
                if (GUILayout.Button("Apply Backup", GUILayout.MaxWidth(100), GUILayout.MaxHeight(25)))
                {
                    terrain.terrainData.ApplyBackup(terrain.terrain);
                }

                if (GUILayout.Button("Delete Backup", GUILayout.MaxWidth(100), GUILayout.MaxHeight(25)))
                {
                    if (EditorUtility.DisplayDialog("uNature Backup", "Do you wish to delete the current backup?\nThat cannot be undone!", "Yes", "No"))
                    {
                        terrain.terrainData.DeleteBackup();
                    }
                }
            }

            GUILayout.EndHorizontal();

            GUILayout.EndVertical();

            GUILayout.Space(15);

            if (GUILayout.Button("Copy Foliage"))
            {
                if (FoliageCore_MainManager.instance != null)
                {
                    if (terrain.terrainData.backedUpTerrainData == null)
                    {
                        if (EditorUtility.DisplayDialog("uNature Backup", "It seems you have no backup created for the terrain data\nWould you want to create one?", "Yes", "No"))
                        {
                            terrain.terrainData.Backup();
                        }
                    }

                    FoliageCore_MainManager.instance.InsertFoliageFromTerrain(terrain.terrain);
                }
                else
                {
                    string message = "Cannot copy Foliage. FoliageManager can't be found.";

                    EditorUtility.DisplayDialog("uNature Error", message, "Ok");

                    return;
                }
            }
            if (GUILayout.Button("Remove Foliage From Terrain"))
            {
                int[,] newData = new int[terrain.terrainData.terrainData.detailWidth, terrain.terrainData.terrainData.detailHeight];

                for (int i = 0; i < terrain.terrainData.terrainData.detailPrototypes.Length; i++)
                {
                    terrain.terrainData.terrainData.SetDetailLayer(0, 0, i, newData);
                }
            }
        }