/// <summary> /// 设置动画窗口的当前动画片段项 /// </summary> /// <param name="clipName"></param> public static void SetActiveAnimationClip(string clipName) { AnimationWindowReflect animationWindowReflect = GetAnimationWindowReflect(); if (!animationWindowReflect.firstAnimationWindow) { return; } GameObject activeRootGameObject = animationWindowReflect.activeRootGameObject; if (activeRootGameObject == null) { Debug.Log("没有动画 activeRootGameObject!"); return; } AnimationClip animationClipSelected = null; AnimationClip[] animationClips = AnimationUtility.GetAnimationClips(activeRootGameObject); for (int i = 0; i < animationClips.Length; i++) { if (animationClips[i].name == clipName) { animationClipSelected = animationClips[i]; break; } } if (animationClipSelected == null) { Debug.Log("没有动画 " + clipName); return; } animationWindowReflect.activeAnimationClip = animationClipSelected; }
private static AnimationWindowReflect GetAnimationWindowReflect() { AnimationWindowReflect animationWindowReflect = new AnimationWindowReflect(); if (!animationWindowReflect.firstAnimationWindow) { //Debug.Log("没有动画编辑器!"); } return(animationWindowReflect); }
/// <summary> /// 获取当前活动的动画片段 /// </summary> /// <returns></returns> public static AnimationClip GetActiveAnimationClip() { AnimationWindowReflect animationWindowReflect = GetAnimationWindowReflect(); if (!animationWindowReflect.firstAnimationWindow) { return(null); } return(animationWindowReflect.activeAnimationClip); }
public static void Repaint() { AnimationWindowReflect animationWindowReflect = GetAnimationWindowReflect(); if (!animationWindowReflect.firstAnimationWindow) { return; } animationWindowReflect.firstAnimationWindow.Repaint(); }
public static float GetCurrentTime() { AnimationWindowReflect animationWindowReflect = GetAnimationWindowReflect(); if (!animationWindowReflect.firstAnimationWindow) { return(-1f); } return(animationWindowReflect.currentTime); }
public static void SetCurrentTime(float time) { AnimationWindowReflect animationWindowReflect = GetAnimationWindowReflect(); if (!animationWindowReflect.firstAnimationWindow) { return; } animationWindowReflect.recording = true; animationWindowReflect.currentTime = time; animationWindowReflect.firstAnimationWindow.Repaint(); }
public static void SetCurrentTime(float time) { AnimationWindowReflect animationWindowReflect = GetAnimationWindowReflect(); if (!animationWindowReflect.firstAnimationWindow) { return; } animationWindowReflect.currentTime = time; animationWindowReflect.StartRecording(); animationWindowReflect.StopPlayback(); animationWindowReflect.ResampleAnimation(); animationWindowReflect.firstAnimationWindow.Repaint(); }
/// <summary> /// 注册动画窗口的时间轴时间变化监听 /// 注意:只监听第一个动画窗口 /// </summary> public static void RegisterTimeChangeListener(Action <float> currentTimeChange) { AnimationWindowReflect animationWindowReflect = GetAnimationWindowReflect(); if (!animationWindowReflect.firstAnimationWindow) { return; } s_GetCurrentTimeFunc = () => { return(animationWindowReflect.currentTime); }; s_PrevCurrentTime = -1f; s_CurrentTimeChange = currentTimeChange; EditorApplication.update = (EditorApplication.CallbackFunction) Delegate.RemoveAll(EditorApplication.update, new EditorApplication.CallbackFunction(OnCurrentTimeListening)); EditorApplication.update = (EditorApplication.CallbackFunction) Delegate.Combine(EditorApplication.update, new EditorApplication.CallbackFunction(OnCurrentTimeListening)); }
public static void SetCurrentTime(float time) { AnimationWindowReflect animationWindowReflect = GetAnimationWindowReflect(); if (!animationWindowReflect.firstAnimationWindow) { return; } animationWindowReflect.currentTime = time; #if !UNITY_5_6_OR_NEWER animationWindowReflect.recording = true; animationWindowReflect.playing = false; animationWindowReflect.ResampleAnimation(); #endif animationWindowReflect.firstAnimationWindow.Repaint(); }
public static void SetOnClipSelectionChanged(Action onClipSelectionChangedAction, bool removeOnly = false) { AnimationWindowReflect animationWindowReflect = GetAnimationWindowReflect(); if (!animationWindowReflect.firstAnimationWindow) { return; } Action onClipSelectionChanged = animationWindowReflect.onClipSelectionChanged; onClipSelectionChanged = (Action)Delegate.RemoveAll(onClipSelectionChanged, onClipSelectionChangedAction); if (!removeOnly) { onClipSelectionChanged = (Action)Delegate.Combine(onClipSelectionChanged, onClipSelectionChangedAction); } animationWindowReflect.onClipSelectionChanged = onClipSelectionChanged; }
public static void SetOnFrameRateChange(Action <float> onFrameRateChangeAction, bool removeOnly = false) { AnimationWindowReflect animationWindowReflect = GetAnimationWindowReflect(); if (!animationWindowReflect.firstAnimationWindow) { return; } Action <float> onFrameRateChange = animationWindowReflect.onFrameRateChange; onFrameRateChange = (Action <float>)Delegate.RemoveAll(onFrameRateChange, onFrameRateChangeAction); if (!removeOnly) { onFrameRateChange = (Action <float>)Delegate.Combine(onFrameRateChange, onFrameRateChangeAction); } animationWindowReflect.onFrameRateChange = onFrameRateChange; }
/// <summary> /// 设置动画窗口的当前动画片段项 /// </summary> /// <param name="clipName"></param> public static bool SetActiveAnimationClip(AnimationClip clip) { AnimationWindowReflect animationWindowReflect = GetAnimationWindowReflect(); if (!animationWindowReflect.firstAnimationWindow) { return(false); } GameObject activeRootGameObject = animationWindowReflect.activeRootGameObject; if (activeRootGameObject == null) { Debug.Log("没有动画 activeRootGameObject!"); return(false); } animationWindowReflect.activeAnimationClip = clip; return(true); }
private void DoKeyframeTangentToConstant() { AnimationWindowReflect animationWindowReflect = AnimationWindowUtil.GetAnimationWindowReflect(); if (!animationWindowReflect.firstAnimationWindow) { SimpleDisplayDialog("Animation 窗口没有打开"); return; } AnimationClip activeAnimationClip = animationWindowReflect.activeAnimationClip; if (activeAnimationClip == null) { SimpleDisplayDialog("Animation 窗口没有任何动画片段"); return; } float currentTime = animationWindowReflect.currentTime; if ((activeAnimationClip.hideFlags & HideFlags.NotEditable) != HideFlags.None) { // FBX 动画则自动执行拷贝 AnimationClip oldClip = activeAnimationClip; activeAnimationClip = CopyAnimationClipAsset(activeAnimationClip); animationWindowReflect.activeAnimationClip = activeAnimationClip; animationWindowReflect.currentTime = currentTime; if (onClipCopyModify != null) { onClipCopyModify(oldClip, activeAnimationClip); } } KeyframeTangentToConstant(activeAnimationClip, currentTime); animationWindowReflect.firstAnimationWindow.Repaint(); }