diff --git a/Assets/Editor/Animation/ShapeKeyDriver.meta b/Assets/Editor/Animation/ShapeKeyDriver.meta new file mode 100644 index 0000000..bcc5a94 --- /dev/null +++ b/Assets/Editor/Animation/ShapeKeyDriver.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 4e74e16a6ca98044cbeef5940c4a6b50 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Editor/Animation/ShapeKeyDriver/ShapeKeyDrawer.cs b/Assets/Editor/Animation/ShapeKeyDriver/ShapeKeyDrawer.cs new file mode 100644 index 0000000..e9a6255 --- /dev/null +++ b/Assets/Editor/Animation/ShapeKeyDriver/ShapeKeyDrawer.cs @@ -0,0 +1,74 @@ +using UnityEditor; +using UnityEngine; + +namespace BitStrap +{ + [CustomPropertyDrawer(typeof(ShapeKeyDefinition))] + public class ShapeKeyDrawer : PropertyDrawer + { + string[] blendShapeNames = null; + + public override float GetPropertyHeight(SerializedProperty property, GUIContent label) + { + if (FindSkinnedMeshRenderer(property) == null) + return 0.0f; + return base.GetPropertyHeight(property, label); + } + + public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) + { + PropertyDrawerHelper.LoadAttributeTooltip( this, label ); + + var nameProperty = property.GetMemberProperty( p => p.name ); + + var skinnedMeshRenderer = FindSkinnedMeshRenderer(property); + if (skinnedMeshRenderer != null) + { + if (blendShapeNames == null) + { + var blendShapeCount = skinnedMeshRenderer.sharedMesh.blendShapeCount; + blendShapeNames = new string[blendShapeCount]; + for (int i = 0; i < blendShapeCount; i++) + { + blendShapeNames[i] = skinnedMeshRenderer.sharedMesh.GetBlendShapeName(i); + } + } + + int currentIndex = System.Array.IndexOf(blendShapeNames, nameProperty.stringValue); + + EditorGUI.BeginChangeCheck(); + currentIndex = EditorGUI.Popup( position, label.text, currentIndex, blendShapeNames ); + + if( EditorGUI.EndChangeCheck() ) + { + nameProperty.stringValue = blendShapeNames[currentIndex]; + property.serializedObject.ApplyModifiedProperties(); + } + } + } + + private SkinnedMeshRenderer FindSkinnedMeshRenderer(SerializedProperty property) + { + var behaviour = property.serializedObject.targetObject as MonoBehaviour; + if (behaviour != null) + { + if (fieldInfo.GetAttribute(false) + .TryGet(out var skinnedMeshRendererFieldAttribute)) + { + var skinnedMeshRendererProperty = + property.serializedObject.FindProperty(skinnedMeshRendererFieldAttribute.skinnedMeshRendererFieldName); + if (skinnedMeshRendererProperty != null) + return skinnedMeshRendererProperty.objectReferenceValue as SkinnedMeshRenderer; + } + else + { + var skinnedMeshRendererProperty = property.serializedObject.FindProperty("skinnedMeshRenderer"); + if (skinnedMeshRendererProperty != null) + return skinnedMeshRendererProperty.objectReferenceValue as SkinnedMeshRenderer; + } + } + + return null; + } + } +} diff --git a/Assets/Editor/Animation/ShapeKeyDriver/ShapeKeyDrawer.cs.meta b/Assets/Editor/Animation/ShapeKeyDriver/ShapeKeyDrawer.cs.meta new file mode 100644 index 0000000..9d065b8 --- /dev/null +++ b/Assets/Editor/Animation/ShapeKeyDriver/ShapeKeyDrawer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 464b20d8e40d6e6478403921bffbb7b3 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Editor/Animation/ShapeKeyDriver/ShapeKeyPositionConfigDrawer.cs b/Assets/Editor/Animation/ShapeKeyDriver/ShapeKeyPositionConfigDrawer.cs new file mode 100644 index 0000000..f119301 --- /dev/null +++ b/Assets/Editor/Animation/ShapeKeyDriver/ShapeKeyPositionConfigDrawer.cs @@ -0,0 +1,190 @@ +using UnityEditor; +using UnityEngine; + +namespace BitStrap +{ + [CustomPropertyDrawer(typeof(ShapeKeyPositionConfig))] + public class ShapeKeyPositionConfigDrawer : PropertyDrawer + { + public override float GetPropertyHeight( SerializedProperty property, GUIContent label ) + { + if (property.isExpanded) + return EditorHelper.SingleLineHeight * 8; + + return EditorHelper.SingleLineHeight; + } + public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) + { + PropertyDrawerHelper.LoadAttributeTooltip( this, label ); + var rowFoldout = position.Row(0); + var rowDriverTransform = position.Row(1); + var rowPositionType = position.Row(2); + var rowAxis = position.Row(3); + var rowValues = position.Row(4); + var rowCurve = position.Row(5); + + property.isExpanded = EditorGUI.Foldout(rowFoldout, property.isExpanded, label); + + if (!property.isExpanded) + return; + + using (IndentLevel.Do(EditorGUI.indentLevel + 1)) + using (LabelWidth.Do(128.0f)) + { + var driverTransformProperty = property.GetMemberProperty( k => k.driverTransform); + EditorGUI.PropertyField(rowDriverTransform, driverTransformProperty); + + var positionTypeProperty = property.GetMemberProperty( k => k.positionType); + EditorGUI.PropertyField(rowPositionType, positionTypeProperty); + + var startPropertyLabel = new GUIContent("Start Position"); + var endPropertyLabel = new GUIContent("End Position"); + + switch ((ShapeKeyPositionConfig.PositionType)positionTypeProperty.enumValueIndex) + { + case ShapeKeyPositionConfig.PositionType.OneAxis: + { + var axisProperty = property.GetMemberProperty( k => k.positionOneAxis); + var positionAxisLabel = new GUIContent("Axis"); + EditorGUI.PropertyField(rowAxis, axisProperty, positionAxisLabel); + + rowValues.Left(rowValues.width * 0.5f, out var leftRect).Expand(out var rightRect); + leftRect.Right(26.0f, out var leftButtonRect).Left(-2.0f).Expand(out var outLeftRect); + rightRect.Right(26.0f, out var rightButtonRect).Left(-2.0f).Expand(out var outRightRect); + + var startValueProperty = property.GetMemberProperty( k => k.oneAxisStartPosition); + EditorGUI.PropertyField(outLeftRect, startValueProperty, startPropertyLabel); + + if (GUI.Button(leftButtonRect, EditorGUIUtility.IconContent("d_Transform Icon"))) + { + SetOneAxis(axisProperty, startValueProperty, driverTransformProperty); + } + + var endValueProperty = property.GetMemberProperty( k => k.oneAxisEndPosition); + EditorGUI.PropertyField(outRightRect, endValueProperty, endPropertyLabel); + + if (GUI.Button(rightButtonRect, EditorGUIUtility.IconContent("d_Transform Icon"))) + { + SetOneAxis(axisProperty, endValueProperty, driverTransformProperty); + } + + break; + } + case ShapeKeyPositionConfig.PositionType.TwoAxis: + { + var axisProperty = property.GetMemberProperty(k => k.positionTwoAxis); + var positionAxisLabel = new GUIContent("Axis"); + EditorGUI.PropertyField(rowAxis, axisProperty, positionAxisLabel); + + rowValues.Left(rowValues.width * 0.5f, out var leftRect).Expand(out var rightRect); + leftRect.Right(26.0f, out var leftButtonRect).Left(-2.0f).Expand(out var outLeftRect); + rightRect.Right(26.0f, out var rightButtonRect).Left(-2.0f).Expand(out var outRightRect); + + var startValueProperty = property.GetMemberProperty( k => k.twoAxisStartPosition); + EditorGUI.PropertyField(outLeftRect, startValueProperty, startPropertyLabel); + + if (GUI.Button(leftButtonRect, EditorGUIUtility.IconContent("d_Transform Icon"))) + { + SetTwoAxis(axisProperty, startValueProperty, driverTransformProperty); + } + + var endValueProperty = property.GetMemberProperty( k => k.twoAxisEndPosition); + EditorGUI.PropertyField(outRightRect, endValueProperty, endPropertyLabel); + + if (GUI.Button(rightButtonRect, EditorGUIUtility.IconContent("d_Transform Icon"))) + { + SetTwoAxis(axisProperty, endValueProperty, driverTransformProperty); + } + + break; + } + case ShapeKeyPositionConfig.PositionType.ThreeAxis: + { + rowValues.Left(rowValues.width * 0.5f, out var leftRect).Expand(out var rightRect); + leftRect.Right(26.0f, out var leftButtonRect).Left(-2.0f).Expand(out var outLeftRect); + rightRect.Right(26.0f, out var rightButtonRect).Left(-2.0f).Expand(out var outRightRect); + + var startValueProperty = property.GetMemberProperty(k => k.threeAxisStartPosition); + EditorGUI.PropertyField(outLeftRect, startValueProperty, startPropertyLabel); + + if (GUI.Button(leftButtonRect, EditorGUIUtility.IconContent("d_Transform Icon"))) + { + SetThreeAxis(startValueProperty, driverTransformProperty); + } + + var endValueProperty = property.GetMemberProperty(k => k.threeAxisEndPosition); + EditorGUI.PropertyField(outRightRect, endValueProperty, endPropertyLabel); + + if (GUI.Button(rightButtonRect, EditorGUIUtility.IconContent("d_Transform Icon"))) + { + SetThreeAxis(endValueProperty, driverTransformProperty); + } + + break; + } + } + var interpolationCurve = property.GetMemberProperty( k => k.interpolationCurve); + var curveLabel = new GUIContent("Curve"); + + rowCurve.height = EditorHelper.SingleLineHeight * 3; + EditorGUI.PropertyField(rowCurve, interpolationCurve, curveLabel); + } + } + + private void SetOneAxis(SerializedProperty axisProperty, SerializedProperty propertyToSet, + SerializedProperty driverTransformProperty) + { + var driverTransformPosition = ((Transform)driverTransformProperty.objectReferenceValue).position; + + switch ((ShapeKeyPositionConfig.PositionOneAxis)axisProperty.enumValueIndex) + { + case ShapeKeyPositionConfig.PositionOneAxis.X: + propertyToSet.floatValue = driverTransformPosition.x; + break; + case ShapeKeyPositionConfig.PositionOneAxis.Y: + propertyToSet.floatValue = driverTransformPosition.y; + break; + case ShapeKeyPositionConfig.PositionOneAxis.Z: + propertyToSet.floatValue = driverTransformPosition.z; + break; + } + } + + private void SetTwoAxis(SerializedProperty axisProperty, SerializedProperty propertyToSet, + SerializedProperty driverTransformProperty) + { + var driverTransformPosition = ((Transform)driverTransformProperty.objectReferenceValue).position; + + var driverPos = driverTransformPosition; + + switch ((ShapeKeyPositionConfig.PositionTwoAxis)axisProperty.enumValueIndex) + { + case ShapeKeyPositionConfig.PositionTwoAxis.XY: + propertyToSet.vector2Value = new Vector2(driverPos.x, driverPos.y); + break; + case ShapeKeyPositionConfig.PositionTwoAxis.XZ: + propertyToSet.vector2Value = new Vector2(driverPos.x, driverPos.z); + break; + case ShapeKeyPositionConfig.PositionTwoAxis.YX: + propertyToSet.vector2Value = new Vector2(driverPos.y, driverPos.x); + break; + case ShapeKeyPositionConfig.PositionTwoAxis.YZ: + propertyToSet.vector2Value = new Vector2(driverPos.y, driverPos.z); + break; + case ShapeKeyPositionConfig.PositionTwoAxis.ZY: + propertyToSet.vector2Value = new Vector2(driverPos.z, driverPos.y); + break; + case ShapeKeyPositionConfig.PositionTwoAxis.ZX: + propertyToSet.vector2Value = new Vector2(driverPos.z, driverPos.x); + break; + } + } + + private void SetThreeAxis(SerializedProperty propertyToSet, SerializedProperty driverTransformProperty) + { + var driverTransformPosition = ((Transform)driverTransformProperty.objectReferenceValue).position; + + propertyToSet.vector3Value = driverTransformPosition; + } + } +} diff --git a/Assets/Editor/Animation/ShapeKeyDriver/ShapeKeyPositionConfigDrawer.cs.meta b/Assets/Editor/Animation/ShapeKeyDriver/ShapeKeyPositionConfigDrawer.cs.meta new file mode 100644 index 0000000..9af2891 --- /dev/null +++ b/Assets/Editor/Animation/ShapeKeyDriver/ShapeKeyPositionConfigDrawer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: d4f9b79689c72ba4699217d48e10e974 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Editor/Animation/ShapeKeyDriver/ShapeKeyRecipeDrawer.cs b/Assets/Editor/Animation/ShapeKeyDriver/ShapeKeyRecipeDrawer.cs new file mode 100644 index 0000000..d894d14 --- /dev/null +++ b/Assets/Editor/Animation/ShapeKeyDriver/ShapeKeyRecipeDrawer.cs @@ -0,0 +1,52 @@ +using UnityEditor; +using UnityEngine; + +namespace BitStrap +{ + [CustomPropertyDrawer(typeof(ShapeKeyRecipe))] + public class ShapeKeyRecipeDrawer : PropertyDrawer + { + public override float GetPropertyHeight( SerializedProperty property, GUIContent label ) + { + return EditorHelper.SingleLineHeight * 10; + } + + public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) + { + var rowShapeKeyDefinition = position.Row(0); + var rowDriverType = position.Row(1); + var rowShapeKeyConfigs = position.Row(2); + + var shapeKeyProperty = property.GetMemberProperty( k => k.shapeKeyDefinition); + EditorGUI.PropertyField(rowShapeKeyDefinition, shapeKeyProperty); + + var driverTypeProperty = property.GetMemberProperty( k => k.driverType); + EditorGUI.PropertyField(rowDriverType, driverTypeProperty); + + switch ((ShapeKeyRecipe.DriverType)driverTypeProperty.enumValueIndex) + { + case ShapeKeyRecipe.DriverType.Rotation: + { + var shapeKeyRotationProperty = + property.GetMemberProperty(k => k.shapeKeyRotationConfig); + EditorGUI.PropertyField(rowShapeKeyConfigs, shapeKeyRotationProperty); + break; + } + case ShapeKeyRecipe.DriverType.Position: + { + var shapeKeyPositionProperty = + property.GetMemberProperty(k => k.shapeKeyPositionConfig); + EditorGUI.PropertyField(rowShapeKeyConfigs, shapeKeyPositionProperty); + break; + } + // TODO: implement + // case ShapeKeyRecipe.DriverType.MecanimParameter: + // break; + // case ShapeKeyRecipe.DriverType.Callback: + // break; + } + + } + } +} + diff --git a/Assets/Editor/Animation/ShapeKeyDriver/ShapeKeyRecipeDrawer.cs.meta b/Assets/Editor/Animation/ShapeKeyDriver/ShapeKeyRecipeDrawer.cs.meta new file mode 100644 index 0000000..b71cfb4 --- /dev/null +++ b/Assets/Editor/Animation/ShapeKeyDriver/ShapeKeyRecipeDrawer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 3d2d849eba043cf4385ce1b9219e762b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Editor/Animation/ShapeKeyDriver/ShapeKeyRotationConfigDrawer.cs b/Assets/Editor/Animation/ShapeKeyDriver/ShapeKeyRotationConfigDrawer.cs new file mode 100644 index 0000000..ed2446a --- /dev/null +++ b/Assets/Editor/Animation/ShapeKeyDriver/ShapeKeyRotationConfigDrawer.cs @@ -0,0 +1,123 @@ +using UnityEditor; +using UnityEngine; + +namespace BitStrap +{ + [CustomPropertyDrawer(typeof(ShapeKeyRotationConfig))] + public class ShapeKeyRotationConfigDrawer : PropertyDrawer + { + static readonly GUIContent CurveLabel = new GUIContent("Curve"); + private Vector3 driverTransformEulerAngles; + + public override float GetPropertyHeight( SerializedProperty property, GUIContent label ) + { + if (property.isExpanded) + return EditorHelper.SingleLineHeight * 8; + + return EditorHelper.SingleLineHeight; + } + public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) + { + PropertyDrawerHelper.LoadAttributeTooltip( this, label ); + var rowFoldout = position.Row(0); + var rowDriverTransform = position.Row(1); + var rowRotationType = position.Row(2); + var rowAxis = position.Row(3); + var rowValues = position.Row(4); + var rowCurve = position.Row(5); + + property.isExpanded = EditorGUI.Foldout(rowFoldout, property.isExpanded, label); + + if (!property.isExpanded) + return; + + // Draw Rotation Config + using (IndentLevel.Do(EditorGUI.indentLevel + 1)) + using (LabelWidth.Do(128.0f)) + { + var driverTransformProperty = property.GetMemberProperty( k => k.driverTransform); + var rotationTypeProperty = property.GetMemberProperty( k => k.rotationType); + var interpolationCurve = property.GetMemberProperty( k => k.interpolationCurve); + + var startRotationLabel = new GUIContent("Start Rotation"); + var endRotationLabel = new GUIContent("End Rotation"); + + EditorGUI.PropertyField(rowDriverTransform, driverTransformProperty); + EditorGUI.PropertyField(rowRotationType, rotationTypeProperty); + + rowValues.Left(rowValues.width * 0.5f, out var leftRect).Expand(out var rightRect); + leftRect.Right(26.0f, out var leftButtonRect).Left(-2.0f).Expand(out var outLeftRect); + rightRect.Right(26.0f, out var rightButtonRect).Left(-2.0f).Expand(out var outRightRect); + + if (driverTransformProperty.objectReferenceValue != null) + driverTransformEulerAngles = ((Transform)driverTransformProperty.objectReferenceValue).localEulerAngles; + + if (rotationTypeProperty.enumValueIndex == (int)ShapeKeyRotationConfig.RotationType.SingleAxis) + { + var rotationAxisProperty = property.GetMemberProperty( k => k.rotationAxis); + var startValueProperty = property.GetMemberProperty( k => k.singleAxisStartRotation); + var endValueProperty = property.GetMemberProperty( k => k.singleAxisEndRotation); + + // Draw Property + EditorGUI.PropertyField(rowAxis, rotationAxisProperty); + + EditorGUI.PropertyField(outLeftRect, startValueProperty, startRotationLabel); + if (GUI.Button(leftButtonRect, EditorGUIUtility.IconContent("d_Transform Icon"))) + { + switch ((ShapeKeyRotationConfig.RotationAxis)rotationAxisProperty.enumValueIndex) + { + case ShapeKeyRotationConfig.RotationAxis.X: + startValueProperty.floatValue = driverTransformEulerAngles.x; + break; + case ShapeKeyRotationConfig.RotationAxis.Y: + startValueProperty.floatValue = driverTransformEulerAngles.y; + break; + case ShapeKeyRotationConfig.RotationAxis.Z: + startValueProperty.floatValue = driverTransformEulerAngles.z; + break; + } + } + + EditorGUI.PropertyField(outRightRect, endValueProperty, endRotationLabel); + if (GUI.Button(rightButtonRect, EditorGUIUtility.IconContent("d_Transform Icon"))) + { + switch (rotationAxisProperty.enumValueIndex) + { + case 0: + endValueProperty.floatValue = driverTransformEulerAngles.x; + break; + case 1: + endValueProperty.floatValue = driverTransformEulerAngles.y; + break; + case 2: + endValueProperty.floatValue = driverTransformEulerAngles.z; + break; + } + } + } + else + { + var startRotationProperty = property.GetMemberProperty( k => k.multiAxisStartRotation); + var endRotationProperty = property.GetMemberProperty( k => k.multiAxisEndRotation); + + EditorGUI.PropertyField(outLeftRect, startRotationProperty, startRotationLabel); + if (GUI.Button(leftButtonRect, EditorGUIUtility.IconContent("d_Transform Icon"))) + { + startRotationProperty.vector3Value = driverTransformEulerAngles; + } + + EditorGUI.PropertyField(outRightRect, endRotationProperty, endRotationLabel); + if (GUI.Button(rightButtonRect, EditorGUIUtility.IconContent("d_Transform Icon"))) + { + endRotationProperty.vector3Value = driverTransformEulerAngles; + } + } + + + rowCurve.height = EditorHelper.SingleLineHeight * 3; + EditorGUI.PropertyField(rowCurve, interpolationCurve, CurveLabel); + + } + } + } +} diff --git a/Assets/Editor/Animation/ShapeKeyDriver/ShapeKeyRotationConfigDrawer.cs.meta b/Assets/Editor/Animation/ShapeKeyDriver/ShapeKeyRotationConfigDrawer.cs.meta new file mode 100644 index 0000000..27db18a --- /dev/null +++ b/Assets/Editor/Animation/ShapeKeyDriver/ShapeKeyRotationConfigDrawer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 1eeee3f5cd3263944a7c0639d5c20181 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Editor/AssetImporter/EventsImporter.cs b/Assets/Editor/AssetImporter/EventsImporter.cs index cc7517a..ba9e259 100644 --- a/Assets/Editor/AssetImporter/EventsImporter.cs +++ b/Assets/Editor/AssetImporter/EventsImporter.cs @@ -18,8 +18,8 @@ private void OnPostprocessAnimation(GameObject root, AnimationClip clip) foreach (var action in eventsData.ActionsMarkers) { - var clipName = clip.name.Split('|'); - if (clipName[1] == action.Name) + var clipName = clip.name.Split('|', 2); + if (clipName.Length == 2 && clipName[1] == action.Name) { List allAnimationEvents = new List(); foreach (var marker in action.Markers) diff --git a/Assets/Editor/Extensions/RectExtensions.cs b/Assets/Editor/Extensions/RectExtensions.cs index d9d8346..a732c62 100644 --- a/Assets/Editor/Extensions/RectExtensions.cs +++ b/Assets/Editor/Extensions/RectExtensions.cs @@ -1,5 +1,6 @@ using UnityEditor; using UnityEngine; +using UnityEngine.UIElements; namespace BitStrap { @@ -20,8 +21,8 @@ public static class RectExtensions /// public static Rect Row( this Rect position, int rowNumber ) { - position.y += EditorGUIUtility.singleLineHeight * rowNumber; - position.height = EditorGUIUtility.singleLineHeight; + position.y += EditorHelper.SingleLineHeight * rowNumber; + position.height = EditorHelper.SingleLineHeight; return position; } @@ -149,5 +150,6 @@ public static void Expand( this Rect position, out Rect target ) { target = position; } + } } \ No newline at end of file diff --git a/Assets/Editor/Helpers/EditorHelper.cs b/Assets/Editor/Helpers/EditorHelper.cs index fb6792f..20931f8 100644 --- a/Assets/Editor/Helpers/EditorHelper.cs +++ b/Assets/Editor/Helpers/EditorHelper.cs @@ -81,6 +81,8 @@ public static GUIStyle Warning } } + public static float SingleLineHeight = EditorGUIUtility.singleLineHeight + 2.0f; + private static string searchField = ""; private static Vector2 scroll = Vector2.zero; private static Texture[] unityIcons = null; @@ -203,7 +205,7 @@ public static Rect Rect( float height ) { return GUILayoutUtility.GetRect( 0.0f, height, GUILayout.ExpandWidth( true ) ); } - + /// /// Returns a GUIContent containing a label and the tooltip defined in GUI.tooltip. /// diff --git a/Assets/Editor/Presets/FBXImporter_Generic.preset b/Assets/Editor/Presets/FBXImporter_Generic.preset new file mode 100644 index 0000000..1f01e6c --- /dev/null +++ b/Assets/Editor/Presets/FBXImporter_Generic.preset @@ -0,0 +1,387 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!181963792 &2655988077585873504 +Preset: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: FBXImporter_Generic + m_TargetType: + m_NativeTypeID: 1041 + m_ManagedTypePPtr: {fileID: 0} + m_ManagedTypeFallback: + m_Properties: + - target: {fileID: 0} + propertyPath: m_ExternalObjects.Array.size + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_MaterialImportMode + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_MaterialName + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_MaterialSearch + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_MaterialLocation + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_LegacyGenerateAnimations + value: 4 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_BakeSimulation + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_ResampleCurves + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_OptimizeGameObjects + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_RemoveConstantScaleCurves + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_MotionNodeName + value: + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_RigImportErrors + value: + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_RigImportWarnings + value: + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_AnimationImportErrors + value: + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_AnimationImportWarnings + value: + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_AnimationRetargetingWarnings + value: + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_AnimationDoRetargetingWarnings + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_ImportAnimatedCustomProperties + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_ImportConstraints + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_AnimationCompression + value: 3 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_AnimationRotationError + value: 0.5 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_AnimationPositionError + value: 0.5 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_AnimationScaleError + value: 0.5 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_AnimationWrapMode + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_ExtraExposedTransformPaths.Array.size + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_ExtraUserProperties.Array.size + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_ClipAnimations.Array.size + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_IsReadable + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_LODScreenPercentages.Array.size + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_GlobalScale + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_MeshCompression + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_AddColliders + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_UseSRGBMaterialColor + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_SortHierarchyByName + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_ImportVisibility + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_ImportBlendShapes + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_ImportCameras + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_ImportLights + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_NodeNameCollisionStrategy + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: swapUVChannels + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: generateSecondaryUV + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_UseFileUnits + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: keepQuads + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: weldVertices + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: bakeAxisConversion + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_PreserveHierarchy + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: skinWeightsMode + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: maxBonesPerVertex + value: 4 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: minBoneWeight + value: 0.001 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: optimizeBones + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: meshOptimizationFlags + value: -1 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: indexFormat + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: secondaryUVAngleDistortion + value: 8 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: secondaryUVAreaDistortion + value: 15.000001 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: secondaryUVHardAngle + value: 88 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: secondaryUVMarginMethod + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: secondaryUVMinLightmapResolution + value: 40 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: secondaryUVMinObjectScale + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: secondaryUVPackMargin + value: 4 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_UseFileScale + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: normalSmoothAngle + value: 60 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: normalImportMode + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: tangentImportMode + value: 3 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: normalCalculationMode + value: 4 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: legacyComputeAllNormalsFromSmoothingGroupsWhenMeshHasBlendShapes + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: blendShapeNormalImportMode + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: normalSmoothingSource + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_ReferencedClips.Array.size + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_ImportAnimation + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_HumanDescription.m_Human.Array.size + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_HumanDescription.m_Skeleton.Array.size + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_HumanDescription.m_ArmTwist + value: 0.5 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_HumanDescription.m_ForeArmTwist + value: 0.5 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_HumanDescription.m_UpperLegTwist + value: 0.5 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_HumanDescription.m_LegTwist + value: 0.5 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_HumanDescription.m_ArmStretch + value: 0.05 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_HumanDescription.m_LegStretch + value: 0.05 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_HumanDescription.m_FeetSpacing + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_HumanDescription.m_GlobalScale + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_HumanDescription.m_RootMotionBoneName + value: + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_HumanDescription.m_HasTranslationDoF + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_HumanDescription.m_HasExtraRoot + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_HumanDescription.m_SkeletonHasParents + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_LastHumanDescriptionAvatarSource + value: + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_AutoGenerateAvatarMappingIfUnspecified + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_AnimationType + value: 2 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_HumanoidOversampling + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_AvatarSetup + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_AddHumanoidExtraRootOnlyWhenUsingAvatar + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_AdditionalBone + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_UserData + value: + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_AssetBundleName + value: + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_AssetBundleVariant + value: + objectReference: {fileID: 0} + m_ExcludedProperties: [] diff --git a/Assets/Editor/Presets/FBXImporter_Generic.preset.meta b/Assets/Editor/Presets/FBXImporter_Generic.preset.meta new file mode 100644 index 0000000..6420c7d --- /dev/null +++ b/Assets/Editor/Presets/FBXImporter_Generic.preset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 5610357c12c40f44b87b8e29d22acb1d +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 2655988077585873504 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Runtime/Animation/ShapeKeyDriver.meta b/Assets/Runtime/Animation/ShapeKeyDriver.meta new file mode 100644 index 0000000..b349341 --- /dev/null +++ b/Assets/Runtime/Animation/ShapeKeyDriver.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: a11a852b1d3098e4d904cc4dc0e67cd2 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Runtime/Animation/ShapeKeyDriver/ShapeKeyDefinition.cs b/Assets/Runtime/Animation/ShapeKeyDriver/ShapeKeyDefinition.cs new file mode 100644 index 0000000..2e61947 --- /dev/null +++ b/Assets/Runtime/Animation/ShapeKeyDriver/ShapeKeyDefinition.cs @@ -0,0 +1,160 @@ +using UnityEngine; + +[System.Serializable] +public struct ShapeKeyDefinition +{ + public string name; + public int index; +} + +/// +/// Lets you use ShapeKeyDefinition even when its MonoBehaviour does not have a sibling SkinnedMeshRenderer component. +/// +[System.AttributeUsage( System.AttributeTargets.Field, AllowMultiple = false, Inherited = true )] +public sealed class SkinnedMeshRendererFieldAttribute : System.Attribute +{ + public string skinnedMeshRendererFieldName; + + public SkinnedMeshRendererFieldAttribute( string skinnedMeshRendererFieldName ) + { + this.skinnedMeshRendererFieldName = skinnedMeshRendererFieldName; + } +} + +[System.Serializable] +public struct ShapeKeyRotationConfig +{ + public enum RotationType + { + SingleAxis, + MultiAxis + } + + public enum RotationAxis + { + X, + Y, + Z + } + + public Transform driverTransform; + public RotationType rotationType; + public RotationAxis rotationAxis; + public float singleAxisStartRotation; + public float singleAxisEndRotation; + public Vector3 multiAxisStartRotation; + public Vector3 multiAxisEndRotation; + public AnimationCurve interpolationCurve; + + public float GetTargetSingleRotation() + { + switch (rotationAxis) + { + case RotationAxis.X: + return driverTransform.localEulerAngles.x; + case RotationAxis.Y: + return driverTransform.localEulerAngles.y; + case RotationAxis.Z: + return driverTransform.localEulerAngles.z; + } + + return -1.0f; + } +} + +[System.Serializable] +public struct ShapeKeyPositionConfig +{ + public enum PositionType + { + OneAxis, + TwoAxis, + ThreeAxis, + } + + public enum PositionOneAxis + { + X, + Y, + Z + } + + public enum PositionTwoAxis + { + XY, + XZ, + YX, + YZ, + ZY, + ZX + } + + public Transform driverTransform; + public Transform targetTransform; + public PositionType positionType; + public PositionOneAxis positionOneAxis; + public PositionTwoAxis positionTwoAxis; + public float oneAxisStartPosition; + public float oneAxisEndPosition; + public Vector2 twoAxisStartPosition; + public Vector2 twoAxisEndPosition; + public Vector3 threeAxisStartPosition; + public Vector3 threeAxisEndPosition; + public AnimationCurve interpolationCurve; + + public float GetTargetOneAxisPosition() + { + switch (positionOneAxis) + { + case PositionOneAxis.X: + return driverTransform.position.x; + case PositionOneAxis.Y: + return driverTransform.position.y; + case PositionOneAxis.Z: + return driverTransform.position.z; + } + return -1.0f; + } + + public Vector2 GetTargetTwoAxisPosition() + { + var position = driverTransform.position; + + switch (positionTwoAxis) + { + case PositionTwoAxis.XY: + return new Vector2(position.x, position.y); + case PositionTwoAxis.XZ: + return new Vector2(position.x, position.z); + case PositionTwoAxis.YX: + return new Vector2(position.y, position.x); + case PositionTwoAxis.YZ: + return new Vector2(position.y, position.z); + case PositionTwoAxis.ZY: + return new Vector2(position.z, position.y); + case PositionTwoAxis.ZX: + return new Vector2(position.z, position.x); + } + return Vector2.zero; + } +} + +[System.Serializable] +public struct ShapeKeyRecipe +{ + public ShapeKeyDefinition shapeKeyDefinition; + + public enum DriverType + { + Rotation, + Position, + + // TODO: implement + // MecanimParameter, + // Callback, + } + + public DriverType driverType; + public ShapeKeyRotationConfig shapeKeyRotationConfig; + public ShapeKeyPositionConfig shapeKeyPositionConfig; +} \ No newline at end of file diff --git a/Assets/Runtime/Animation/ShapeKeyDriver/ShapeKeyDefinition.cs.meta b/Assets/Runtime/Animation/ShapeKeyDriver/ShapeKeyDefinition.cs.meta new file mode 100644 index 0000000..1bc2918 --- /dev/null +++ b/Assets/Runtime/Animation/ShapeKeyDriver/ShapeKeyDefinition.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 4d788e8a0bbca5f47ad2ef80e76527f5 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Runtime/Animation/ShapeKeyDriver/ShapeKeyDriver.cs b/Assets/Runtime/Animation/ShapeKeyDriver/ShapeKeyDriver.cs new file mode 100644 index 0000000..18dc181 --- /dev/null +++ b/Assets/Runtime/Animation/ShapeKeyDriver/ShapeKeyDriver.cs @@ -0,0 +1,160 @@ +using UnityEngine; + + +[ExecuteAlways] +public sealed class ShapeKeyDriver : MonoBehaviour +{ + [SerializeField] public SkinnedMeshRenderer skinnedMeshRenderer; + [SerializeField] private ShapeKeyRecipe shapeKeyRecipe; + + private void Update() + { + if (skinnedMeshRenderer == null) + return; + + switch(shapeKeyRecipe.driverType) + { + case ShapeKeyRecipe.DriverType.Rotation: + Debug.Log("Cheguei"); + if (shapeKeyRecipe.shapeKeyRotationConfig.driverTransform == null) + return; + SwitchRotationConfig(); + break; + case ShapeKeyRecipe.DriverType.Position: + if (shapeKeyRecipe.shapeKeyPositionConfig.driverTransform == null) + return; + SwitchPositionConfig(); + break; + } + } + + private void SwitchRotationConfig() + { + switch (shapeKeyRecipe.shapeKeyRotationConfig.rotationType) + { + case ShapeKeyRotationConfig.RotationType.SingleAxis: + { + var currentRotation = shapeKeyRecipe.shapeKeyRotationConfig.GetTargetSingleRotation(); + var percentage = Mathf.InverseLerp(shapeKeyRecipe.shapeKeyRotationConfig.singleAxisStartRotation, + shapeKeyRecipe.shapeKeyRotationConfig.singleAxisEndRotation, currentRotation); + var interpolation = Mathf.Lerp(0, 100, + shapeKeyRecipe.shapeKeyRotationConfig.interpolationCurve.Evaluate(percentage)); + skinnedMeshRenderer.SetBlendShapeWeight(shapeKeyRecipe.shapeKeyDefinition.index, interpolation); + break; + } + case ShapeKeyRotationConfig.RotationType.MultiAxis: + { + var start = Quaternion.Euler(shapeKeyRecipe.shapeKeyRotationConfig.multiAxisStartRotation); + var end = Quaternion.Euler(shapeKeyRecipe.shapeKeyRotationConfig.multiAxisEndRotation); + var mid = Quaternion.SlerpUnclamped(start, end, 0.5f); + // var projected = Vector3.ProjectOnPlane(shapeKeyRecipe.shapeKeyRotationConfig.driverTransform.forward, normal); + var maxAngle = Quaternion.Angle(start, end); + + if (maxAngle < 0) + maxAngle += 360.0f; + + var angleFromStart = + Quaternion.Angle(start, shapeKeyRecipe.shapeKeyRotationConfig.driverTransform.localRotation); + + if (angleFromStart < 0) + angleFromStart += 360.0f; + + var angleToEnd = + Quaternion.Angle(shapeKeyRecipe.shapeKeyRotationConfig.driverTransform.localRotation, end); + + if (angleToEnd < 0) + angleToEnd += 360.0f; + + var angleToMid = Quaternion.Angle(shapeKeyRecipe.shapeKeyRotationConfig.driverTransform.localRotation, + mid); + + if (angleToMid < 0) + angleToMid += 360.0f; + + var percentage = 0.0f; + if (angleFromStart < angleToEnd) + percentage = Mathf.InverseLerp(maxAngle / 2.0f, 0.0f, angleToMid) / 2.0f; + else + percentage = Mathf.InverseLerp(0.0f, maxAngle, angleToMid) + 0.5f; + + // var percentage = Mathf.InverseLerp(0, maxAngle, angle); + + // Debug.Log($"Max: {maxAngle}, Angle From Start: {angleFromStart}, Angle to End: {angleToEnd}, Angle to Mid: {angleToMid}"); + + // var cross = Vector3.Cross(start, projected); + // var max = normal.magnitude; + // var t = cross.magnitude; + // var percentage = t / max; + + var interpolation = shapeKeyRecipe.shapeKeyRotationConfig.interpolationCurve.Evaluate(percentage) * 100; + + skinnedMeshRenderer.SetBlendShapeWeight(shapeKeyRecipe.shapeKeyDefinition.index, interpolation); + break; + } + } + } + private void SwitchPositionConfig() + { + var posConf = shapeKeyRecipe.shapeKeyPositionConfig; + + switch (posConf.positionType) + { + case ShapeKeyPositionConfig.PositionType.OneAxis: + { + var currentPosition = posConf.GetTargetOneAxisPosition(); + var percentage = Mathf.InverseLerp(posConf.oneAxisStartPosition, + posConf.oneAxisEndPosition, currentPosition); + var interpolation = Mathf.Lerp(0, 100, + posConf.interpolationCurve.Evaluate(percentage)); + skinnedMeshRenderer.SetBlendShapeWeight(shapeKeyRecipe.shapeKeyDefinition.index, interpolation); + break; + } + + case ShapeKeyPositionConfig.PositionType.TwoAxis: + { + var currentPosition = posConf.GetTargetTwoAxisPosition(); + + var percentageX = Mathf.InverseLerp(posConf.twoAxisStartPosition.x, + posConf.twoAxisEndPosition.x, currentPosition.x); + + var percentageY = Mathf.InverseLerp(posConf.twoAxisStartPosition.y, + posConf.twoAxisEndPosition.y, currentPosition.y); + + var percentageMedian = (percentageX + percentageY) / 2; + + var interpolation = Mathf.Lerp(0, 100, posConf.interpolationCurve.Evaluate(percentageMedian)); + skinnedMeshRenderer.SetBlendShapeWeight(shapeKeyRecipe.shapeKeyDefinition.index, interpolation); + break; + } + + case ShapeKeyPositionConfig.PositionType.ThreeAxis: + { + var currentPosition = posConf.driverTransform.position; + + var percentageX = Mathf.InverseLerp(posConf.threeAxisStartPosition.x, + posConf.threeAxisEndPosition.x, currentPosition.x); + + var percentageY = Mathf.InverseLerp(posConf.threeAxisStartPosition.y, + posConf.threeAxisEndPosition.y, currentPosition.y); + + var percentageZ = Mathf.InverseLerp(posConf.threeAxisStartPosition.z, + posConf.threeAxisEndPosition.z, currentPosition.z); + + var percentageMean = (percentageX + percentageY + percentageZ) / 3; + + var interpolation = Mathf.Lerp(0, 100, posConf.interpolationCurve.Evaluate(percentageMean)); + skinnedMeshRenderer.SetBlendShapeWeight(shapeKeyRecipe.shapeKeyDefinition.index, interpolation); + + break; + } + } + } + + + public static float InverseLerp(Vector3 a, Vector3 b, Vector3 value) + { + Vector3 AB = b - a; + Vector3 AV = value - a; + return Vector3.Dot(AV, AB) / Vector3.Dot(AB, AB); + } +} diff --git a/Assets/Runtime/Animation/ShapeKeyDriver/ShapeKeyDriver.cs.meta b/Assets/Runtime/Animation/ShapeKeyDriver/ShapeKeyDriver.cs.meta new file mode 100644 index 0000000..7b0cbcc --- /dev/null +++ b/Assets/Runtime/Animation/ShapeKeyDriver/ShapeKeyDriver.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: ea86ae99dbd067b4db1f44da1c93a5c7 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/manifest.json b/Packages/manifest.json index 1d14866..844d8f5 100644 --- a/Packages/manifest.json +++ b/Packages/manifest.json @@ -2,8 +2,8 @@ "dependencies": { "com.unity.2d.sprite": "1.0.0", "com.unity.2d.tilemap": "1.0.0", - "com.unity.ide.rider": "3.0.7", - "com.unity.ide.visualstudio": "2.0.12", + "com.unity.ide.rider": "3.0.9", + "com.unity.ide.visualstudio": "2.0.14", "com.unity.ide.vscode": "1.2.4", "com.unity.test-framework": "1.1.29", "com.unity.textmeshpro": "3.0.6", diff --git a/Packages/packages-lock.json b/Packages/packages-lock.json index 7acfca2..6dd6cc0 100644 --- a/Packages/packages-lock.json +++ b/Packages/packages-lock.json @@ -20,7 +20,7 @@ "url": "https://packages.unity.com" }, "com.unity.ide.rider": { - "version": "3.0.7", + "version": "3.0.9", "depth": 0, "source": "registry", "dependencies": { @@ -29,7 +29,7 @@ "url": "https://packages.unity.com" }, "com.unity.ide.visualstudio": { - "version": "2.0.12", + "version": "2.0.14", "depth": 0, "source": "registry", "dependencies": { diff --git a/ProjectSettings/PresetManager.asset b/ProjectSettings/PresetManager.asset index 23fddb1..bb8acaf 100644 --- a/ProjectSettings/PresetManager.asset +++ b/ProjectSettings/PresetManager.asset @@ -42,3 +42,7 @@ PresetManager: type: 2} m_Filter: glob:"SK_*.fbx" m_Disabled: 0 + - m_Preset: {fileID: 2655988077585873504, guid: 5610357c12c40f44b87b8e29d22acb1d, + type: 2} + m_Filter: + m_Disabled: 0 diff --git a/ProjectSettings/ProjectVersion.txt b/ProjectSettings/ProjectVersion.txt index 86fa6b5..1f6fff2 100644 --- a/ProjectSettings/ProjectVersion.txt +++ b/ProjectSettings/ProjectVersion.txt @@ -1,2 +1,2 @@ -m_EditorVersion: 2021.2.6f1 -m_EditorVersionWithRevision: 2021.2.6f1 (8c4e826ba445) +m_EditorVersion: 2021.2.11f1 +m_EditorVersionWithRevision: 2021.2.11f1 (e50cafbb4399)