Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Examples: Make Bake and Clear buttons visible again #182

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 18 additions & 9 deletions Assets/Examples/Editor/NavMeshPrefabInstanceEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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))
{
Expand All @@ -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<GameObject>(path);

if (string.IsNullOrEmpty(path))
{
Expand Down