Skip to content

Commit

Permalink
fix animator bugs.
Browse files Browse the repository at this point in the history
  • Loading branch information
hecomi committed Dec 27, 2022
1 parent 4145264 commit 4154939
Show file tree
Hide file tree
Showing 5 changed files with 194 additions and 21 deletions.
25 changes: 18 additions & 7 deletions Assets/uLipSync/Editor/uLipSyncAnimatorEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,18 @@ protected void DrawAnimatorReorderableList()

protected void DrawParameterListItem(Rect rect, int index)
{
var animator = anim.animator;
if (!animator) return;

if (!animator.isInitialized)
{
animator.Rebind();
}

rect.y += 2f;
rect.height = EditorGUIUtility.singleLineHeight;

var animatorParams = anim.animator.parameters;
var animatorParams = animator.parameters;
var param = anim.parameters[index];
float singleLineHeight =
EditorGUIUtility.singleLineHeight +
Expand All @@ -146,14 +154,15 @@ protected void DrawParameterListItem(Rect rect, int index)

rect.y += singleLineHeight;

var newIndex = EditorGUI.Popup(rect, "Parameter", param.index + 1, GetParameterArray());
if (newIndex != param.index + 1 || param.name != animatorParams[param.index + 1].name)
var curIndex = param.index + 1;
var newIndex = EditorGUI.Popup(rect, "Parameter", curIndex, GetParameterArray());
if (newIndex != curIndex ||
param.name != animatorParams[curIndex].name)
{
Undo.RecordObject(target, "Change Parameter");
param.index = newIndex - 1;
param.name = animatorParams[param.index + 1].name;
param.nameHash = Animator.StringToHash(param.name);
// Debug.Log($"parameter: {param.name} - {param.nameHash}");
}

rect.y += singleLineHeight;
Expand All @@ -179,13 +188,15 @@ protected virtual string[] GetParameterArray()
{
return new string[0];
}
var parAnimator = anim.animator.parameters;

var parameters = anim.animator.parameters;
var names = new List<string>();
for (int i = 0; i < parAnimator.Length; ++i)
for (int i = 0; i < parameters.Length; ++i)
{
var name = parAnimator[i].name;
var name = parameters[i].name;
names.Add(name);
}

return names.ToArray();
}

