modify animator

This commit is contained in:
Chikashi Miyama 2019-11-01 13:33:23 +01:00
parent a69f121053
commit 86a6c66405
5 changed files with 104 additions and 110 deletions

View file

@ -15,7 +15,7 @@ AnimatorState:
m_StateMachineBehaviours: [] m_StateMachineBehaviours: []
m_Position: {x: 50, y: 50, z: 0} m_Position: {x: 50, y: 50, z: 0}
m_IKOnFeet: 0 m_IKOnFeet: 0
m_WriteDefaultValues: 1 m_WriteDefaultValues: 0
m_Mirror: 0 m_Mirror: 0
m_SpeedParameterActive: 0 m_SpeedParameterActive: 0
m_MirrorParameterActive: 0 m_MirrorParameterActive: 0
@ -36,11 +36,11 @@ AnimatorController:
m_Name: Cube m_Name: Cube
serializedVersion: 5 serializedVersion: 5
m_AnimatorParameters: m_AnimatorParameters:
- m_Name: AnimTrigger - m_Name: Moving
m_Type: 9 m_Type: 4
m_DefaultFloat: 0 m_DefaultFloat: 0
m_DefaultInt: 0 m_DefaultInt: 0
m_DefaultBool: 1 m_DefaultBool: 0
m_Controller: {fileID: 0} m_Controller: {fileID: 0}
m_AnimatorLayers: m_AnimatorLayers:
- serializedVersion: 5 - serializedVersion: 5
@ -90,9 +90,9 @@ AnimatorStateTransition:
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_Name: m_Name:
m_Conditions: m_Conditions:
- m_ConditionMode: 1 - m_ConditionMode: 6
m_ConditionEvent: AnimTrigger m_ConditionEvent: Moving
m_EventTreshold: 0 m_EventTreshold: 1
m_DstStateMachine: {fileID: 0} m_DstStateMachine: {fileID: 0}
m_DstState: {fileID: -985118024630667659} m_DstState: {fileID: -985118024630667659}
m_Solo: 0 m_Solo: 0
@ -101,9 +101,9 @@ AnimatorStateTransition:
serializedVersion: 3 serializedVersion: 3
m_TransitionDuration: 0.25 m_TransitionDuration: 0.25
m_TransitionOffset: 0 m_TransitionOffset: 0
m_ExitTime: 0.75 m_ExitTime: 1
m_HasExitTime: 1 m_HasExitTime: 0
m_HasFixedDuration: 1 m_HasFixedDuration: 0
m_InterruptionSource: 0 m_InterruptionSource: 0
m_OrderedInterruption: 1 m_OrderedInterruption: 1
m_CanTransitionToSelf: 1 m_CanTransitionToSelf: 1
@ -114,18 +114,21 @@ AnimatorStateTransition:
m_PrefabInstance: {fileID: 0} m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_Name: m_Name:
m_Conditions: [] m_Conditions:
- m_ConditionMode: 2
m_ConditionEvent: Moving
m_EventTreshold: 0
m_DstStateMachine: {fileID: 0} m_DstStateMachine: {fileID: 0}
m_DstState: {fileID: 1370166835903048213} m_DstState: {fileID: 1370166835903048213}
m_Solo: 0 m_Solo: 0
m_Mute: 0 m_Mute: 0
m_IsExit: 0 m_IsExit: 0
serializedVersion: 3 serializedVersion: 3
m_TransitionDuration: 0.5383635 m_TransitionDuration: 0
m_TransitionOffset: 0 m_TransitionOffset: 0
m_ExitTime: 0.40248495 m_ExitTime: 1
m_HasExitTime: 1 m_HasExitTime: 0
m_HasFixedDuration: 1 m_HasFixedDuration: 0
m_InterruptionSource: 0 m_InterruptionSource: 0
m_OrderedInterruption: 1 m_OrderedInterruption: 1
m_CanTransitionToSelf: 1 m_CanTransitionToSelf: 1
@ -140,10 +143,10 @@ AnimatorStateMachine:
m_ChildStates: m_ChildStates:
- serializedVersion: 1 - serializedVersion: 1
m_State: {fileID: 1370166835903048213} m_State: {fileID: 1370166835903048213}
m_Position: {x: 300, y: 60, z: 0} m_Position: {x: 340, y: 60, z: 0}
- serializedVersion: 1 - serializedVersion: 1
m_State: {fileID: -985118024630667659} m_State: {fileID: -985118024630667659}
m_Position: {x: 620, y: -60, z: 0} m_Position: {x: 340, y: -30, z: 0}
m_ChildStateMachines: [] m_ChildStateMachines: []
m_AnyStateTransitions: [] m_AnyStateTransitions: []
m_EntryTransitions: [] m_EntryTransitions: []
@ -151,6 +154,6 @@ AnimatorStateMachine:
m_StateMachineBehaviours: [] m_StateMachineBehaviours: []
m_AnyStatePosition: {x: 50, y: 20, z: 0} m_AnyStatePosition: {x: 50, y: 20, z: 0}
m_EntryPosition: {x: 50, y: 120, z: 0} m_EntryPosition: {x: 50, y: 120, z: 0}
m_ExitPosition: {x: 800, y: 120, z: 0} m_ExitPosition: {x: 520, y: 140, z: 0}
m_ParentStateMachinePosition: {x: 800, y: 20, z: 0} m_ParentStateMachinePosition: {x: 800, y: 20, z: 0}
m_DefaultState: {fileID: 1370166835903048213} m_DefaultState: {fileID: 1370166835903048213}

