Exemplo n.º 1
0
        private void Initialize(ICellMatrixConfiguration cfg)
        {
            _cellSize = cfg.cellSize;
            _origin   = cfg.origin;
            _start    = cfg.origin;
            _start.x -= this.columns * 0.5f * _cellSize;
            _start.z -= this.rows * 0.5f * _cellSize;

            _obstacleSensitivityRange   = cfg.obstacleSensitivityRange;
            _generateHeightMap          = cfg.generateHeightmap && (GameServices.heightStrategy.heightMode == HeightSamplingMode.HeightMap);
            _upperBoundary              = cfg.upperBoundary;
            _lowerBoundary              = cfg.lowerBoundary;
            _obstacleAndGroundDetection = cfg.obstacleAndGroundDetection;
            _obstacleAndGroundDetector  = cfg.obstacleAndGroundDetector;

            _granularity = GameServices.heightStrategy.sampleGranularity;

            if (_generateHeightMap)
            {
                _heightMapSizeX       = Mathf.RoundToInt(this.columns * this.cellSize / _granularity) + 1;
                _heightMapSizeZ       = Mathf.RoundToInt(this.rows * this.cellSize / _granularity) + 1;
                _heightLookupType     = cfg.heightLookupType;
                _heightLookupMaxDepth = cfg.heightLookupMaxDepth;
            }

            _bounds = cfg.bounds;

            _shortcutPortals = new List <PortalCell>();
        }
Exemplo n.º 2
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);
            _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");

            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);
        }
Exemplo n.º 3
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);
            _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");

            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);
        }