From a69f12105371be28aa09f66dd1c431c7ae72bb83 Mon Sep 17 00:00:00 2001 From: Chikashi Miyama Date: Fri, 1 Nov 2019 12:06:54 +0100 Subject: [PATCH] Change StateManager interface --- .../Assets/Scenes/Examples/MIDI/MIDI.unity | 62 ++++++++++++++----- .../Scenes/Examples/MIDI/script/OrangeCube.cs | 2 + .../Assets/Scripts/PdConnection/PdBackend.cs | 7 +-- .../Scripts/StateManagement/StateManager.cs | 12 ++-- 4 files changed, 59 insertions(+), 24 deletions(-) diff --git a/UnityProject/Assets/Scenes/Examples/MIDI/MIDI.unity b/UnityProject/Assets/Scenes/Examples/MIDI/MIDI.unity index 36daa8c..6b45e93 100644 --- a/UnityProject/Assets/Scenes/Examples/MIDI/MIDI.unity +++ b/UnityProject/Assets/Scenes/Examples/MIDI/MIDI.unity @@ -212,6 +212,54 @@ Transform: m_Father: {fileID: 0} m_RootOrder: 3 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1 &337815214 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 337815216} + - component: {fileID: 337815215} + m_Layer: 0 + m_Name: StateManager + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!114 &337815215 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 337815214} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: e6be1ae37d9581545a6d213046b19b8c, type: 3} + m_Name: + m_EditorClassIdentifier: + csvFileName: qlist + onStateChanged: + m_PersistentCalls: + m_Calls: [] + sceneSelection: 0 +--- !u!4 &337815216 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 337815214} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 10 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &517164549 GameObject: m_ObjectHideFlags: 0 @@ -1044,7 +1092,6 @@ GameObject: - component: {fileID: 1843145351} - component: {fileID: 1843145350} - component: {fileID: 1843145349} - - component: {fileID: 1843145348} - component: {fileID: 1843145352} - component: {fileID: 1843145347} m_Layer: 0 @@ -1073,19 +1120,6 @@ Animator: m_HasTransformHierarchy: 1 m_AllowConstantClipSamplingOptimization: 1 m_KeepAnimatorControllerStateOnDisable: 0 ---- !u!65 &1843145348 -BoxCollider: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1843145346} - m_Material: {fileID: 0} - m_IsTrigger: 0 - m_Enabled: 1 - serializedVersion: 2 - m_Size: {x: 1, y: 1, z: 1} - m_Center: {x: 0, y: 0, z: 0} --- !u!23 &1843145349 MeshRenderer: m_ObjectHideFlags: 0 diff --git a/UnityProject/Assets/Scenes/Examples/MIDI/script/OrangeCube.cs b/UnityProject/Assets/Scenes/Examples/MIDI/script/OrangeCube.cs index f974cc6..e7efe7a 100644 --- a/UnityProject/Assets/Scenes/Examples/MIDI/script/OrangeCube.cs +++ b/UnityProject/Assets/Scenes/Examples/MIDI/script/OrangeCube.cs @@ -11,5 +11,7 @@ namespace cylvester { anim.SetTrigger(AnimTrigger); } + + } } diff --git a/UnityProject/Assets/Scripts/PdConnection/PdBackend.cs b/UnityProject/Assets/Scripts/PdConnection/PdBackend.cs index 713ccee..1696c5f 100644 --- a/UnityProject/Assets/Scripts/PdConnection/PdBackend.cs +++ b/UnityProject/Assets/Scripts/PdConnection/PdBackend.cs @@ -86,7 +86,6 @@ namespace cylvester samplePlaybackObserver_.ValueChanged -= onSamplePlaybackChanged_; midiParser_.MidiMessageReceived -= onMidiMessageReceived_; midiParser_.MidiSyncReceived -= onMidiSyncReceived_; - } public void Update() @@ -100,9 +99,9 @@ namespace cylvester public void SendState(IStateManager stateManager) { - pdSender_.Send("state previous " + stateManager.PreviousState); - pdSender_.Send("state current " + stateManager.CurrentState); - pdSender_.Send("state next " + stateManager.NextState); + pdSender_.Send("state previous " + (stateManager.PreviousState.HasValue ? stateManager.PreviousState.Value.Title : "---")); + pdSender_.Send("state current " + stateManager.CurrentState.Title); + pdSender_.Send("state next " + (stateManager.NextState.HasValue ? stateManager.NextState.Value.Title : "---")); } } diff --git a/UnityProject/Assets/Scripts/StateManagement/StateManager.cs b/UnityProject/Assets/Scripts/StateManagement/StateManager.cs index ccdfd92..4816074 100644 --- a/UnityProject/Assets/Scripts/StateManagement/StateManager.cs +++ b/UnityProject/Assets/Scripts/StateManagement/StateManager.cs @@ -13,9 +13,9 @@ namespace cylvester int SelectedState { set; } State[] States { get; } - string CurrentState { get; } - string PreviousState { get; } - string NextState { get; } + State CurrentState { get; } + State? PreviousState { get; } + State? NextState { get; } void OnMidiReceived(MidiMessage message); } @@ -70,11 +70,11 @@ namespace cylvester public State[] States { get; private set; } - public string CurrentState => States[sceneSelection].Title; + public State CurrentState => States[sceneSelection]; - public string PreviousState => sceneSelection == 0 ? "---" : States[sceneSelection-1].Title; + public State? PreviousState => sceneSelection == 0 ? (State?) null : States[sceneSelection-1]; - public string NextState => sceneSelection == States.Length - 1 ? "---" : States[sceneSelection + 1].Title; + public State? NextState => sceneSelection == States.Length - 1 ? (State?) null : States[sceneSelection + 1]; public int SelectedState {