private GameObject GetGameObjectFromIndexPath(SceneAddress address) { var path = address.HierarchyIndexPath; if (path.Count == 0) { return(null); } GameObject[] roots = SceneRoots(address.ScenePath).ToArray(); if (path[0] >= roots.Length) { return(null); } Transform curr = roots[path[0]].transform; for (int i = 1; i < path.Count; i++) { curr = curr.GetChild(path[i]); if (curr == null) { return(null); } } return(curr.gameObject); }
private SceneAddress GetRecoveryData(GameObject go, Component co, string scene) { var result = new SceneAddress(); result.ScenePath = scene; result.HierarchyPath = GetGameObjectPath(go.transform); result.HierarchyIndexPath = GetGameObjectIndexPath(go.transform); if (co != null) { result.ComponentType = co.GetType(); result.ComponentIndex = (go.GetComponents(co.GetType()) as IList).IndexOf(co); } return(result); }
public override object GetSource(ValidationProfileResult entry) { if (entry.Source as UnityEngine.Object) { return(entry.Source); } SceneAddress address = (SceneAddress)entry.SourceRecoveryData; // This should work. bool openScene = true; foreach (SceneSetup setupScene in EditorSceneManager.GetSceneManagerSetup()) { if (setupScene.path == address.ScenePath) { openScene = false; if (!setupScene.isActive) { EditorSceneManager.SetActiveScene(EditorSceneManager.GetSceneByPath(setupScene.path)); } break; } } if (openScene) { if (!EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo()) { return(null); } EditorSceneManager.OpenScene(address.ScenePath, OpenSceneMode.Single); } GameObject go = this.GetGameObjectFromIndexPath(address); if (go != null) { entry.Source = go; if (address.ComponentType != null) { Component component = null; Component[] components = go.GetComponents(address.ComponentType); if (address.ComponentIndex >= 0 && address.ComponentIndex < components.Length) { component = components[address.ComponentIndex]; } if (component != null) { entry.Source = component; } } } return(entry.Source); }