123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- using UnityEditor.IMGUI.Controls;
- using UnityEditorInternal;
- using UnityEngine.AI;
- using UnityEngine;
- namespace UnityEditor.AI
- {
- [CanEditMultipleObjects]
- [CustomEditor(typeof(NavMeshModifierVolume))]
- class NavMeshModifierVolumeEditor : Editor
- {
- SerializedProperty m_AffectedAgents;
- SerializedProperty m_Area;
- SerializedProperty m_Center;
- SerializedProperty m_Size;
- static Color s_HandleColor = new Color(187f, 138f, 240f, 210f) / 255;
- static Color s_HandleColorDisabled = new Color(187f * 0.75f, 138f * 0.75f, 240f * 0.75f, 100f) / 255;
- BoxBoundsHandle m_BoundsHandle = new BoxBoundsHandle();
- bool editingCollider
- {
- get { return EditMode.editMode == EditMode.SceneViewEditMode.Collider && EditMode.IsOwner(this); }
- }
- void OnEnable()
- {
- m_AffectedAgents = serializedObject.FindProperty("m_AffectedAgents");
- m_Area = serializedObject.FindProperty("m_Area");
- m_Center = serializedObject.FindProperty("m_Center");
- m_Size = serializedObject.FindProperty("m_Size");
- NavMeshVisualizationSettings.showNavigation++;
- }
- void OnDisable()
- {
- NavMeshVisualizationSettings.showNavigation--;
- }
- Bounds GetBounds()
- {
- var navModifier = (NavMeshModifierVolume)target;
- return new Bounds(navModifier.transform.position, navModifier.size);
- }
- public override void OnInspectorGUI()
- {
- serializedObject.Update();
- EditMode.DoEditModeInspectorModeButton(EditMode.SceneViewEditMode.Collider, "Edit Volume",
- EditorGUIUtility.IconContent("EditCollider"), GetBounds, this);
- EditorGUILayout.PropertyField(m_Size);
- EditorGUILayout.PropertyField(m_Center);
- NavMeshComponentsGUIUtility.AreaPopup("Area Type", m_Area);
- NavMeshComponentsGUIUtility.AgentMaskPopup("Affected Agents", m_AffectedAgents);
- EditorGUILayout.Space();
- serializedObject.ApplyModifiedProperties();
- }
- [DrawGizmo(GizmoType.Selected | GizmoType.Active)]
- static void RenderBoxGizmo(NavMeshModifierVolume navModifier, GizmoType gizmoType)
- {
- var color = navModifier.enabled ? s_HandleColor : s_HandleColorDisabled;
- var colorTrans = new Color(color.r * 0.75f, color.g * 0.75f, color.b * 0.75f, color.a * 0.15f);
- var oldColor = Gizmos.color;
- var oldMatrix = Gizmos.matrix;
- Gizmos.matrix = navModifier.transform.localToWorldMatrix;
- Gizmos.color = colorTrans;
- Gizmos.DrawCube(navModifier.center, navModifier.size);
- Gizmos.color = color;
- Gizmos.DrawWireCube(navModifier.center, navModifier.size);
- Gizmos.matrix = oldMatrix;
- Gizmos.color = oldColor;
- Gizmos.DrawIcon(navModifier.transform.position, "NavMeshModifierVolume Icon", true);
- }
- [DrawGizmo(GizmoType.NotInSelectionHierarchy | GizmoType.Pickable)]
- static void RenderBoxGizmoNotSelected(NavMeshModifierVolume navModifier, GizmoType gizmoType)
- {
- if (NavMeshVisualizationSettings.showNavigation > 0)
- {
- var color = navModifier.enabled ? s_HandleColor : s_HandleColorDisabled;
- var oldColor = Gizmos.color;
- var oldMatrix = Gizmos.matrix;
- Gizmos.matrix = navModifier.transform.localToWorldMatrix;
- Gizmos.color = color;
- Gizmos.DrawWireCube(navModifier.center, navModifier.size);
- Gizmos.matrix = oldMatrix;
- Gizmos.color = oldColor;
- }
- Gizmos.DrawIcon(navModifier.transform.position, "NavMeshModifierVolume Icon", true);
- }
- void OnSceneGUI()
- {
- if (!editingCollider)
- return;
- var vol = (NavMeshModifierVolume)target;
- var color = vol.enabled ? s_HandleColor : s_HandleColorDisabled;
- using (new Handles.DrawingScope(color, vol.transform.localToWorldMatrix))
- {
- m_BoundsHandle.center = vol.center;
- m_BoundsHandle.size = vol.size;
- EditorGUI.BeginChangeCheck();
- m_BoundsHandle.DrawHandle();
- if (EditorGUI.EndChangeCheck())
- {
- Undo.RecordObject(vol, "Modified NavMesh Modifier Volume");
- Vector3 center = m_BoundsHandle.center;
- Vector3 size = m_BoundsHandle.size;
- vol.center = center;
- vol.size = size;
- EditorUtility.SetDirty(target);
- }
- }
- }
- [MenuItem("GameObject/AI/NavMesh Modifier Volume", false, 2001)]
- static public void CreateNavMeshModifierVolume(MenuCommand menuCommand)
- {
- var parent = menuCommand.context as GameObject;
- var go = NavMeshComponentsGUIUtility.CreateAndSelectGameObject("NavMesh Modifier Volume", parent);
- go.AddComponent<NavMeshModifierVolume>();
- var view = SceneView.lastActiveSceneView;
- if (view != null)
- view.MoveToView(go.transform);
- }
- }
- }
|