Esempio n. 1
0
        public override void OnInspectorGUI()
        {
            if (Application.isPlaying)
            {
                EditorGUILayout.HelpBox("These settings cannot be edited in play mode.", MessageType.Info);
                return;
            }

            this.serializedObject.Update();

            int baked         = 0;
            var editedObjects = this.serializedObject.targetObjects;

            for (int i = 0; i < editedObjects.Length; i++)
            {
                var g = editedObjects[i] as GridComponent;
                if (g.bakedData != null)
                {
                    baked++;
                }
            }

            EditorGUILayout.Separator();

            if (baked > 0 && baked < editedObjects.Length)
            {
                EditorGUILayout.LabelField("A mix of baked and unbaked grids cannot be edited at the same time.");
                return;
            }

            //If data is baked, only offer an option to edit or rebake
            if (baked == editedObjects.Length)
            {
                EditorGUILayout.LabelField("The grid has been baked. To change it press the Edit button below.");

                GUILayout.BeginHorizontal();

                if (GUILayout.Button("Edit"))
                {
                    foreach (var o in editedObjects)
                    {
                        var g = o as GridComponent;
                        EditorUtilities.RemoveAsset(g.bakedData);
                        g.bakedData = null;
                        g.ResetGrid();
                        EditorUtility.SetDirty(g);
                    }
                }

                if (GUILayout.Button("Re-bake Grid"))
                {
                    foreach (var o in editedObjects)
                    {
                        var g = o as GridComponent;
                        BakeGrid(g);
                    }
                }

                GUILayout.EndHorizontal();
                return;
            }

            EditorGUILayout.PropertyField(_friendlyName);

            EditorUtilities.Section("Layout");

            EditorGUILayout.PropertyField(_linkOriginToTransform);

            if (!_linkOriginToTransform.hasMultipleDifferentValues)
            {
                if (_linkOriginToTransform.boolValue)
                {
                    EditorGUI.indentLevel++;
                    EditorGUILayout.PropertyField(_originOffset, true);
                    EditorGUI.indentLevel--;
                }
                else
                {
                    EditorGUILayout.PropertyField(_origin, true);
                }
            }

            EditorGUILayout.PropertyField(_sizeX);
            EditorGUILayout.PropertyField(_sizeZ);
            EditorGUILayout.PropertyField(_cellSize);
            EditorGUILayout.PropertyField(_lowerBoundary);
            EditorGUILayout.PropertyField(_upperBoundary);
            EditorGUILayout.PropertyField(_obstacleSensitivityRange);
            EditorGUILayout.PropertyField(_obstacleAndGroundDetection);

            EditorUtilities.Section("Subsections");

            EditorGUILayout.PropertyField(_subSectionsX);
            EditorGUILayout.PropertyField(_subSectionsZ);
            EditorGUILayout.PropertyField(_subSectionsCellOverlap);

            ShowHeightMapOptions();

            EditorUtilities.Section("Initialization");
            EditorGUILayout.PropertyField(_automaticInitialization);
            EditorGUILayout.PropertyField(_automaticConnections);

            EditorGUILayout.Separator();
            EditorGUILayout.PropertyField(_storeBakedDataAsAsset);

            this.serializedObject.ApplyModifiedProperties();

            if (GUILayout.Button(new GUIContent("Bake Grid", "Calculates grid data such as blocked areas and height map and stores this snapshot. The snapshot is then used to initialize the grid at runtime.\nPlease note that baking is completely optional.")))
            {
                foreach (var o in editedObjects)
                {
                    var g = o as GridComponent;
                    BakeGrid(g);
                }
            }
        }
