initial upload
This commit is contained in:
@ -0,0 +1,239 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using UnityEditor;
|
||||
using UnityEngine.Playables;
|
||||
using System;
|
||||
|
||||
namespace RootMotion
|
||||
{
|
||||
public class BakerInspector : Editor
|
||||
{
|
||||
|
||||
protected void DrawKeyframeSettings(Baker script)
|
||||
{
|
||||
if (script.isBaking) return;
|
||||
EditorGUILayout.Space();
|
||||
|
||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("frameRate"));
|
||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("keyReductionError"));
|
||||
}
|
||||
|
||||
protected void DrawModeSettings(Baker script)
|
||||
{
|
||||
if (script.isBaking) return;
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
switch(script.mode)
|
||||
{
|
||||
case Baker.Mode.AnimationClips:
|
||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("inheritClipSettings"));
|
||||
if (!serializedObject.FindProperty("inheritClipSettings").boolValue) DrawClipSettings();
|
||||
break;
|
||||
default:
|
||||
DrawClipSettings();
|
||||
break;
|
||||
}
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("mode"));
|
||||
|
||||
switch (script.mode)
|
||||
{
|
||||
case Baker.Mode.AnimationClips:
|
||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("animationClips"), true);
|
||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("appendName"));
|
||||
break;
|
||||
case Baker.Mode.AnimationStates:
|
||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("animationStates"), true);
|
||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("appendName"));
|
||||
|
||||
break;
|
||||
case Baker.Mode.PlayableDirector:
|
||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("saveName"));
|
||||
break;
|
||||
default:
|
||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("saveName"));
|
||||
break;
|
||||
}
|
||||
|
||||
//EditorGUILayout.BeginHorizontal();
|
||||
EditorGUILayout.Space();
|
||||
EditorGUILayout.LabelField(new GUIContent("Save To Folder"));
|
||||
|
||||
if (EditorGUILayout.DropdownButton(new GUIContent(serializedObject.FindProperty("saveToFolder").stringValue, "The folder to save the baked AnimationClips to."), FocusType.Passive, GUILayout.MaxWidth(400)))
|
||||
{
|
||||
serializedObject.FindProperty("saveToFolder").stringValue = SaveClipFolderPanel.Apply(serializedObject.FindProperty("saveToFolder").stringValue);
|
||||
}
|
||||
//EditorGUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
private void DrawClipSettings()
|
||||
{
|
||||
var p = serializedObject.FindProperty("clipSettings");
|
||||
|
||||
EditorGUILayout.PropertyField(p, false);
|
||||
|
||||
if (p.isExpanded)
|
||||
{
|
||||
EditorGUILayout.BeginVertical("Box");
|
||||
EditorGUI.indentLevel++;
|
||||
|
||||
EditorGUILayout.PropertyField(p.FindPropertyRelative("loopTime"));
|
||||
EditorGUI.indentLevel++;
|
||||
EditorGUILayout.PropertyField(p.FindPropertyRelative("loopBlend"), new GUIContent("Loop Pose"));
|
||||
EditorGUILayout.PropertyField(p.FindPropertyRelative("cycleOffset"));
|
||||
EditorGUI.indentLevel--;
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
EditorGUILayout.LabelField(new GUIContent("Root Transform Rotation"));
|
||||
EditorGUI.indentLevel++;
|
||||
EditorGUILayout.PropertyField(p.FindPropertyRelative("loopBlendOrientation"), new GUIContent("Bake Into Pose"));
|
||||
EditorGUILayout.PropertyField(p.FindPropertyRelative("basedUponRotation"), new GUIContent("Based Upon"));
|
||||
EditorGUILayout.PropertyField(p.FindPropertyRelative("orientationOffsetY"), new GUIContent("Offset"));
|
||||
EditorGUI.indentLevel--;
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
EditorGUILayout.LabelField(new GUIContent("Root Transform Position (Y)"));
|
||||
EditorGUI.indentLevel++;
|
||||
EditorGUILayout.PropertyField(p.FindPropertyRelative("loopBlendPositionY"), new GUIContent("Bake Into Pose"));
|
||||
EditorGUILayout.PropertyField(p.FindPropertyRelative("basedUponY"), new GUIContent("Based Upon (at Start)"));
|
||||
EditorGUILayout.PropertyField(p.FindPropertyRelative("level"), new GUIContent("Offset"));
|
||||
EditorGUI.indentLevel--;
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
EditorGUILayout.LabelField(new GUIContent("Root Transform Position (XZ)"));
|
||||
EditorGUI.indentLevel++;
|
||||
EditorGUILayout.PropertyField(p.FindPropertyRelative("loopBlendPositionXZ"), new GUIContent("Bake Into Pose"));
|
||||
EditorGUILayout.PropertyField(p.FindPropertyRelative("basedUponXZ"), new GUIContent("Based Upon"));
|
||||
EditorGUI.indentLevel--;
|
||||
|
||||
EditorGUILayout.Space();
|
||||
EditorGUILayout.PropertyField(p.FindPropertyRelative("mirror"));
|
||||
|
||||
EditorGUI.indentLevel--;
|
||||
EditorGUILayout.EndVertical();
|
||||
}
|
||||
}
|
||||
|
||||
private void TryBake(Baker script)
|
||||
{
|
||||
switch (script.mode)
|
||||
{
|
||||
case Baker.Mode.AnimationClips:
|
||||
if (script.animator == null)
|
||||
{
|
||||
EditorGUILayout.LabelField("No Animator found on Baker GameObject", EditorStyles.helpBox);
|
||||
return;
|
||||
}
|
||||
|
||||
if (script.animator.isHuman && script.animator.runtimeAnimatorController == null)
|
||||
{
|
||||
EditorGUILayout.LabelField("Humanoid Animator needs to have a valid Controller assigned for clip baking (Unity crash bug)", EditorStyles.helpBox);
|
||||
return;
|
||||
}
|
||||
|
||||
if (script.animationClips.Length == 0)
|
||||
{
|
||||
EditorGUILayout.LabelField("Please add AnimationClips to bake", EditorStyles.helpBox);
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (AnimationClip clip in script.animationClips)
|
||||
{
|
||||
if (clip == null)
|
||||
{
|
||||
EditorGUILayout.LabelField("One of the AnimationClips is null, can not bake.", EditorStyles.helpBox);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (GUILayout.Button("Bake Animation Clips")) script.BakeClip();
|
||||
return;
|
||||
case Baker.Mode.AnimationStates:
|
||||
if (script.animator == null)
|
||||
{
|
||||
EditorGUILayout.LabelField("No Animator found on Baker GameObject", EditorStyles.helpBox);
|
||||
return;
|
||||
}
|
||||
|
||||
if (script.animationStates.Length == 0)
|
||||
{
|
||||
EditorGUILayout.LabelField("Please add Animation State names to bake. The Animator must contain AnimationStates with matching names. If AnimationState names match with clip names used in them, you can have the Baker fill the names in automatically by right-clicking on the component header and selecting 'Find Animation States'.", EditorStyles.helpBox);
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < script.animationStates.Length; i++)
|
||||
{
|
||||
if (script.animationStates[i] == string.Empty || script.animationStates[i] == "")
|
||||
{
|
||||
EditorGUILayout.LabelField("One of the animation state names in 'Animation States' is empty, can not bake.", EditorStyles.helpBox);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (GUILayout.Button("Bake Animation States")) script.BakeClip();
|
||||
return;
|
||||
case Baker.Mode.PlayableDirector:
|
||||
if (script.director == null)
|
||||
{
|
||||
EditorGUILayout.LabelField("No PlayableDirector found on Baker GameObject", EditorStyles.helpBox);
|
||||
return;
|
||||
}
|
||||
|
||||
if (GUILayout.Button("Bake Timeline")) script.BakeClip();
|
||||
break;
|
||||
case Baker.Mode.Realtime:
|
||||
if (GUILayout.Button("Start Baking")) script.StartBaking();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
protected void DrawButtons(Baker script)
|
||||
{
|
||||
if (!script.enabled) return;
|
||||
|
||||
if (script.animator == null)
|
||||
{
|
||||
serializedObject.FindProperty("animator").objectReferenceValue = script.GetComponent<Animator>();
|
||||
}
|
||||
|
||||
if (script.director == null)
|
||||
{
|
||||
serializedObject.FindProperty("director").objectReferenceValue = script.GetComponent<PlayableDirector>();
|
||||
}
|
||||
|
||||
if (!Application.isPlaying)
|
||||
{
|
||||
EditorGUILayout.LabelField("Enter Play Mode to bake.", EditorStyles.helpBox);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!script.isBaking)
|
||||
{
|
||||
TryBake(script);
|
||||
}
|
||||
else
|
||||
{
|
||||
GUI.color = Color.red;
|
||||
|
||||
switch (script.mode)
|
||||
{
|
||||
case Baker.Mode.Realtime:
|
||||
if (GUILayout.Button("Stop Baking")) script.StopBaking();
|
||||
break;
|
||||
default:
|
||||
GUILayout.Label("Baking Progress: " + System.Math.Round(script.bakingProgress, 2));
|
||||
break;
|
||||
}
|
||||
|
||||
GUI.color = Color.white;
|
||||
EditorUtility.SetDirty(script);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dcf5801ad3ff7fa43b06824f09d82160
|
||||
timeCreated: 1516619065
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,52 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using UnityEditor;
|
||||
|
||||
namespace RootMotion
|
||||
{
|
||||
[CustomEditor(typeof(GenericBaker))]
|
||||
public class GenericBakerInspector : BakerInspector
|
||||
{
|
||||
private GenericBaker script { get { return target as GenericBaker; } }
|
||||
|
||||
private MonoScript monoScript;
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
// Changing the script execution order
|
||||
if (!Application.isPlaying)
|
||||
{
|
||||
monoScript = MonoScript.FromMonoBehaviour(script);
|
||||
int currentExecutionOrder = MonoImporter.GetExecutionOrder(monoScript);
|
||||
if (currentExecutionOrder != 15001) MonoImporter.SetExecutionOrder(monoScript, 15001);
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
serializedObject.Update();
|
||||
|
||||
DrawKeyframeSettings(script as Baker);
|
||||
DrawGenericKeyframeSettings(script);
|
||||
DrawModeSettings(script as Baker);
|
||||
DrawButtons(script as Baker);
|
||||
|
||||
if (serializedObject.ApplyModifiedProperties())
|
||||
{
|
||||
EditorUtility.SetDirty(script);
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawGenericKeyframeSettings(GenericBaker script)
|
||||
{
|
||||
if (script.isBaking) return;
|
||||
|
||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("markAsLegacy"));
|
||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("root"));
|
||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("rootNode"));
|
||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("ignoreList"), true);
|
||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("bakePositionList"), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8f544a5bc87054e74ac2e415889ba75a
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 73b96cf8495867d429c9c5b31ff6d6da
|
||||
folderAsset: yes
|
||||
timeCreated: 1516621014
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,38 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using UnityEditor;
|
||||
|
||||
namespace RootMotion
|
||||
{
|
||||
public static class AnimationUtilityExtended
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Copies the curves with the specified property names from clipFrom to clipTo.
|
||||
/// </summary>
|
||||
/// <param name="fromClip">copy from clip.</param>
|
||||
/// <param name="toClip">paste to clip</param>
|
||||
/// <param name="propertyNames">Property names ("Root.T", "Root.Q", "LeftFoot.T"...).</param>
|
||||
public static void CopyCurves(AnimationClip fromClip, AnimationClip toClip, string[] propertyNames)
|
||||
{
|
||||
EditorCurveBinding[] bindings = AnimationUtility.GetCurveBindings(fromClip);
|
||||
|
||||
for (int i = 0; i < bindings.Length; i++)
|
||||
{
|
||||
for (int n = 0; n < propertyNames.Length; n++)
|
||||
{
|
||||
if (bindings[i].propertyName == propertyNames[n])
|
||||
{
|
||||
CopyCurve(fromClip, toClip, bindings[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void CopyCurve(AnimationClip fromClip, AnimationClip toClip, EditorCurveBinding binding)
|
||||
{
|
||||
AnimationCurve curve = AnimationUtility.GetEditorCurve(fromClip, binding);
|
||||
toClip.SetCurve(string.Empty, typeof(Animator), binding.propertyName, curve);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 054c55a0c5c10dc4fafcfd81aeaaec56
|
||||
timeCreated: 1516620625
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,22 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System.IO;
|
||||
using System;
|
||||
|
||||
namespace RootMotion
|
||||
{
|
||||
public class SaveClipFolderPanel : EditorWindow
|
||||
{
|
||||
public static string Apply(string currentPath)
|
||||
{
|
||||
string path = EditorUtility.SaveFolderPanel("Save clip(s) to folder", currentPath, "");
|
||||
|
||||
if (path.Length != 0)
|
||||
{
|
||||
return path.Substring(path.IndexOf("Assets/"));
|
||||
}
|
||||
|
||||
return currentPath;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7edb6cbf0a3b9924d8f631c4c00fd38a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,52 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using UnityEditor;
|
||||
|
||||
namespace RootMotion
|
||||
{
|
||||
[CustomEditor(typeof(HumanoidBaker))]
|
||||
public class HumanoidBakerInspector : BakerInspector
|
||||
{
|
||||
|
||||
private HumanoidBaker script { get { return target as HumanoidBaker; } }
|
||||
|
||||
private MonoScript monoScript;
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
// Changing the script execution order
|
||||
if (!Application.isPlaying)
|
||||
{
|
||||
monoScript = MonoScript.FromMonoBehaviour(script);
|
||||
int currentExecutionOrder = MonoImporter.GetExecutionOrder(monoScript);
|
||||
if (currentExecutionOrder != 15000) MonoImporter.SetExecutionOrder(monoScript, 15000);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO Move this to BakerInspector.cs
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
serializedObject.Update();
|
||||
|
||||
DrawKeyframeSettings(script as Baker);
|
||||
DrawHumanoidKeyframeSettings(script);
|
||||
DrawModeSettings(script as Baker);
|
||||
DrawButtons(script as Baker);
|
||||
|
||||
if (serializedObject.ApplyModifiedProperties())
|
||||
{
|
||||
EditorUtility.SetDirty(script);
|
||||
}
|
||||
}
|
||||
|
||||
protected void DrawHumanoidKeyframeSettings(HumanoidBaker script)
|
||||
{
|
||||
if (script.isBaking) return;
|
||||
|
||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("IKKeyReductionError"));
|
||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("muscleFrameRateDiv"));
|
||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("bakeHandIK"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f8139af98945e154885b65eedbb102cc
|
||||
timeCreated: 1516265598
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user