UnityEditor.NavMeshEditorHelpers.DrawAgentDiagram C# (CSharp) Method

DrawAgentDiagram() public static method

public static DrawAgentDiagram ( Rect rect, float agentRadius, float agentHeight, float agentClimb, float agentSlope ) : void
rect UnityEngine.Rect
agentRadius float
agentHeight float
agentClimb float
agentSlope float
return void
        public static void DrawAgentDiagram(Rect rect, float agentRadius, float agentHeight, float agentClimb, float agentSlope)
        {
            if (Event.current.type == EventType.Repaint)
            {
                float num = agentRadius;
                float b = agentHeight;
                float num3 = agentClimb;
                float num4 = 1f;
                float num5 = 0.35f;
                float num6 = 20f;
                float num7 = 10f;
                float num8 = rect.height - (num6 + num7);
                num4 = Mathf.Min((float) (num8 / (b + ((num * 2f) * num5))), (float) (num8 / (num * 2f)));
                b *= num4;
                num *= num4;
                num3 *= num4;
                float x = rect.xMin + (rect.width * 0.5f);
                float y = (rect.yMax - num7) - (num * num5);
                Vector3[] points = new Vector3[40];
                Vector3[] vectorArray2 = new Vector3[20];
                Vector3[] vectorArray3 = new Vector3[20];
                for (int i = 0; i < 20; i++)
                {
                    float f = (((float) i) / 19f) * 3.141593f;
                    float num13 = Mathf.Cos(f);
                    float num14 = Mathf.Sin(f);
                    points[i] = new Vector3(x + (num13 * num), (y - b) - ((num14 * num) * num5), 0f);
                    points[i + 20] = new Vector3(x - (num13 * num), y + ((num14 * num) * num5), 0f);
                    vectorArray2[i] = new Vector3(x - (num13 * num), (y - b) + ((num14 * num) * num5), 0f);
                    vectorArray3[i] = new Vector3(x - (num13 * num), (y - num3) + ((num14 * num) * num5), 0f);
                }
                Color color = Handles.color;
                float xMin = rect.xMin;
                float num16 = y - num3;
                float num17 = x - (num8 * 0.75f);
                float num18 = y;
                float num19 = x + (num8 * 0.75f);
                float num20 = y;
                float num21 = num19;
                float num22 = num20;
                float num23 = Mathf.Min(rect.xMax - num19, b);
                num21 += Mathf.Cos(agentSlope * 0.01745329f) * num23;
                num22 -= Mathf.Sin(agentSlope * 0.01745329f) * num23;
                Vector3[] vectorArray4 = new Vector3[] { new Vector3(xMin, y, 0f), new Vector3(num21, y, 0f) };
                Vector3[] vectorArray5 = new Vector3[] { new Vector3(xMin, num16, 0f), new Vector3(num17, num16, 0f), new Vector3(num17, num18, 0f), new Vector3(num19, num20, 0f), new Vector3(num21, num22, 0f) };
                Handles.color = !EditorGUIUtility.isProSkin ? new Color(1f, 1f, 1f, 0.5f) : new Color(0f, 0f, 0f, 0.5f);
                Handles.DrawAAPolyLine((float) 2f, vectorArray4);
                Handles.color = !EditorGUIUtility.isProSkin ? new Color(0f, 0f, 0f, 0.5f) : new Color(1f, 1f, 1f, 0.5f);
                Handles.DrawAAPolyLine((float) 3f, vectorArray5);
                Handles.color = Color.Lerp(new Color(0f, 0.75f, 1f, 1f), new Color(0.5f, 0.5f, 0.5f, 0.5f), 0.2f);
                Handles.DrawAAConvexPolygon(points);
                Handles.color = new Color(0f, 0f, 0f, 0.5f);
                Handles.DrawAAPolyLine((float) 2f, vectorArray3);
                Handles.color = new Color(1f, 1f, 1f, 0.4f);
                Handles.DrawAAPolyLine((float) 2f, vectorArray2);
                Vector3[] vectorArray6 = new Vector3[] { new Vector3(x, y - b, 0f), new Vector3(x + num, y - b, 0f) };
                Handles.color = new Color(0f, 0f, 0f, 0.5f);
                Handles.DrawAAPolyLine((float) 2f, vectorArray6);
                GUI.Label(new Rect((x + num) + 5f, (y - (b * 0.5f)) - 10f, 150f, 20f), string.Format("H = {0}", agentHeight));
                GUI.Label(new Rect(x, ((y - b) - (num * num5)) - 15f, 150f, 20f), string.Format("R = {0}", agentRadius));
                GUI.Label(new Rect(((xMin + num17) * 0.5f) - 20f, num16 - 15f, 150f, 20f), string.Format("{0}", agentClimb));
                GUI.Label(new Rect(num19 + 20f, num20 - 15f, 150f, 20f), string.Format("{0}\x00b0", agentSlope));
                Handles.color = color;
            }
        }
    }

Usage Example

        private void AgentSettings()
        {
            if (m_Agents == null)
            {
                InitAgents();
            }
            m_NavMeshProjectSettingsObject.Update();

            if (m_AgentsList.index < 0)
            {
                m_AgentsList.index = 0;
            }

            using (new GUILayout.VerticalScope(EditorStyles.defaultContentMargins))
            {
                m_AgentsList.DoLayoutList();
            }

            if (m_AgentsList.index >= 0 && m_AgentsList.index < m_Agents.arraySize)
            {
                SerializedProperty nameProp      = m_SettingNames.GetArrayElementAtIndex(m_AgentsList.index);
                SerializedProperty selectedAgent = m_Agents.GetArrayElementAtIndex(m_AgentsList.index);

                SerializedProperty radiusProp     = selectedAgent.FindPropertyRelative("agentRadius");
                SerializedProperty heightProp     = selectedAgent.FindPropertyRelative("agentHeight");
                SerializedProperty stepHeightProp = selectedAgent.FindPropertyRelative("agentClimb");
                SerializedProperty maxSlopeProp   = selectedAgent.FindPropertyRelative("agentSlope");

                const float kDiagramHeight   = 120.0f;
                Rect        agentDiagramRect = EditorGUILayout.GetControlRect(false, kDiagramHeight);
                NavMeshEditorHelpers.DrawAgentDiagram(agentDiagramRect, radiusProp.floatValue, heightProp.floatValue, stepHeightProp.floatValue, maxSlopeProp.floatValue);

                EditorGUILayout.PropertyField(nameProp, EditorGUIUtility.TempContent("Name"));
                EditorGUILayout.PropertyField(radiusProp, EditorGUIUtility.TempContent("Radius"));
                EditorGUILayout.PropertyField(heightProp, EditorGUIUtility.TempContent("Height"));
                EditorGUILayout.PropertyField(stepHeightProp, EditorGUIUtility.TempContent("Step Height"));

                const float kMaxSlopeAngle = 60.0f;
                EditorGUILayout.Slider(maxSlopeProp, 0.0f, kMaxSlopeAngle, EditorGUIUtility.TempContent("Max Slope"));
            }

            EditorGUILayout.Space();

            m_NavMeshProjectSettingsObject.ApplyModifiedProperties();
        }
All Usage Examples Of UnityEditor.NavMeshEditorHelpers::DrawAgentDiagram
NavMeshEditorHelpers