static UInt64 GetFileIDForCorrespondingObjectFromSourceAtPath(GameObject gameObject, string prefabAssetPath) { if (gameObject == null) { return(0); } if (EditorUtility.IsPersistent(gameObject)) { return(0); } if (!PrefabUtility.IsPartOfNonAssetPrefabInstance(gameObject)) { return(0); } GameObject assetGameObject = PrefabUtility.GetCorrespondingObjectFromSourceAtPath(gameObject, prefabAssetPath); if (assetGameObject == null) { return(0); } return(SceneHierarchyState.GetOrGenerateFileID(assetGameObject)); }
static void HandleSelectionWhenSwithingToNewPrefabMode(GameObject prefabContentsRoot, UInt64 previousFileID) { GameObject newSelection = null; if (previousFileID != 0) { newSelection = SceneHierarchyState.FindFirstGameObjectThatMatchesFileID(prefabContentsRoot.transform, previousFileID); } if (newSelection == null) { newSelection = prefabContentsRoot; } Selection.activeGameObject = newSelection; // For Prefab Mode we restore the last expanded tree view state for the opened Prefab. For usability // if a child GameObject on the Prefab Instance is selected when entering the Prefab Asset Mode we select the corresponding // child GameObject in the Asset. Here we ensure that selction is revealed and framed in the Scene hierarchy. if (newSelection != prefabContentsRoot) { foreach (SceneHierarchyWindow shw in SceneHierarchyWindow.GetAllSceneHierarchyWindows()) { shw.FrameObject(newSelection.GetInstanceID(), false); } } }
static void HandleSelectionWhenSwithingToNewPrefabMode(GameObject prefabContentsRoot, UInt64 previousFileID) { GameObject newSelection = null; if (previousFileID != 0) { newSelection = SceneHierarchyState.FindFirstGameObjectThatMatchesFileID(prefabContentsRoot.transform, previousFileID); } if (newSelection == null) { newSelection = prefabContentsRoot; } Selection.activeGameObject = newSelection; }