Browse Source
Fully documented all methods on GameController.cs Documented all classes and most public functions.master
chrisgregan
11 years ago
19 changed files with 3182 additions and 414 deletions
@ -1,26 +1,32 @@ |
|||||||
using UnityEngine; |
using UnityEngine; |
||||||
using System.Collections; |
using System.Collections; |
||||||
using Fungus; |
|
||||||
|
|
||||||
// Listens for animation events |
namespace Fungus |
||||||
// Usage: |
|
||||||
// 1. Attach this script to the animated sprite that you want to listen to for events. |
|
||||||
// 2. Add an event on the animation timeline |
|
||||||
// 3. Edit the event and choose the 'CallRoomMethod' function |
|
||||||
// 4. In the string parameters box, enter the name of the method to call in the active Room's script. |
|
||||||
public class AnimationListener : MonoBehaviour |
|
||||||
{ |
{ |
||||||
// Handler method for animation events |
/** |
||||||
// The string event parameter is used to call a named method on the active room class |
* Listener component to handle animation events. |
||||||
void CallRoomMethod(string methodName) |
* Usage: |
||||||
|
* 1. Attach this script to the animated sprite that you want to listen to for events. |
||||||
|
* 2. Add an event on the animation timeline |
||||||
|
* 3. Edit the event and choose the 'CallRoomMethod' function |
||||||
|
* 4. In the string parameters box, enter the name of the method to call in the active Room's script. |
||||||
|
*/ |
||||||
|
public class AnimationListener : MonoBehaviour |
||||||
{ |
{ |
||||||
Room room = Game.GetInstance().activeRoom; |
/** |
||||||
if (room == null) |
* Handler method for animation events. |
||||||
|
* The string event parameter is used to call a named method on the active room class
|
||||||
|
*/ |
||||||
|
void CallRoomMethod(string methodName) |
||||||
{ |
{ |
||||||
return; |
Room room = Game.GetInstance().activeRoom; |
||||||
} |
if (room == null) |
||||||
|
{ |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
CommandQueue commandQueue = Game.GetInstance().commandQueue; |
CommandQueue commandQueue = Game.GetInstance().commandQueue; |
||||||
commandQueue.CallCommandMethod(room.gameObject, methodName); |
commandQueue.CallCommandMethod(room.gameObject, methodName); |
||||||
|
} |
||||||
} |
} |
||||||
} |
} |
@ -1,267 +1,443 @@ |
|||||||
using UnityEngine; |
using UnityEngine; |
||||||
using System; |
using System; |
||||||
using System.Collections; |
using System.Collections; |
||||||
using Fungus; |
|
||||||
|
|
||||||
// This facade class gives easy access to all game control |
namespace Fungus |
||||||
// functionality available in Fungus |
|
||||||
public class GameController : MonoBehaviour |
|
||||||
{ |
{ |
||||||
// |
/** |
||||||
// Synchronous methods |
* This class gives easy access to every scripting command available in Fungus. |
||||||
// The following methods all execute immediately |
*/ |
||||||
// |
public class GameController : MonoBehaviour |
||||||
|
{ |
||||||
// Return true if the boolean flag for the key has been set to true |
#region General Methods |
||||||
public bool GetFlag(string key) |
|
||||||
{ |
/** |
||||||
GameState state = Game.GetInstance().state; |
* Transitions from the current Room to another Room. |
||||||
return state.GetFlag(key); |
* This method returns immediately but it queues an asynchronous command for later execution. |
||||||
} |
* @param room The Room to transition to. |
||||||
|
*/ |
||||||
// Returns the count value for the key |
public void MoveToRoom(Room room) |
||||||
// Returns zero if no value has been set. |
{ |
||||||
public int GetCounter(string key) |
CommandQueue commandQueue = Game.GetInstance().commandQueue; |
||||||
{ |
commandQueue.AddCommand(new MoveToRoomCommand(room)); |
||||||
GameState state = Game.GetInstance().state; |
} |
||||||
return state.GetCounter(key); |
|
||||||
} |
/** |
||||||
|
* Wait for a period of time before executing the next command. |
||||||
// Returns the inventory count value for the key |
* This method returns immediately but it queues an asynchronous command for later execution. |
||||||
// Returns zero if no inventory count has been set. |
* @param duration The wait duration in seconds |
||||||
public int GetInventory(string key) |
*/ |
||||||
{ |
public void Wait(float duration) |
||||||
GameState state = Game.GetInstance().state; |
{ |
||||||
return state.GetInventory(key); |
CommandQueue commandQueue = Game.GetInstance().commandQueue; |
||||||
} |
commandQueue.AddCommand(new WaitCommand(duration)); |
||||||
|
} |
||||||
// Returns true if the inventory count for the key is greater than zero |
|
||||||
public bool HasInventory(string key) |
/** |
||||||
{ |
* Call a delegate method provided by the client. |
||||||
GameState state = Game.GetInstance().state; |
* Used to queue the execution of arbitrary code as part of a command sequeunce. |
||||||
return (state.GetInventory(key) > 0); |
* This method returns immediately but it queues an asynchronous command for later execution. |
||||||
} |
* @param callAction The Action delegate method to be called when the command executes. |
||||||
|
*/ |
||||||
|
public void Call(Action callAction) |
||||||
|
{ |
||||||
|
CommandQueue commandQueue = Game.GetInstance().commandQueue; |
||||||
|
commandQueue.AddCommand(new CallCommand(callAction)); |
||||||
|
} |
||||||
|
|
||||||
|
#endregion |
||||||
|
#region View Methods |
||||||
|
|
||||||
// |
/** |
||||||
// Asynchronous methods |
* Sets the currently active View immediately. |
||||||
// The following methods all queue commands for later execution in strict serial order |
* The main camera snaps to the new active View. If the View contains a Page object, this Page becomes the active Page. |
||||||
// |
* This method returns immediately but it queues an asynchronous command for later execution. |
||||||
|
* @param view The View object to make active |
||||||
// Wait for a period of time before executing the next command |
*/ |
||||||
public void Wait(float duration) |
public void SetView(View view) |
||||||
{ |
{ |
||||||
CommandQueue commandQueue = Game.GetInstance().commandQueue; |
CommandQueue commandQueue = Game.GetInstance().commandQueue; |
||||||
commandQueue.AddCommand(new WaitCommand(duration)); |
commandQueue.AddCommand(new SetViewCommand(view)); |
||||||
} |
} |
||||||
|
|
||||||
// Call a delegate method provided by the client |
|
||||||
// Used to queue the execution of arbitrary code. |
|
||||||
public void Call(Action callAction) |
|
||||||
{ |
|
||||||
CommandQueue commandQueue = Game.GetInstance().commandQueue; |
|
||||||
commandQueue.AddCommand(new CallCommand(callAction)); |
|
||||||
} |
|
||||||
|
|
||||||
// Sets the currently active view immediately. |
|
||||||
// The main camera snaps to the active view. |
|
||||||
public void SetView(View view) |
|
||||||
{ |
|
||||||
CommandQueue commandQueue = Game.GetInstance().commandQueue; |
|
||||||
commandQueue.AddCommand(new SetViewCommand(view)); |
|
||||||
} |
|
||||||
|
|
||||||
// Sets the currently active page for text rendering |
|
||||||
public void SetPage(Page page) |
|
||||||
{ |
|
||||||
CommandQueue commandQueue = Game.GetInstance().commandQueue; |
|
||||||
commandQueue.AddCommand(new SetPageCommand(page)); |
|
||||||
} |
|
||||||
|
|
||||||
// Sets the title text displayed at the top of the active page |
|
||||||
public void Title(string titleText) |
|
||||||
{ |
|
||||||
CommandQueue commandQueue = Game.GetInstance().commandQueue; |
|
||||||
commandQueue.AddCommand(new TitleCommand(titleText)); |
|
||||||
} |
|
||||||
|
|
||||||
// Writes story text to the currently active page. |
|
||||||
// A 'continue' button is displayed when the text has fully appeared. |
|
||||||
public void Say(string storyText) |
|
||||||
{ |
|
||||||
CommandQueue commandQueue = Game.GetInstance().commandQueue; |
|
||||||
commandQueue.AddCommand(new SayCommand(storyText)); |
|
||||||
} |
|
||||||
|
|
||||||
// Adds an option button to the current list of options. |
|
||||||
// Use the Choose command to display added options. |
|
||||||
public void AddOption(string optionText, Action optionAction) |
|
||||||
{ |
|
||||||
CommandQueue commandQueue = Game.GetInstance().commandQueue; |
|
||||||
commandQueue.AddCommand(new AddOptionCommand(optionText, optionAction)); |
|
||||||
} |
|
||||||
|
|
||||||
// Display all previously added options as buttons, with no text prompt |
/** |
||||||
public void Choose() |
* Pans the camera to the target View over a period of time. |
||||||
{ |
* The pan starts at the current camera position and performs a smoothed linear pan to the target View. |
||||||
Choose(""); |
* Command execution blocks until the pan completes. When the camera arrives at the target View, this View becomes the active View. |
||||||
} |
* This method returns immediately but it queues an asynchronous command for later execution. |
||||||
|
* @param targetView The View to pan the camera to. |
||||||
// Displays a text prompt, followed by all previously added options as buttons. |
* @param duration The length of time in seconds needed to complete the pan. |
||||||
public void Choose(string chooseText) |
*/ |
||||||
{ |
public void PanToView(View targetView, float duration) |
||||||
CommandQueue commandQueue = Game.GetInstance().commandQueue; |
{ |
||||||
commandQueue.AddCommand(new ChooseCommand(chooseText)); |
CommandQueue commandQueue = Game.GetInstance().commandQueue; |
||||||
} |
commandQueue.AddCommand(new PanToViewCommand(targetView, duration)); |
||||||
|
} |
||||||
// Changes the active room to a different room |
|
||||||
public void MoveToRoom(Room room) |
/** |
||||||
{ |
* Pans the camera through a sequence of target Views over a period of time. |
||||||
CommandQueue commandQueue = Game.GetInstance().commandQueue; |
* The pan starts at the current camera position and performs a smooth pan through all Views in the list. |
||||||
commandQueue.AddCommand(new MoveToRoomCommand(room)); |
* Command execution blocks until the pan completes. When the camera arrives at the last View in the list, this View becomes the active View. |
||||||
} |
* If more control is required over the camera path then you should instead use an Animator component to precisely control the Camera path. |
||||||
|
* This method returns immediately but it queues an asynchronous command for later execution. |
||||||
// Sets a global boolean flag value |
* @param duration The length of time in seconds needed to complete the pan. |
||||||
public void SetFlag(string key, bool value) |
* @param targetViews A parameter list of views to visit during the pan. |
||||||
{ |
*/ |
||||||
CommandQueue commandQueue = Game.GetInstance().commandQueue; |
public void PanToPath(float duration, params View[] targetViews) |
||||||
commandQueue.AddCommand(new SetFlagCommand(key, value)); |
{ |
||||||
} |
CommandQueue commandQueue = Game.GetInstance().commandQueue; |
||||||
|
commandQueue.AddCommand(new PanToPathCommand(targetViews, duration)); |
||||||
// Sets a global integer counter value |
} |
||||||
public void SetCounter(string key, int value) |
|
||||||
{ |
/** |
||||||
CommandQueue commandQueue = Game.GetInstance().commandQueue; |
* Fades out the current camera View, and fades in again using the target View. |
||||||
commandQueue.AddCommand(new SetCounterCommand(key, value)); |
* If the target View contains a Page object, this Page becomes the active Page. |
||||||
} |
* This method returns immediately but it queues an asynchronous command for later execution. |
||||||
|
* @param targetView The View object to fade to. |
||||||
// Sets a global inventory count value |
* @param duration The length of time in seconds needed to complete the pan. |
||||||
// Assumes that the count value is 1 (common case) |
*/ |
||||||
public void SetInventory(string key) |
public void FadeToView(View targetView, float duration) |
||||||
{ |
{ |
||||||
CommandQueue commandQueue = Game.GetInstance().commandQueue; |
CommandQueue commandQueue = Game.GetInstance().commandQueue; |
||||||
commandQueue.AddCommand(new SetInventoryCommand(key, 1)); |
commandQueue.AddCommand(new FadeToViewCommand(targetView, duration)); |
||||||
} |
} |
||||||
|
|
||||||
// Sets a global inventory count value |
#endregion |
||||||
public void SetInventory(string key, int value) |
#region Page Methods |
||||||
{ |
|
||||||
CommandQueue commandQueue = Game.GetInstance().commandQueue; |
/** |
||||||
commandQueue.AddCommand(new SetInventoryCommand(key, value)); |
* Sets the title text displayed at the top of the active Page. |
||||||
} |
* The title text is only displayed when there is some story text or options to be shown. |
||||||
|
* This method returns immediately but it queues an asynchronous command for later execution. |
||||||
// Sets sprite alpha to 0 immediately |
* @param titleText The text to display as the title of the Page. |
||||||
public void HideSprite(SpriteRenderer spriteRenderer) |
*/ |
||||||
{ |
public void Title(string titleText) |
||||||
FadeSprite(spriteRenderer, 0, 0, Vector2.zero); |
{ |
||||||
} |
CommandQueue commandQueue = Game.GetInstance().commandQueue; |
||||||
|
commandQueue.AddCommand(new TitleCommand(titleText)); |
||||||
// Sets sprite alpha to 1 immediately |
} |
||||||
public void ShowSprite(SpriteRenderer spriteRenderer) |
|
||||||
{ |
/** |
||||||
FadeSprite(spriteRenderer, 1, 0, Vector2.zero); |
* Sets the currently active Page for story text display. |
||||||
} |
* Once this command executes, all story text added using Say(), AddOption(), Choose(), etc. will be displayed on this Page. |
||||||
|
* When a Room contains multiple Page objects, this method can be used to control which Page object is active at a given time. |
||||||
// Fades a sprite to a given alpha value over a period of time |
* This method returns immediately but it queues an asynchronous command for later execution. |
||||||
public void FadeSprite(SpriteRenderer spriteRenderer, float targetAlpha, float duration) |
* @param page The Page object to make active |
||||||
{ |
*/ |
||||||
FadeSprite(spriteRenderer, targetAlpha, duration, Vector2.zero); |
public void SetPage(Page page) |
||||||
} |
{ |
||||||
|
CommandQueue commandQueue = Game.GetInstance().commandQueue; |
||||||
// Fades a sprite to a given alpha value over a period of time, and applies a sliding motion to the sprite transform |
commandQueue.AddCommand(new SetPageCommand(page)); |
||||||
public void FadeSprite(SpriteRenderer spriteRenderer, float targetAlpha, float duration, Vector2 slideOffset) |
} |
||||||
{ |
|
||||||
CommandQueue commandQueue = Game.GetInstance().commandQueue; |
/** |
||||||
Color color = spriteRenderer.color; |
* Writes story text to the currently active Page. |
||||||
color.a = targetAlpha; |
* A 'continue' button is displayed when the text has fully appeared. |
||||||
commandQueue.AddCommand(new FadeSpriteCommand(spriteRenderer, color, duration, slideOffset)); |
* Command execution halts until the user chooses to continue. |
||||||
} |
* This method returns immediately but it queues an asynchronous command for later execution. |
||||||
|
* @param storyText The text to be written to the currently active Page. |
||||||
// Makes a sprite behave as a clickable button |
*/ |
||||||
public void AddButton(SpriteRenderer buttonSprite, Action buttonAction) |
public void Say(string storyText) |
||||||
{ |
{ |
||||||
CommandQueue commandQueue = Game.GetInstance().commandQueue; |
CommandQueue commandQueue = Game.GetInstance().commandQueue; |
||||||
commandQueue.AddCommand(new AddButtonCommand(buttonSprite, buttonAction)); |
commandQueue.AddCommand(new SayCommand(storyText)); |
||||||
} |
} |
||||||
|
|
||||||
// Makes a sprite stop behaving as a clickable button |
/** |
||||||
public void RemoveButton(SpriteRenderer buttonSprite) |
* Adds an option to the current list of player options. |
||||||
{ |
* Use the Choose() method to display previously added options. |
||||||
CommandQueue commandQueue = Game.GetInstance().commandQueue; |
* This method returns immediately but it queues an asynchronous command for later execution. |
||||||
commandQueue.AddCommand(new RemoveButtonCommand(buttonSprite)); |
* @param optionText The text to be displayed for this option |
||||||
} |
* @param optionAction The Action delegate method to be called when the player selects the option |
||||||
|
*/ |
||||||
// Sets an animator trigger to change the animation state for an animated sprite |
public void AddOption(string optionText, Action optionAction) |
||||||
public void SetAnimatorTrigger(Animator animator, string triggerName) |
{ |
||||||
{ |
CommandQueue commandQueue = Game.GetInstance().commandQueue; |
||||||
CommandQueue commandQueue = Game.GetInstance().commandQueue; |
commandQueue.AddCommand(new AddOptionCommand(optionText, optionAction)); |
||||||
commandQueue.AddCommand(new SetAnimatorTriggerCommand(animator, triggerName)); |
} |
||||||
} |
|
||||||
|
/** |
||||||
// Pans the camera to the target view over a period of time |
* Display all previously added options as buttons, with no text prompt. |
||||||
public void PanToView(View targetView, float duration) |
* This method returns immediately but it queues an asynchronous command for later execution. |
||||||
{ |
*/ |
||||||
CommandQueue commandQueue = Game.GetInstance().commandQueue; |
public void Choose() |
||||||
commandQueue.AddCommand(new PanToViewCommand(targetView, duration)); |
{ |
||||||
} |
Choose(""); |
||||||
|
} |
||||||
// Pans the camera through a sequence of target views over a period of time |
|
||||||
public void PanToPath(float duration, params View[] targetViews) |
/** |
||||||
{ |
* Displays a story text prompt, followed by all previously added options. |
||||||
CommandQueue commandQueue = Game.GetInstance().commandQueue; |
* This method returns immediately but it queues an asynchronous command for later execution. |
||||||
commandQueue.AddCommand(new PanToPathCommand(targetViews, duration)); |
* @param chooseText The story text to be written above the list of options |
||||||
} |
*/ |
||||||
|
public void Choose(string chooseText) |
||||||
// Snaps the camera to the target view immediately |
{ |
||||||
public void SnapToView(View targetView) |
CommandQueue commandQueue = Game.GetInstance().commandQueue; |
||||||
{ |
commandQueue.AddCommand(new ChooseCommand(chooseText)); |
||||||
CommandQueue commandQueue = Game.GetInstance().commandQueue; |
} |
||||||
commandQueue.AddCommand(new PanToViewCommand(targetView, 0f)); |
|
||||||
} |
#endregion |
||||||
|
#region State Methods |
||||||
// Fades out the current camera view, and fades in again using the target view. |
|
||||||
public void FadeToView(View targetView, float duration) |
/** |
||||||
{ |
* Sets a boolean flag value. |
||||||
CommandQueue commandQueue = Game.GetInstance().commandQueue; |
* This method returns immediately but it queues an asynchronous command for later execution. |
||||||
commandQueue.AddCommand(new FadeToViewCommand(targetView, duration)); |
* @param key The name of the flag |
||||||
} |
* @param value The boolean value to set the flag to |
||||||
|
*/ |
||||||
// Plays game music using an audio clip |
public void SetFlag(string key, bool value) |
||||||
public void PlayMusic(AudioClip audioClip) |
{ |
||||||
{ |
CommandQueue commandQueue = Game.GetInstance().commandQueue; |
||||||
CommandQueue commandQueue = Game.GetInstance().commandQueue; |
commandQueue.AddCommand(new SetFlagCommand(key, value)); |
||||||
commandQueue.AddCommand(new PlayMusicCommand(audioClip)); |
} |
||||||
} |
|
||||||
|
/** |
||||||
// Stops playing game music |
* Gets the current state of a flag. |
||||||
public void StopMusic() |
* Flag values are set using SetFlag(). |
||||||
{ |
* Returns false if the flag has previously been set to false, or has not yet been set. |
||||||
CommandQueue commandQueue = Game.GetInstance().commandQueue; |
* @param key The name of the flag |
||||||
commandQueue.AddCommand(new StopMusicCommand()); |
* @return The boolean state of the flag. |
||||||
} |
*/ |
||||||
|
public bool GetFlag(string key) |
||||||
// Sets music volume immediately |
{ |
||||||
public void SetMusicVolume(float musicVolume) |
GameState state = Game.GetInstance().state; |
||||||
{ |
return state.GetFlag(key); |
||||||
SetMusicVolume(musicVolume, 0f); |
} |
||||||
} |
|
||||||
|
/** |
||||||
// Fades music volume to required level over a period of time |
* Sets an integer counter value. |
||||||
public void SetMusicVolume(float musicVolume, float duration) |
* This method returns immediately but it queues an asynchronous command for later execution. |
||||||
{ |
* @param key The name of the counter |
||||||
CommandQueue commandQueue = Game.GetInstance().commandQueue; |
* @param value The value to set the counter to |
||||||
commandQueue.AddCommand(new SetMusicVolumeCommand(musicVolume, duration)); |
*/ |
||||||
} |
public void SetCounter(string key, int value) |
||||||
|
{ |
||||||
// Plays a sound effect once |
CommandQueue commandQueue = Game.GetInstance().commandQueue; |
||||||
public void PlaySound(AudioClip audioClip) |
commandQueue.AddCommand(new SetCounterCommand(key, value)); |
||||||
{ |
} |
||||||
PlaySound(audioClip, 1f); |
|
||||||
} |
/** |
||||||
|
* Gets the current value of a counter. |
||||||
// Plays a sound effect once, at the specified volume |
* Counter values are set using SetCounter(). |
||||||
public void PlaySound(AudioClip audioClip, float volume) |
* Returns zero if the counter has not previously been set to a value. |
||||||
{ |
* @param key The name of the counter |
||||||
CommandQueue commandQueue = Game.GetInstance().commandQueue; |
* @return The current value of the counter |
||||||
commandQueue.AddCommand(new PlaySoundCommand(audioClip, volume)); |
*/ |
||||||
|
public int GetCounter(string key) |
||||||
|
{ |
||||||
|
GameState state = Game.GetInstance().state; |
||||||
|
return state.GetCounter(key); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Sets an inventory item count to 1. |
||||||
|
* This supports the common case where the player can only collect 1 instance of an inventory item. |
||||||
|
* This method returns immediately but it queues an asynchronous command for later execution. |
||||||
|
* @param key The name of the inventory item |
||||||
|
*/ |
||||||
|
public void SetInventory(string key) |
||||||
|
{ |
||||||
|
CommandQueue commandQueue = Game.GetInstance().commandQueue; |
||||||
|
commandQueue.AddCommand(new SetInventoryCommand(key, 1)); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Sets the inventory count for an item. |
||||||
|
* This method returns immediately but it queues an asynchronous command for later execution. |
||||||
|
* @param key The name of the inventory item |
||||||
|
* @param value The inventory count for the item |
||||||
|
*/ |
||||||
|
public void SetInventory(string key, int value) |
||||||
|
{ |
||||||
|
CommandQueue commandQueue = Game.GetInstance().commandQueue; |
||||||
|
commandQueue.AddCommand(new SetInventoryCommand(key, value)); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Gets the current inventory count for an item. |
||||||
|
* Inventory counts are set using SetInventory(). |
||||||
|
* Returns zero if the inventory count has not previously been set to a value. |
||||||
|
* @param key The name of the inventory item |
||||||
|
* @return The current inventory count of the item |
||||||
|
*/ |
||||||
|
public int GetInventory(string key) |
||||||
|
{ |
||||||
|
GameState state = Game.GetInstance().state; |
||||||
|
return state.GetInventory(key); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Check if player has an inventory item. |
||||||
|
* @param key The name of the inventory item |
||||||
|
* @return Returns true if the inventory count for an item is greater than zero |
||||||
|
*/ |
||||||
|
public bool HasInventory(string key) |
||||||
|
{ |
||||||
|
GameState state = Game.GetInstance().state; |
||||||
|
return (state.GetInventory(key) > 0); |
||||||
|
} |
||||||
|
|
||||||
|
#endregion |
||||||
|
#region Sprite Methods |
||||||
|
|
||||||
|
/** |
||||||
|
* Makes a sprite completely transparent immediately. |
||||||
|
* This changes the alpha component of the sprite renderer color to 0. |
||||||
|
* This method returns immediately but it queues an asynchronous command for later execution. |
||||||
|
* @param spriteRenderer The sprite to be modified |
||||||
|
*/ |
||||||
|
public void HideSprite(SpriteRenderer spriteRenderer) |
||||||
|
{ |
||||||
|
FadeSprite(spriteRenderer, 0, 0, Vector2.zero); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Makes a sprite completely opaque immediately. |
||||||
|
* This changes the alpha component of the sprite renderer color to 1. |
||||||
|
* This method returns immediately but it queues an asynchronous command for later execution. |
||||||
|
* @param spriteRenderer The sprite to be modified |
||||||
|
*/ |
||||||
|
public void ShowSprite(SpriteRenderer spriteRenderer) |
||||||
|
{ |
||||||
|
FadeSprite(spriteRenderer, 1, 0, Vector2.zero); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Fades the transparency of a sprite over a period of time. |
||||||
|
* This method returns immediately but it queues an asynchronous command for later execution. |
||||||
|
* @param spriteRenderer The sprite to be modified |
||||||
|
* @param targetAlpha The final required transparency value [0..1] |
||||||
|
* @param duration The duration of the fade transition in seconds |
||||||
|
*/ |
||||||
|
public void FadeSprite(SpriteRenderer spriteRenderer, float targetAlpha, float duration) |
||||||
|
{ |
||||||
|
FadeSprite(spriteRenderer, targetAlpha, duration, Vector2.zero); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Fades the transparency of a sprite over a period of time, and applies a sliding motion to the sprite's position. |
||||||
|
* The sprite starts at a position calculated by adding the current sprite position + the slide offset. |
||||||
|
* The sprite then smoothly moves from this starting position to the original position of the sprite. |
||||||
|
* Automatically adds a SpriteFader component to the sprite object to perform the transition. |
||||||
|
* This method returns immediately but it queues an asynchronous command for later execution. |
||||||
|
* @param spriteRenderer The sprite to be modified |
||||||
|
* @param targetAlpha The final required transparency value [0..1] |
||||||
|
* @param duration The duration of the fade transition in seconds |
||||||
|
* @param slideOffset Offset to the starting position for the slide effect. |
||||||
|
*/ |
||||||
|
public void FadeSprite(SpriteRenderer spriteRenderer, float targetAlpha, float duration, Vector2 slideOffset) |
||||||
|
{ |
||||||
|
CommandQueue commandQueue = Game.GetInstance().commandQueue; |
||||||
|
Color color = spriteRenderer.color; |
||||||
|
color.a = targetAlpha; |
||||||
|
commandQueue.AddCommand(new FadeSpriteCommand(spriteRenderer, color, duration, slideOffset)); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Makes a sprite behave as a clickable button. |
||||||
|
* Automatically adds a Button component to the object to respond to player input. |
||||||
|
* If no Collider2D already exists on the object, then a BoxCollider2D is automatically added. |
||||||
|
* Use RemoveButton() to make a sprite non-clickable again. |
||||||
|
* This method returns immediately but it queues an asynchronous command for later execution. |
||||||
|
* @param spriteRenderer The sprite to be made clickable |
||||||
|
* @param buttonAction The Action delegate method to be called when the player clicks on the button |
||||||
|
*/ |
||||||
|
public void AddButton(SpriteRenderer spriteRenderer, Action buttonAction) |
||||||
|
{ |
||||||
|
CommandQueue commandQueue = Game.GetInstance().commandQueue; |
||||||
|
commandQueue.AddCommand(new AddButtonCommand(spriteRenderer, buttonAction)); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Makes a sprite stop behaving as a clickable button. |
||||||
|
* Removes the Button component from the sprite object. |
||||||
|
* This method returns immediately but it queues an asynchronous command for later execution. |
||||||
|
* @param spriteRenderer The sprite to be made non-clickable |
||||||
|
*/ |
||||||
|
public void RemoveButton(SpriteRenderer spriteRenderer) |
||||||
|
{ |
||||||
|
CommandQueue commandQueue = Game.GetInstance().commandQueue; |
||||||
|
commandQueue.AddCommand(new RemoveButtonCommand(spriteRenderer)); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Sets an animator trigger to change the animation state for an animated sprite. |
||||||
|
* This is the primary method of controlling Unity animations from a Fungus command sequence. |
||||||
|
* This method returns immediately but it queues an asynchronous command for later execution. |
||||||
|
* @param animator The sprite to be made non-clickable |
||||||
|
* @param triggerName Name of a trigger parameter in the animator controller |
||||||
|
*/ |
||||||
|
public void SetAnimatorTrigger(Animator animator, string triggerName) |
||||||
|
{ |
||||||
|
CommandQueue commandQueue = Game.GetInstance().commandQueue; |
||||||
|
commandQueue.AddCommand(new SetAnimatorTriggerCommand(animator, triggerName)); |
||||||
|
} |
||||||
|
|
||||||
|
#endregion |
||||||
|
#region Audio Methods |
||||||
|
|
||||||
|
/** |
||||||
|
* Plays game music using an audio clip. |
||||||
|
* One music clip may be played at a time. |
||||||
|
* @param audioClip The music clip to play |
||||||
|
*/ |
||||||
|
public void PlayMusic(AudioClip audioClip) |
||||||
|
{ |
||||||
|
CommandQueue commandQueue = Game.GetInstance().commandQueue; |
||||||
|
commandQueue.AddCommand(new PlayMusicCommand(audioClip)); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Stops playing game music. |
||||||
|
*/ |
||||||
|
public void StopMusic() |
||||||
|
{ |
||||||
|
CommandQueue commandQueue = Game.GetInstance().commandQueue; |
||||||
|
commandQueue.AddCommand(new StopMusicCommand()); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Sets the game music volume immediately. |
||||||
|
* @param musicVolume The new music volume value [0..1] |
||||||
|
*/ |
||||||
|
public void SetMusicVolume(float musicVolume) |
||||||
|
{ |
||||||
|
SetMusicVolume(musicVolume, 0f); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Fades the game music volume to required level over a period of time. |
||||||
|
* @param musicVolume The new music volume value [0..1] |
||||||
|
* @param duration The length of time in seconds needed to complete the volume change. |
||||||
|
*/ |
||||||
|
public void SetMusicVolume(float musicVolume, float duration) |
||||||
|
{ |
||||||
|
CommandQueue commandQueue = Game.GetInstance().commandQueue; |
||||||
|
commandQueue.AddCommand(new SetMusicVolumeCommand(musicVolume, duration)); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Plays a sound effect once. |
||||||
|
* Multiple sound effects can be played at the same time. |
||||||
|
* @param audioClip The sound effect clip to play |
||||||
|
*/ |
||||||
|
public void PlaySound(AudioClip audioClip) |
||||||
|
{ |
||||||
|
PlaySound(audioClip, 1f); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Plays a sound effect once, at the specified volume. |
||||||
|
* Multiple sound effects can be played at the same time. |
||||||
|
* @param audioClip The sound effect clip to play |
||||||
|
* @param volume The volume level of the sound effect |
||||||
|
*/ |
||||||
|
public void PlaySound(AudioClip audioClip, float volume) |
||||||
|
{ |
||||||
|
CommandQueue commandQueue = Game.GetInstance().commandQueue; |
||||||
|
commandQueue.AddCommand(new PlaySoundCommand(audioClip, volume)); |
||||||
|
} |
||||||
|
|
||||||
|
#endregion |
||||||
} |
} |
||||||
} |
} |
After Width: | Height: | Size: 54 KiB |
@ -0,0 +1,45 @@ |
|||||||
|
fileFormatVersion: 2 |
||||||
|
guid: 901325229c7f9494b8810f5a5b8add9b |
||||||
|
TextureImporter: |
||||||
|
serializedVersion: 2 |
||||||
|
mipmaps: |
||||||
|
mipMapMode: 0 |
||||||
|
enableMipMap: 1 |
||||||
|
linearTexture: 0 |
||||||
|
correctGamma: 0 |
||||||
|
fadeOut: 0 |
||||||
|
borderMipMap: 0 |
||||||
|
mipMapFadeDistanceStart: 1 |
||||||
|
mipMapFadeDistanceEnd: 3 |
||||||
|
bumpmap: |
||||||
|
convertToNormalMap: 0 |
||||||
|
externalNormalMap: 0 |
||||||
|
heightScale: .25 |
||||||
|
normalMapFilter: 0 |
||||||
|
isReadable: 0 |
||||||
|
grayScaleToAlpha: 0 |
||||||
|
generateCubemap: 0 |
||||||
|
seamlessCubemap: 0 |
||||||
|
textureFormat: -1 |
||||||
|
maxTextureSize: 1024 |
||||||
|
textureSettings: |
||||||
|
filterMode: -1 |
||||||
|
aniso: -1 |
||||||
|
mipBias: -1 |
||||||
|
wrapMode: -1 |
||||||
|
nPOTScale: 1 |
||||||
|
lightmap: 0 |
||||||
|
compressionQuality: 50 |
||||||
|
spriteMode: 0 |
||||||
|
spriteExtrude: 1 |
||||||
|
spriteMeshType: 1 |
||||||
|
alignment: 0 |
||||||
|
spritePivot: {x: .5, y: .5} |
||||||
|
spritePixelsToUnits: 100 |
||||||
|
alphaIsTransparency: 0 |
||||||
|
textureType: -1 |
||||||
|
buildTargetSettings: [] |
||||||
|
spriteSheet: |
||||||
|
sprites: [] |
||||||
|
spritePackingTag: |
||||||
|
userData: |
Loading…
Reference in new issue