diff --git a/Editor/FaceEmoteProcessor.cs b/Editor/FaceEmoteProcessor.cs index e99e5c3..5a1777d 100644 --- a/Editor/FaceEmoteProcessor.cs +++ b/Editor/FaceEmoteProcessor.cs @@ -65,7 +65,7 @@ protected AnimatorControllerLayer GenerateIdleLayer(Runtime.FaceEmoteInstaller i }; var state = layer.stateMachine.AddState("Idle"); - state.writeDefaultValues = false; + state.writeDefaultValues = installer.WriteDefaultsValues; state.motion = installer.IdleMotion; return layer; @@ -80,79 +80,35 @@ protected AnimatorControllerLayer GenerateHandLayer(Runtime.FaceEmoteInstaller i stateMachine = new AnimatorStateMachine(), }; - var idleState = new AnimatorState() - { - name = "Idle", - motion = EmptyAnimation, - writeDefaultValues = false, - }; + var idleState = GenerateAnimatorState("Idle", EmptyAnimation); layer.stateMachine.AddState(idleState, new Vector3(-100, 0)); layer.stateMachine.defaultState = idleState; - if (installer.Definitions == null) installer.Definitions = new List(); - for (int i = 0; i < installer.Definitions.Count; i++) + AnimatorState GenerateAnimatorState(string name, AnimationClip motion) { - var def = installer.Definitions[i]; - var initialState = new AnimatorState() - { - name = $"Idle {i}", - motion = EmptyAnimation, - writeDefaultValues = false, - }; - - var fistState = new AnimatorState() - { - name = $"Fist {i}", - motion = def.Fist ?? EmptyAnimation, - writeDefaultValues = false, - }; - - var openState = new AnimatorState() + return new AnimatorState() { - name = $"Open {i}", - motion = def.Open ?? EmptyAnimation, - writeDefaultValues = false, - }; - - var pointState = new AnimatorState() - { - name = $"Point {i}", - motion = def.Point ?? EmptyAnimation, - writeDefaultValues = false, - }; - - var peaceState = new AnimatorState() - { - name = $"Peace {i}", - motion = def.Peace ?? EmptyAnimation, - writeDefaultValues = false, - }; - - var rockNRollState = new AnimatorState() - { - name = $"RockNRoll {i}", - motion = def.RockNRoll ?? EmptyAnimation, - writeDefaultValues = false, - }; - - var gunState = new AnimatorState() - { - name = $"Gun {i}", - motion = def.Gun ?? EmptyAnimation, - writeDefaultValues = false, + name = name, + motion = motion ?? EmptyAnimation, + writeDefaultValues = installer.WriteDefaultsValues, }; + } - var thumbsUpState = new AnimatorState() - { - name = $"Thumbs up {i}", - motion = def.ThumbsUp ?? EmptyAnimation, - writeDefaultValues = false, - }; + if (installer.Definitions == null) installer.Definitions = new List(); + for (int i = 0; i < installer.Definitions.Count; i++) + { + var def = installer.Definitions[i]; + var initialState = GenerateAnimatorState($"Idle {i}", EmptyAnimation); layer.stateMachine.AddState(initialState, new Vector3(i * 100, 0)); var gestureStates = new AnimatorState[] { - fistState, openState, pointState, peaceState, rockNRollState, gunState, thumbsUpState, + GenerateAnimatorState($"Fist {i}", def.Fist), + GenerateAnimatorState($"Open {i}", def.Open), + GenerateAnimatorState( $"Point {i}", def.Point), + GenerateAnimatorState($"Peace {i}", def.Peace), + GenerateAnimatorState($"RockNRoll {i}", def.RockNRoll), + GenerateAnimatorState($"Thumbs up {i}",def.ThumbsUp), }; // ExpressionSet切り替えの遷移 diff --git a/Runtime/FaceEmoteInstaller.cs b/Runtime/FaceEmoteInstaller.cs index efd9e51..0457b37 100644 --- a/Runtime/FaceEmoteInstaller.cs +++ b/Runtime/FaceEmoteInstaller.cs @@ -14,6 +14,8 @@ public sealed class FaceEmoteInstaller : MonoBehaviour, IEditorOnly public float TransitionSeconds = 0.1f; [SerializeField] public AnimationClip IdleMotion; + [SerializeField] + public bool WriteDefaultsValues; [SerializeField] public List Definitions; diff --git a/Tests/FaceEmoteProcessorTest.cs b/Tests/FaceEmoteProcessorTest.cs index 0d9df74..5d616c7 100644 --- a/Tests/FaceEmoteProcessorTest.cs +++ b/Tests/FaceEmoteProcessorTest.cs @@ -85,11 +85,13 @@ public void TestProcess_GeneratesAnimatorWithParameters() } [Test] - public void TestProcess_GeneratesAnimatorBasedOnFaceEmoteDefinition() + [TestCase(false)] + [TestCase(true)] + public void TestProcess_GeneratesAnimatorBasedOnFaceEmoteDefinition(bool writeDefaultValues) { - var gameObject = new GameObject("Test Target"); var installerComponent = gameObject.AddComponent(); + installerComponent.WriteDefaultsValues = writeDefaultValues; var idleAnim = new AnimationClip(); var idleAnimEvent = new AnimationEvent() { stringParameter = "testFist", time = 10f, floatParameter = 0f }; @@ -145,6 +147,7 @@ void ValidateIdleLayer(AnimatorControllerLayer layer) var idleState = layer.stateMachine.defaultState; Assert.AreEqual(idleAnim, idleState.motion); + Assert.AreEqual(writeDefaultValues, idleState.writeDefaultValues); } void ValidateHandLayer(AnimatorControllerLayer layer, string handSide) @@ -158,7 +161,7 @@ void ValidateHandLayer(AnimatorControllerLayer layer, string handSide) void ValidateEmoteSetStateMachineRoot(AnimatorState root, string handSide) { Assert.IsTrue(((AnimationClip)root.motion).empty); - Assert.AreEqual(false, root.writeDefaultValues); + Assert.AreEqual(writeDefaultValues, root.writeDefaultValues); foreach (var trans in root.transitions) { @@ -188,7 +191,7 @@ void ValidateEmoteSetStateMachineRoot(AnimatorState root, string handSide) void ValidateEmoteSetStateMachineSubSetRoot(AnimatorState node, int setIndex, string handSide) { Assert.IsTrue(((AnimationClip)node.motion).empty); - Assert.AreEqual(false, node.writeDefaultValues); + Assert.AreEqual(writeDefaultValues, node.writeDefaultValues); // assert each expression set Idle to layer root var childIdleToGlobalIdle = node.transitions.Where(trans => trans.destinationState.name == "Idle").Single(); @@ -215,7 +218,7 @@ void ValidateEmoteSetStateMachineSubSetRoot(AnimatorState node, int setIndex, st void ValidateEmoteSetStateMachineSubSetEmote(AnimatorState node, int setIndex, int gestureIndex, string handSide) { - Assert.AreEqual(false, node.writeDefaultValues); + Assert.AreEqual(writeDefaultValues, node.writeDefaultValues); // assert selected motion var def = installerComponent.Definitions[setIndex];