private static ScriptableObject CloneReferencedPlayableAsset(ScriptableObject original, PlayableDirector directorInstance) { ScriptableObject scriptableObject = Object.Instantiate <ScriptableObject>(original); if (scriptableObject == null || !(scriptableObject is IPlayableAsset)) { throw new InvalidCastException("could not cast instantiated object into IPlayableAsset"); } if (directorInstance != null) { SerializedObject serializedObject = new SerializedObject(original); SerializedObject serializedObject2 = new SerializedObject(scriptableObject); SerializedProperty iterator = serializedObject.GetIterator(); if (iterator.Next(true)) { do { serializedObject2.CopyFromSerializedProperty(iterator); }while (iterator.Next(false)); } serializedObject2.ApplyModifiedProperties(); EditorUtility.SetDirty(directorInstance); } if (directorInstance != null) { List <FieldInfo> list = (from f in scriptableObject.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic) where f.FieldType.IsGenericType && f.FieldType.GetGenericTypeDefinition() == typeof(ExposedReference) select f).ToList <FieldInfo>(); foreach (FieldInfo current in list) { object value = current.GetValue(scriptableObject); FieldInfo field = value.GetType().GetField("exposedName"); if (field != null) { PropertyName propertyName = (PropertyName)field.GetValue(value); bool flag = false; Object referenceValue = directorInstance.GetReferenceValue(propertyName, ref flag); if (flag) { PropertyName propertyName2 = new PropertyName(GUID.Generate().ToString()); directorInstance.SetReferenceValue(propertyName2, referenceValue); field.SetValue(value, propertyName2); } } current.SetValue(scriptableObject, value); } } IEnumerable <FieldInfo> enumerable = from f in scriptableObject.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic) where !f.IsNotSerialized && f.FieldType == typeof(AnimationClip) select f; foreach (FieldInfo current2 in enumerable) { current2.SetValue(scriptableObject, TimelineHelpers.CloneAnimationClipIfRequired(current2.GetValue(scriptableObject) as AnimationClip, original)); } return(scriptableObject); }
public static TrackAsset Clone(PlayableAsset parent, TrackAsset trackAsset, PlayableDirector directorInstance) { TrackAsset result; if (trackAsset == null) { result = null; } else { TimelineAsset timelineAsset = trackAsset.timelineAsset; if (timelineAsset == null) { result = null; } else { TrackAsset trackAsset2 = Object.Instantiate <TrackAsset>(trackAsset); trackAsset2.SetClips(new List <TimelineClip>()); trackAsset2.parent = parent; trackAsset2.subTracks = new List <TrackAsset>(); string[] array = (from x in timelineAsset.flattenedTracks select x.get_name()).ToArray <string>(); trackAsset2.set_name(ObjectNames.GetUniqueName(array, trackAsset.get_name())); if (trackAsset.animClip != null) { trackAsset2.animClip = TimelineHelpers.CloneAnimationClipIfRequired(trackAsset.animClip, trackAsset); } TimelineClip[] clips = trackAsset.clips; for (int i = 0; i < clips.Length; i++) { TimelineClip clip = clips[i]; TimelineClip timelineClip = TimelineHelpers.Clone(clip, directorInstance); timelineClip.parentTrack = trackAsset2; trackAsset2.AddClip(timelineClip); } trackAsset2.SetCollapsed(trackAsset.GetCollapsed()); if (SelectionManager.Contains(trackAsset)) { SelectionManager.Remove(trackAsset); SelectionManager.Add(trackAsset2); } result = trackAsset2; } } return(result); }