diff --git a/Assets/Examples/Editor/NavMeshPrefabInstanceEditor.cs b/Assets/Examples/Editor/NavMeshPrefabInstanceEditor.cs index 3c3f5890..ad5b9827 100644 --- a/Assets/Examples/Editor/NavMeshPrefabInstanceEditor.cs +++ b/Assets/Examples/Editor/NavMeshPrefabInstanceEditor.cs @@ -35,20 +35,30 @@ public override void OnInspectorGUI() serializedObject.ApplyModifiedProperties(); } - void OnInspectorGUIPrefab(GameObject go) + string GetAssetPath(GameObject go) { - var prefab = PrefabUtility.GetPrefabInstanceHandle(go); - var path = AssetDatabase.GetAssetPath(prefab); + var stage = UnityEditor.Experimental.SceneManagement.PrefabStageUtility.GetCurrentPrefabStage(); + if (stage != null && stage.IsPartOfPrefabContents(go)) + { + return stage.prefabAssetPath; + } + return PrefabUtility.GetPrefabAssetPathOfNearestInstanceRoot(go); + } - if (prefab && string.IsNullOrEmpty(path)) + void OnInspectorGUIPrefab(GameObject go) + { + var stage = UnityEditor.Experimental.SceneManagement.PrefabStageUtility.GetCurrentPrefabStage(); + if (stage == null || !stage.IsPartOfPrefabContents(go)) { - if (GUILayout.Button("Select the Prefab asset to bake or clear the navmesh", EditorStyles.helpBox)) + if (GUILayout.Button("Edit the Prefab asset to bake or clear the navmesh", EditorStyles.helpBox)) { Selection.activeObject = PrefabUtility.GetCorrespondingObjectFromSource(go); EditorGUIUtility.PingObject(Selection.activeObject); } + return; } + var path = GetAssetPath(go); if (string.IsNullOrEmpty(path)) return; @@ -85,8 +95,7 @@ void OnClear() { var instance = (NavMeshPrefabInstance)tgt; var go = instance.gameObject; - var prefab = PrefabUtility.GetPrefabInstanceHandle(go); - var path = AssetDatabase.GetAssetPath(prefab); + var path = GetAssetPath(go); if (string.IsNullOrEmpty(path)) { @@ -105,8 +114,8 @@ void OnBake() { var instance = (NavMeshPrefabInstance)tgt; var go = instance.gameObject; - var prefab = PrefabUtility.GetPrefabInstanceHandle(go); - var path = AssetDatabase.GetAssetPath(prefab); + var path = GetAssetPath(go); + var prefab = AssetDatabase.LoadAssetAtPath(path); if (string.IsNullOrEmpty(path)) {