Use "BoundsHandle" for sceneview manipulation of volumes.
This commit is contained in:
Родитель
c85768be5c
Коммит
b2b29937de
|
@ -1,5 +1,7 @@
|
|||
using UnityEngine;
|
||||
using UnityEditor.IMGUI.Controls;
|
||||
using UnityEditorInternal;
|
||||
using UnityEngine.AI;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityEditor.AI
|
||||
{
|
||||
|
@ -15,6 +17,14 @@ namespace UnityEditor.AI
|
|||
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;
|
||||
|
||||
static int s_HandleControlIDHint = typeof(NavMeshModifierVolumeEditor).Name.GetHashCode();
|
||||
BoxBoundsHandle m_BoundsHandle = new BoxBoundsHandle(s_HandleControlIDHint);
|
||||
|
||||
bool editingCollider
|
||||
{
|
||||
get { return EditMode.editMode == EditMode.SceneViewEditMode.Collider && EditMode.IsOwner(this); }
|
||||
}
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
m_AffectedAgents = serializedObject.FindProperty("m_AffectedAgents");
|
||||
|
@ -34,6 +44,8 @@ namespace UnityEditor.AI
|
|||
{
|
||||
serializedObject.Update();
|
||||
|
||||
InspectorEditButtonGUI();
|
||||
|
||||
EditorGUILayout.PropertyField(m_Size);
|
||||
EditorGUILayout.PropertyField(m_Center);
|
||||
|
||||
|
@ -47,9 +59,7 @@ namespace UnityEditor.AI
|
|||
[DrawGizmo(GizmoType.Selected | GizmoType.Active)]
|
||||
static void RenderBoxGizmo(NavMeshModifierVolume navModifier, GizmoType gizmoType)
|
||||
{
|
||||
var color = s_HandleColor;
|
||||
if (!navModifier.enabled)
|
||||
color = s_HandleColorDisabled;
|
||||
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;
|
||||
|
@ -74,10 +84,7 @@ namespace UnityEditor.AI
|
|||
{
|
||||
if (NavMeshVisualizationSettings.showNavigation > 0)
|
||||
{
|
||||
var color = s_HandleColor;
|
||||
if (!navModifier.enabled)
|
||||
color = s_HandleColorDisabled;
|
||||
|
||||
var color = navModifier.enabled ? s_HandleColor : s_HandleColorDisabled;
|
||||
var oldColor = Gizmos.color;
|
||||
var oldMatrix = Gizmos.matrix;
|
||||
|
||||
|
@ -93,6 +100,47 @@ namespace UnityEditor.AI
|
|||
Gizmos.DrawIcon(navModifier.transform.position, "NavMeshModifierVolume Icon", true);
|
||||
}
|
||||
|
||||
void InspectorEditButtonGUI()
|
||||
{
|
||||
var navModifier = (NavMeshModifierVolume)target;
|
||||
var bounds = new Bounds(navModifier.transform.position, navModifier.size);
|
||||
|
||||
EditMode.DoEditModeInspectorModeButton(
|
||||
EditMode.SceneViewEditMode.Collider,
|
||||
"Edit Volume",
|
||||
EditorGUIUtility.IconContent("EditCollider"),
|
||||
bounds,
|
||||
this
|
||||
);
|
||||
}
|
||||
|
||||
void OnSceneGUI()
|
||||
{
|
||||
if (!editingCollider)
|
||||
return;
|
||||
|
||||
var vol = (NavMeshModifierVolume)target;
|
||||
using (new Handles.MatrixScope(vol.transform.localToWorldMatrix))
|
||||
{
|
||||
var color = vol.enabled ? s_HandleColor : s_HandleColorDisabled;
|
||||
m_BoundsHandle.SetColor(color);
|
||||
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)
|
||||
{
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using UnityEditor.IMGUI.Controls;
|
||||
using UnityEditor.SceneManagement;
|
||||
using UnityEditorInternal;
|
||||
using UnityEngine.AI;
|
||||
using UnityEngine;
|
||||
using System.Linq;
|
||||
|
||||
namespace UnityEditor.AI
|
||||
{
|
||||
|
@ -45,6 +47,14 @@ namespace UnityEditor.AI
|
|||
static Color s_HandleColorSelected = new Color(127f, 214f, 244f, 210f) / 255;
|
||||
static Color s_HandleColorDisabled = new Color(127f * 0.75f, 214f * 0.75f, 244f * 0.75f, 100f) / 255;
|
||||
|
||||
static int s_HandleControlIDHint = typeof(NavMeshSurfaceEditor).Name.GetHashCode();
|
||||
BoxBoundsHandle m_BoundsHandle = new BoxBoundsHandle(s_HandleControlIDHint);
|
||||
|
||||
bool editingCollider
|
||||
{
|
||||
get { return EditMode.editMode == EditMode.SceneViewEditMode.Collider && EditMode.IsOwner(this); }
|
||||
}
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
m_AgentTypeID = serializedObject.FindProperty("m_AgentTypeID");
|
||||
|
@ -155,9 +165,15 @@ namespace UnityEditor.AI
|
|||
if ((CollectObjects)m_CollectObjects.enumValueIndex == CollectObjects.Volume)
|
||||
{
|
||||
EditorGUI.indentLevel++;
|
||||
InspectorEditButtonGUI();
|
||||
EditorGUILayout.PropertyField(m_Size);
|
||||
EditorGUILayout.PropertyField(m_Center);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (editingCollider)
|
||||
EditMode.QuitEditMode();
|
||||
}
|
||||
|
||||
EditorGUILayout.PropertyField(m_LayerMask, s_Styles.m_LayerMask);
|
||||
EditorGUILayout.PropertyField(m_UseGeometry);
|
||||
|
@ -344,6 +360,49 @@ namespace UnityEditor.AI
|
|||
Gizmos.DrawIcon(navSurface.transform.position, "NavMeshSurface Icon", true);
|
||||
}
|
||||
|
||||
void InspectorEditButtonGUI()
|
||||
{
|
||||
var navSurface = (NavMeshSurface)target;
|
||||
var bounds = new Bounds(navSurface.transform.position, navSurface.size);
|
||||
|
||||
EditMode.DoEditModeInspectorModeButton(
|
||||
EditMode.SceneViewEditMode.Collider,
|
||||
"Edit Volume",
|
||||
EditorGUIUtility.IconContent("EditCollider"),
|
||||
bounds,
|
||||
this
|
||||
);
|
||||
}
|
||||
|
||||
void OnSceneGUI()
|
||||
{
|
||||
if (!editingCollider)
|
||||
return;
|
||||
|
||||
var navSurface = (NavMeshSurface)target;
|
||||
var localToWorld = Matrix4x4.TRS(navSurface.transform.position, navSurface.transform.rotation, Vector3.one);
|
||||
using (new Handles.MatrixScope(localToWorld))
|
||||
{
|
||||
var color = navSurface.enabled ? s_HandleColor : s_HandleColorDisabled;
|
||||
m_BoundsHandle.SetColor(color);
|
||||
m_BoundsHandle.center = navSurface.center;
|
||||
m_BoundsHandle.size = navSurface.size;
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
m_BoundsHandle.DrawHandle();
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
Undo.RecordObject(navSurface, "Modified NavMesh Surface");
|
||||
Vector3 center = m_BoundsHandle.center;
|
||||
Vector3 size = m_BoundsHandle.size;
|
||||
navSurface.center = center;
|
||||
navSurface.size = size;
|
||||
EditorUtility.SetDirty(target);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
[MenuItem("GameObject/AI/NavMesh Surface", false, 2000)]
|
||||
static public void CreateNavMeshSurface(MenuCommand menuCommand)
|
||||
{
|
||||
|
|
Загрузка…
Ссылка в новой задаче