예제 #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);
                }
            }
        }
예제 #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);
                }
            }
        }
        public override void OnInspectorGUI()
        {
            if (Application.isPlaying)
            {
                EditorGUILayout.HelpBox("These settings cannot be edited in play mode.", MessageType.Info);
                return;
            }

            var lb = this.target as LoadBalancerComponent;

            foreach (var cfg in lb.configurations)
            {
                bool foldOut = false;
                _foldedOut.TryGetValue(cfg.targetLoadBalancer, out foldOut);
                _foldedOut[cfg.targetLoadBalancer] = EditorGUILayout.Foldout(foldOut, EditorUtilities.SplitToWords(cfg.targetLoadBalancer));
                if (_foldedOut[cfg.targetLoadBalancer])
                {
                    if (DrawConfigEditor(cfg))
                    {
                        EditorUtility.SetDirty(lb);
                    }
                }
            }

            EditorUtilities.Section("Marshaller");
            EditorGUILayout.PropertyField(_mashallerMaxMillisecondPerFrame, new GUIContent("Max Milliseconds Per Frame", "The maximum number of milliseconds per frame to allow for marshalling calls onto the main thread."));
        }
예제 #4
0
        private void OnGUI()
        {
            var rect = EditorGUILayout.BeginVertical(GUILayout.Width(400), GUILayout.Height(400));

            EditorGUIUtility.labelWidth = 200f;

            EditorGUILayout.HelpBox("This tool allows you to easily generate a grid field, that is a number of grids stitched together in order to cover a large scene", MessageType.Info);
            EditorGUILayout.Separator();

            EditorUtilities.Section("Field");

            _fieldSizeX      = EditorGUILayout.IntField(new GUIContent("Grids along x-axis", "Number of grids along the x-axis."), _fieldSizeX);
            _fieldSizeZ      = EditorGUILayout.IntField(new GUIContent("Grids along z-axis", "Number of grids along the x-axis."), _fieldSizeZ);
            _disableAutoInit = EditorGUILayout.Toggle(new GUIContent("Disable Automatic Initialization", "Sets the grid's automatic initialization setting to false."), _disableAutoInit);

            EditorGUILayout.Separator();
            _friendlyName = EditorGUILayout.TextField(new GUIContent("Grid Base Name", "An optional friendly name for the grids, each grid will also get a number post fix."), _friendlyName);

            EditorUtilities.Section("Layout");

            _sizeX = EditorGUILayout.IntField(new GUIContent("Size X", "Number of cells along the x-axis."), _sizeX);
            _sizeZ = EditorGUILayout.IntField(new GUIContent("Size Z", "Number of cells along the z-axis."), _sizeZ);

            _cellSize                 = EditorGUILayout.FloatField(new GUIContent("Cell Size", "The size of each grid cell, expressed as the length of one side."), _cellSize);
            _connectorPortalWidth     = EditorGUILayout.FloatField(new GUIContent("Connector Portal Width", "The width of the connector portals.\nIf left at 0 it will default to the cellSize, but if larger units need to be able to traverse a connector the width must be set accordingly."), _connectorPortalWidth);
            _lowerBoundary            = EditorGUILayout.FloatField(new GUIContent("Lower Boundary", "How far below the grid's plane does the grid have influence."), _lowerBoundary);
            _upperBoundary            = EditorGUILayout.FloatField(new GUIContent("Upper Boundary", "How far above the grid's plane does the grid have influence."), _upperBoundary);
            _obstacleSensitivityRange = EditorGUILayout.FloatField(new GUIContent("Obstacle Sensitivity Range", "How close to the center of a cell must an obstacle be to block the cell."), _obstacleSensitivityRange);

            if (_obstacleSensitivityRange > (_cellSize / 2.0f))
            {
                _obstacleSensitivityRange = _cellSize / 2.0f;
            }

            EditorUtilities.Section("Subsections");

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

            EditorGUI.indentLevel -= 1;
            EditorGUILayout.Separator();
            _generateHeightMap     = EditorGUILayout.Toggle(new GUIContent("Generate Height Map", "Controls whether the grid generates a height map to allow height sensitive navigation."), _generateHeightMap);
            EditorGUI.indentLevel += 1;

            if (_generateHeightMap)
            {
                _heightLookupType = (HeightLookupType)EditorGUILayout.EnumPopup(new GUIContent("Lookup Type", "Dictionaries are fast but dense. Quad Trees are sparse but slower and are very dependent on height distributions. Use Quad trees on maps with large same height areas."), _heightLookupType);
                if (_heightLookupType == HeightLookupType.QuadTree)
                {
                    _heightLookupMaxDepth = EditorGUILayout.IntField(new GUIContent("Tree Depth", "The higher the allowed depth, the more sparse the tree will be but it will also get slower."), _heightLookupMaxDepth);
                }
            }

            EditorGUILayout.Separator();
            if (GUILayout.Button("Create Grid Field"))
            {
                CreateGridField();

                this.Close();
            }

            EditorGUILayout.Separator();
            EditorGUIUtility.labelWidth = 0f;
            EditorGUILayout.EndVertical();
            this.minSize = new Vector2(rect.width, rect.height);
        }