Beispiel #1
0
        private void BakeSettings()
        {
            EditorGUILayout.LabelField(s_Styles.m_AgentSizeHeader, EditorStyles.boldLabel, new GUILayoutOption[0]);
            Rect rect = EditorGUILayout.GetControlRect(false, 120f, new GUILayoutOption[0]);

            this.DrawAgentDiagram(rect, this.m_AgentRadius.floatValue, this.m_AgentHeight.floatValue, this.m_AgentClimb.floatValue, this.m_AgentSlope.floatValue);
            float num2 = EditorGUILayout.FloatField(s_Styles.m_AgentRadiusContent, this.m_AgentRadius.floatValue, new GUILayoutOption[0]);

            if ((num2 >= 0.001f) && !Mathf.Approximately(num2 - this.m_AgentRadius.floatValue, 0f))
            {
                this.m_AgentRadius.floatValue = num2;
                if (!this.m_ManualCellSize.boolValue)
                {
                    this.m_CellSize.floatValue = (2f * this.m_AgentRadius.floatValue) / 6f;
                }
            }
            if ((this.m_AgentRadius.floatValue < 0.05f) && !this.m_ManualCellSize.boolValue)
            {
                EditorGUILayout.HelpBox("The agent radius you've set is really small, this can slow down the build.\nIf you intended to allow the agent to move close to the borders and walls, please adjust voxel size in advaced settings to ensure correct bake.", MessageType.Warning);
            }
            float num3 = EditorGUILayout.FloatField(s_Styles.m_AgentHeightContent, this.m_AgentHeight.floatValue, new GUILayoutOption[0]);

            if ((num3 >= 0.001f) && !Mathf.Approximately(num3 - this.m_AgentHeight.floatValue, 0f))
            {
                this.m_AgentHeight.floatValue = num3;
            }
            EditorGUILayout.Slider(this.m_AgentSlope, 0f, 60f, s_Styles.m_AgentSlopeContent, new GUILayoutOption[0]);
            if (this.m_AgentSlope.floatValue > 60f)
            {
                EditorGUILayout.HelpBox("The maximum slope should be set to less than " + 60f + " degrees to prevent NavMesh build artifacts on slopes. ", MessageType.Warning);
            }
            float num5 = EditorGUILayout.FloatField(s_Styles.m_AgentClimbContent, this.m_AgentClimb.floatValue, new GUILayoutOption[0]);

            if ((num5 >= 0f) && !Mathf.Approximately(this.m_AgentClimb.floatValue - num5, 0f))
            {
                this.m_AgentClimb.floatValue = num5;
            }
            if (this.m_AgentClimb.floatValue > this.m_AgentHeight.floatValue)
            {
                EditorGUILayout.HelpBox("Step height should be less than agent height.\nClamping step height to " + this.m_AgentHeight.floatValue + " internally when baking.", MessageType.Warning);
            }
            float floatValue = this.m_CellSize.floatValue;
            float num7       = floatValue * 0.5f;
            int   num8       = (int)Mathf.Ceil(this.m_AgentClimb.floatValue / num7);
            float num9       = Mathf.Tan((this.m_AgentSlope.floatValue / 180f) * 3.141593f) * floatValue;
            int   num10      = (int)Mathf.Ceil((num9 * 2f) / num7);

            if (num10 > num8)
            {
                float f     = (num8 * num7) / (floatValue * 2f);
                float num12 = (Mathf.Atan(f) / 3.141593f) * 180f;
                float num13 = (num10 - 1) * num7;
                EditorGUILayout.HelpBox("Step Height conflicts with Max Slope. This makes some slopes unwalkable.\nConsider decreasing Max Slope to < " + num12.ToString("0.0") + " degrees.\nOr, increase Step Height to > " + num13.ToString("0.00") + ".", MessageType.Warning);
            }
            EditorGUILayout.Space();
            EditorGUILayout.LabelField(s_Styles.m_OffmeshHeader, EditorStyles.boldLabel, new GUILayoutOption[0]);
            float num14 = EditorGUILayout.FloatField(s_Styles.m_AgentDropContent, this.m_LedgeDropHeight.floatValue, new GUILayoutOption[0]);

            if ((num14 >= 0f) && !Mathf.Approximately(num14 - this.m_LedgeDropHeight.floatValue, 0f))
            {
                this.m_LedgeDropHeight.floatValue = num14;
            }
            float num15 = EditorGUILayout.FloatField(s_Styles.m_AgentJumpContent, this.m_MaxJumpAcrossDistance.floatValue, new GUILayoutOption[0]);

            if ((num15 >= 0f) && !Mathf.Approximately(num15 - this.m_MaxJumpAcrossDistance.floatValue, 0f))
            {
                this.m_MaxJumpAcrossDistance.floatValue = num15;
            }
            EditorGUILayout.Space();
            this.m_Advanced = GUILayout.Toggle(this.m_Advanced, s_Styles.m_AdvancedHeader, EditorStyles.foldout, new GUILayoutOption[0]);
            if (this.m_Advanced)
            {
                EditorGUI.indentLevel++;
                bool flag = EditorGUILayout.Toggle(s_Styles.m_ManualCellSizeContent, this.m_ManualCellSize.boolValue, new GUILayoutOption[0]);
                if (flag != this.m_ManualCellSize.boolValue)
                {
                    this.m_ManualCellSize.boolValue = flag;
                    if (!flag)
                    {
                        this.m_CellSize.floatValue = (2f * this.m_AgentRadius.floatValue) / 6f;
                    }
                }
                EditorGUI.BeginDisabledGroup(!this.m_ManualCellSize.boolValue);
                EditorGUI.indentLevel++;
                float num16 = EditorGUILayout.FloatField(s_Styles.m_CellSizeContent, this.m_CellSize.floatValue, new GUILayoutOption[0]);
                if ((num16 > 0f) && !Mathf.Approximately(num16 - this.m_CellSize.floatValue, 0f))
                {
                    this.m_CellSize.floatValue = Math.Max(0.01f, num16);
                }
                if (num16 < 0.01f)
                {
                    EditorGUILayout.HelpBox("The voxel size should be larger than 0.01.", MessageType.Warning);
                }
                float num17 = (this.m_CellSize.floatValue <= 0f) ? 0f : (this.m_AgentRadius.floatValue / this.m_CellSize.floatValue);
                EditorGUILayout.LabelField(" ", num17.ToString("0.00") + " voxels per agent radius", EditorStyles.miniLabel, new GUILayoutOption[0]);
                if (this.m_ManualCellSize.boolValue)
                {
                    float num19 = this.m_CellSize.floatValue * 0.5f;
                    if (((int)Mathf.Floor(this.m_AgentHeight.floatValue / num19)) > 250)
                    {
                        EditorGUILayout.HelpBox("The number of voxels per agent height is too high. This will reduce the accuracy of the navmesh. Consider using voxel size of at least " + (((this.m_AgentHeight.floatValue / 250f) / 0.5f)).ToString("0.000") + ".", MessageType.Warning);
                    }
                    if (num17 < 1f)
                    {
                        EditorGUILayout.HelpBox("The number of voxels per agent radius is too small. The agent may not avoid walls and ledges properly. Consider using voxel size of at least " + ((this.m_AgentRadius.floatValue / 2f)).ToString("0.000") + " (2 voxels per agent radius).", MessageType.Warning);
                    }
                    else if (num17 > 8f)
                    {
                        EditorGUILayout.HelpBox("The number of voxels per agent radius is too high. It can cause excessive build times. Consider using voxel size closer to " + ((this.m_AgentRadius.floatValue / 8f)).ToString("0.000") + " (8 voxels per radius).", MessageType.Warning);
                    }
                }
                if (this.m_ManualCellSize.boolValue)
                {
                    EditorGUILayout.HelpBox("Voxel size controls how accurately the navigation mesh is generated from the level geometry. A good voxel size is 2-4 voxels per agent radius. Making voxel size smaller will increase build time.", MessageType.None);
                }
                EditorGUI.indentLevel--;
                EditorGUI.EndDisabledGroup();
                EditorGUILayout.Space();
                float num23 = EditorGUILayout.FloatField(s_Styles.m_MinRegionAreaContent, this.m_MinRegionArea.floatValue, new GUILayoutOption[0]);
                if ((num23 >= 0f) && (num23 != this.m_MinRegionArea.floatValue))
                {
                    this.m_MinRegionArea.floatValue = num23;
                }
                EditorGUILayout.Space();
                bool flag2 = EditorGUILayout.Toggle(s_Styles.m_AgentPlacementContent, this.m_AccuratePlacement.boolValue, new GUILayoutOption[0]);
                if (flag2 != this.m_AccuratePlacement.boolValue)
                {
                    this.m_AccuratePlacement.boolValue = flag2;
                }
                EditorGUI.indentLevel--;
            }
            if (Unsupported.IsDeveloperBuild())
            {
                EditorGUILayout.Space();
                GUILayout.Label("Internal Bake Debug Options", EditorStyles.boldLabel, new GUILayoutOption[0]);
                EditorGUILayout.HelpBox("Note: The debug visualization is build during bake, so you'll need to bake for these settings to take effect.", MessageType.None);
                bool showAutoOffMeshLinkSampling = NavMeshVisualizationSettings.showAutoOffMeshLinkSampling;
                if (showAutoOffMeshLinkSampling != EditorGUILayout.Toggle(new GUIContent("Show Auto-Off-MeshLink Sampling"), showAutoOffMeshLinkSampling, new GUILayoutOption[0]))
                {
                    NavMeshVisualizationSettings.showAutoOffMeshLinkSampling = !showAutoOffMeshLinkSampling;
                }
                bool showVoxels = NavMeshVisualizationSettings.showVoxels;
                if (showVoxels != EditorGUILayout.Toggle(new GUIContent("Show Voxels"), showVoxels, new GUILayoutOption[0]))
                {
                    NavMeshVisualizationSettings.showVoxels = !showVoxels;
                }
                bool showWalkable = NavMeshVisualizationSettings.showWalkable;
                if (showWalkable != EditorGUILayout.Toggle(new GUIContent("Show Walkable"), showWalkable, new GUILayoutOption[0]))
                {
                    NavMeshVisualizationSettings.showWalkable = !showWalkable;
                }
                bool showRawContours = NavMeshVisualizationSettings.showRawContours;
                if (showRawContours != EditorGUILayout.Toggle(new GUIContent("Show Raw Contours"), showRawContours, new GUILayoutOption[0]))
                {
                    NavMeshVisualizationSettings.showRawContours = !showRawContours;
                }
                bool showContours = NavMeshVisualizationSettings.showContours;
                if (showContours != EditorGUILayout.Toggle(new GUIContent("Show Contours"), showContours, new GUILayoutOption[0]))
                {
                    NavMeshVisualizationSettings.showContours = !showContours;
                }
                bool showInputs = NavMeshVisualizationSettings.showInputs;
                if (showInputs != EditorGUILayout.Toggle(new GUIContent("Show Inputs"), showInputs, new GUILayoutOption[0]))
                {
                    NavMeshVisualizationSettings.showInputs = !showInputs;
                }
                if (GUILayout.Button("Clear Visualiation Data", new GUILayoutOption[0]))
                {
                    NavMeshVisualizationSettings.ClearVisualizationData();
                    RepaintSceneAndGameViews();
                }
                EditorGUILayout.Space();
            }
        }
