internal static PrefabStage OpenPrefab(string prefabAssetPath, GameObject openedFromInstance, PrefabStage.Mode prefabStageMode, StageNavigationManager.Analytics.ChangeType changeTypeAnalytics) { if (string.IsNullOrEmpty(prefabAssetPath)) { throw new ArgumentNullException(nameof(prefabAssetPath)); } if (openedFromInstance != null && !PrefabUtility.IsPartOfPrefabInstance(openedFromInstance)) { throw new ArgumentException("GameObject must be part of a Prefab instance, or null.", nameof(openedFromInstance)); } if (!prefabAssetPath.EndsWith(".prefab", StringComparison.OrdinalIgnoreCase)) { throw new ArgumentException("Incorrect file extension: " + prefabAssetPath + ". Must be '.prefab'", nameof(prefabAssetPath)); } if (AssetDatabase.LoadMainAssetAtPath(prefabAssetPath) == null) { throw new ArgumentException("Prefab not found at path " + prefabAssetPath, nameof(prefabAssetPath)); } return(OpenPrefabMode(prefabAssetPath, openedFromInstance, prefabStageMode, changeTypeAnalytics)); }
internal static PrefabStage OpenPrefab(string prefabAssetPath, GameObject openedFromInstance, StageNavigationManager.Analytics.ChangeType changeTypeAnalytics) { var prefabStageMode = openedFromInstance != null ? PrefabStage.Mode.InContext : PrefabStage.Mode.InIsolation; return(OpenPrefab(prefabAssetPath, openedFromInstance, prefabStageMode, changeTypeAnalytics)); }
internal static PrefabStage OpenPrefab(string prefabAssetPath, GameObject instanceRoot, StageNavigationManager.Analytics.ChangeType changeTypeAnalytics) { if (string.IsNullOrEmpty(prefabAssetPath)) { throw new ArgumentNullException(prefabAssetPath); } if (!prefabAssetPath.EndsWith(".prefab", StringComparison.OrdinalIgnoreCase)) { throw new ArgumentException("Incorrect file extension: " + prefabAssetPath + ". Must be '.prefab'", prefabAssetPath); } if (AssetDatabase.LoadMainAssetAtPath(prefabAssetPath) == null) { throw new ArgumentException("Prefab not found at path " + prefabAssetPath, prefabAssetPath); } return(StageNavigationManager.instance.OpenPrefabMode(prefabAssetPath, instanceRoot, changeTypeAnalytics)); }
internal static PrefabStage OpenPrefabMode(string prefabAssetPath, GameObject openedFromInstance, PrefabStage.Mode prefabStageMode, StageNavigationManager.Analytics.ChangeType changeTypeAnalytics) { if (EditorApplication.isPlaying) { bool blockPrefabModeInPlaymode = CheckIfAnyComponentShouldBlockPrefabModeInPlayMode(prefabAssetPath); if (blockPrefabModeInPlaymode) { return(null); } } PrefabStage prevPrefabStage = GetCurrentPrefabStage(); bool setAsFirstItemAfterMainStage = prevPrefabStage == null || !IsPartOfPrefabStage(openedFromInstance, prevPrefabStage); var previousSelection = Selection.activeGameObject; UInt64 previousFileID = (openedFromInstance != null) ? GetFileIDForCorrespondingObjectFromSourceAtPath(previousSelection, prefabAssetPath) : 0; // Ensure valid prefabStageMode (if no context then do not allow Prefab Mode in Context) if (openedFromInstance == null && prefabStageMode != PrefabStage.Mode.InIsolation) { prefabStageMode = PrefabStage.Mode.InIsolation; } Stage contextStage = null; if (prefabStageMode == PrefabStage.Mode.InContext) { var stageHistory = StageNavigationManager.instance.stageHistory; contextStage = stageHistory[stageHistory.Count - 1].GetContextStage(); } var prefabStage = GetExistingPrefabStage(prefabAssetPath, openedFromInstance, prefabStageMode); if (prefabStage == null) { prefabStage = PrefabStage.CreatePrefabStage(prefabAssetPath, openedFromInstance, prefabStageMode, contextStage); } if (StageNavigationManager.instance.SwitchToStage(prefabStage, setAsFirstItemAfterMainStage, changeTypeAnalytics)) { // If selection did not change by switching stage by us or user (or if current selection is not part of // the opened prefab stage) then handle automatic selection in new prefab mode. if (Selection.activeGameObject == previousSelection || !prefabStage.IsPartOfPrefabContents(Selection.activeGameObject)) { HandleSelectionWhenSwithingToNewPrefabMode(GetCurrentPrefabStage().prefabContentsRoot, previousFileID); } SceneView.RepaintAll(); return(prefabStage); } else { // Failed to switch to new stage return(null); } }
internal static PrefabStage OpenPrefab(string prefabAssetPath, GameObject instanceRoot, StageNavigationManager.Analytics.ChangeType changeTypeAnalytics) { if (string.IsNullOrEmpty(prefabAssetPath)) { throw new ArgumentNullException(prefabAssetPath); } if (AssetDatabase.LoadMainAssetAtPath(prefabAssetPath) == null) { throw new ArgumentException("Prefab not found at path " + prefabAssetPath, prefabAssetPath); } return(StageNavigationManager.instance.OpenPrefabMode(prefabAssetPath, instanceRoot, changeTypeAnalytics)); }