导入leg插件,完成腿部动画
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7d638a4fb97b8d04bace243b5971b7ff
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,63 @@
|
||||
using FIMSpace.AnimationTools;
|
||||
using FIMSpace.FTools;
|
||||
using UnityEngine;
|
||||
|
||||
namespace FIMSpace.FProceduralAnimation
|
||||
{
|
||||
[System.Serializable]
|
||||
public class AxisLockableIK : FimpIK_Limb
|
||||
{
|
||||
public enum EIKAxisLock { None = 0, X = 2, Y = 4, Z = 8 }
|
||||
public EIKAxisLock FirstBoneAxisLock = EIKAxisLock.None;
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
if (!Initialized) return;
|
||||
|
||||
Refresh();
|
||||
|
||||
// Foot IK Position ---------------------------------------------------
|
||||
|
||||
float posWeight = IKPositionWeight * IKWeight;
|
||||
StartIKBone.sqrMagn = (MiddleIKBone.transform.position - StartIKBone.transform.position).sqrMagnitude;
|
||||
MiddleIKBone.sqrMagn = (EndIKBone.transform.position - MiddleIKBone.transform.position).sqrMagnitude;
|
||||
|
||||
targetElbowNormal = GetDefaultFlexNormal();
|
||||
if (ExtraHintAdjustementOffset != Vector3.zero)
|
||||
{
|
||||
targetElbowNormal = Vector3.Lerp(targetElbowNormal, CalculateElbowNormalToPosition(EndIKBone.transform.position + EndIKBone.transform.rotation * ExtraHintAdjustementOffset), ExtraHintAdjustementOffset.magnitude).normalized;
|
||||
}
|
||||
|
||||
Vector3 orientationDirection = GetOrientationDirection(IKTargetPosition, InverseHint ? -targetElbowNormal : targetElbowNormal);
|
||||
if (orientationDirection == Vector3.zero) orientationDirection = MiddleIKBone.transform.position - StartIKBone.transform.position;
|
||||
|
||||
if (posWeight > 0f)
|
||||
{
|
||||
Quaternion sBoneRot = StartIKBone.GetRotation(orientationDirection, targetElbowNormal) * StartBoneRotationOffset;
|
||||
if (posWeight < 1f) sBoneRot = Quaternion.LerpUnclamped(StartIKBone.srcRotation, sBoneRot, posWeight);
|
||||
|
||||
if (FirstBoneAxisLock != EIKAxisLock.None) ApplyAxisLock(FirstBoneAxisLock, StartIKBone, ref sBoneRot);
|
||||
|
||||
StartIKBone.transform.rotation = sBoneRot;
|
||||
|
||||
Quaternion sMidBoneRot = MiddleIKBone.GetRotation(IKTargetPosition - MiddleIKBone.transform.position, MiddleIKBone.GetCurrentOrientationNormal());
|
||||
if (posWeight < 1f) sMidBoneRot = Quaternion.LerpUnclamped(MiddleIKBone.srcRotation, sMidBoneRot, posWeight);
|
||||
//if (SecondBoneAxisLock != EIKAxisLock.None) ApplyAxisLock(SecondBoneAxisLock, MiddleIKBone, ref sMidBoneRot);
|
||||
MiddleIKBone.transform.rotation = sMidBoneRot;
|
||||
}
|
||||
|
||||
postIKAnimatorEndBoneRot = EndIKBone.transform.rotation;
|
||||
|
||||
EndBoneRotation();
|
||||
}
|
||||
|
||||
void ApplyAxisLock(EIKAxisLock axisLock, IKBone ikBone, ref Quaternion targetRotation)
|
||||
{
|
||||
Vector3 local = FEngineering.QToLocal(ikBone.transform.parent.rotation, targetRotation).eulerAngles;
|
||||
if ((axisLock & EIKAxisLock.X) != 0) local.x = ikBone.LastKeyLocalRotation.eulerAngles.x;
|
||||
if ((axisLock & EIKAxisLock.Y) != 0) local.y = ikBone.LastKeyLocalRotation.eulerAngles.y;
|
||||
if ((axisLock & EIKAxisLock.Z) != 0) local.z = ikBone.LastKeyLocalRotation.eulerAngles.z;
|
||||
targetRotation = FEngineering.QToWorld(ikBone.transform.parent.rotation, AnimationGenerateUtils.EnsureQuaternionContinuity(targetRotation, Quaternion.Euler(local)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d8eb946c461acbd48a0945e786205976
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,17 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!114 &11400000
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: d180cb244931ee347a2a3cb0bffea79b, type: 3}
|
||||
m_Name: IK Algorithm Switch - Axis Lock IK
|
||||
m_EditorClassIdentifier:
|
||||
lockX: 1
|
||||
lockY: 0
|
||||
lockZ: 0
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bd5ae1786526f0a41ac10d123176abac
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 11400000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,64 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace FIMSpace.FProceduralAnimation
|
||||
{
|
||||
/// <summary>
|
||||
/// Example class for assigning custom inherited IK processor to the legs animator
|
||||
/// </summary>
|
||||
//[CreateAssetMenu]
|
||||
public class LAM_IKAlgorithmSwitch : LegsAnimatorControlModuleBase
|
||||
{
|
||||
public bool lockX = true;
|
||||
public bool lockY = false;
|
||||
public bool lockZ = false;
|
||||
|
||||
[NonSerialized] List<AxisLockableIK> playmodeIKProcessors = null;
|
||||
|
||||
public override void OnInit(LegsAnimator.LegsAnimatorCustomModuleHelper helper)
|
||||
{
|
||||
base.OnInit(helper);
|
||||
playmodeIKProcessors = new List<AxisLockableIK>();
|
||||
|
||||
for (int i = 0; i < LegsAnim.Legs.Count; i++)
|
||||
{
|
||||
var leg = LegsAnim.Legs[i];
|
||||
AxisLockableIK newIK = new AxisLockableIK();
|
||||
playmodeIKProcessors.Add(newIK);
|
||||
leg.AssignCustomIKProcessor(newIK);
|
||||
}
|
||||
|
||||
OnValidateAfterManualChanges(helper);
|
||||
}
|
||||
|
||||
AxisLockableIK.EIKAxisLock GetLock()
|
||||
{
|
||||
AxisLockableIK.EIKAxisLock lockFlag = AxisLockableIK.EIKAxisLock.None;
|
||||
if (lockX) lockFlag |= AxisLockableIK.EIKAxisLock.X;
|
||||
if (lockY) lockFlag |= AxisLockableIK.EIKAxisLock.Y;
|
||||
if (lockZ) lockFlag |= AxisLockableIK.EIKAxisLock.Z;
|
||||
|
||||
return lockFlag;
|
||||
}
|
||||
|
||||
private void OnValidate()
|
||||
{
|
||||
OnValidateAfterManualChanges(null);
|
||||
}
|
||||
|
||||
public override void OnValidateAfterManualChanges(LegsAnimator.LegsAnimatorCustomModuleHelper helper)
|
||||
{
|
||||
if ( helper != null) base.OnValidateAfterManualChanges(helper);
|
||||
|
||||
if (playmodeIKProcessors == null) return;
|
||||
|
||||
for (int i = 0; i < playmodeIKProcessors.Count; i++)
|
||||
{
|
||||
var ik = playmodeIKProcessors[i];
|
||||
ik.FirstBoneAxisLock = GetLock();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d180cb244931ee347a2a3cb0bffea79b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: a5d56514a4a6be14bb151cf321fe54ef, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,13 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace FIMSpace.FProceduralAnimation
|
||||
{
|
||||
//[CreateAssetMenu(fileName = "LAM_FadeGluingOnAnimator", menuName = "LAM_FadeGluingOnAnimator", order = 1)]
|
||||
public class LAM_FadeGluingOnAnimator : LAM_FadeOnAnimatorStatusBase
|
||||
{
|
||||
protected override void OnFadeAction(LegsAnimator.LegsAnimatorCustomModuleHelper helper, float fadeValue)
|
||||
{
|
||||
helper.Parent.MainGlueBlend = fadeValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 784341415dd04c14dbcff7c4546ffc34
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: a5d56514a4a6be14bb151cf321fe54ef, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,60 @@
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
#endif
|
||||
using UnityEngine;
|
||||
using static FIMSpace.FProceduralAnimation.LegsAnimator;
|
||||
|
||||
namespace FIMSpace.FProceduralAnimation
|
||||
{
|
||||
//[CreateAssetMenu(fileName = "LAM_FadeGluingOnAnimatorParam", menuName = "FImpossible Creations/Legs Animator/LAM_FadeGluingOnAnimatorParam", order = 2)]
|
||||
public class LAM_FadeGluingOnAnimatorParam : LegsAnimatorControlModuleBase
|
||||
{
|
||||
int _hash = -1;
|
||||
public override void OnInit(LegsAnimator.LegsAnimatorCustomModuleHelper helper)
|
||||
{
|
||||
string boolParamName = helper.RequestVariable("Disable Gluing On Bool Param", "Animator Param Name").GetString();
|
||||
_hash = Animator.StringToHash(boolParamName);
|
||||
}
|
||||
|
||||
public override void OnUpdate(LegsAnimatorCustomModuleHelper helper)
|
||||
{
|
||||
if (helper.Parent.Mecanim.GetBool(_hash))
|
||||
{
|
||||
helper.Parent.MainGlueBlend = Mathf.MoveTowards(helper.Parent.MainGlueBlend, 0.001f, Time.deltaTime * 7f);
|
||||
}
|
||||
else
|
||||
{
|
||||
helper.Parent.MainGlueBlend = Mathf.MoveTowards(helper.Parent.MainGlueBlend, 1f, Time.deltaTime * 7f);
|
||||
}
|
||||
}
|
||||
|
||||
#region Editor Code
|
||||
|
||||
#if UNITY_EDITOR
|
||||
|
||||
public override void Editor_InspectorGUI(LegsAnimator legsAnimator, LegsAnimator.LegsAnimatorCustomModuleHelper helper)
|
||||
{
|
||||
EditorGUILayout.HelpBox("Fade off Legs Animator gluing when animator bool parameter is true.", UnityEditor.MessageType.Info);
|
||||
GUILayout.Space(3);
|
||||
|
||||
var boolParamName = helper.RequestVariable("Disable Gluing On Bool Param", "Animator Param Name");
|
||||
boolParamName.Editor_DisplayVariableGUI();
|
||||
|
||||
if (helper.Parent.Mecanim == null)
|
||||
{
|
||||
EditorGUILayout.HelpBox("This module requires animator to be assigned under Legs Animator 'Extra -> Control' bookmark!", UnityEditor.MessageType.Warning);
|
||||
}
|
||||
|
||||
if ( Initialized)
|
||||
{
|
||||
if (!legsAnimator.Mecanim) return;
|
||||
EditorGUILayout.LabelField("Hash " + _hash + " value for animator is = " + legsAnimator.Mecanim.GetBool(_hash));
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 41c05f5ae617111478101e99487d35e4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: a5d56514a4a6be14bb151cf321fe54ef, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,13 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace FIMSpace.FProceduralAnimation
|
||||
{
|
||||
//[CreateAssetMenu(fileName = "LAM_FadeLegsSystemOnAnimator", menuName = "LAM_FadeLegsSystemOnAnimator", order = 1)]
|
||||
public class LAM_FadeLegsSystemOnAnimator : LAM_FadeOnAnimatorStatusBase
|
||||
{
|
||||
protected override void OnFadeAction(LegsAnimator.LegsAnimatorCustomModuleHelper helper, float fadeValue)
|
||||
{
|
||||
helper.Parent.LegsAnimatorBlend = Mathf.Max(0.001f, fadeValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 58cf4ef326b08a649b5f39587ab387a6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: a5d56514a4a6be14bb151cf321fe54ef, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user