コード例 #1
0
        private void DrawGeometryGUI()
        {
            string label = "Geometry";
            string id    = "geometry" + data.Id;

            bool deferredUpdate = EditorPrefs.GetBool(GEditorCommon.GetProjectRelatedEditorPrefsKey(DEFERRED_UPDATE_KEY), false);

            GenericMenu menu = new GenericMenu();

            menu.AddItem(
                new GUIContent("Reset"),
                false,
                () => { ConfirmAndResetGeometry(); });
            menu.AddItem(
                new GUIContent("Update"),
                false,
                () => { data.Geometry.SetRegionDirty(GCommon.UnitRect); data.SetDirty(GTerrainData.DirtyFlags.Geometry); });
            menu.AddItem(
                new GUIContent("Match Edges"),
                false,
                () => { terrain.MatchEdges(); });
            menu.AddItem(
                new GUIContent("Clean Up"),
                false,
                () => { data.Geometry.CleanUp(); });

            if (geometryAdditionalContextAction != null && geometryAdditionalContextAction.Count > 0)
            {
                menu.AddSeparator(null);
                for (int i = 0; i < geometryAdditionalContextAction.Count; ++i)
                {
                    GGenericMenuItem item = geometryAdditionalContextAction[i];
                    menu.AddItem(
                        new GUIContent(item.Name),
                        item.IsOn,
                        item.Action);
                }
            }

            menu.AddSeparator(null);
            menu.AddItem(
                new GUIContent("Toggle Deferred Update"),
                deferredUpdate,
                () =>
            {
                deferredUpdate = !deferredUpdate;
                EditorPrefs.SetBool(GEditorCommon.GetProjectRelatedEditorPrefsKey(DEFERRED_UPDATE_KEY), deferredUpdate);
            });
            menu.AddSeparator(null);
            menu.AddItem(
                new GUIContent("Advanced/Remove Height Map"),
                false,
                () => { ConfirmAndRemoveHeightMap(); });
            List <string> warnings = new List <string>();

            if (terrain != null &&
                terrain.geometryVersion < GStylizedTerrain.GEOMETRY_VERSION_CHUNK_POSITION_AT_CHUNK_CENTER)
            {
                warnings.Add("- Chunk position placement has been changed for better level streaming and baking. Go to CONTEXT>Update to re-generate the terrain.");
            }

#if !GRIFFIN_BURST
            warnings.Add("- Install Burst Compiler (com.unity.burst) to speed up generation.");
#endif
#if !GRIFFIN_EDITOR_COROUTINES
            if (data.Geometry.AllowTimeSlicedGeneration == true)
            {
                warnings.Add("- Install Editor Coroutines (com.unity.editorcoroutines) to enable time-sliced generation in editor.");
            }
#endif

            string headerWarning = GUtilities.ListElementsToString(warnings, "\n");

            GEditorCommon.Foldout(label, false, id, () =>
            {
                GGeometry settings = data.Geometry;
                EditorGUI.BeginChangeCheck();

                GEditorCommon.Header("Dimension");
                settings.Width  = EditorGUILayout.DelayedFloatField("Width", settings.Width);
                settings.Height = EditorGUILayout.DelayedFloatField("Height", settings.Height);
                settings.Length = EditorGUILayout.DelayedFloatField("Length", settings.Length);

                GEditorCommon.Header("Height Map");
                settings.HeightMapResolution = EditorGUILayout.DelayedIntField("Height Map Resolution", settings.HeightMapResolution);

                GEditorCommon.Header("Mesh Generation");
                settings.MeshBaseResolution      = EditorGUILayout.DelayedIntField("Mesh Base Resolution", settings.MeshBaseResolution);
                settings.MeshResolution          = EditorGUILayout.DelayedIntField("Mesh Resolution", settings.MeshResolution);
                settings.ChunkGridSize           = EditorGUILayout.DelayedIntField("Grid Size", settings.ChunkGridSize);
                settings.LODCount                = EditorGUILayout.DelayedIntField("LOD Count", settings.LODCount);
                settings.DisplacementSeed        = EditorGUILayout.DelayedIntField("Displacement Seed", settings.DisplacementSeed);
                settings.DisplacementStrength    = EditorGUILayout.DelayedFloatField("Displacement Strength", settings.DisplacementStrength);
                settings.AlbedoToVertexColorMode = (GAlbedoToVertexColorMode)EditorGUILayout.EnumPopup("Albedo To Vertex Color", settings.AlbedoToVertexColorMode);
                settings.SmoothNormal            = EditorGUILayout.Toggle("Smooth Normal", settings.SmoothNormal);
                if (settings.SmoothNormal)
                {
                    settings.UseSmoothNormalMask = EditorGUILayout.Toggle("Smooth Normal Use Mask (G)", settings.UseSmoothNormalMask);
                }
                GEditorCommon.Header("Utilities");
                settings.StorageMode = (GGeometry.GStorageMode)EditorGUILayout.EnumPopup("Storage", settings.StorageMode);
                settings.AllowTimeSlicedGeneration = EditorGUILayout.Toggle("Time Sliced", settings.AllowTimeSlicedGeneration);

                if (EditorGUI.EndChangeCheck() && !deferredUpdate)
                {
                    data.Geometry.SetRegionDirty(new Rect(0, 0, 1, 1));
                    data.SetDirty(GTerrainData.DirtyFlags.GeometryTimeSliced);
                }

                if (deferredUpdate)
                {
                    GEditorCommon.Separator();
                    if (GUILayout.Button("Update Immediately"))
                    {
                        data.Geometry.SetRegionDirty(new Rect(0, 0, 1, 1));
                        data.SetDirty(GTerrainData.DirtyFlags.GeometryTimeSliced);
                    }
                }
            },
                                  menu,
                                  headerWarning.ToString());
        }
