Skip to content

Commit

Permalink
Add button press sounds
Browse files Browse the repository at this point in the history
  • Loading branch information
timtmok committed Jul 24, 2016
1 parent bb865be commit 37f5f4a
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 6 deletions.
8 changes: 4 additions & 4 deletions Assets/Examples/example.unity
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ Prefab:
propertyPath: m_Name
value: Needy_Math
objectReference: {fileID: 0}
- target: {fileID: 113266, guid: 00e9615969527414b8593f0b6988ffb6, type: 2}
propertyPath: m_IsActive
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_ParentPrefab: {fileID: 100100000, guid: 00e9615969527414b8593f0b6988ffb6, type: 2}
m_IsPrefabParent: 0
Expand Down Expand Up @@ -314,10 +318,6 @@ Prefab:
propertyPath: m_Name
value: Emoji_Math
objectReference: {fileID: 0}
- target: {fileID: 112556, guid: d10cfbece335a044fb5ed7388de530dc, type: 2}
propertyPath: m_IsActive
value: 1
objectReference: {fileID: 0}
m_RemovedComponents: []
m_ParentPrefab: {fileID: 100100000, guid: d10cfbece335a044fb5ed7388de530dc, type: 2}
m_IsPrefabParent: 0
Expand Down
13 changes: 13 additions & 0 deletions Assets/Prefabs/Emoji Math.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ GameObject:
- 114: {fileID: 11410792}
- 114: {fileID: 11430578}
- 114: {fileID: 11411916}
- 114: {fileID: 11476316}
m_Layer: 0
m_Name: Emoji Math
m_TagString: Untagged
Expand Down Expand Up @@ -3391,6 +3392,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: b6492499aaa2583498dcb4867f02c38c, type: 3}
m_Name:
m_EditorClassIdentifier:
KMAudio: {fileID: 11476316}
Buttons:
- {fileID: 11452056}
- {fileID: 11407408}
Expand Down Expand Up @@ -3605,6 +3607,17 @@ MonoBehaviour:
m_EditorClassIdentifier:
HighlightScale: {x: 0, y: 0, z: 0}
OutlineAmount: 0
--- !u!114 &11476316
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 112556}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: -1675560866, guid: 45b809be76fd7a3468b6f517bced6f28, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!114 &11481904
MonoBehaviour:
m_ObjectHideFlags: 1
Expand Down
13 changes: 13 additions & 0 deletions Assets/Prefabs/Needy Math.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ GameObject:
- 114: {fileID: 11429032}
- 114: {fileID: 11498638}
- 114: {fileID: 11471928}
- 114: {fileID: 11460476}
m_Layer: 0
m_Name: Needy Math
m_TagString: Untagged
Expand Down Expand Up @@ -3580,6 +3581,17 @@ MonoBehaviour:
Highlight: {fileID: 11466802}
SelectableArea: {fileID: 0}
DefaultSelectableIndex: 0
--- !u!114 &11460476
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 113266}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: -1675560866, guid: 45b809be76fd7a3468b6f517bced6f28, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!114 &11465220
MonoBehaviour:
m_ObjectHideFlags: 1
Expand Down Expand Up @@ -3658,6 +3670,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 34e683c97b7b44847a2665bf2e8a8d34, type: 3}
m_Name:
m_EditorClassIdentifier:
KMAudio: {fileID: 11460476}
Buttons:
- {fileID: 11428284}
- {fileID: 11493538}
Expand Down
19 changes: 17 additions & 2 deletions Assets/Scripts/MathModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public abstract class MathModule : MonoBehaviour

protected delegate void AnswerUpdate();

// ReSharper disable once InconsistentNaming
public KMAudio KMAudio;
public KMSelectable[] Buttons;

protected virtual void Init()
Expand All @@ -21,6 +23,19 @@ protected virtual void Init()
SetUpNumberButtons();
SetUpMinusButton();
SetUpEnterButton();
SetUpButtonAudio();
}

private void SetUpButtonAudio()
{
foreach (var button in Buttons)
{
button.OnInteract += delegate
{
if (KMAudio != null) KMAudio.HandlePlayGameSoundAtTransform(KMSoundOverride.SoundEffect.ButtonPress, transform);
return false;
};
}
}

private void SetUpEnterButton()
Expand All @@ -41,7 +56,7 @@ private void SetUpMinusButton()
{
Debug.Log("Minus button pressed");
Sign *= -1;
OnAnswerUpdate();
if (OnAnswerUpdate != null) OnAnswerUpdate();
return false;
};
}
Expand All @@ -57,7 +72,7 @@ private void SetUpNumberButtons()
// ReSharper disable once UseStringInterpolation
Debug.Log(string.Format("{0} button pressed", buttonText));
Answer += buttonText;
OnAnswerUpdate();
if (OnAnswerUpdate != null) OnAnswerUpdate();
return false;
};
}
Expand Down

0 comments on commit 37f5f4a

Please sign in to comment.