View file

@ -13,33 +13,33 @@ AnimationClip:
m_UseHighQualityCurve: 1 m_UseHighQualityCurve: 1
m_RotationCurves: [] m_RotationCurves: []
m_CompressedRotationCurves: [] m_CompressedRotationCurves: []
m_EulerCurves: m_EulerCurves: []
m_PositionCurves:
- curve: - curve:
serializedVersion: 2 serializedVersion: 2
m_Curve: m_Curve:
- serializedVersion: 3 - serializedVersion: 3
time: 0 time: 0
value: {x: 0, y: 0, z: 0} value: {x: -5, y: -5, z: 0}
inSlope: {x: 0, y: 0, z: 0} inSlope: {x: 0, y: 0, z: 0}
outSlope: {x: 0, y: 0, z: 0} outSlope: {x: 10, y: 0, z: 0}
tangentMode: 0 tangentMode: 0
weightedMode: 0 weightedMode: 0
inWeight: {x: 0.33333334, y: 0.33333334, z: 0.33333334} inWeight: {x: 0.33333334, y: 0.33333334, z: 0.33333334}
outWeight: {x: 0.33333334, y: 0.33333334, z: 0.33333334} outWeight: {x: 0.33333334, y: 0.33333334, z: 0.33333334}
- serializedVersion: 3 - serializedVersion: 3
time: 1 time: 1
value: {x: 360, y: 360, z: 360} value: {x: 5, y: -5, z: 0}
inSlope: {x: 0, y: 0, z: 0} inSlope: {x: 10, y: 0, z: 0}
outSlope: {x: 0, y: 0, z: 0} outSlope: {x: 0, y: 0, z: 0}
tangentMode: 0 tangentMode: 0
weightedMode: 0 weightedMode: 0
inWeight: {x: 0.33333334, y: 0.33333334, z: 0.33333334} inWeight: {x: 0.050967038, y: 0.33333334, z: 0.33333334}
outWeight: {x: 0.33333334, y: 0.33333334, z: 0.33333334} outWeight: {x: 0.33333334, y: 0.33333334, z: 0.33333334}
m_PreInfinity: 2 m_PreInfinity: 2
m_PostInfinity: 2 m_PostInfinity: 2
m_RotationOrder: 4 m_RotationOrder: 4
path: path:
m_PositionCurves: []
m_ScaleCurves: [] m_ScaleCurves: []
m_FloatCurves: [] m_FloatCurves: []
m_PPtrCurves: [] m_PPtrCurves: []
@ -52,10 +52,10 @@ AnimationClip:
genericBindings: genericBindings:
- serializedVersion: 2 - serializedVersion: 2
path: 0 path: 0
attribute: 4 attribute: 1
script: {fileID: 0} script: {fileID: 0}
typeID: 4 typeID: 4
customType: 4 customType: 0
isPPtrCurve: 0 isPPtrCurve: 0
pptrCurveMapping: [] pptrCurveMapping: []
m_AnimationClipSettings: m_AnimationClipSettings:
@ -68,7 +68,7 @@ AnimationClip:
m_Level: 0 m_Level: 0
m_CycleOffset: 0 m_CycleOffset: 0
m_HasAdditiveReferencePose: 0 m_HasAdditiveReferencePose: 0
m_LoopTime: 1 m_LoopTime: 0
m_LoopBlend: 0 m_LoopBlend: 0
m_LoopBlendOrientation: 0 m_LoopBlendOrientation: 0
m_LoopBlendPositionY: 0 m_LoopBlendPositionY: 0
@ -84,7 +84,35 @@ AnimationClip:
m_Curve: m_Curve:
- serializedVersion: 3 - serializedVersion: 3
time: 0 time: 0
value: 0 value: -5
inSlope: 0
outSlope: 10
tangentMode: 65
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
- serializedVersion: 3
time: 1
value: 5
inSlope: 10
outSlope: 0
tangentMode: 5
weightedMode: 0
inWeight: 0.050967038
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
attribute: m_LocalPosition.x
path:
classID: 4
script: {fileID: 0}
- curve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: -5
inSlope: 0 inSlope: 0
outSlope: 0 outSlope: 0
tangentMode: 136 tangentMode: 136
@ -93,7 +121,7 @@ AnimationClip:
outWeight: 0.33333334 outWeight: 0.33333334
- serializedVersion: 3 - serializedVersion: 3
time: 1 time: 1
value: 360 value: -5
inSlope: 0 inSlope: 0
outSlope: 0 outSlope: 0
tangentMode: 136 tangentMode: 136
@ -103,7 +131,7 @@ AnimationClip:
m_PreInfinity: 2 m_PreInfinity: 2
m_PostInfinity: 2 m_PostInfinity: 2
m_RotationOrder: 4 m_RotationOrder: 4
attribute: localEulerAnglesRaw.x attribute: m_LocalPosition.y
path: path:
classID: 4 classID: 4
script: {fileID: 0} script: {fileID: 0}
@ -121,25 +149,6 @@ AnimationClip:
outWeight: 0.33333334 outWeight: 0.33333334
- serializedVersion: 3 - serializedVersion: 3
time: 1 time: 1
value: 360
inSlope: 0
outSlope: 0
tangentMode: 136
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
attribute: localEulerAnglesRaw.y
path:
classID: 4
script: {fileID: 0}
- curve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 0 value: 0
inSlope: 0 inSlope: 0
outSlope: 0 outSlope: 0
@ -147,53 +156,14 @@ AnimationClip:
weightedMode: 0 weightedMode: 0
inWeight: 0.33333334 inWeight: 0.33333334
outWeight: 0.33333334 outWeight: 0.33333334
- serializedVersion: 3
time: 1
value: 360
inSlope: 0
outSlope: 0
tangentMode: 136
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2 m_PreInfinity: 2
m_PostInfinity: 2 m_PostInfinity: 2
m_RotationOrder: 4 m_RotationOrder: 4
attribute: localEulerAnglesRaw.z attribute: m_LocalPosition.z
path:
classID: 4
script: {fileID: 0}
m_EulerEditorCurves:
- curve:
serializedVersion: 2
m_Curve: []
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
attribute: m_LocalEulerAngles.x
path:
classID: 4
script: {fileID: 0}
- curve:
serializedVersion: 2
m_Curve: []
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
attribute: m_LocalEulerAngles.y
path:
classID: 4
script: {fileID: 0}
- curve:
serializedVersion: 2
m_Curve: []
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
attribute: m_LocalEulerAngles.z
path: path:
classID: 4 classID: 4
script: {fileID: 0} script: {fileID: 0}
m_EulerEditorCurves: []
m_HasGenericRootTransform: 1 m_HasGenericRootTransform: 1
m_HasMotionFloatCurves: 0 m_HasMotionFloatCurves: 0
m_Events: [] m_Events: []