Beispiel #2
0
        private void BakeSettings()
        {
            EditorGUILayout.LabelField(NavMeshEditorWindow.s_Styles.m_AgentSizeHeader, EditorStyles.boldLabel, new GUILayoutOption[0]);
            this.DrawAgentDiagram(EditorGUILayout.GetControlRect(false, 120f, new GUILayoutOption[0]), this.m_AgentRadius.floatValue, this.m_AgentHeight.floatValue, this.m_AgentClimb.floatValue, this.m_AgentSlope.floatValue);
            float num1 = EditorGUILayout.FloatField(NavMeshEditorWindow.s_Styles.m_AgentRadiusContent, this.m_AgentRadius.floatValue, new GUILayoutOption[0]);

            if ((double)num1 >= 1.0 / 1000.0 && !Mathf.Approximately(num1 - this.m_AgentRadius.floatValue, 0.0f))
            {
                this.m_AgentRadius.floatValue = num1;
                if (!this.m_ManualCellSize.boolValue)
                {
                    this.m_CellSize.floatValue = (float)(2.0 * (double)this.m_AgentRadius.floatValue / 6.0);
                }
            }
            if ((double)this.m_AgentRadius.floatValue < 0.0500000007450581 && !this.m_ManualCellSize.boolValue)
            {
                EditorGUILayout.HelpBox("The agent radius you've set is really small, this can slow down the build.\nIf you intended to allow the agent to move close to the borders and walls, please adjust voxel size in advaced settings to ensure correct bake.", MessageType.Warning);
            }
            float num2 = EditorGUILayout.FloatField(NavMeshEditorWindow.s_Styles.m_AgentHeightContent, this.m_AgentHeight.floatValue, new GUILayoutOption[0]);

            if ((double)num2 >= 1.0 / 1000.0 && !Mathf.Approximately(num2 - this.m_AgentHeight.floatValue, 0.0f))
            {
                this.m_AgentHeight.floatValue = num2;
            }
            EditorGUILayout.Slider(this.m_AgentSlope, 0.0f, 60f, NavMeshEditorWindow.s_Styles.m_AgentSlopeContent, new GUILayoutOption[0]);
            if ((double)this.m_AgentSlope.floatValue > 60.0)
            {
                EditorGUILayout.HelpBox("The maximum slope should be set to less than " + (object)60f + " degrees to prevent NavMesh build artifacts on slopes. ", MessageType.Warning);
            }
            float num3 = EditorGUILayout.FloatField(NavMeshEditorWindow.s_Styles.m_AgentClimbContent, this.m_AgentClimb.floatValue, new GUILayoutOption[0]);

            if ((double)num3 >= 0.0 && !Mathf.Approximately(this.m_AgentClimb.floatValue - num3, 0.0f))
            {
                this.m_AgentClimb.floatValue = num3;
            }
            if ((double)this.m_AgentClimb.floatValue > (double)this.m_AgentHeight.floatValue)
            {
                EditorGUILayout.HelpBox("Step height should be less than agent height.\nClamping step height to " + (object)this.m_AgentHeight.floatValue + " internally when baking.", MessageType.Warning);
            }
            float floatValue = this.m_CellSize.floatValue;
            float num4       = floatValue * 0.5f;
            int   num5       = (int)Mathf.Ceil(this.m_AgentClimb.floatValue / num4);
            int   num6       = (int)Mathf.Ceil(Mathf.Tan((float)((double)this.m_AgentSlope.floatValue / 180.0 * 3.14159274101257)) * floatValue * 2f / num4);

            if (num6 > num5)
            {
                EditorGUILayout.HelpBox("Step Height conflicts with Max Slope. This makes some slopes unwalkable.\nConsider decreasing Max Slope to < " + ((float)((double)Mathf.Atan((float)((double)num5 * (double)num4 / ((double)floatValue * 2.0))) / 3.14159274101257 * 180.0)).ToString("0.0") + " degrees.\nOr, increase Step Height to > " + ((float)(num6 - 1) * num4).ToString("0.00") + ".", MessageType.Warning);
            }
            EditorGUILayout.Space();
            EditorGUILayout.LabelField(NavMeshEditorWindow.s_Styles.m_OffmeshHeader, EditorStyles.boldLabel, new GUILayoutOption[0]);
            float num7 = EditorGUILayout.FloatField(NavMeshEditorWindow.s_Styles.m_AgentDropContent, this.m_LedgeDropHeight.floatValue, new GUILayoutOption[0]);

            if ((double)num7 >= 0.0 && !Mathf.Approximately(num7 - this.m_LedgeDropHeight.floatValue, 0.0f))
            {
                this.m_LedgeDropHeight.floatValue = num7;
            }
            float num8 = EditorGUILayout.FloatField(NavMeshEditorWindow.s_Styles.m_AgentJumpContent, this.m_MaxJumpAcrossDistance.floatValue, new GUILayoutOption[0]);

            if ((double)num8 >= 0.0 && !Mathf.Approximately(num8 - this.m_MaxJumpAcrossDistance.floatValue, 0.0f))
            {
                this.m_MaxJumpAcrossDistance.floatValue = num8;
            }
            EditorGUILayout.Space();
            this.m_Advanced = GUILayout.Toggle(this.m_Advanced, NavMeshEditorWindow.s_Styles.m_AdvancedHeader, EditorStyles.foldout, new GUILayoutOption[0]);
            if (this.m_Advanced)
            {
                ++EditorGUI.indentLevel;
                bool flag1 = EditorGUILayout.Toggle(NavMeshEditorWindow.s_Styles.m_ManualCellSizeContent, this.m_ManualCellSize.boolValue, new GUILayoutOption[0]);
                if (flag1 != this.m_ManualCellSize.boolValue)
                {
                    this.m_ManualCellSize.boolValue = flag1;
                    if (!flag1)
                    {
                        this.m_CellSize.floatValue = (float)(2.0 * (double)this.m_AgentRadius.floatValue / 6.0);
                    }
                }
                EditorGUI.BeginDisabledGroup(!this.m_ManualCellSize.boolValue);
                ++EditorGUI.indentLevel;
                float val2 = EditorGUILayout.FloatField(NavMeshEditorWindow.s_Styles.m_CellSizeContent, this.m_CellSize.floatValue, new GUILayoutOption[0]);
                if ((double)val2 > 0.0 && !Mathf.Approximately(val2 - this.m_CellSize.floatValue, 0.0f))
                {
                    this.m_CellSize.floatValue = Math.Max(0.01f, val2);
                }
                if ((double)val2 < 0.00999999977648258)
                {
                    EditorGUILayout.HelpBox("The voxel size should be larger than 0.01.", MessageType.Warning);
                }
                float num9 = (double)this.m_CellSize.floatValue <= 0.0 ? 0.0f : this.m_AgentRadius.floatValue / this.m_CellSize.floatValue;
                EditorGUILayout.LabelField(" ", num9.ToString("0.00") + " voxels per agent radius", EditorStyles.miniLabel, new GUILayoutOption[0]);
                if (this.m_ManualCellSize.boolValue)
                {
                    if ((int)Mathf.Floor(this.m_AgentHeight.floatValue / (this.m_CellSize.floatValue * 0.5f)) > 250)
                    {
                        EditorGUILayout.HelpBox("The number of voxels per agent height is too high. This will reduce the accuracy of the navmesh. Consider using voxel size of at least " + ((float)((double)this.m_AgentHeight.floatValue / 250.0 / 0.5)).ToString("0.000") + ".", MessageType.Warning);
                    }
                    if ((double)num9 < 1.0)
                    {
                        EditorGUILayout.HelpBox("The number of voxels per agent radius is too small. The agent may not avoid walls and ledges properly. Consider using voxel size of at least " + (this.m_AgentRadius.floatValue / 2f).ToString("0.000") + " (2 voxels per agent radius).", MessageType.Warning);
                    }
                    else if ((double)num9 > 8.0)
                    {
                        EditorGUILayout.HelpBox("The number of voxels per agent radius is too high. It can cause excessive build times. Consider using voxel size closer to " + (this.m_AgentRadius.floatValue / 8f).ToString("0.000") + " (8 voxels per radius).", MessageType.Warning);
                    }
                }
                if (this.m_ManualCellSize.boolValue)
                {
                    EditorGUILayout.HelpBox("Voxel size controls how accurately the navigation mesh is generated from the level geometry. A good voxel size is 2-4 voxels per agent radius. Making voxel size smaller will increase build time.", MessageType.None);
                }
                --EditorGUI.indentLevel;
                EditorGUI.EndDisabledGroup();
                EditorGUILayout.Space();
                float num10 = EditorGUILayout.FloatField(NavMeshEditorWindow.s_Styles.m_MinRegionAreaContent, this.m_MinRegionArea.floatValue, new GUILayoutOption[0]);
                if ((double)num10 >= 0.0 && (double)num10 != (double)this.m_MinRegionArea.floatValue)
                {
                    this.m_MinRegionArea.floatValue = num10;
                }
                EditorGUILayout.Space();
                bool flag2 = EditorGUILayout.Toggle(NavMeshEditorWindow.s_Styles.m_AgentPlacementContent, this.m_AccuratePlacement.boolValue, new GUILayoutOption[0]);
                if (flag2 != this.m_AccuratePlacement.boolValue)
                {
                    this.m_AccuratePlacement.boolValue = flag2;
                }
                --EditorGUI.indentLevel;
            }
            if (!Unsupported.IsDeveloperBuild())
            {
                return;
            }
            EditorGUILayout.Space();
            GUILayout.Label("Internal Bake Debug Options", EditorStyles.boldLabel, new GUILayoutOption[0]);
            EditorGUILayout.HelpBox("Note: The debug visualization is build during bake, so you'll need to bake for these settings to take effect.", MessageType.None);
            bool meshLinkSampling = NavMeshVisualizationSettings.showAutoOffMeshLinkSampling;

            if (meshLinkSampling != EditorGUILayout.Toggle(new GUIContent("Show Auto-Off-MeshLink Sampling"), meshLinkSampling, new GUILayoutOption[0]))
            {
                NavMeshVisualizationSettings.showAutoOffMeshLinkSampling = !meshLinkSampling;
            }
            bool showVoxels = NavMeshVisualizationSettings.showVoxels;

            if (showVoxels != EditorGUILayout.Toggle(new GUIContent("Show Voxels"), showVoxels, new GUILayoutOption[0]))
            {
                NavMeshVisualizationSettings.showVoxels = !showVoxels;
            }
            bool showWalkable = NavMeshVisualizationSettings.showWalkable;

            if (showWalkable != EditorGUILayout.Toggle(new GUIContent("Show Walkable"), showWalkable, new GUILayoutOption[0]))
            {
                NavMeshVisualizationSettings.showWalkable = !showWalkable;
            }
            bool showRawContours = NavMeshVisualizationSettings.showRawContours;

            if (showRawContours != EditorGUILayout.Toggle(new GUIContent("Show Raw Contours"), showRawContours, new GUILayoutOption[0]))
            {
                NavMeshVisualizationSettings.showRawContours = !showRawContours;
            }
            bool showContours = NavMeshVisualizationSettings.showContours;

            if (showContours != EditorGUILayout.Toggle(new GUIContent("Show Contours"), showContours, new GUILayoutOption[0]))
            {
                NavMeshVisualizationSettings.showContours = !showContours;
            }
            bool showInputs = NavMeshVisualizationSettings.showInputs;

            if (showInputs != EditorGUILayout.Toggle(new GUIContent("Show Inputs"), showInputs, new GUILayoutOption[0]))
            {
                NavMeshVisualizationSettings.showInputs = !showInputs;
            }
            if (GUILayout.Button("Clear Visualiation Data"))
            {
                NavMeshVisualizationSettings.ClearVisualizationData();
                NavMeshEditorWindow.RepaintSceneAndGameViews();
            }
            EditorGUILayout.Space();
        }