コード例 #2
0
        private void DrawGeometryGUI()
        {
            bool   isGenerating = terrain != null && terrain.Internal_IsGeneratingInBackground;
            string label        = "Geometry" + (isGenerating ? " (Working)" : "");
            string id           = "geometry" + data.Id;

            bool deferredUpdate = EditorPrefs.GetBool(GEditorCommon.GetProjectRelatedEditorPrefsKey(DEFERRED_UPDATE_KEY), false);

            GenericMenu menu = new GenericMenu();

            menu.AddItem(
                new GUIContent("Reset"),
                false,
                () => { ConfirmAndResetGeometry(); });
            menu.AddItem(
                new GUIContent("Update"),
                false,
                () => { data.Geometry.SetRegionDirty(GCommon.UnitRect); data.SetDirty(GTerrainData.DirtyFlags.GeometryAsync); });
            menu.AddItem(
                new GUIContent("Clean Up"),
                false,
                () => { data.Geometry.CleanUp(); });

            if (geometryAdditionalContextAction != null && geometryAdditionalContextAction.Count > 0)
            {
                menu.AddSeparator(null);
                for (int i = 0; i < geometryAdditionalContextAction.Count; ++i)
                {
                    GGenericMenuItem item = geometryAdditionalContextAction[i];
                    menu.AddItem(
                        new GUIContent(item.Name),
                        item.IsOn,
                        item.Action);
                }
            }

            menu.AddSeparator(null);
            menu.AddItem(
                new GUIContent("Toggle Deferred Update"),
                deferredUpdate,
                () =>
            {
                deferredUpdate = !deferredUpdate;
                EditorPrefs.SetBool(GEditorCommon.GetProjectRelatedEditorPrefsKey(DEFERRED_UPDATE_KEY), deferredUpdate);
            });

            string headerWarning = null;

            if (terrain != null &&
                terrain.geometryVersion < GStylizedTerrain.GEOMETRY_VERSION_CHUNK_POSITION_AT_CHUNK_CENTER)
            {
                headerWarning = "Chunk position placement has been changed for better level streaming and baking. Go to CONTEXT>Update to re-generate the terrain.";
            }

            GEditorCommon.Foldout(label, false, id, () =>
            {
                GGeometry settings = data.Geometry;
                EditorGUI.BeginChangeCheck();

                GUI.enabled = !isGenerating;
                EditorGUILayout.LabelField("Use with cause, takes time to process.", GEditorCommon.WordWrapItalicLabel);
                settings.Width  = EditorGUILayout.DelayedFloatField("Width", settings.Width);
                settings.Height = EditorGUILayout.DelayedFloatField("Height", settings.Height);
                settings.Length = EditorGUILayout.DelayedFloatField("Length", settings.Length);
                settings.HeightMapResolution = EditorGUILayout.DelayedIntField("Height Map Resolution", settings.HeightMapResolution);
                if (settings.PolygonDistribution == GPolygonDistributionMode.Dynamic)
                {
                    settings.MeshBaseResolution = EditorGUILayout.DelayedIntField("Mesh Base Resolution", settings.MeshBaseResolution);
                }
                settings.MeshResolution       = EditorGUILayout.DelayedIntField("Mesh Resolution", settings.MeshResolution);
                settings.ChunkGridSize        = EditorGUILayout.DelayedIntField("Grid Size", settings.ChunkGridSize);
                settings.LODCount             = EditorGUILayout.DelayedIntField("LOD Count", settings.LODCount);
                settings.DisplacementSeed     = EditorGUILayout.DelayedIntField("Displacement Seed", settings.DisplacementSeed);
                settings.DisplacementStrength = EditorGUILayout.DelayedFloatField("Displacement Strength", settings.DisplacementStrength);
                settings.PolygonDistribution  = (GPolygonDistributionMode)EditorGUILayout.EnumPopup("Polygon Distribution", settings.PolygonDistribution);
                try
                {
                    settings.PolygonProcessorName = GEditorCommon.PolygonProcessorSelector("Polygon Processor", settings.PolygonProcessorName);
                }
                catch (System.Exception e)
                {
                    Debug.LogError(e);
                    settings.PolygonProcessorName = null;
                }

                if (EditorGUI.EndChangeCheck() && !deferredUpdate)
                {
                    data.Geometry.SetRegionDirty(new Rect(0, 0, 1, 1));
                    data.SetDirty(GTerrainData.DirtyFlags.GeometryAsync);
                }

                if (deferredUpdate)
                {
                    GEditorCommon.Separator();
                    if (GUILayout.Button("Update"))
                    {
                        data.Geometry.SetRegionDirty(new Rect(0, 0, 1, 1));
                        data.SetDirty(GTerrainData.DirtyFlags.GeometryAsync);
                    }
                }
                GUI.enabled = true;
            },
                                  menu,
                                  headerWarning);
        }