diff --git a/Unity Runtime Recorder/Scripts/UnityAnimSaver/Editor/UnityAnimationRecorderEditor.cs b/Unity Runtime Recorder/Scripts/UnityAnimSaver/Editor/UnityAnimationRecorderEditor.cs index f2b2b87..87cdd3e 100644 --- a/Unity Runtime Recorder/Scripts/UnityAnimSaver/Editor/UnityAnimationRecorderEditor.cs +++ b/Unity Runtime Recorder/Scripts/UnityAnimSaver/Editor/UnityAnimationRecorderEditor.cs @@ -20,9 +20,12 @@ public class UnityAnimationRecorderEditor : Editor { SerializedProperty changeTimeScale; SerializedProperty timeScaleOnStart; SerializedProperty timeScaleOnRecord; + SerializedProperty smoothTangents; + SerializedProperty recordEachFrame; + SerializedProperty howOftenFrame; - void OnEnable () { + void OnEnable () { savePath = serializedObject.FindProperty ("savePath"); fileName = serializedObject.FindProperty ("fileName"); @@ -37,8 +40,12 @@ void OnEnable () { changeTimeScale = serializedObject.FindProperty ("changeTimeScale"); timeScaleOnStart = serializedObject.FindProperty ("timeScaleOnStart"); timeScaleOnRecord = serializedObject.FindProperty ("timeScaleOnRecord"); - - } + smoothTangents = serializedObject.FindProperty("smoothTangents"); + + recordEachFrame = serializedObject.FindProperty("recordEachFrame"); + howOftenFrame = serializedObject.FindProperty("howOftenFrame"); + + } public override void OnInspectorGUI () { serializedObject.Update (); @@ -87,7 +94,16 @@ public override void OnInspectorGUI () { // recording frames setting recordLimitedFrames.boolValue = EditorGUILayout.Toggle( "Record Limited Frames", recordLimitedFrames.boolValue ); - if (recordLimitedFrames.boolValue) + smoothTangents.boolValue = EditorGUILayout.Toggle("Smooth tangents of animation curves", smoothTangents.boolValue); + + recordEachFrame.boolValue = EditorGUILayout.Toggle("Record animation in every frame", recordEachFrame.boolValue); + if (!recordEachFrame.boolValue) + { + howOftenFrame.floatValue = EditorGUILayout.FloatField("Distance betwen recorded frames", howOftenFrame.floatValue); + + } + + if (recordLimitedFrames.boolValue) EditorGUILayout.PropertyField (recordFrames); serializedObject.ApplyModifiedProperties (); diff --git a/Unity Runtime Recorder/Scripts/UnityAnimSaver/UnityAnimationRecorder.cs b/Unity Runtime Recorder/Scripts/UnityAnimSaver/UnityAnimationRecorder.cs index 7459ec2..0495c86 100644 --- a/Unity Runtime Recorder/Scripts/UnityAnimSaver/UnityAnimationRecorder.cs +++ b/Unity Runtime Recorder/Scripts/UnityAnimSaver/UnityAnimationRecorder.cs @@ -22,6 +22,7 @@ public class UnityAnimationRecorder : MonoBehaviour { public bool changeTimeScale = false; public float timeScaleOnStart = 0.0f; public float timeScaleOnRecord = 1.0f; + public bool smoothTangents = true; Transform[] recordObjs; UnityObjectAnimation[] objRecorders; @@ -54,13 +55,7 @@ void Update () { StopRecording (); } - if (isStart) { - nowTime += Time.deltaTime; - - for (int i = 0; i < objRecorders.Length; i++) { - objRecorders [i].AddFrame (nowTime); - } - } + } @@ -78,19 +73,30 @@ public void StopRecording () { ExportAnimationClip (); } - - - - void FixedUpdate () { + + public bool recordEachFrame = true; + + public float howOftenFrame = 0.2f; + + float lastTime = 0f; + void FixedUpdate () { if (isStart) { if (frameIndex < recordFrames) { - for (int i = 0; i < objRecorders.Length; i++) { - objRecorders [i].AddFrame (nowTime); - } - - ++frameIndex; + + nowTime += Time.fixedDeltaTime; + if (lastTime==0|| nowTime > lastTime + howOftenFrame||recordEachFrame) + { + lastTime = nowTime; + + for (int i = 0; i < objRecorders.Length; i++) + { + objRecorders[i].AddFrame(nowTime); + } + + ++frameIndex; + } } else { isStart = false; ExportAnimationClip (); @@ -107,7 +113,14 @@ void OnGUI () { void ExportAnimationClip () { string exportFilePath = savePath + fileName; - + if(smoothTangents) + { + for (int i = 0; i < objRecorders.Length; i++) + { + objRecorders[i].smoothCurves(); + + } + } AnimationClip clip = new AnimationClip (); clip.name = fileName; diff --git a/Unity Runtime Recorder/Scripts/UnityAnimSaver/UnityCurveContainer.cs b/Unity Runtime Recorder/Scripts/UnityAnimSaver/UnityCurveContainer.cs index f80a652..ae12235 100644 --- a/Unity Runtime Recorder/Scripts/UnityAnimSaver/UnityCurveContainer.cs +++ b/Unity Runtime Recorder/Scripts/UnityAnimSaver/UnityCurveContainer.cs @@ -16,4 +16,11 @@ public void AddValue( float animTime, float animValue ) Keyframe key = new Keyframe (animTime, animValue, 0.0f, 0.0f); animCurve.AddKey (key); } + public void SmoothTangents() + { + for (int i = 0; i < animCurve.keys.Length; ++i) + { + animCurve.SmoothTangents(i, 0); //zero weight means average + } + } } diff --git a/Unity Runtime Recorder/Scripts/UnityAnimSaver/UnityObjectAnimation.cs b/Unity Runtime Recorder/Scripts/UnityAnimSaver/UnityObjectAnimation.cs index e67ffa0..f328095 100644 --- a/Unity Runtime Recorder/Scripts/UnityAnimSaver/UnityObjectAnimation.cs +++ b/Unity Runtime Recorder/Scripts/UnityAnimSaver/UnityObjectAnimation.cs @@ -44,4 +44,11 @@ public void AddFrame ( float time ) { curves [9].AddValue (time, observeGameObject.localScale.z); } + public void smoothCurves() + { + for (int i = 0; i < curves.Length; i++) + { + curves[i].SmoothTangents(); + } + } }