View file

@ -244,7 +244,18 @@ MonoBehaviour:
csvFileName: qlist csvFileName: qlist
onStateChanged: onStateChanged:
m_PersistentCalls: m_PersistentCalls:
m_Calls: [] m_Calls:
- m_Target: {fileID: 1843145352}
m_MethodName: OnStateChanged
m_Mode: 0
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
sceneSelection: 0 sceneSelection: 0
--- !u!4 &337815216 --- !u!4 &337815216
Transform: Transform:
@ -795,7 +806,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: f5f9defef7af2514590dadc0a6cddbac, type: 3} m_Script: {fileID: 11500000, guid: f5f9defef7af2514590dadc0a6cddbac, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
loopLengthInBeat: 4 loopLengthInBeat: 1
loopStarted: loopStarted:
m_PersistentCalls: m_PersistentCalls:
m_Calls: m_Calls:

View file

@ -5,13 +5,21 @@ namespace cylvester
public class OrangeCube : MonoBehaviour public class OrangeCube : MonoBehaviour
{ {
[SerializeField] private Animator anim; [SerializeField] private Animator anim;
private static readonly int AnimTrigger = Animator.StringToHash("AnimTrigger"); private float speed_ = 1.0f;
private static readonly int Moving = Animator.StringToHash("Moving");
private bool trigger_;
public void OnTriggerReceived() public void OnTriggerReceived()
{ {
anim.SetTrigger(AnimTrigger); anim.speed = speed_;
anim.SetBool(Moving, false);
anim.SetBool(Moving, true);
} }
public void OnStateChanged(IStateReader currentState)
{
speed_ = currentState.CurrentState.Speed;
}
} }
} }