Expand Down
1 change: 0 additions & 1 deletion Assets/uLipSync/Runtime/uLipSyncAnimator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
namespace uLipSync
{

[ExecuteAlways]
public class uLipSyncAnimator : MonoBehaviour
{
[System.Serializable]
Expand Down
172 changes: 167 additions & 5 deletions Assets/uLipSync/Samples/09. Animator/09. Animator.unity
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,142 @@ PrefabInstance:
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 400002, guid: 49f2055d53eeb4e5a92af590a44bddee, type: 3}
propertyPath: m_LocalRotation.w
value: 0.99984735
objectReference: {fileID: 0}
- target: {fileID: 400002, guid: 49f2055d53eeb4e5a92af590a44bddee, type: 3}
propertyPath: m_LocalRotation.x
value: 0.0033316324
objectReference: {fileID: 0}
- target: {fileID: 400002, guid: 49f2055d53eeb4e5a92af590a44bddee, type: 3}
propertyPath: m_LocalRotation.y
value: -0.016953701
objectReference: {fileID: 0}
- target: {fileID: 400002, guid: 49f2055d53eeb4e5a92af590a44bddee, type: 3}
propertyPath: m_LocalRotation.z
value: -0.0026204465
objectReference: {fileID: 0}
- target: {fileID: 400006, guid: 49f2055d53eeb4e5a92af590a44bddee, type: 3}
propertyPath: m_LocalRotation.w
value: 0.9991158
objectReference: {fileID: 0}
- target: {fileID: 400006, guid: 49f2055d53eeb4e5a92af590a44bddee, type: 3}
propertyPath: m_LocalRotation.x
value: 0.0045698783
objectReference: {fileID: 0}
- target: {fileID: 400006, guid: 49f2055d53eeb4e5a92af590a44bddee, type: 3}
propertyPath: m_LocalRotation.y
value: 0.04177777
objectReference: {fileID: 0}
- target: {fileID: 400006, guid: 49f2055d53eeb4e5a92af590a44bddee, type: 3}
propertyPath: m_LocalRotation.z
value: 0.0011832331
objectReference: {fileID: 0}
- target: {fileID: 400016, guid: 49f2055d53eeb4e5a92af590a44bddee, type: 3}
propertyPath: m_LocalRotation.w
value: 0.99970824
objectReference: {fileID: 0}
- target: {fileID: 400016, guid: 49f2055d53eeb4e5a92af590a44bddee, type: 3}
propertyPath: m_LocalRotation.x
value: -0.014208468
objectReference: {fileID: 0}
- target: {fileID: 400016, guid: 49f2055d53eeb4e5a92af590a44bddee, type: 3}
propertyPath: m_LocalRotation.y
value: -0.008251851
objectReference: {fileID: 0}
- target: {fileID: 400016, guid: 49f2055d53eeb4e5a92af590a44bddee, type: 3}
propertyPath: m_LocalRotation.z
value: -0.01770875
objectReference: {fileID: 0}
- target: {fileID: 400042, guid: 49f2055d53eeb4e5a92af590a44bddee, type: 3}
propertyPath: m_LocalRotation.w
value: 0.7103707
objectReference: {fileID: 0}
- target: {fileID: 400042, guid: 49f2055d53eeb4e5a92af590a44bddee, type: 3}
propertyPath: m_LocalRotation.x
value: 0.55629915
objectReference: {fileID: 0}
- target: {fileID: 400120, guid: 49f2055d53eeb4e5a92af590a44bddee, type: 3}
propertyPath: m_LocalRotation.w
value: 0.99749005
objectReference: {fileID: 0}
- target: {fileID: 400120, guid: 49f2055d53eeb4e5a92af590a44bddee, type: 3}
propertyPath: m_LocalRotation.x
value: 0.02437098
objectReference: {fileID: 0}
- target: {fileID: 400120, guid: 49f2055d53eeb4e5a92af590a44bddee, type: 3}
propertyPath: m_LocalRotation.y
value: -0.06598203
objectReference: {fileID: 0}
- target: {fileID: 400120, guid: 49f2055d53eeb4e5a92af590a44bddee, type: 3}
propertyPath: m_LocalRotation.z
value: -0.008131703
objectReference: {fileID: 0}
- target: {fileID: 400150, guid: 49f2055d53eeb4e5a92af590a44bddee, type: 3}
propertyPath: m_LocalRotation.w
value: 0.9980724
objectReference: {fileID: 0}
- target: {fileID: 400150, guid: 49f2055d53eeb4e5a92af590a44bddee, type: 3}
propertyPath: m_LocalRotation.x
value: 0.0027491862
objectReference: {fileID: 0}
- target: {fileID: 400150, guid: 49f2055d53eeb4e5a92af590a44bddee, type: 3}
propertyPath: m_LocalRotation.y
value: -0.06182895
objectReference: {fileID: 0}
- target: {fileID: 400150, guid: 49f2055d53eeb4e5a92af590a44bddee, type: 3}
propertyPath: m_LocalRotation.z
value: 0.004609379
objectReference: {fileID: 0}
- target: {fileID: 400172, guid: 49f2055d53eeb4e5a92af590a44bddee, type: 3}
propertyPath: m_LocalRotation.w
value: 0.06080669
objectReference: {fileID: 0}
- target: {fileID: 400172, guid: 49f2055d53eeb4e5a92af590a44bddee, type: 3}
propertyPath: m_LocalRotation.x
value: -0.093746535
objectReference: {fileID: 0}
- target: {fileID: 400172, guid: 49f2055d53eeb4e5a92af590a44bddee, type: 3}
propertyPath: m_LocalRotation.y
value: 0.6978551
objectReference: {fileID: 0}
- target: {fileID: 400172, guid: 49f2055d53eeb4e5a92af590a44bddee, type: 3}
propertyPath: m_LocalRotation.z
value: 0.707469
objectReference: {fileID: 0}
- target: {fileID: 400286, guid: 49f2055d53eeb4e5a92af590a44bddee, type: 3}
propertyPath: m_LocalRotation.w
value: 0.9999994
objectReference: {fileID: 0}
- target: {fileID: 400286, guid: 49f2055d53eeb4e5a92af590a44bddee, type: 3}
propertyPath: m_LocalRotation.x
value: -0.00012384402
objectReference: {fileID: 0}
- target: {fileID: 400286, guid: 49f2055d53eeb4e5a92af590a44bddee, type: 3}
propertyPath: m_LocalRotation.y
value: 0.0010411701
objectReference: {fileID: 0}
- target: {fileID: 400286, guid: 49f2055d53eeb4e5a92af590a44bddee, type: 3}
propertyPath: m_LocalRotation.z
value: -0.000427518
objectReference: {fileID: 0}
- target: {fileID: 400304, guid: 49f2055d53eeb4e5a92af590a44bddee, type: 3}
propertyPath: m_LocalRotation.w
value: 0.9989798
objectReference: {fileID: 0}
- target: {fileID: 400304, guid: 49f2055d53eeb4e5a92af590a44bddee, type: 3}
propertyPath: m_LocalRotation.x
value: 0.012592069
objectReference: {fileID: 0}
- target: {fileID: 400304, guid: 49f2055d53eeb4e5a92af590a44bddee, type: 3}
propertyPath: m_LocalRotation.y
value: -0.043249443
objectReference: {fileID: 0}
- target: {fileID: 400304, guid: 49f2055d53eeb4e5a92af590a44bddee, type: 3}
propertyPath: m_LocalRotation.z
value: -0.0032244502
objectReference: {fileID: 0}
- target: {fileID: 400328, guid: 49f2055d53eeb4e5a92af590a44bddee, type: 3}
propertyPath: m_RootOrder
value: 3
Expand Down Expand Up @@ -281,6 +417,10 @@ PrefabInstance:
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 9500000, guid: 49f2055d53eeb4e5a92af590a44bddee, type: 3}
propertyPath: m_Controller
value:
objectReference: {fileID: 9100000, guid: 7d01098ed95f54ac3bc8dfe0368ddcb1, type: 2}
- target: {fileID: 11400040, guid: 49f2055d53eeb4e5a92af590a44bddee, type: 3}
propertyPath: m_Enabled
value: 0
Expand Down Expand Up @@ -337,7 +477,9 @@ PrefabInstance:
propertyPath: m_BlendShapeWeights.Array.data[10]
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_RemovedComponents:
- {fileID: 11400042, guid: 49f2055d53eeb4e5a92af590a44bddee, type: 3}
- {fileID: 11400040, guid: 49f2055d53eeb4e5a92af590a44bddee, type: 3}
m_SourcePrefab: {fileID: 100100000, guid: 49f2055d53eeb4e5a92af590a44bddee, type: 3}
--- !u!1 &496503018 stripped
GameObject:
Expand Down Expand Up @@ -456,8 +598,8 @@ MonoBehaviour:
onLipSyncUpdate:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 0}
m_TargetAssemblyTypeName: uLipSync.uLipSyncBlendShape, uLipSync.Runtime
- m_Target: {fileID: 496503030}
m_TargetAssemblyTypeName: uLipSync.uLipSyncAnimator, uLipSync.Runtime
m_MethodName: OnLipSyncUpdate
m_Mode: 0
m_Arguments:
Expand Down Expand Up @@ -491,10 +633,30 @@ MonoBehaviour:
animator: {fileID: 496503028}
parameters:
- phoneme: A
name: Next
nameHash: -1541554430
name: A
nameHash: -740712821
index: -1
maxWeight: 1
- phoneme: I
name: I
nameHash: -587065671
index: 0
maxWeight: 1
- phoneme: U
name: U
nameHash: -922531082
index: 1
maxWeight: 1
- phoneme: E
name: E
nameHash: -726377838
index: 2
maxWeight: 1
- phoneme: O
name: O
nameHash: 878818188
index: 3
maxWeight: 1
minVolume: -2.5
maxVolume: -1.5
smoothness: 0.05
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ AnimatorController:
m_SyncedLayerAffectsTiming: 0
m_Controller: {fileID: 9100000}
- serializedVersion: 5
m_Name: Face
m_Name: Mouth
m_StateMachine: {fileID: 110720301}
m_Mask: {fileID: 101100000, guid: c6893d99d338240cd834967aa6448379, type: 2}
m_Mask: {fileID: 101100000, guid: 05d4fe4dbc72446a1a1124dbf00627ce, type: 2}
m_Motions: []
m_Behaviours: []
m_BlendingMode: 0
Expand Down Expand Up @@ -257,7 +257,7 @@ AnimatorStateMachine:
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: Face
m_Name: Mouth
m_ChildStates:
- serializedVersion: 1
m_State: {fileID: -1105067801183814876}
Expand Down
11 changes: 6 additions & 5 deletions Assets/uLipSync/Samples/09. Animator/mouth only mask.mask
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
--- !u!319 &101100000
AvatarMask:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: mouth only mask
m_Mask: 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
m_Elements:
Expand Down Expand Up @@ -105,13 +106,13 @@ AvatarMask:
- m_Path: Character1_Reference/Character1_Hips/Character1_Spine/Character1_Spine1/Character1_Spine2/Character1_Neck/Character1_Head
m_Weight: 0
- m_Path: Character1_Reference/Character1_Hips/Character1_Spine/Character1_Spine1/Character1_Spine2/Character1_Neck/Character1_Head/BLW_DEF
m_Weight: 1
m_Weight: 0
- m_Path: Character1_Reference/Character1_Hips/Character1_Spine/Character1_Spine1/Character1_Spine2/Character1_Neck/Character1_Head/eye_base_old
m_Weight: 0
- m_Path: Character1_Reference/Character1_Hips/Character1_Spine/Character1_Spine1/Character1_Spine2/Character1_Neck/Character1_Head/EYE_DEF
m_Weight: 1
m_Weight: 0
- m_Path: Character1_Reference/Character1_Hips/Character1_Spine/Character1_Spine1/Character1_Spine2/Character1_Neck/Character1_Head/EYE_DEF/EL_DEF
m_Weight: 1
m_Weight: 0
- m_Path: Character1_Reference/Character1_Hips/Character1_Spine/Character1_Spine1/Character1_Spine2/Character1_Neck/Character1_Head/eye_L_old
m_Weight: 0
- m_Path: Character1_Reference/Character1_Hips/Character1_Spine/Character1_Spine1/Character1_Spine2/Character1_Neck/Character1_Head/eye_R_old
Expand Down

0 comments on commit 4154939

Please sign in to comment.