// Helper that finds the animation clip we are recording and the relative time to that clip static bool GetClipAndRelativeTime(UnityEngine.Object target, WindowState state, out AnimationClip outClip, out double keyTime, out bool keyInRange) { const float floatToDoubleError = 0.00001f; outClip = null; keyTime = 0; keyInRange = false; double startTime = 0; double timeScale = 1; AnimationClip clip = null; IPlayableAsset playableAsset = target as IPlayableAsset; Component component = target as Component; // Handle recordable playable assets if (playableAsset != null) { var curvesOwner = AnimatedParameterUtility.ToCurvesOwner(playableAsset, state.editSequence.asset); if (curvesOwner != null) { if (curvesOwner.curves == null) { curvesOwner.CreateCurves(curvesOwner.GetUniqueRecordedClipName()); } clip = curvesOwner.curves; var timelineClip = curvesOwner as TimelineClip; if (timelineClip != null) { startTime = timelineClip.start; timeScale = timelineClip.timeScale; } } } // Handle recording components, including infinite clip else if (component != null) { var asset = GetTrackForGameObject(component.gameObject, state); if (asset != null) { clip = GetRecordingClip(asset, state, out startTime, out timeScale); } } if (clip == null) { return(false); } keyTime = (state.editSequence.time - startTime) * timeScale; outClip = clip; keyInRange = keyTime >= 0 && keyTime <= (clip.length * timeScale + floatToDoubleError); return(true); }
internal static IEnumerable <FieldInfo> GetScriptPlayableFields(IPlayableAsset asset) { if (asset == null) { return(new FieldInfo[0]); } return(asset.GetType().GetFields().Where(f => f.IsPublic && !f.IsStatic && typeof(IPlayableBehaviour).IsAssignableFrom(f.FieldType))); }
internal static TimelineClip FindClipWithAsset(TimelineAsset asset, IPlayableAsset target) { if (target == null || asset == null) { return(null); } var clips = asset.flattenedTracks.SelectMany(x => x.clips); return(clips.FirstOrDefault(x => x != null && x.asset != null && target == x.asset as IPlayableAsset)); }
static FieldInfo[] GetScriptPlayableFields_Internal(IPlayableAsset asset) { return(asset.GetType() .GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic) .Where( f => typeof(IPlayableBehaviour).IsAssignableFrom(f.FieldType) && // The field is an IPlayableBehaviour (f.IsPublic || f.GetCustomAttributes(typeof(SerializeField), false).Any()) && // The field is either public or marked with [SerializeField] !f.GetCustomAttributes(typeof(NotKeyableAttribute), false).Any() && // The field is not marked with [NotKeyable] !f.GetCustomAttributes(typeof(HideInInspector), false).Any() && // The field is not marked with [HideInInspector] !f.FieldType.GetCustomAttributes(typeof(NotKeyableAttribute), false).Any()) // The field is not of a type marked with [NotKeyable] .ToArray()); }
/// <summary> /// Creates a timeline clip from an existing playable asset. /// </summary> /// <param name="asset"></param> /// <returns></returns> internal TimelineClip CreateClipFromPlayableAsset(IPlayableAsset asset) { if (asset == null) throw new ArgumentNullException("asset"); if ((asset as ScriptableObject) == null) throw new System.ArgumentException("CreateClipFromPlayableAsset " + " only supports ScriptableObject-derived Types"); if (!ValidateClipType(asset.GetType())) throw new System.InvalidOperationException("Clips of type " + asset.GetType() + " are not permitted on tracks of type " + GetType()); return CreateClipFromAsset(asset as ScriptableObject); }
// Helper that finds the animation clip we are recording and the relative time to that clip static bool GetClipAndRelativeTime(UnityEngine.Object target, WindowState state, out AnimationClip outClip, out double keyTime, out bool keyInRange) { const float floatToDoubleError = 0.00001f; outClip = null; keyTime = 0; keyInRange = false; double startTime = 0; double timeScale = 1; AnimationClip clip = null; IPlayableAsset playableAsset = target as IPlayableAsset; Component component = target as Component; // Handle recordable playable assets if (playableAsset != null) { var timelineClip = FindClipWithAsset(state.editSequence.asset, playableAsset, state.editSequence.director); if (timelineClip != null && state.IsArmedForRecord(timelineClip.parentTrack)) { AnimatedParameterExtensions.CreateCurvesIfRequired(timelineClip); clip = timelineClip.curves; startTime = timelineClip.start; timeScale = timelineClip.timeScale; } } // Handle recording components, including infinite clip else if (component != null) { var asset = GetTrackForGameObject(component.gameObject, state); if (asset != null) { clip = GetRecordingClip(asset, state, out startTime, out timeScale); } } if (clip == null) { return(false); } keyTime = (state.editSequence.time - startTime) * timeScale; outClip = clip; keyInRange = keyTime >= 0 && keyTime <= (clip.length * timeScale + floatToDoubleError); return(true); }
internal virtual void OnCreateClipFromAsset(Object asset, TimelineClip clip) { clip.asset = asset; clip.displayName = asset.name; IPlayableAsset playableAsset = asset as IPlayableAsset; if (playableAsset != null) { double duration = playableAsset.duration; if (duration > 0.0 && !double.IsInfinity(duration)) { clip.duration = duration; } } }
public static FieldInfo[] GetScriptPlayableFields(IPlayableAsset asset) { if (asset == null) { return(new FieldInfo[0]); } FieldInfo[] scriptPlayableFields; if (!AnimatedParameterCache.TryGetScriptPlayableFields(asset.GetType(), out scriptPlayableFields)) { scriptPlayableFields = GetScriptPlayableFields_Internal(asset); AnimatedParameterCache.SetScriptPlayableFields(asset.GetType(), scriptPlayableFields); } return(scriptPlayableFields); }
internal static IEnumerable <FieldInfo> GetScriptPlayableFields(IPlayableAsset asset) { IEnumerable <FieldInfo> result; if (asset == null) { result = new FieldInfo[0]; } else { result = from f in asset.GetType().GetFields() where f.IsPublic && !f.IsStatic && typeof(IPlayableBehaviour).IsAssignableFrom(f.FieldType) select f; } return(result); }
public static ICurvesOwner ToCurvesOwner(IPlayableAsset playableAsset, TimelineAsset timeline) { if (playableAsset == null) { return(null); } var curvesOwner = playableAsset as ICurvesOwner; if (curvesOwner == null) { // If the asset is not directly an ICurvesOwner, it might be the asset for a TimelineClip curvesOwner = TimelineRecording.FindClipWithAsset(timeline, playableAsset); } return(curvesOwner); }
//Finds the TimelineClip corresponding to a playable asset in a timeline public static TimelineClip GetClip(TimelineAsset timeline, IPlayableAsset Clip) { if (timeline != null) { for (int i = 0; i < timeline.rootTrackCount; i++) { TimelineClip clip = GetClipInAllTracks(timeline.GetRootTrack(i), Clip); if (clip != null) { return(clip); } } } return(null); }
//Finds the TimelineClip corresponding to a playable asset in a parent track public static TimelineClip GetClip(TrackAsset track, IPlayableAsset Clip) { if (track != null) { IEnumerable <TimelineClip> clips = track.GetClips(); foreach (TimelineClip clip in clips) { if (clip.asset == (Object)Clip) { return(clip); } } } return(null); }
public static int get_outputs(IntPtr l) { int result; try { IPlayableAsset playableAsset = (IPlayableAsset)LuaObject.checkSelf(l); LuaObject.pushValue(l, true); LuaObject.pushValue(l, playableAsset.outputs); result = 2; } catch (Exception e) { result = LuaObject.error(l, e); } return(result); }
//Finds the TimelineClip corresponding to a playable asset in a timeline public static TimelineClip GetClip(TimelineAsset timeline, IPlayableAsset Clip) { if (timeline != null) { foreach (TrackAsset track in timeline.GetRootTracks()) { TimelineClip clip = GetClipInAllTracks(track, Clip); if (clip != null) { return(clip); } } } return(null); }
public void AddObjectProperties(Object obj, AnimationClip clip) { if (!(obj == null) && !(clip == null)) { IPlayableAsset playableAsset = obj as IPlayableAsset; IPlayableBehaviour playableBehaviour = obj as IPlayableBehaviour; if (playableAsset != null) { if (playableBehaviour == null) { this.AddSerializedPlayableModifications(playableAsset, clip); } else { AnimationMode.InitializePropertyModificationForObject(obj, clip); } } } }
private static TimelineClip GetClipInAllTracks(TrackAsset track, IPlayableAsset Clip) { TimelineClip clip = GetClip(track, Clip); if (clip != null) { return(clip); } foreach (TrackAsset childTrack in track.GetChildTracks()) { clip = GetClipInAllTracks(childTrack, Clip); if (clip != null) { return(clip); } } return(null); }
protected internal virtual Playable CreatePlayable(PlayableGraph graph, GameObject go, TimelineClip clip) { IPlayableAsset playableAsset = clip.asset as IPlayableAsset; Playable result; if (playableAsset != null) { Playable playable = playableAsset.CreatePlayable(graph, go); if (playable.IsValid <Playable>()) { playable.SetAnimatedProperties(clip.curves); playable.SetSpeed(clip.timeScale); } result = playable; } else { result = Playable.Null; } return(result); }
public static int CreatePlayable(IntPtr l) { int result; try { IPlayableAsset playableAsset = (IPlayableAsset)LuaObject.checkSelf(l); PlayableGraph graph; LuaObject.checkValueType <PlayableGraph>(l, 2, out graph); GameObject owner; LuaObject.checkType <GameObject>(l, 3, out owner); Playable playable = playableAsset.CreatePlayable(graph, owner); LuaObject.pushValue(l, true); LuaObject.pushValue(l, playable); result = 2; } catch (Exception e) { result = LuaObject.error(l, e); } return(result); }
private void AddSerializedPlayableModifications(IPlayableAsset asset, AnimationClip clip) { Object @object = asset as Object; if (!(@object == null)) { AnimationModeDriver previewDriver = TimelineWindow.TimelineState.previewDriver; if (!(previewDriver == null) && AnimationMode.InAnimationMode(previewDriver)) { EditorCurveBinding[] bindings = AnimationClipCurveCache.Instance.GetCurveInfo(clip).bindings; List <FieldInfo> list = AnimatedParameterExtensions.GetScriptPlayableFields(asset).ToList <FieldInfo>(); EditorCurveBinding[] array = bindings; for (int i = 0; i < array.Length; i++) { EditorCurveBinding editorCurveBinding = array[i]; foreach (FieldInfo current in list) { DrivenPropertyManager.RegisterProperty(previewDriver, @object, current.Name + "." + editorCurveBinding.propertyName); } } } } }