View file

@ -4,31 +4,33 @@ using UnityEngine.Events;
namespace cylvester namespace cylvester
{ {
[Serializable]
public class UnityStateEvent : UnityEvent<IStateManager>
{}
public interface IStateManager public interface IStateReader
{
State CurrentState { get; }
}
public interface IStateManager : IStateReader
{ {
int SelectedState { set; } int SelectedState { set; }
State[] States { get; } State[] States { get; }
State CurrentState { get; }
State? PreviousState { get; } State? PreviousState { get; }
State? NextState { get; } State? NextState { get; }
void OnMidiReceived(MidiMessage message);
} }
public struct State public struct State
{ {
public string Title; public string Title;
public string Note; public string Note;
public int BPM; public int Bpm;
private float Speed => BPM / 60f; // 60 BPM as speed 1f public float Speed => Bpm / 60f; // 60 BPM as speed 1f
} }
[Serializable]
public class UnityStateEvent : UnityEvent<IStateReader>
{}
public class StateManager : MonoBehaviour, IStateManager public class StateManager : MonoBehaviour, IStateManager
{ {
private enum Operation private enum Operation
@ -57,11 +59,11 @@ namespace cylvester
try try
{ {
States[i].BPM = int.Parse(columns[1]); States[i].Bpm = int.Parse(columns[1]);
} }
catch (FormatException) catch (FormatException)
{ {
States[i].BPM = 60; // gracefully fail States[i].Bpm = 60; // gracefully fail
} }
States[i].Note = columns[2]; States[i].Note = columns[2];