public static CSSceneTools.OpenSceneResult OpenSceneForReveal(string path) { var result = CSSceneTools.OpenScene(path); if (result.success) { CSSceneTools.CloseUntitledSceneIfNotDirty(); if (CSEditorTools.lastRevealSceneOpenResult != null) { if (CSSceneTools.IsOpenedSceneNeedsToBeClosed(CSEditorTools.lastRevealSceneOpenResult, path, true)) { if (CSEditorTools.lastRevealSceneOpenResult.scene.isDirty) { if (!CSSceneTools.SaveDirtyScenesWithPrompt( new[] { CSEditorTools.lastRevealSceneOpenResult.scene })) { return(new CSSceneTools.OpenSceneResult()); } } } CSSceneTools.CloseOpenedSceneIfNeeded(CSEditorTools.lastRevealSceneOpenResult, path, true); } CSEditorTools.lastRevealSceneOpenResult = result; } return(result); }
private static bool RevealAndSelectGameObjectInScene(string path, string transformPath, long objectId, long componentId) { Scene targetScene; if (!string.IsNullOrEmpty(path)) { var openResult = OpenSceneForReveal(path); if (!openResult.success) { return(false); } targetScene = openResult.scene; } else { targetScene = CSSceneTools.GetUntitledScene(); } if (!targetScene.IsValid()) { Debug.LogError(Maintainer.ConstructError("Target scene is not valid or not found! Scene path: " + path + ", looked for ObjectID " + objectId + "!")); return(false); } var target = CSObjectTools.FindGameObjectInScene(targetScene, objectId, transformPath); if (target == null) { Debug.LogError(Maintainer.ConstructError("Couldn't find target Game Object " + transformPath + " at " + path + " with ObjectID " + objectId + "!")); return(false); } // workaround for a bug when Unity doesn't expand hierarchy in scene EditorApplication.delayCall += () => { EditorGUIUtility.PingObject(target); }; CSObjectTools.SelectGameObject(target, true); var enclosingAssetInstanceId = CSAssetTools.GetMainAssetInstanceID(path); EditorApplication.delayCall += () => { EditorGUIUtility.PingObject(enclosingAssetInstanceId); }; if (componentId != -1) { return(TryFoldAllComponentsExceptId(componentId)); } return(true); }
public static void RevealAndSelectReferencingEntry(string assetPath, ReferencingEntryData referencingEntry) { if (!string.IsNullOrEmpty(assetPath) && (referencingEntry.location == Location.SceneLightingSettings || referencingEntry.location == Location.SceneNavigationSettings)) { var sceneOpenResult = CSSceneTools.OpenSceneWithSavePrompt(assetPath); if (!sceneOpenResult.success) { Debug.LogError(Maintainer.ConstructError("Can't open scene " + assetPath)); MaintainerWindow.ShowNotification("Can't show it properly"); return; } } switch (referencingEntry.location) { case Location.ScriptAsset: case Location.ScriptableObjectAsset: if (!RevealAndSelectFileAsset(assetPath)) { MaintainerWindow.ShowNotification("Can't show it properly"); } break; case Location.PrefabAssetObject: if (!RevealAndSelectSubAsset(assetPath, referencingEntry.transformPath, referencingEntry.objectId)) { MaintainerWindow.ShowNotification("Can't show it properly"); } break; case Location.PrefabAssetGameObject: case Location.SceneGameObject: if (!RevealAndSelectGameObject(assetPath, referencingEntry.transformPath, referencingEntry.objectId, referencingEntry.componentId)) { MaintainerWindow.ShowNotification("Can't show it properly"); } break; case Location.SceneLightingSettings: if (!CSMenuTools.ShowSceneSettingsLighting()) { Debug.LogError(Maintainer.ConstructError("Can't open Lighting settings!")); MaintainerWindow.ShowNotification("Can't show it properly"); } break; case Location.SceneNavigationSettings: if (!CSMenuTools.ShowSceneSettingsNavigation()) { Debug.LogError(Maintainer.ConstructError("Can't open Navigation settings!")); MaintainerWindow.ShowNotification("Can't show it properly"); } break; case Location.NotFound: case Location.Invisible: break; case Location.TileMap: if (!RevealAndSelectGameObject(assetPath, referencingEntry.transformPath, referencingEntry.objectId, referencingEntry.componentId)) { MaintainerWindow.ShowNotification("Can't show it properly"); } // TODO: open tile map editor window? break; default: throw new ArgumentOutOfRangeException(); } }