Exemple #1
0
        /// <summary>
        /// This is called when the inspector gui should be run.
        /// </summary>
        public override void OnInspectorGUI()
        {
            GUI.changed = false;

            //get the grid
            SearchGrid grid = target as SearchGrid;

            if (grid)
            {
                //calc size limits and display slider
                float gridArea    = grid.transform.localScale.x * grid.transform.localScale.y * grid.transform.localScale.z;
                float minCellSize = Mathf.Pow(gridArea / (float)SearchGrid.mc_nApproxMaxCells, 1.0f / 3.0f);
                float maxCellSize = Mathf.Min(grid.transform.localScale.x, grid.transform.localScale.y, grid.transform.localScale.z);
                float newCellSize = EditorGUILayout.Slider("Cell Size", grid.desiredCellSize, minCellSize, maxCellSize);
                if (newCellSize != grid.desiredCellSize ||
                    SearchGrid.Instance != grid ||
                    GUI.changed ||
                    m_oLastPosition != grid.transform.position ||
                    m_oLastScale != grid.transform.localScale)
                {
                    grid.desiredCellSize = newCellSize;
                    grid.Start();
                    EditorUtility.SetDirty(target);
                }

                //display stats
                EditorGUILayout.LabelField("Grid Center:", grid.CenterWorldPoint.ToString("0.000"));
                EditorGUILayout.LabelField("Grid Size:", grid.WorldSize.ToString("0.000"));
                EditorGUILayout.LabelField("Cell Count:", grid.NumCells + " (" + grid.GridWidth + "x" + grid.GridHeight + "x" + grid.GridDepth + ")");
                EditorGUILayout.Separator();

                //display debug check boxes
                grid.enableDebug     = EditorGUILayout.BeginToggleGroup("Enable Debug", grid.enableDebug);
                grid.drawGridDebug   = EditorGUILayout.Toggle("Draw Grid", grid.drawGridDebug);
                grid.drawCellDebug   = EditorGUILayout.Toggle("Draw Cells", grid.drawCellDebug);
                grid.drawObjectDebug = EditorGUILayout.Toggle("Draw Objects", grid.drawObjectDebug);
                grid.drawSearchDebug = EditorGUILayout.Toggle("Draw Searches", grid.drawSearchDebug);
                grid.drawStatsDebug  = EditorGUILayout.Toggle("Draw Stats", grid.drawStatsDebug);
                EditorGUILayout.EndToggleGroup();

                m_oLastPosition = grid.transform.position;
                m_oLastScale    = grid.transform.localScale;
            }

            if (GUI.changed)
            {
                EditorUtility.SetDirty(target);
            }
        }