Esempio n. 2
0
        public override void OnInspectorGUI()
        {
            if (Application.isPlaying)
            {
                EditorGUILayout.HelpBox("These settings cannot be edited in play mode.", MessageType.Info);
                return;
            }

            this.serializedObject.Update();

            int baked         = 0;
            var editedObjects = this.serializedObject.targetObjects;

            for (int i = 0; i < editedObjects.Length; i++)
            {
                var g = editedObjects[i] as GridComponent;
                if (g.bakedData != null)
                {
                    baked++;
                }
            }

            EditorGUILayout.Separator();

            if (baked > 0 && baked < editedObjects.Length)
            {
                EditorGUILayout.LabelField("A mix of baked and unbaked grids cannot be edited at the same time.");
                return;
            }

            //If data is baked, only offer an option to edit or rebake
            if (baked == editedObjects.Length)
            {
                EditorGUILayout.LabelField("The grid has been baked. To change it press the Edit button below.");

                GUILayout.BeginHorizontal();

                if (GUILayout.Button("Edit"))
                {
                    foreach (var o in editedObjects)
                    {
                        var g = o as GridComponent;
                        EditorUtilities.RemoveAsset(g.bakedData);
                        g.bakedData = null;
                        g.ResetGrid();
                        EditorUtility.SetDirty(g);
                    }
                }

                if (GUILayout.Button("Re-bake Grid"))
                {
                    foreach (var o in editedObjects)
                    {
                        var g = o as GridComponent;
                        BakeGrid(g);
                    }
                }

                GUILayout.EndHorizontal();
                return;
            }

            EditorGUILayout.PropertyField(_friendlyName, new GUIContent("Friendly Name", "An optional friendly name for the grid that will be used in messages and such."));

            EditorUtilities.Section("Layout");

            EditorGUILayout.PropertyField(_linkOriginToTransform, new GUIContent("Link Origin to Transform", "Link the center of the grid to the position of the game object."));

            if (!_linkOriginToTransform.hasMultipleDifferentValues)
            {
                if (_linkOriginToTransform.boolValue)
                {
                    EditorGUI.indentLevel++;
                    EditorGUILayout.PropertyField(_originOffset, new GUIContent("Offset", "The offset in relation to the linked transform."), true);
                    EditorGUI.indentLevel--;
                }
                else
                {
                    EditorGUILayout.PropertyField(_origin, new GUIContent("Origin", "The center of the grid."), true);
                }
            }

            EditorGUILayout.PropertyField(_sizeX, new GUIContent("Size X", "Number of cells along the x-axis."));
            EditorGUILayout.PropertyField(_sizeZ, new GUIContent("Size Z", "Number of cells along the z-axis."));
            EditorGUILayout.PropertyField(_cellSize, new GUIContent("Cell Size", "The size of each grid cell, expressed as the length of one side."));
            EditorGUILayout.PropertyField(_lowerBoundary, new GUIContent("Lower Boundary", "How far below the grid's plane does the grid have influence."));
            EditorGUILayout.PropertyField(_upperBoundary, new GUIContent("Upper Boundary", "How far above the grid's plane does the grid have influence."));
            EditorGUILayout.PropertyField(_obstacleSensitivityRange, new GUIContent("Obstacle Sensitivity Range", "How close to the center of a cell must an obstacle be to block the cell."));
            EditorGUILayout.PropertyField(_obstacleAndGroundDetection, new GUIContent("Obstacle and Ground Detection", "Controls the method used to detect terrain and obstacles. Choose whichever works for your type of terrain."));

            EditorUtilities.Section("Subsections");

            EditorGUILayout.PropertyField(_subSectionsX, new GUIContent("Subsections X", "Number of subsections along the x-axis."));
            EditorGUILayout.PropertyField(_subSectionsZ, new GUIContent("Subsections Z", "Number of subsections along the z-axis."));
            EditorGUILayout.PropertyField(_subSectionsCellOverlap, new GUIContent("Subsections Cell Overlap", "The number of cells by which subsections overlap neighbouring subsections."));

            ShowHeightMapOptions();

            EditorUtilities.Section("Initialization");
            EditorGUILayout.PropertyField(_automaticInitialization, new GUIContent("Automatic Initialization", "Controls whether the grid is automatically initialized when enabled. If unchecked the grid must be manually initialized."));

            EditorGUILayout.Separator();
            EditorGUILayout.PropertyField(_storeBakedDataAsAsset, new GUIContent("Store Grid data as asset", "Store baked data in a separate asset file instead of storing to the scene, this enables prefab'ing."));

            this.serializedObject.ApplyModifiedProperties();

            if (GUILayout.Button("Bake Grid"))
            {
                foreach (var o in editedObjects)
                {
                    var g = o as GridComponent;
                    BakeGrid(g);
                }
            }
        }