提交 3b98e0bd 编写于 作者: J Jakob Hunsballe

Update for new experimental build

. NavMeshSurface supports baking and applying prefab instances.
. NavMeshLink and NavMeshSurface ignore scale.
. NavMeshLink has optional position & rotation when added.
. meta-files added: icons for components in inspector and project
windows.
. HelpURL for components.
. Coding style fixes.
上级 ce83e6ec
fileFormatVersion: 2
guid: 92f4afa3e25264f5b964937ccea49ff2
timeCreated: 1477656497
licenseType: Pro
TextureImporter:
fileIDToRecycleName: {}
serializedVersion: 4
mipmaps:
mipMapMode: 0
enableMipMap: 1
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
filterMode: -1
aniso: -1
mipBias: -1
wrapMode: -1
nPOTScale: 1
lightmap: 0
compressionQuality: 50
spriteMode: 0
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spritePixelsToUnits: 100
alphaUsage: 1
alphaIsTransparency: 0
spriteTessellationDetail: -1
textureType: 0
textureShape: 1
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
platformSettings:
- buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
spritePackingTag:
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: cc7b9475dbddf4f9088d327d6e10ab77
timeCreated: 1477656497
licenseType: Pro
TextureImporter:
fileIDToRecycleName: {}
serializedVersion: 4
mipmaps:
mipMapMode: 0
enableMipMap: 1
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
filterMode: -1
aniso: -1
mipBias: -1
wrapMode: -1
nPOTScale: 1
lightmap: 0
compressionQuality: 50
spriteMode: 0
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spritePixelsToUnits: 100
alphaUsage: 1
alphaIsTransparency: 0
spriteTessellationDetail: -1
textureType: 0
textureShape: 1
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
platformSettings:
- buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
spritePackingTag:
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: e4f97225bcfb64760a1c81f460837f01
timeCreated: 1477656497
licenseType: Pro
TextureImporter:
fileIDToRecycleName: {}
serializedVersion: 4
mipmaps:
mipMapMode: 0
enableMipMap: 1
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
filterMode: -1
aniso: -1
mipBias: -1
wrapMode: -1
nPOTScale: 1
lightmap: 0
compressionQuality: 50
spriteMode: 0
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spritePixelsToUnits: 100
alphaUsage: 1
alphaIsTransparency: 0
spriteTessellationDetail: -1
textureType: 0
textureShape: 1
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
platformSettings:
- buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
spritePackingTag:
userData:
assetBundleName:
assetBundleVariant:
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
namespace UnityEditor.AI namespace UnityEditor.AI
{ {
[CanEditMultipleObjects] [CanEditMultipleObjects]
[CustomEditor (typeof (NavMeshLink))] [CustomEditor(typeof(NavMeshLink))]
class NavMeshLinkEditor : Editor class NavMeshLinkEditor : Editor
{ {
SerializedProperty m_AgentTypeID; SerializedProperty m_AgentTypeID;
...@@ -18,18 +18,18 @@ class NavMeshLinkEditor : Editor ...@@ -18,18 +18,18 @@ class NavMeshLinkEditor : Editor
static int s_SelectedID; static int s_SelectedID;
static int s_SelectedPoint = -1; static int s_SelectedPoint = -1;
static Color s_HandleColor = new Color (255f, 167f, 39f, 210f) / 255; static Color s_HandleColor = new Color(255f, 167f, 39f, 210f) / 255;
static Color s_HandleColorDisabled = new Color (255f*0.75f, 167f*0.75f, 39f*0.75f, 100f) / 255; static Color s_HandleColorDisabled = new Color(255f * 0.75f, 167f * 0.75f, 39f * 0.75f, 100f) / 255;
void OnEnable () void OnEnable()
{ {
m_AgentTypeID = serializedObject.FindProperty ("m_AgentTypeID"); m_AgentTypeID = serializedObject.FindProperty("m_AgentTypeID");
m_Area = serializedObject.FindProperty ("m_Area"); m_Area = serializedObject.FindProperty("m_Area");
m_AutoUpdatePosition = serializedObject.FindProperty ("m_AutoUpdatePosition"); m_AutoUpdatePosition = serializedObject.FindProperty("m_AutoUpdatePosition");
m_Bidirectional = serializedObject.FindProperty ("m_Bidirectional"); m_Bidirectional = serializedObject.FindProperty("m_Bidirectional");
m_EndPoint = serializedObject.FindProperty ("m_EndPoint"); m_EndPoint = serializedObject.FindProperty("m_EndPoint");
m_StartPoint = serializedObject.FindProperty ("m_StartPoint"); m_StartPoint = serializedObject.FindProperty("m_StartPoint");
m_Width = serializedObject.FindProperty ("m_Width"); m_Width = serializedObject.FindProperty("m_Width");
s_SelectedID = 0; s_SelectedID = 0;
s_SelectedPoint = -1; s_SelectedPoint = -1;
...@@ -37,87 +37,92 @@ void OnEnable () ...@@ -37,87 +37,92 @@ void OnEnable ()
NavMeshVisualizationSettings.showNavigation++; NavMeshVisualizationSettings.showNavigation++;
} }
void OnDisable () void OnDisable()
{ {
NavMeshVisualizationSettings.showNavigation--; NavMeshVisualizationSettings.showNavigation--;
} }
void AlignTransformToEndPoints (NavMeshLink navLink) static Matrix4x4 UnscaledLocalToWorldMatrix(Transform t)
{ {
var transform = navLink.transform; return Matrix4x4.TRS(t.position, t.rotation, Vector3.one);
Vector3 worldStartPt = transform.TransformPoint (navLink.startPoint); }
Vector3 worldEndPt = transform.TransformPoint (navLink.endPoint);
Vector3 forward = worldEndPt - worldStartPt; void AlignTransformToEndPoints(NavMeshLink navLink)
Vector3 up = transform.up; {
var mat = UnscaledLocalToWorldMatrix(navLink.transform);
// Flatten var worldStartPt = mat.MultiplyPoint(navLink.startPoint);
forward -= Vector3.Dot (up, forward) * up; var worldEndPt = mat.MultiplyPoint(navLink.endPoint);
var forward = worldEndPt - worldStartPt;
var up = navLink.transform.up;
var rotation = new Quaternion (); // Flatten
rotation.SetLookRotation (forward, up); forward -= Vector3.Dot(up, forward) * up;
transform.rotation = rotation; var transform = navLink.transform;
transform.rotation = Quaternion.LookRotation(forward, up);
transform.position = (worldEndPt + worldStartPt) * 0.5f; transform.position = (worldEndPt + worldStartPt) * 0.5f;
transform.localScale = Vector3.one;
navLink.startPoint = transform.InverseTransformPoint (worldStartPt); navLink.startPoint = transform.InverseTransformPoint(worldStartPt);
navLink.endPoint = transform.InverseTransformPoint (worldEndPt); navLink.endPoint = transform.InverseTransformPoint(worldEndPt);
} }
public override void OnInspectorGUI() public override void OnInspectorGUI()
{ {
serializedObject.Update (); serializedObject.Update();
NavMeshEditorHelpers.AgentTypePopup ("Agent Type", m_AgentTypeID); NavMeshEditorHelpers.AgentTypePopup("Agent Type", m_AgentTypeID);
EditorGUILayout.Space (); EditorGUILayout.Space();
EditorGUILayout.PropertyField (m_StartPoint); EditorGUILayout.PropertyField(m_StartPoint);
EditorGUILayout.PropertyField (m_EndPoint); EditorGUILayout.PropertyField(m_EndPoint);
EditorGUILayout.PropertyField (m_Width); EditorGUILayout.PropertyField(m_Width);
m_Width.floatValue = Mathf.Max (0.0f, m_Width.floatValue); m_Width.floatValue = Mathf.Max(0.0f, m_Width.floatValue);
GUILayout.BeginHorizontal (); GUILayout.BeginHorizontal();
GUILayout.Space (EditorGUIUtility.labelWidth); GUILayout.Space(EditorGUIUtility.labelWidth);
if (GUILayout.Button ("Align Transform To Points")) if (GUILayout.Button("Align Transform To Points"))
{
foreach (NavMeshLink navLink in targets)
{ {
foreach (NavMeshLink navLink in targets) Undo.RecordObject(navLink.transform, "Align Transform to End Points");
{ Undo.RecordObject(navLink, "Align Transform to End Points");
Undo.RecordObject (navLink.transform, "Align Transform to End Points"); AlignTransformToEndPoints(navLink);
Undo.RecordObject (navLink, "Align Transform to End Points");
AlignTransformToEndPoints (navLink);
}
} }
GUILayout.EndHorizontal (); }
EditorGUILayout.Space (); GUILayout.EndHorizontal();
EditorGUILayout.Space();
EditorGUILayout.PropertyField (m_AutoUpdatePosition); EditorGUILayout.PropertyField(m_AutoUpdatePosition);
EditorGUILayout.PropertyField (m_Bidirectional); EditorGUILayout.PropertyField(m_Bidirectional);
NavMeshEditorHelpers.AreaPopup ("Area Type", m_Area); NavMeshEditorHelpers.AreaPopup("Area Type", m_Area);
serializedObject.ApplyModifiedProperties (); serializedObject.ApplyModifiedProperties();
EditorGUILayout.Space (); EditorGUILayout.Space();
} }
static Vector3 CalcLinkRight (NavMeshLink navLink) static Vector3 CalcLinkRight(NavMeshLink navLink)
{ {
Vector3 dir = navLink.endPoint - navLink.startPoint; var dir = navLink.endPoint - navLink.startPoint;
return (new Vector3 (-dir.z, 0.0f, dir.x)).normalized; return (new Vector3(-dir.z, 0.0f, dir.x)).normalized;
} }
static void DrawLink (NavMeshLink navLink) static void DrawLink(NavMeshLink navLink)
{ {
Vector3 right = CalcLinkRight (navLink); var right = CalcLinkRight(navLink);
float rad = navLink.width * 0.5f; var rad = navLink.width * 0.5f;
Gizmos.DrawLine (navLink.startPoint - right * rad, navLink.startPoint + right * rad); Gizmos.DrawLine(navLink.startPoint - right * rad, navLink.startPoint + right * rad);
Gizmos.DrawLine (navLink.endPoint - right * rad, navLink.endPoint + right * rad); Gizmos.DrawLine(navLink.endPoint - right * rad, navLink.endPoint + right * rad);
Gizmos.DrawLine (navLink.startPoint - right * rad, navLink.endPoint - right * rad); Gizmos.DrawLine(navLink.startPoint - right * rad, navLink.endPoint - right * rad);
Gizmos.DrawLine (navLink.startPoint + right * rad, navLink.endPoint + right * rad); Gizmos.DrawLine(navLink.startPoint + right * rad, navLink.endPoint + right * rad);
} }
[DrawGizmo (GizmoType.Selected | GizmoType.Active | GizmoType.Pickable)] [DrawGizmo(GizmoType.Selected | GizmoType.Active | GizmoType.Pickable)]
static void RenderBoxGizmo (NavMeshLink navLink, GizmoType gizmoType) static void RenderBoxGizmo(NavMeshLink navLink, GizmoType gizmoType)
{ {
if (!EditorApplication.isPlaying) if (!EditorApplication.isPlaying)
navLink.UpdateLink(); navLink.UpdateLink();
...@@ -129,19 +134,19 @@ static void RenderBoxGizmo (NavMeshLink navLink, GizmoType gizmoType) ...@@ -129,19 +134,19 @@ static void RenderBoxGizmo (NavMeshLink navLink, GizmoType gizmoType)
var oldColor = Gizmos.color; var oldColor = Gizmos.color;
var oldMatrix = Gizmos.matrix; var oldMatrix = Gizmos.matrix;
Gizmos.matrix = navLink.transform.localToWorldMatrix; Gizmos.matrix = UnscaledLocalToWorldMatrix(navLink.transform);
Gizmos.color = color; Gizmos.color = color;
DrawLink (navLink); DrawLink(navLink);
Gizmos.matrix = oldMatrix; Gizmos.matrix = oldMatrix;
Gizmos.color = oldColor; Gizmos.color = oldColor;
Gizmos.DrawIcon (navLink.transform.position, "NavMeshLink Icon", true); Gizmos.DrawIcon(navLink.transform.position, "NavMeshLink Icon", true);
} }
[DrawGizmo (GizmoType.NotInSelectionHierarchy | GizmoType.Pickable)] [DrawGizmo(GizmoType.NotInSelectionHierarchy | GizmoType.Pickable)]
static void RenderBoxGizmoNotSelected (NavMeshLink navLink, GizmoType gizmoType) static void RenderBoxGizmoNotSelected(NavMeshLink navLink, GizmoType gizmoType)
{ {
if (NavMeshVisualizationSettings.showNavigation > 0) if (NavMeshVisualizationSettings.showNavigation > 0)
{ {
...@@ -152,16 +157,16 @@ static void RenderBoxGizmoNotSelected (NavMeshLink navLink, GizmoType gizmoType) ...@@ -152,16 +157,16 @@ static void RenderBoxGizmoNotSelected (NavMeshLink navLink, GizmoType gizmoType)
var oldColor = Gizmos.color; var oldColor = Gizmos.color;
var oldMatrix = Gizmos.matrix; var oldMatrix = Gizmos.matrix;
Gizmos.matrix = navLink.transform.localToWorldMatrix; Gizmos.matrix = UnscaledLocalToWorldMatrix(navLink.transform);
Gizmos.color = color; Gizmos.color = color;
DrawLink (navLink); DrawLink(navLink);
Gizmos.matrix = oldMatrix; Gizmos.matrix = oldMatrix;
Gizmos.color = oldColor; Gizmos.color = oldColor;
} }
Gizmos.DrawIcon (navLink.transform.position, "NavMeshLink Icon", true); Gizmos.DrawIcon(navLink.transform.position, "NavMeshLink Icon", true);
} }
public void OnSceneGUI() public void OnSceneGUI()
...@@ -170,35 +175,37 @@ public void OnSceneGUI() ...@@ -170,35 +175,37 @@ public void OnSceneGUI()
if (!navLink.enabled) if (!navLink.enabled)
return; return;
Vector3 startPt = navLink.transform.TransformPoint (navLink.startPoint); var mat = UnscaledLocalToWorldMatrix(navLink.transform);
Vector3 endPt = navLink.transform.TransformPoint (navLink.endPoint);
Vector3 midPt = Vector3.Lerp (startPt, endPt, 0.35f); var startPt = mat.MultiplyPoint(navLink.startPoint);
float startSize = HandleUtility.GetHandleSize (startPt); var endPt = mat.MultiplyPoint(navLink.endPoint);
float endSize = HandleUtility.GetHandleSize (endPt); var midPt = Vector3.Lerp(startPt, endPt, 0.35f);
float midSize = HandleUtility.GetHandleSize (midPt); var startSize = HandleUtility.GetHandleSize(startPt);
var endSize = HandleUtility.GetHandleSize(endPt);
var midSize = HandleUtility.GetHandleSize(midPt);
Quaternion zup = Quaternion.FromToRotation (Vector3.forward, Vector3.up); var zup = Quaternion.FromToRotation(Vector3.forward, Vector3.up);
Vector3 right = navLink.transform.TransformVector (CalcLinkRight (navLink)); var right = mat.MultiplyVector(CalcLinkRight(navLink));
Color oldColor = Handles.color; var oldColor = Handles.color;
Handles.color = s_HandleColor; Handles.color = s_HandleColor;
Vector3 pos; Vector3 pos;
if (navLink.GetInstanceID() == s_SelectedID && s_SelectedPoint == 0) if (navLink.GetInstanceID() == s_SelectedID && s_SelectedPoint == 0)
{ {
EditorGUI.BeginChangeCheck (); EditorGUI.BeginChangeCheck();
Handles.CubeCap (0, startPt, zup, 0.1f * startSize); Handles.CubeCap(0, startPt, zup, 0.1f * startSize);
pos = Handles.PositionHandle (startPt, navLink.transform.rotation); pos = Handles.PositionHandle(startPt, navLink.transform.rotation);
if (EditorGUI.EndChangeCheck ()) if (EditorGUI.EndChangeCheck())
{ {
Undo.RecordObject (navLink, "Move link point"); Undo.RecordObject(navLink, "Move link point");
navLink.startPoint = navLink.transform.InverseTransformPoint (pos); navLink.startPoint = mat.inverse.MultiplyPoint(pos);
} }
} }
else else
{ {
if (Handles.Button (startPt, zup, 0.1f * startSize, 0.1f * startSize, Handles.CubeCap)) if (Handles.Button(startPt, zup, 0.1f * startSize, 0.1f * startSize, Handles.CubeCap))
{ {
s_SelectedPoint = 0; s_SelectedPoint = 0;
s_SelectedID = navLink.GetInstanceID(); s_SelectedID = navLink.GetInstanceID();
...@@ -207,52 +214,52 @@ public void OnSceneGUI() ...@@ -207,52 +214,52 @@ public void OnSceneGUI()
if (navLink.GetInstanceID() == s_SelectedID && s_SelectedPoint == 1) if (navLink.GetInstanceID() == s_SelectedID && s_SelectedPoint == 1)
{ {
EditorGUI.BeginChangeCheck (); EditorGUI.BeginChangeCheck();
Handles.CubeCap (0, endPt, zup, 0.1f * startSize); Handles.CubeCap(0, endPt, zup, 0.1f * startSize);
pos = Handles.PositionHandle (endPt, navLink.transform.rotation); pos = Handles.PositionHandle(endPt, navLink.transform.rotation);
if (EditorGUI.EndChangeCheck ()) if (EditorGUI.EndChangeCheck())
{ {
Undo.RecordObject (navLink, "Move link point"); Undo.RecordObject(navLink, "Move link point");
navLink.endPoint = navLink.transform.InverseTransformPoint (pos); navLink.endPoint = mat.inverse.MultiplyPoint(pos);
} }
} }
else else
{ {
if (Handles.Button (endPt, zup, 0.1f * endSize, 0.1f * endSize, Handles.CubeCap)) if (Handles.Button(endPt, zup, 0.1f * endSize, 0.1f * endSize, Handles.CubeCap))
{ {
s_SelectedPoint = 1; s_SelectedPoint = 1;
s_SelectedID = navLink.GetInstanceID(); s_SelectedID = navLink.GetInstanceID();
} }
} }
EditorGUI.BeginChangeCheck (); EditorGUI.BeginChangeCheck();
pos = Handles.Slider (midPt + right * navLink.width*0.5f, right, midSize * 0.03f, Handles.DotCap, 0); pos = Handles.Slider(midPt + right * navLink.width * 0.5f, right, midSize * 0.03f, Handles.DotCap, 0);
if (EditorGUI.EndChangeCheck ()) if (EditorGUI.EndChangeCheck())
{ {
Undo.RecordObject (navLink, "Adjust link width"); Undo.RecordObject(navLink, "Adjust link width");
navLink.width = Mathf.Max (0.0f, Vector3.Dot (right, (pos - midPt)) * 2.0f); navLink.width = Mathf.Max(0.0f, Vector3.Dot(right, (pos - midPt)) * 2.0f);
} }
EditorGUI.BeginChangeCheck (); EditorGUI.BeginChangeCheck();
pos = Handles.Slider (midPt - right * navLink.width*0.5f, -right, midSize * 0.03f, Handles.DotCap, 0); pos = Handles.Slider(midPt - right * navLink.width * 0.5f, -right, midSize * 0.03f, Handles.DotCap, 0);
if (EditorGUI.EndChangeCheck ()) if (EditorGUI.EndChangeCheck())
{ {
Undo.RecordObject (navLink, "Adjust link width"); Undo.RecordObject(navLink, "Adjust link width");
navLink.width = Mathf.Max (0.0f, Vector3.Dot (-right, (pos - midPt)) * 2.0f); navLink.width = Mathf.Max(0.0f, Vector3.Dot(-right, (pos - midPt)) * 2.0f);
} }
Handles.color = oldColor; Handles.color = oldColor;
} }
[MenuItem ("GameObject/AI/NavMesh Link", false, 2002)] [MenuItem("GameObject/AI/NavMesh Link", false, 2002)]
static public void CreateNavMeshLink (MenuCommand menuCommand) static public void CreateNavMeshLink(MenuCommand menuCommand)
{ {
var parent = menuCommand.context as GameObject; var parent = menuCommand.context as GameObject;
GameObject go = NavMeshEditorHelpers.CreateAndSelectGameObject ("NavMesh Link", parent); GameObject go = NavMeshEditorHelpers.CreateAndSelectGameObject("NavMesh Link", parent);
go.AddComponent<NavMeshLink> (); go.AddComponent<NavMeshLink>();
var view = SceneView.lastActiveSceneView; var view = SceneView.lastActiveSceneView;
if (view != null) if (view != null)
view.MoveToView (go.transform); view.MoveToView(go.transform);
} }
} }
} }
fileFormatVersion: 2
guid: ece1e865d1ad84587872fe8580ab5a20
timeCreated: 1477036743
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 6fa04b4743e3947eba4d7b9e5832ea69
timeCreated: 1477036742
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
namespace UnityEditor.AI namespace UnityEditor.AI
{ {
[CanEditMultipleObjects] [CanEditMultipleObjects]
[CustomEditor (typeof (NavMeshModifierVolume))] [CustomEditor(typeof(NavMeshModifierVolume))]
class NavMeshModifierVolumeEditor : Editor class NavMeshModifierVolumeEditor : Editor
{ {
SerializedProperty m_AffectedAgents; SerializedProperty m_AffectedAgents;
...@@ -12,45 +12,45 @@ class NavMeshModifierVolumeEditor : Editor ...@@ -12,45 +12,45 @@ class NavMeshModifierVolumeEditor : Editor
SerializedProperty m_Center; SerializedProperty m_Center;
SerializedProperty m_Size; SerializedProperty m_Size;
static Color s_HandleColor = new Color (187f, 138f, 240f, 210f) / 255; 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 Color s_HandleColorDisabled = new Color(187f * 0.75f, 138f * 0.75f, 240f * 0.75f, 100f) / 255;
void OnEnable () void OnEnable()
{ {
m_AffectedAgents = serializedObject.FindProperty ("m_AffectedAgents"); m_AffectedAgents = serializedObject.FindProperty("m_AffectedAgents");
m_Area = serializedObject.FindProperty ("m_Area"); m_Area = serializedObject.FindProperty("m_Area");
m_Center = serializedObject.FindProperty ("m_Center"); m_Center = serializedObject.FindProperty("m_Center");
m_Size = serializedObject.FindProperty ("m_Size"); m_Size = serializedObject.FindProperty("m_Size");
NavMeshVisualizationSettings.showNavigation++; NavMeshVisualizationSettings.showNavigation++;
} }
void OnDisable () void OnDisable()
{ {
NavMeshVisualizationSettings.showNavigation--; NavMeshVisualizationSettings.showNavigation--;
} }
public override void OnInspectorGUI() public override void OnInspectorGUI()
{ {
serializedObject.Update (); serializedObject.Update();
EditorGUILayout.PropertyField (m_Size); EditorGUILayout.PropertyField(m_Size);
EditorGUILayout.PropertyField (m_Center); EditorGUILayout.PropertyField(m_Center);
NavMeshEditorHelpers.AreaPopup ("Area Type", m_Area); NavMeshEditorHelpers.AreaPopup("Area Type", m_Area);
NavMeshEditorHelpers.AgentMaskPopup ("Affected Agents", m_AffectedAgents); NavMeshEditorHelpers.AgentMaskPopup("Affected Agents", m_AffectedAgents);
EditorGUILayout.Space(); EditorGUILayout.Space();
serializedObject.ApplyModifiedProperties (); serializedObject.ApplyModifiedProperties();
} }
[DrawGizmo (GizmoType.Selected | GizmoType.Active)] [DrawGizmo(GizmoType.Selected | GizmoType.Active)]
static void RenderBoxGizmo (NavMeshModifierVolume navModifier, GizmoType gizmoType) static void RenderBoxGizmo(NavMeshModifierVolume navModifier, GizmoType gizmoType)
{ {
var color = s_HandleColor; var color = s_HandleColor;
if (!navModifier.enabled) if (!navModifier.enabled)
color = s_HandleColorDisabled; color = s_HandleColorDisabled;
var colorTrans = new Color (color.r*0.75f, color.g*0.75f, color.b*0.75f, color.a*0.15f); 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 oldColor = Gizmos.color;
var oldMatrix = Gizmos.matrix; var oldMatrix = Gizmos.matrix;
...@@ -58,19 +58,19 @@ static void RenderBoxGizmo (NavMeshModifierVolume navModifier, GizmoType gizmoTy ...@@ -58,19 +58,19 @@ static void RenderBoxGizmo (NavMeshModifierVolume navModifier, GizmoType gizmoTy
Gizmos.matrix = navModifier.transform.localToWorldMatrix; Gizmos.matrix = navModifier.transform.localToWorldMatrix;
Gizmos.color = colorTrans; Gizmos.color = colorTrans;
Gizmos.DrawCube (navModifier.center, navModifier.size); Gizmos.DrawCube(navModifier.center, navModifier.size);
Gizmos.color = color; Gizmos.color = color;
Gizmos.DrawWireCube (navModifier.center, navModifier.size); Gizmos.DrawWireCube(navModifier.center, navModifier.size);
Gizmos.matrix = oldMatrix; Gizmos.matrix = oldMatrix;
Gizmos.color = oldColor; Gizmos.color = oldColor;
Gizmos.DrawIcon (navModifier.transform.position, "NavMeshModifierVolume Icon", true); Gizmos.DrawIcon(navModifier.transform.position, "NavMeshModifierVolume Icon", true);
} }
[DrawGizmo (GizmoType.NotInSelectionHierarchy | GizmoType.Pickable)] [DrawGizmo(GizmoType.NotInSelectionHierarchy | GizmoType.Pickable)]
static void RenderBoxGizmoNotSelected (NavMeshModifierVolume navModifier, GizmoType gizmoType) static void RenderBoxGizmoNotSelected(NavMeshModifierVolume navModifier, GizmoType gizmoType)
{ {
if (NavMeshVisualizationSettings.showNavigation > 0) if (NavMeshVisualizationSettings.showNavigation > 0)
{ {
...@@ -84,24 +84,24 @@ static void RenderBoxGizmoNotSelected (NavMeshModifierVolume navModifier, GizmoT ...@@ -84,24 +84,24 @@ static void RenderBoxGizmoNotSelected (NavMeshModifierVolume navModifier, GizmoT
Gizmos.matrix = navModifier.transform.localToWorldMatrix; Gizmos.matrix = navModifier.transform.localToWorldMatrix;
Gizmos.color = color; Gizmos.color = color;
Gizmos.DrawWireCube (navModifier.center, navModifier.size); Gizmos.DrawWireCube(navModifier.center, navModifier.size);
Gizmos.matrix = oldMatrix; Gizmos.matrix = oldMatrix;
Gizmos.color = oldColor; Gizmos.color = oldColor;
} }
Gizmos.DrawIcon (navModifier.transform.position, "NavMeshModifierVolume Icon", true); Gizmos.DrawIcon(navModifier.transform.position, "NavMeshModifierVolume Icon", true);
} }
[MenuItem ("GameObject/AI/NavMesh Modifier Volume", false, 2001)] [MenuItem("GameObject/AI/NavMesh Modifier Volume", false, 2001)]
static public void CreateNavMeshModifierVolume (MenuCommand menuCommand) static public void CreateNavMeshModifierVolume(MenuCommand menuCommand)
{ {
var parent = menuCommand.context as GameObject; var parent = menuCommand.context as GameObject;
var go = NavMeshEditorHelpers.CreateAndSelectGameObject ("NavMesh Modifier Volume", parent); var go = NavMeshEditorHelpers.CreateAndSelectGameObject("NavMesh Modifier Volume", parent);
go.AddComponent<NavMeshModifierVolume> (); go.AddComponent<NavMeshModifierVolume>();
var view = SceneView.lastActiveSceneView; var view = SceneView.lastActiveSceneView;
if (view != null) if (view != null)
view.MoveToView (go.transform); view.MoveToView(go.transform);
} }
} }
} }
fileFormatVersion: 2
guid: c0f3bef2a67ae4e139538afec3e59b03
timeCreated: 1477036743
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
using UnityEditor.SceneManagement; using UnityEditor.SceneManagement;
using UnityEngine.AI; using UnityEngine.AI;
using UnityEngine; using UnityEngine;
using System.Linq;
namespace UnityEditor.AI namespace UnityEditor.AI
{ {
...@@ -68,10 +69,10 @@ void OnDisable() ...@@ -68,10 +69,10 @@ void OnDisable()
NavMeshVisualizationSettings.showNavigation--; NavMeshVisualizationSettings.showNavigation--;
} }
static string GetAndEnsureTargetPath(NavMeshSurfaceEditor instance) static string GetAndEnsureTargetPath(NavMeshSurface surface)
{ {
// Create directory for the asset if it does not exist yet. // Create directory for the asset if it does not exist yet.
var activeScenePath = EditorSceneManager.GetActiveScene().path; var activeScenePath = surface.gameObject.scene.path;
var targetPath = "Assets"; var targetPath = "Assets";
if (!string.IsNullOrEmpty(activeScenePath)) if (!string.IsNullOrEmpty(activeScenePath))
...@@ -81,54 +82,14 @@ static string GetAndEnsureTargetPath(NavMeshSurfaceEditor instance) ...@@ -81,54 +82,14 @@ static string GetAndEnsureTargetPath(NavMeshSurfaceEditor instance)
return targetPath; return targetPath;
} }
void SaveCombinedAsset() void SaveNavMeshAsset(NavMeshSurface surface)
{ {
// Create an asset describing all surfaces. var targetPath = GetAndEnsureTargetPath(surface);
var targetPath = GetAndEnsureTargetPath(this);
var combinedAssetData = new List<NavMeshData>();
// Collect valid navmesh data. var combinedAssetPath = Path.Combine(targetPath, "NavMesh-" + surface.name + ".asset");
foreach (var s in NavMeshSurface.activeSurfaces) combinedAssetPath = AssetDatabase.GenerateUniqueAssetPath(combinedAssetPath);
{ AssetDatabase.CreateAsset(surface.bakedNavMeshData, combinedAssetPath);
if (s.bakedNavMeshData != null) AssetDatabase.SaveAssets();
{
combinedAssetData.Add(s.bakedNavMeshData);
}
}
// Clear the legacy navmesh data reference on the scene
if (NavMeshEditorHelpers.CurrentNavMeshAssetFormat() == NavMeshEditorHelpers.NavMeshDataFormat.Single)
NavMeshBuilder.ClearAllNavMeshes();
// Store baked navmesh data in one asset.
var combinedAssetPath = Path.Combine(targetPath, "NavMesh.asset");
if (combinedAssetData.Count == 0)
{
AssetDatabase.DeleteAsset(combinedAssetPath);
}
else
{
if (!File.Exists(combinedAssetPath))
{
// NOTE: Creates empty dummy NavMeshData to represent the main asset,
// this is done in order to show all the built meshes equally in the list.
var dummy = new NavMeshData();
AssetDatabase.CreateAsset(dummy, combinedAssetPath);
}
// Only add the data that has not been added already.
// Call to NavMeshSurface.Clear () also deletes the data from the asset.
foreach (var data in combinedAssetData)
{
if (!AssetDatabase.Contains(data))
{
AssetDatabase.AddObjectToAsset(data, combinedAssetPath);
}
}
AssetDatabase.SaveAssets();
AssetDatabase.ImportAsset(combinedAssetPath);
}
} }
void BakeSurface(NavMeshSurface navSurface) void BakeSurface(NavMeshSurface navSurface)
...@@ -136,7 +97,9 @@ void BakeSurface(NavMeshSurface navSurface) ...@@ -136,7 +97,9 @@ void BakeSurface(NavMeshSurface navSurface)
var destroy = navSurface.bakedNavMeshData; var destroy = navSurface.bakedNavMeshData;
navSurface.Bake(s_DebugVisualization); navSurface.Bake(s_DebugVisualization);
DestroyImmediate(destroy, true); AssetDatabase.DeleteAsset(AssetDatabase.GetAssetPath(destroy));
SaveNavMeshAsset(navSurface);
ApplyIfPrefab(navSurface);
// Explicitly set the scene as dirty - otherwise the reference will be lost // Explicitly set the scene as dirty - otherwise the reference will be lost
EditorSceneManager.MarkSceneDirty(navSurface.gameObject.scene); EditorSceneManager.MarkSceneDirty(navSurface.gameObject.scene);
} }
...@@ -148,21 +111,31 @@ void ClearSurface(NavMeshSurface navSurface) ...@@ -148,21 +111,31 @@ void ClearSurface(NavMeshSurface navSurface)
navSurface.RemoveData(); navSurface.RemoveData();
if (destroy) if (destroy)
{ {
DestroyImmediate(destroy, true); AssetDatabase.DeleteAsset(AssetDatabase.GetAssetPath(destroy));
ApplyIfPrefab(navSurface);
// Explicitly set the scene as dirty // Explicitly set the scene as dirty
EditorSceneManager.MarkSceneDirty(navSurface.gameObject.scene); EditorSceneManager.MarkSceneDirty(navSurface.gameObject.scene);
} }
} }
void ApplyIfPrefab(NavMeshSurface navSurface)
{
var prefabParent = PrefabUtility.GetPrefabParent(navSurface.gameObject);
if (prefabParent)
{
PrefabUtility.ReplacePrefab(navSurface.gameObject, prefabParent, ReplacePrefabOptions.ConnectToPrefab);
}
}
public override void OnInspectorGUI() public override void OnInspectorGUI()
{ {
if (s_Styles == null) if (s_Styles == null)
s_Styles = new Styles(); s_Styles = new Styles();
var isPrefab = PrefabUtility.GetPrefabObject(target) != null; var targetsContainPrefab = targets.Any(x => PrefabUtility.GetPrefabType(x) == PrefabType.Prefab);
if (isPrefab) if (targetsContainPrefab)
{ {
EditorGUILayout.HelpBox("Prefabs are currently not supported", MessageType.Warning); EditorGUILayout.HelpBox ("A Prefab instance is necessary for baking / clearing", MessageType.Warning);
return; return;
} }
...@@ -330,17 +303,19 @@ public override void OnInspectorGUI() ...@@ -330,17 +303,19 @@ public override void OnInspectorGUI()
using (new EditorGUI.DisabledScope(Application.isPlaying || m_AgentTypeID.intValue == -1)) using (new EditorGUI.DisabledScope(Application.isPlaying || m_AgentTypeID.intValue == -1))
{ {
var targetsContainPrefabInstance = targets.Any(x => PrefabUtility.GetPrefabType(x) == PrefabType.PrefabInstance);
if (targetsContainPrefabInstance)
{
EditorGUILayout.HelpBox ("Prefab changes are applied when baking / clearing", MessageType.Warning);
}
GUILayout.BeginHorizontal(); GUILayout.BeginHorizontal();
GUILayout.Space(EditorGUIUtility.labelWidth); GUILayout.Space(EditorGUIUtility.labelWidth);
if (GUILayout.Button("Clear")) if (GUILayout.Button("Clear"))
{ {
if (NavMeshEditorHelpers.AllowToOverwriteExistingData(NavMeshEditorHelpers.NavMeshDataFormat.Nested)) foreach (NavMeshSurface s in targets)
{ ClearSurface(s);
foreach (NavMeshSurface s in targets) SceneView.RepaintAll();
ClearSurface(s);
SaveCombinedAsset();
SceneView.RepaintAll();
}
} }
var allTargetsActive = true; var allTargetsActive = true;
...@@ -355,13 +330,9 @@ public override void OnInspectorGUI() ...@@ -355,13 +330,9 @@ public override void OnInspectorGUI()
GUI.enabled = allTargetsActive; GUI.enabled = allTargetsActive;
if (GUILayout.Button("Bake")) if (GUILayout.Button("Bake"))
{ {
if (NavMeshEditorHelpers.AllowToOverwriteExistingData(NavMeshEditorHelpers.NavMeshDataFormat.Nested)) foreach (NavMeshSurface navSurface in targets)
{ BakeSurface(navSurface);
foreach (NavMeshSurface navSurface in targets) SceneView.RepaintAll();
BakeSurface(navSurface);
SaveCombinedAsset();
SceneView.RepaintAll();
}
} }
GUI.enabled = true; GUI.enabled = true;
GUILayout.EndHorizontal(); GUILayout.EndHorizontal();
......
fileFormatVersion: 2
guid: 1c32167dbf3314852b6006a288eb449b
timeCreated: 1476968447
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
...@@ -2,9 +2,10 @@ ...@@ -2,9 +2,10 @@
namespace UnityEngine.AI namespace UnityEngine.AI
{ {
[AddComponentMenu("Navigation/NavMeshLink", 33)]
[ExecuteInEditMode] [ExecuteInEditMode]
[DefaultExecutionOrder(-101)] [DefaultExecutionOrder(-101)]
[AddComponentMenu("Navigation/NavMeshLink", 33)]
[HelpURL("https://github.com/Unity-Technologies/NavMeshComponents#further-documentation-draft")]
public class NavMeshLink : MonoBehaviour public class NavMeshLink : MonoBehaviour
{ {
[SerializeField] [SerializeField]
...@@ -39,7 +40,6 @@ public class NavMeshLink : MonoBehaviour ...@@ -39,7 +40,6 @@ public class NavMeshLink : MonoBehaviour
Vector3 m_LastPosition = Vector3.zero; Vector3 m_LastPosition = Vector3.zero;
Quaternion m_LastRotation = Quaternion.identity; Quaternion m_LastRotation = Quaternion.identity;
Vector3 m_LastScale = Vector3.one;
static readonly List<NavMeshLink> s_Tracked = new List<NavMeshLink>(); static readonly List<NavMeshLink> s_Tracked = new List<NavMeshLink>();
...@@ -108,28 +108,25 @@ void AddLink() ...@@ -108,28 +108,25 @@ void AddLink()
#endif #endif
var link = new NavMeshLinkData(); var link = new NavMeshLinkData();
link.startPosition = transform.TransformPoint(m_StartPoint); link.startPosition = m_StartPoint;
link.endPosition = transform.TransformPoint(m_EndPoint); link.endPosition = m_EndPoint;
link.width = m_Width; link.width = m_Width;
link.upAxis = transform.up;
link.costModifier = -1.0f; link.costModifier = -1.0f;
link.bidirectional = m_Bidirectional; link.bidirectional = m_Bidirectional;
link.area = m_Area; link.area = m_Area;
link.agentTypeID = m_AgentTypeID; link.agentTypeID = m_AgentTypeID;
m_LinkInstance = NavMesh.AddLink(link); m_LinkInstance = NavMesh.AddLink(link, transform.position, transform.rotation);
if (m_LinkInstance.valid) if (m_LinkInstance.valid)
m_LinkInstance.owner = this; m_LinkInstance.owner = this;
m_LastPosition = transform.position; m_LastPosition = transform.position;
m_LastRotation = transform.rotation; m_LastRotation = transform.rotation;
m_LastScale = transform.lossyScale;
} }
bool HasTransformChanged() bool HasTransformChanged()
{ {
if (m_LastPosition != transform.position) return true; if (m_LastPosition != transform.position) return true;
if (m_LastRotation != transform.rotation) return true; if (m_LastRotation != transform.rotation) return true;
if (m_LastScale != transform.lossyScale) return true;
return false; return false;
} }
......
fileFormatVersion: 2
guid: 6eeb5dc026fdf4b488bc7ae0138ab719
timeCreated: 1477924439
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: 92f4afa3e25264f5b964937ccea49ff2, type: 3}
userData:
assetBundleName:
assetBundleVariant:
...@@ -2,8 +2,9 @@ ...@@ -2,8 +2,9 @@
namespace UnityEngine.AI namespace UnityEngine.AI
{ {
[AddComponentMenu ("Navigation/NavMeshModifier", 32)]
[ExecuteInEditMode] [ExecuteInEditMode]
[AddComponentMenu("Navigation/NavMeshModifier", 32)]
[HelpURL("https://github.com/Unity-Technologies/NavMeshComponents#further-documentation-draft")]
public class NavMeshModifier : MonoBehaviour public class NavMeshModifier : MonoBehaviour
{ {
[SerializeField] [SerializeField]
......
fileFormatVersion: 2
guid: 1e3fdca004f2d45fe8abbed571a8abd5
timeCreated: 1477924411
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: cc7b9475dbddf4f9088d327d6e10ab77, type: 3}
userData:
assetBundleName:
assetBundleVariant:
...@@ -2,8 +2,9 @@ ...@@ -2,8 +2,9 @@
namespace UnityEngine.AI namespace UnityEngine.AI
{ {
[AddComponentMenu ("Navigation/NavMeshModifierVolume", 31)]
[ExecuteInEditMode] [ExecuteInEditMode]
[AddComponentMenu("Navigation/NavMeshModifierVolume", 31)]
[HelpURL("https://github.com/Unity-Technologies/NavMeshComponents#further-documentation-draft")]
public class NavMeshModifierVolume : MonoBehaviour public class NavMeshModifierVolume : MonoBehaviour
{ {
[SerializeField] [SerializeField]
......
fileFormatVersion: 2
guid: 35e95dc5ff2b64380880dd7ac5922847
timeCreated: 1477924430
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: cc7b9475dbddf4f9088d327d6e10ab77, type: 3}
userData:
assetBundleName:
assetBundleVariant:
...@@ -9,9 +9,10 @@ public enum CollectObjects ...@@ -9,9 +9,10 @@ public enum CollectObjects
Children = 2, Children = 2,
} }
[AddComponentMenu("Navigation/NavMeshSurface", 30)]
[ExecuteInEditMode] [ExecuteInEditMode]
[DefaultExecutionOrder(-102)] [DefaultExecutionOrder(-102)]
[AddComponentMenu("Navigation/NavMeshSurface", 30)]
[HelpURL("https://github.com/Unity-Technologies/NavMeshComponents#further-documentation-draft")]
public class NavMeshSurface : MonoBehaviour public class NavMeshSurface : MonoBehaviour
{ {
[SerializeField] [SerializeField]
...@@ -73,12 +74,10 @@ public class NavMeshSurface : MonoBehaviour ...@@ -73,12 +74,10 @@ public class NavMeshSurface : MonoBehaviour
NavMeshData m_BakedNavMeshData; NavMeshData m_BakedNavMeshData;
public NavMeshData bakedNavMeshData { get { return m_BakedNavMeshData; } set { m_BakedNavMeshData = value; } } public NavMeshData bakedNavMeshData { get { return m_BakedNavMeshData; } set { m_BakedNavMeshData = value; } }
// Do not serialize. // Do not serialize - runtime only state.
NavMeshDataInstance m_NavMeshDataInstance = new NavMeshDataInstance(); NavMeshDataInstance m_NavMeshDataInstance;
Vector3 m_LastPosition = Vector3.zero; Vector3 m_LastPosition = Vector3.zero;
Quaternion m_LastRotation = Quaternion.identity; Quaternion m_LastRotation = Quaternion.identity;
Vector3 m_LastScale = Vector3.one;
static readonly List<NavMeshSurface> s_NavMeshSurfaces = new List<NavMeshSurface>(); static readonly List<NavMeshSurface> s_NavMeshSurfaces = new List<NavMeshSurface>();
...@@ -90,18 +89,6 @@ public static List<NavMeshSurface> activeSurfaces ...@@ -90,18 +89,6 @@ public static List<NavMeshSurface> activeSurfaces
void OnEnable() void OnEnable()
{ {
Register(this); Register(this);
// Workaround: Make sure we have unique navmesh data, if not, delete reference to the data.
// HasUniqueNavMeshData () assumes that the original copy got registered before us.
if (!HasUniqueNavMeshData())
{
if (m_BakedNavMeshData != null)
{
Debug.LogWarning("Duplicating NavMeshSurface does not duplicate the referenced navmesh data");
m_BakedNavMeshData = null;
}
}
AddData(); AddData();
} }
...@@ -124,12 +111,12 @@ public void AddData() ...@@ -124,12 +111,12 @@ public void AddData()
m_LastPosition = transform.position; m_LastPosition = transform.position;
m_LastRotation = transform.rotation; m_LastRotation = transform.rotation;
m_LastScale = transform.lossyScale;
} }
public void RemoveData() public void RemoveData()
{ {
m_NavMeshDataInstance.Remove(); m_NavMeshDataInstance.Remove();
m_NavMeshDataInstance = new NavMeshDataInstance();
} }
public NavMeshBuildSettings GetBuildSettings() public NavMeshBuildSettings GetBuildSettings()
...@@ -201,17 +188,6 @@ static void UpdateActive() ...@@ -201,17 +188,6 @@ static void UpdateActive()
s_NavMeshSurfaces[i].UpdateDataIfTransformChanged(); s_NavMeshSurfaces[i].UpdateDataIfTransformChanged();
} }
bool HasUniqueNavMeshData()
{
for (var i = 0; i < s_NavMeshSurfaces.Count; ++i)
{
var surface = s_NavMeshSurfaces[i];
if (surface != this && surface.m_BakedNavMeshData == m_BakedNavMeshData)
return false;
}
return true;
}
void AppendModifierVolumes(ref List<NavMeshBuildSource> sources) void AppendModifierVolumes(ref List<NavMeshBuildSource> sources)
{ {
// Modifiers // Modifiers
...@@ -354,7 +330,6 @@ bool HasTransformChanged() ...@@ -354,7 +330,6 @@ bool HasTransformChanged()
{ {
if (m_LastPosition != transform.position) return true; if (m_LastPosition != transform.position) return true;
if (m_LastRotation != transform.rotation) return true; if (m_LastRotation != transform.rotation) return true;
if (m_LastScale != transform.lossyScale) return true;
return false; return false;
} }
...@@ -368,10 +343,36 @@ void UpdateDataIfTransformChanged() ...@@ -368,10 +343,36 @@ void UpdateDataIfTransformChanged()
} }
#if UNITY_EDITOR #if UNITY_EDITOR
bool UnshareNavMeshAsset()
{
// Nothing to unshare
if (m_BakedNavMeshData == null)
return false;
// Prefabs can share asset reference
var prefab = UnityEditor.PrefabUtility.GetPrefabObject(this);
if (prefab != null)
return false;
// Don't allow referencing an asset that's assigned to another surface
for (var i = 0; i < s_NavMeshSurfaces.Count; ++i)
{
var surface = s_NavMeshSurfaces[i];
if (surface != this && surface.m_BakedNavMeshData == m_BakedNavMeshData)
return true;
}
// asset is not referenced by known surfaces
return false;
}
void OnValidate() void OnValidate()
{ {
if (!s_NavMeshSurfaces.Contains(this)) if (UnshareNavMeshAsset())
return; {
Debug.LogWarning("Duplicating NavMeshSurface does not duplicate the referenced navmesh data");
m_BakedNavMeshData = null;
}
var settings = NavMesh.GetSettingsByID(m_AgentTypeID); var settings = NavMesh.GetSettingsByID(m_AgentTypeID);
if (settings.agentTypeID != -1) if (settings.agentTypeID != -1)
......
fileFormatVersion: 2
guid: 7a5ac11cc976e418e8d13136b07e1f52
timeCreated: 1477658803
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: e4f97225bcfb64760a1c81f460837f01, type: 3}
userData:
assetBundleName:
assetBundleVariant:
...@@ -21,7 +21,7 @@ https://docs.google.com/document/d/1g1KE59K7HQq25kAMxweRt5ePXkEMvgNnAU3zfX_R7m8 ...@@ -21,7 +21,7 @@ https://docs.google.com/document/d/1g1KE59K7HQq25kAMxweRt5ePXkEMvgNnAU3zfX_R7m8
Download the feature build which is based on Unity 5.5 Download the feature build which is based on Unity 5.5
http://beta.unity3d.com/download/98b817aefff4/public_download.html http://beta.unity3d.com/download/701843f9b69e/public_download.html
Clone or download this repository and open the project using the feature build. Clone or download this repository and open the project using the feature build.
Alternatively, you can copy the contents of `Assets/` to an existing project. Alternatively, you can copy the contents of `Assets/` to an existing project.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册