Пример #1
0
		/// <summary>
		/// Search the given map for cross-scene references.
		/// </summary>
		/// <param name="map">The map to search</param>
		/// <returns>The list of cross-scene references found in the map</returns>
		private static List<EditorCrossSceneReference> ComputeCrossSceneReferences( List<KeyValuePair<SerializedProperty, Object>> map )
		{
			var refSubSceneMap = new List<EditorCrossSceneReference>();
			var cache = new Dictionary<Object,Scene>();

			// We figure out what the subScene mapping is (from which subScene to which subScene).
			foreach( var pair in map )
			{
				Scene fromScene = FindSceneCached( pair.Key.serializedObject.targetObject, cache );
				Scene toScene = FindSceneCached( pair.Value, cache );

				// Always safe to reference nothing, or a persistent object
				if ( !fromScene.IsValid() || !toScene.IsValid() )
					continue;

				bool bIsWithinSameScene = fromScene.Equals(toScene);
				if ( bIsWithinSameScene )
					continue;

				EditorCrossSceneReference crossRef = new EditorCrossSceneReference();
				crossRef.fromScene = fromScene;
				crossRef.toScene = toScene;
				crossRef.fromProperty = pair.Key;
				crossRef.toInstance = pair.Value;

				refSubSceneMap.Add( crossRef );
			}

			return refSubSceneMap;
		}
        /// <summary>
        /// Check a cross-scene reference for data that cannot be saved by simple field look-ups at runtime.
        /// </summary>
        static List <GenericData> GetCustomCrossSceneReferenceData(EditorCrossSceneReference crossRef)
        {
            var playableDirector = crossRef.fromObject as PlayableDirector;

            if (!playableDirector)
            {
                throw new System.ArgumentException("crossRef.fromObject contained an incompatible class");
            }

            List <GenericData> genericData = new List <GenericData>();

            var    fromProperty     = crossRef.fromProperty;
            string propertyPath     = fromProperty.propertyPath;
            var    serializedObject = fromProperty.serializedObject;

            if (propertyPath.StartsWith("m_SceneBindings") && propertyPath.EndsWith("value"))
            {
                var spElement = serializedObject.FindProperty(fromProperty.propertyPath.Substring(0, fromProperty.propertyPath.Length - fromProperty.name.Length - 1));
                genericData.Add(spElement.FindPropertyRelative("key").objectReferenceValue);
            }
            else if (propertyPath.StartsWith("m_ExposedReferences") && propertyPath.EndsWith("second"))
            {
                var spElement = serializedObject.FindProperty(propertyPath.Substring(0, propertyPath.Length - fromProperty.name.Length - 1));
                genericData.Add(spElement.FindPropertyRelative("first").stringValue);
            }

            return(genericData);
        }
Пример #3
0
		private static EditorCrossSceneReference CreateEditorCrossSceneReference( Object fromObject, Scene fromScene, SerializedProperty fromProperty, Object toObject, Scene toScene )
		{
			EditorCrossSceneReference crossRef = new EditorCrossSceneReference();
			crossRef.fromScene = fromScene;
			crossRef.toScene = toScene;
			crossRef.fromProperty = fromProperty;
			crossRef.toInstance = toObject;

			// Now see if we have a custom processor...
			CustomDataProcessorDelegate customDataProcessor;
			if ( _customCrossSceneReferenceDataProcessors.TryGetValue( fromObject.GetType(), out customDataProcessor ) )
			{
				var customData = customDataProcessor( crossRef );
				if ( customData != null && customData.Count > 0 )
					crossRef.data = customData;
			}

			return crossRef;
		}