static void RestoreCrossSceneReferences()
		{
			Scene activeScene = new Scene();
			AmsMultiSceneSetup activeSetup = null;
			List<AmsMultiSceneSetup.SceneEntry> bakedScenes = new List<AmsMultiSceneSetup.SceneEntry>();

			GetCommonParameters( ref activeScene, ref activeSetup, bakedScenes );
			if ( bakedScenes.Count < 1 )
				return;

			AmsDebug.Log( null, "Running RestoreCrossSceneReferences on Scene {0}", activeScene.name );

			// Do the merge (bake)
			var targetCrossRefs = AmsCrossSceneReferences.GetSceneSingleton( activeScene, false );
			if ( targetCrossRefs )
				targetCrossRefs.ResolvePendingCrossSceneReferences();

			foreach( var entry in bakedScenes )
			{
				if ( !entry.scene.isLoaded )
				{
					AmsDebug.LogError( activeSetup, "Could not restore cross-scene references for non-loaded scene: {0}", entry.scene.name );
					continue;
				}

				var sourceCrossRefs = AmsCrossSceneReferences.GetSceneSingleton( entry.scene.scene, false );
				if ( sourceCrossRefs )
					sourceCrossRefs.ResolvePendingCrossSceneReferences();
			}
		}
		static void MergeScenes()
		{
			Scene activeScene = new Scene();
			AmsMultiSceneSetup activeSetup = null;
			List<AmsMultiSceneSetup.SceneEntry> bakedScenes = new List<AmsMultiSceneSetup.SceneEntry>();

			GetCommonParameters( ref activeScene, ref activeSetup, bakedScenes );
			if ( bakedScenes.Count < 1 )
				return;

			AmsDebug.Log( null, "Running MergeScenes on Scene {0}", activeScene.name );

			foreach( var entry in bakedScenes )
			{
				if ( !entry.scene.isLoaded )
				{
					AmsDebug.LogError( activeSetup, "Could not merge non-loaded scene: {0}", entry.scene.name );
					continue;
				}

				var sourceCrossRefs = AmsCrossSceneReferences.GetSceneSingleton( entry.scene.scene, false );
				if ( sourceCrossRefs )
					GameObject.DestroyImmediate( sourceCrossRefs.gameObject, false );

				AmsDebug.Log( null, "Merging {0} into {1}", entry.scene.name, activeScene.name );
				EditorSceneManager.MergeScenes( entry.scene.scene, activeScene );
			}
		} // MergeScenes
		static void MergeScenes()
		{
			Scene activeScene = new Scene();
			AmsMultiSceneSetup activeSetup = null;
			List<AmsMultiSceneSetup.SceneEntry> bakedScenes = new List<AmsMultiSceneSetup.SceneEntry>();

			GetCommonParameters( ref activeScene, ref activeSetup, bakedScenes );
			if ( bakedScenes.Count < 1 )
				return;

			AmsDebug.Log( null, "Running AMS MergeScenes on Scene {0} ({1})", activeScene.name, activeSetup.scenePath );

			foreach( var entry in bakedScenes )
			{
				if ( !entry.scene.isLoaded )
				{
					AmsDebug.LogError( activeSetup, "Could not merge non-loaded scene: {0}", entry.scene.name );
					continue;
				}

				// Merge the cross-scene references (and keep track of the merges)
				var bakedSceneSetup = GameObjectEx.GetSceneSingleton<AmsMultiSceneSetup>( entry.scene.scene, false );
				if ( bakedSceneSetup )
					AmsCrossSceneReferences.EditorBuildPipelineMergeScene( bakedSceneSetup, activeSetup );

				AmsDebug.Log( null, "Running Unity MergeScenes for {0} into {1}", entry.scene.name, activeScene.name );
				EditorSceneManager.MergeScenes( entry.scene.scene, activeScene );
			}
		} // MergeScenes
