public UniqueObject( Object obj ) { #if USE_STRONG_EDITOR_REFS editorLocalId = 0; #endif scene = new AmsSceneReference(); fullPath = string.Empty; componentName = string.Empty; version = CurrentSerializedVersion; componentIndex = 0; if ( !obj ) return; GameObject gameObject = GameObjectEx.EditorGetGameObjectFromComponent( obj ); if ( gameObject ) { scene = new AmsSceneReference( gameObject.scene ); fullPath = gameObject.GetFullName(); Component comp = obj as Component; if ( comp ) { componentName = obj.GetType().AssemblyQualifiedName; gameObject.GetComponents( obj.GetType(), _reusableComponentsList ); componentIndex = _reusableComponentsList.IndexOf( comp ); } } #if USE_STRONG_EDITOR_REFS editorLocalId = GetEditorId( obj ); #endif }
/// <summary> /// Construct from a Unity SceneSetup /// </summary> public SceneEntry(UnityEditor.SceneManagement.SceneSetup sceneSetup) { scene = new AmsSceneReference(sceneSetup.path); loadInEditor = sceneSetup.isLoaded; loadMethod = LoadMethod.Additive; }
/// <summary> /// Allow us to construct a UniqueObject at runtime. /// This will allow us to store references across scenes at runtime if we desire. /// </summary> /// <param name="component">The component to point to.</param> public UniqueObject(Component component) { if (!component) { throw new System.ArgumentNullException("component"); } editorLocalId = 0; editorPrefabRelativePath = string.Empty; version = CurrentSerializedVersion; // The full scene/path var gameObject = component.gameObject; scene = new AmsSceneReference(gameObject.scene); fullPath = gameObject.GetFullName(); // Component (Type) Name var compType = component.GetType(); componentName = compType.AssemblyQualifiedName; // Get Components gameObject.GetComponents(compType, _reusableComponentsList); componentIndex = _reusableComponentsList.IndexOf(component); }
/// <summary> /// Construct from a Unity SceneSetup /// </summary> public SceneEntry( UnityEditor.SceneManagement.SceneSetup sceneSetup ) { scene = new AmsSceneReference( sceneSetup.path ); loadInEditor = sceneSetup.isLoaded; loadMethod = LoadMethod.Additive; }
public UniqueObject(Object obj) { scene = new AmsSceneReference(); fullPath = string.Empty; componentName = string.Empty; version = CurrentSerializedVersion; componentIndex = 0; editorLocalId = 0; editorPrefabRelativePath = string.Empty; if (!obj) { return; } GameObject gameObject = GameObjectEx.EditorGetGameObjectFromComponent(obj); if (gameObject) { scene = new AmsSceneReference(gameObject.scene); fullPath = gameObject.GetFullName(); Component comp = obj as Component; if (comp) { componentName = obj.GetType().AssemblyQualifiedName; gameObject.GetComponents(obj.GetType(), _reusableComponentsList); componentIndex = _reusableComponentsList.IndexOf(comp); } } #if UNITY_2018_3_OR_NEWER // Get the nearest root (which will have an editor id) var prefabObj = PrefabUtility.GetPrefabInstanceHandle(obj); if (prefabObj) { editorLocalId = GetEditorId(prefabObj); var prefabRoot = PrefabUtility.GetOutermostPrefabInstanceRoot(obj); editorPrefabRelativePath = TransformEx.GetPathRelativeTo(gameObject.transform, prefabRoot.transform); } #else // Get the prefab object var prefabObj = PrefabUtility.GetPrefabObject(obj); if (prefabObj) { GameObject prefabRoot = PrefabUtility.FindPrefabRoot(gameObject); editorLocalId = prefabRoot ? GetEditorId(prefabRoot) : GetEditorId(obj); editorPrefabRelativePath = TransformEx.GetPathRelativeTo(gameObject.transform, prefabRoot.transform); } #endif if (editorLocalId == 0) { editorLocalId = GetEditorId(obj); } }
void Awake() { AmsDebug.Log(this, "{0}.Awake() Scene: {1}. IsLoaded: {2}. Path: {3}. Frame: {4}. Root Count: {5}", GetType().Name, gameObject.scene.name, gameObject.scene.isLoaded, gameObject.scene.path, Time.frameCount, gameObject.scene.rootCount); // Upgrade us (we upgraded the Cross-Scene Reference data) // This may freak out users on their first run since it will look like their cross-scene references are gone // In reality, they are just in the scene, ready to be re-created on save if (_version < CurrentSerializedVersion) { int numCrossSceneRefs = _crossSceneReferences.Count; ConditionalResolveReferences(_crossSceneReferences); if (numCrossSceneRefs != _crossSceneReferences.Count) { AmsDebug.LogWarning(this, "{0} was upgraded. {1} cross-scene references will be re-created on next save.", name, numCrossSceneRefs - _crossSceneReferences.Count); } else { AmsDebug.LogWarning(this, "{0} needs upgrading. Please resave {1}", name, gameObject.scene.name); } #if UNITY_EDITOR if (!Application.isPlaying) { GameObject gameObject = this.gameObject; EditorApplication.delayCall += () => { if (gameObject) { EditorSceneManager.MarkSceneDirty(gameObject.scene); } }; } #endif } // Make sure we keep track of all of the merged scenes AmsSceneReference thisScene = new AmsSceneReference(gameObject.scene); foreach (var prevScene in _mergedScenes) { _activeMergedScenes.Add(prevScene, thisScene); } // We need to queue our cross-scene references super early in case we get merged. _referencesToResolve.Clear(); _referencesToResolve.AddRange(_crossSceneReferences); // We should be able to merge our cross-scene references to any other loaded scene here. ResolvePendingCrossSceneReferences(); }
/// <summary> /// This is called during the build pipeline to ensure a proper merge from one scene into another, taking into account cross-scene references /// </summary> /// <param name="sourceSceneSetup">The scene we're merging from</param> /// <param name="destSceneSetup">The scene we're merging to</param> public static void EditorBuildPipelineMergeScene(AmsMultiSceneSetup sourceSceneSetup, AmsMultiSceneSetup destSceneSetup) { // This is happening during the build system, so we're going to end up with a scene name of 0.backup // So we need to get the actual path from the AmsMultiSceneSetup object and clobber it. var amsFromSceneRef = new AmsSceneReference(sourceSceneSetup.gameObject.scene); amsFromSceneRef.editorPath = sourceSceneSetup.scenePath; var amsIntoSceneRef = new AmsSceneReference(destSceneSetup.gameObject.scene); amsIntoSceneRef.editorPath = destSceneSetup.scenePath; // Now get the cross-scene references from both scenes to merge them var srcCrossSceneRefs = GetSceneSingleton(sourceSceneSetup.gameObject.scene, false); if (!srcCrossSceneRefs) { return; } var destCrossSceneRefs = GetSceneSingleton(destSceneSetup.gameObject.scene, true); for (int i = 0; i < srcCrossSceneRefs._crossSceneReferences.Count; ++i) { var xRef = srcCrossSceneRefs._crossSceneReferences[i]; if (!srcCrossSceneRefs._referencesToResolve.Contains(xRef)) { AmsDebug.Log(srcCrossSceneRefs, "Already resolved xRef {0}. No need to merge it.", xRef); continue; } AmsDebug.Log(destSceneSetup, "Merging {0} into Scene {1}", xRef, amsIntoSceneRef.editorPath); xRef.DEPRECATED_fromScene = amsIntoSceneRef; destCrossSceneRefs.AddReference(xRef); } // Mark this as a merged scene in the destination, so when we look-up cross-scene references we're aware. destCrossSceneRefs._mergedScenes.Add(amsFromSceneRef); // Destroy this object after the merge is complete (we don't want it merged into the scene) GameObject.DestroyImmediate(srcCrossSceneRefs.gameObject, false); }
public UniqueObject(Object obj) { scene = new AmsSceneReference(); fullPath = string.Empty; componentName = string.Empty; version = CurrentSerializedVersion; componentIndex = 0; editorLocalId = 0; editorPrefabRelativePath = string.Empty; if (!obj) { return; } GameObject gameObject = GameObjectEx.EditorGetGameObjectFromComponent(obj); if (gameObject) { scene = new AmsSceneReference(gameObject.scene); fullPath = gameObject.GetFullName(); Component comp = obj as Component; if (comp) { componentName = obj.GetType().AssemblyQualifiedName; gameObject.GetComponents(obj.GetType(), _reusableComponentsList); componentIndex = _reusableComponentsList.IndexOf(comp); } } // Get the prefab object var prefabObj = PrefabUtility.GetPrefabObject(obj); if (prefabObj) { GameObject prefabRoot = PrefabUtility.FindPrefabRoot(gameObject); editorLocalId = prefabObj ? GetEditorId(prefabObj) : GetEditorId(obj); editorPrefabRelativePath = TransformEx.GetPathRelativeTo(gameObject.transform, prefabRoot.transform); } }
public UniqueObject(Object obj) { #if USE_STRONG_EDITOR_REFS editorLocalId = 0; #endif scene = new AmsSceneReference(); fullPath = string.Empty; componentName = string.Empty; version = CurrentSerializedVersion; componentIndex = 0; if (!obj) { return; } GameObject gameObject = GameObjectEx.EditorGetGameObjectFromComponent(obj); if (gameObject) { scene = new AmsSceneReference(gameObject.scene); fullPath = gameObject.GetFullName(); Component comp = obj as Component; if (comp) { componentName = obj.GetType().AssemblyQualifiedName; gameObject.GetComponents(obj.GetType(), _reusableComponentsList); componentIndex = _reusableComponentsList.IndexOf(comp); } } #if USE_STRONG_EDITOR_REFS editorLocalId = GetEditorId(obj); #endif }