Browse Source

More button improvements

- Auto Buttons stay hidden while executing wait commands
- Added WaitForInput() command to wait for a click/tap/keypress
- Replaced click sound with a quieter version
master
chrisgregan 11 years ago
parent
commit
e6d17dee32
  1. 5
      Assets/Fungus/Audio.meta
  2. BIN
      Assets/Fungus/Audio/Click.wav
  3. 6
      Assets/Fungus/Audio/Click.wav.meta
  4. BIN
      Assets/Fungus/Prefabs/Game.prefab
  5. 3
      Assets/Fungus/Scripts/ButtonController.cs
  6. 32
      Assets/Fungus/Scripts/Commands.cs
  7. 6
      Assets/Fungus/Scripts/Game.cs
  8. 10
      Assets/Fungus/Scripts/GameController.cs
  9. BIN
      Assets/FungusExample/Audio/click.wav
  10. BIN
      Assets/FungusExample/Scenes/Example.unity
  11. 3
      Assets/FungusExample/Scripts/ButtonRoom.cs

5
Assets/Fungus/Audio.meta

@ -0,0 +1,5 @@
fileFormatVersion: 2
guid: d9780867e1f2c456a9bd67af4ed5e2e4
folderAsset: yes
DefaultImporter:
userData:

BIN
Assets/Fungus/Audio/Click.wav

Binary file not shown.

6
Assets/FungusExample/Audio/click.wav.meta → Assets/Fungus/Audio/Click.wav.meta

@ -1,9 +1,9 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: 05266cba5e04d4b13abd1e60df58cea9 guid: c18ae2c530c264a6880266d5e0a71337
AudioImporter: AudioImporter:
serializedVersion: 4 serializedVersion: 4
format: 0 format: -1
quality: .5 quality: -.280000001
stream: 1 stream: 1
3D: 0 3D: 0
forceToMono: 0 forceToMono: 0

BIN
Assets/Fungus/Prefabs/Game.prefab

Binary file not shown.

3
Assets/Fungus/Scripts/ButtonController.cs

@ -13,7 +13,8 @@ namespace Fungus
bool showAutoButtons = false; bool showAutoButtons = false;
Page page = Game.GetInstance().activePage; Page page = Game.GetInstance().activePage;
if (page != null && if (page != null &&
page.mode == Page.Mode.Idle) page.mode == Page.Mode.Idle &&
!Game.GetInstance().waiting)
{ {
showAutoButtons = true; showAutoButtons = true;
} }

32
Assets/Fungus/Scripts/Commands.cs

@ -55,6 +55,7 @@ namespace Fungus
public override void Execute(CommandQueue commandQueue, Action onComplete) public override void Execute(CommandQueue commandQueue, Action onComplete)
{ {
Game.GetInstance().waiting = true;
commandQueue.StartCoroutine(WaitCoroutine(duration, onComplete)); commandQueue.StartCoroutine(WaitCoroutine(duration, onComplete));
} }
@ -63,6 +64,37 @@ namespace Fungus
yield return new WaitForSeconds(duration); yield return new WaitForSeconds(duration);
if (onComplete != null) if (onComplete != null)
{ {
Game.GetInstance().waiting = false;
onComplete();
}
}
}
/**
* Wait for a player tap/click/key press
*/
public class WaitForInputCommand : CommandQueue.Command
{
public override void Execute(CommandQueue commandQueue, Action onComplete)
{
Game.GetInstance().waiting = true;
commandQueue.StartCoroutine(WaitCoroutine(onComplete));
}
IEnumerator WaitCoroutine(Action onComplete)
{
while (true)
{
if (Input.GetMouseButtonDown(0) || Input.anyKeyDown)
{
break;
}
yield return null;
}
if (onComplete != null)
{
Game.GetInstance().waiting = false;
onComplete(); onComplete();
} }
} }

6
Assets/Fungus/Scripts/Game.cs

@ -93,6 +93,12 @@ namespace Fungus
[HideInInspector] [HideInInspector]
public ButtonController buttonController; public ButtonController buttonController;
/**
* True when executing a Wait() or WaitForTap() command
*/
[HideInInspector]
public bool waiting;
static Game instance; static Game instance;
public static Game GetInstance() public static Game GetInstance()

10
Assets/Fungus/Scripts/GameController.cs

@ -33,6 +33,16 @@ namespace Fungus
commandQueue.AddCommand(new Command.WaitCommand(duration)); commandQueue.AddCommand(new Command.WaitCommand(duration));
} }
/**
* Wait until player taps, clicks or presses a key before executing the next command.
* This method returns immediately but it queues an asynchronous command for later execution.
*/
public void WaitForInput()
{
CommandQueue commandQueue = Game.GetInstance().commandQueue;
commandQueue.AddCommand(new Command.WaitForInputCommand());
}
/** /**
* Call a delegate method provided by the client. * Call a delegate method provided by the client.
* Used to queue the execution of arbitrary code as part of a command sequeunce. * Used to queue the execution of arbitrary code as part of a command sequeunce.

BIN
Assets/FungusExample/Audio/click.wav

Binary file not shown.

BIN
Assets/FungusExample/Scenes/Example.unity

Binary file not shown.

3
Assets/FungusExample/Scripts/ButtonRoom.cs

@ -26,6 +26,9 @@ public class ButtonRoom : Room
Say("The Mushroom read his book with great interest."); Say("The Mushroom read his book with great interest.");
Say("After turning the last page, he considered his options."); Say("After turning the last page, he considered his options.");
// Uncomment this line to make the player tap the screen before showing the buttons
// WaitForInput();
// Once the last Say command executes the page will dissappear because there's no more content to show. // Once the last Say command executes the page will dissappear because there's no more content to show.
// At that point, the game will automatically fade in all Auto Buttons in the room // At that point, the game will automatically fade in all Auto Buttons in the room
} }

Loading…
Cancel
Save