Пример #4
0
        /// <summary>
        /// Save all of the passed-in cross-scene references.  The entries in the passed-in list will be removed as they are properly accounted for.
        /// </summary>
        /// <param name="editorCrossSceneRefs"></param>
        public static void SaveCrossSceneReferences( List<EditorCrossSceneReference> editorCrossSceneRefs )
        {
            // Save all of the cross-scene references, removing them from our input list as we receive them
            for( int i = editorCrossSceneRefs.Count-1 ; i >= 0 ; --i)
            {
                var xRef = editorCrossSceneRefs[i];

				AmsDebug.Log( null, "Saving Cross-Scene Reference: {0}", xRef );
				
                try
                {
					RuntimeCrossSceneReference serializedReference = xRef.ToSerializable();

					try
					{
						// Save the object
						var initialObject = xRef.fromProperty.objectReferenceValue;
						
						// Resolve it (this can throw exceptions)
						AmsCrossSceneReferenceResolver.Resolve( serializedReference );
#if UNITY_5_6_OR_NEWER
						xRef.fromProperty.serializedObject.UpdateIfRequiredOrScript();
#else
						xRef.fromProperty.serializedObject.UpdateIfDirtyOrScript();
#endif

						// Check to make sure it resolved properly
						if ( initialObject && xRef.fromProperty.objectReferenceValue != initialObject )
							throw new ResolveException( string.Format("Resolve should have pointed to {0} ({1}) but instead resolved to {2} ({3})", initialObject ? initialObject.ToString() : "(null)", initialObject ? initialObject.GetInstanceID() : 0, xRef.fromProperty.objectReferenceValue, xRef.fromProperty.objectReferenceInstanceIDValue) );
					}
					catch ( System.Exception ex )
					{
						AmsDebug.LogError( xRef.fromObject, "Could not perform a runtime resolve on cross-scene reference {0}.\nReason: {1}. Please review Documentation.", serializedReference, ex.Message );
						continue;
					}

					// Record the cross-scene reference
					var crossSceneRefBehaviour = AmsCrossSceneReferences.GetSceneSingleton( xRef.fromScene, true );
					crossSceneRefBehaviour.AddReference( serializedReference );

                    // Add an updated reference map value
                    if ( _referenceMap != null )
                        _referenceMap.Add( new KeyValuePair<SerializedProperty, Object>(xRef.fromProperty, xRef.fromProperty.objectReferenceValue) );
                }
                catch ( UnityException ex )
                {
                    Debug.LogException( ex );
                }
            }
        }
Пример #5
0
        /// <summary>
        /// Given a property, let's return a runtime serializeable field string.
        /// </summary>
        /// <param name="property">The property to capture the field from</param>
        /// <returns>The field string which can be parsed at runtime</returns>
        private string ToRuntimeSerializableField(SerializedProperty property)
        {
            const string ARRAY_INDICATOR      = "@ArrayIndex[";
            int          arrayIndicatorLength = ARRAY_INDICATOR.Length;

            // Give us an easy sentinel value to scan for in case of arrays
            string parseablePropertyPath = property.propertyPath.Replace(".Array.data[", "." + ARRAY_INDICATOR);
            var    splitPaths            = parseablePropertyPath.Split('.');

            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            for (int i = 0; i < splitPaths.Length; ++i)
            {
                string pathPiece = splitPaths[i];

                bool bIsArrayIndex = pathPiece.StartsWith(ARRAY_INDICATOR);
                if (!bIsArrayIndex)
                {
                    // Append the . if we're a nested object
                    if (i > 0)
                    {
                        sb.Append('.');
                    }

                    sb.Append(pathPiece);
                }
                else
                {
                    // It's an array, so we're doing the index portion of @ArrayIndex[index]
                    string indexString = pathPiece.Substring(arrayIndicatorLength, pathPiece.Length - arrayIndicatorLength - 1);

                    int arrayIndex = 0;
                    if (int.TryParse(indexString, out arrayIndex))
                    {
                        // Arrays are of the form fieldName,arrayIndex
                        sb.Append(',');
                        sb.Append(arrayIndex);
                    }
                    else
                    {
                        AmsDebug.LogError(null, "Could not parse array index for property path {0}", property.propertyPath);
                    }
                }
            }

            return(sb.ToString());
        }
        internal static void LoadScenesForMerging()
		{
			Scene activeScene = new Scene();
			AmsMultiSceneSetup activeSetup = null;
			List<AmsMultiSceneSetup.SceneEntry> bakedScenes = new List<AmsMultiSceneSetup.SceneEntry>();

			GetCommonParameters( ref activeScene, ref activeSetup, bakedScenes );
			if ( bakedScenes.Count < 1 )
				return;

			AmsDebug.Log( null, "Running LoadScenesForBaking on Scene {0}", activeScene.name );

			// Now load all of the scenes
			foreach( var entry in bakedScenes )
			{
				var realScene = entry.scene.scene;
				if ( !realScene.IsValid() )
				{
					// This is good.  This means it's not loaded yet.
					realScene = EditorSceneManager.OpenScene( entry.scene.editorPath, OpenSceneMode.Additive );

					if ( !realScene.IsValid() )
					{
						AmsDebug.LogError( activeSetup, "BakeScene: Scene {0} ({1}) referenced from Multi-Scene Setup in {2} is invalid.", entry.scene.editorPath, entry.scene.name, activeScene.name );
						continue;
					}
				}

				// Let's catch this...
				if ( !realScene.isLoaded )
				{
					realScene = EditorSceneManager.OpenScene( realScene.path, OpenSceneMode.Additive );
					
					// if we're still not loaded, we're probably in trouble.
					if ( !realScene.isLoaded )
					{
						AmsDebug.LogError( activeSetup, "BakeScene: Scene {0} ({1}) referenced from Multi-Scene Setup in {2} could not load.", entry.scene.editorPath, entry.scene.name, activeScene.name );
						continue;
					}
				}
			}
		}