Browse Source
- There is now only one Page game object. It is created automatically by the Game class on startup. - To control Page layout, use the new SetPageTop(), SetPageMiddle(), SetPageBottom(), SetPageRect() & SetPageBounds() commands. - You can still specify Page layout in the editor using the new PageBounds script & prefab, using the SetPageBounds() method. - Replaced Game.mainCamera with built-in Camera.main - Added StoreView() and PanToStoredView() - Game class now handles rendering fade texture (instead of CameraController) - Game class handles rendering pan / continue icons - Added new StartManualPan() and StopManualPan() commands to manually pan between 2 views - Removed continueStyle class & prefab (replaced by continue icon rendering) - Removed Game.activeView as it’s not needed - Parallax factor can now be controlled in X & Y - Reorganised command classes - Added PanToPosition() command - Pages now default to display full-size at bottom of screen. - Changed Page.VerticalAlign to Page.Layout and provided better options for controlling how the page automatically resizes.master
chrisgregan
11 years ago
28 changed files with 1474 additions and 1152 deletions
@ -1,98 +0,0 @@ |
|||||||
using UnityEditor; |
|
||||||
using UnityEngine; |
|
||||||
using System.Collections; |
|
||||||
using System.Collections.Generic; |
|
||||||
|
|
||||||
namespace Fungus |
|
||||||
{ |
|
||||||
[CanEditMultipleObjects] |
|
||||||
[CustomEditor (typeof(Page))] |
|
||||||
public class PageEditor : Editor |
|
||||||
{ |
|
||||||
void OnSceneGUI () |
|
||||||
{ |
|
||||||
Page t = target as Page; |
|
||||||
|
|
||||||
// Render the parent view to help user position the page |
|
||||||
Transform parent = t.transform.parent; |
|
||||||
if (parent != null) |
|
||||||
{ |
|
||||||
View view = parent.gameObject.GetComponent<View>(); |
|
||||||
if (view != null) |
|
||||||
{ |
|
||||||
ViewEditor.DrawView(view); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
if (t.enabled) |
|
||||||
{ |
|
||||||
EditPageBounds(); |
|
||||||
} |
|
||||||
|
|
||||||
if (GUI.changed) |
|
||||||
{ |
|
||||||
EditorUtility.SetDirty(target); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
void EditPageBounds() |
|
||||||
{ |
|
||||||
Page t = target as Page; |
|
||||||
Vector3 pos = t.transform.position; |
|
||||||
|
|
||||||
Vector3[] verts = new Vector3[4]; |
|
||||||
verts[0] = new Vector3(pos.x + t.pageBounds.min.x, pos.y + t.pageBounds.min.y, 0); |
|
||||||
verts[1] = new Vector3(pos.x + t.pageBounds.min.x, pos.y + t.pageBounds.max.y, 0); |
|
||||||
verts[2] = new Vector3(pos.x + t.pageBounds.max.x, pos.y + t.pageBounds.max.y, 0); |
|
||||||
verts[3] = new Vector3(pos.x + t.pageBounds.max.x, pos.y + t.pageBounds.min.y, 0); |
|
||||||
|
|
||||||
Handles.DrawSolidRectangleWithOutline(verts, new Color(1,1,1,0.2f), new Color(0,0,0,1)); |
|
||||||
|
|
||||||
for(int i = 0; i < 4; ++i) |
|
||||||
{ |
|
||||||
Vector3 vert = verts[i]; |
|
||||||
Vector3 newPos = Handles.FreeMoveHandle(vert, |
|
||||||
Quaternion.identity, |
|
||||||
HandleUtility.GetHandleSize(pos) * 0.1f, |
|
||||||
Vector3.zero, |
|
||||||
Handles.CubeCap); |
|
||||||
newPos.z = 0; |
|
||||||
verts[i] = newPos; |
|
||||||
|
|
||||||
if (vert != newPos) |
|
||||||
{ |
|
||||||
switch(i) |
|
||||||
{ |
|
||||||
case 0: |
|
||||||
verts[1].x = newPos.x; |
|
||||||
verts[3].y = newPos.y; |
|
||||||
break; |
|
||||||
case 1: |
|
||||||
verts[0].x = newPos.x; |
|
||||||
verts[2].y = newPos.y; |
|
||||||
break; |
|
||||||
case 2: |
|
||||||
verts[3].x = newPos.x; |
|
||||||
verts[1].y = newPos.y; |
|
||||||
break; |
|
||||||
case 3: |
|
||||||
verts[2].x = newPos.x; |
|
||||||
verts[0].y = newPos.y; |
|
||||||
break; |
|
||||||
} |
|
||||||
break; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
Bounds newBounds = new Bounds(verts[0], Vector3.zero); |
|
||||||
newBounds.Encapsulate(verts[1]); |
|
||||||
newBounds.Encapsulate(verts[2]); |
|
||||||
newBounds.Encapsulate(verts[3]); |
|
||||||
|
|
||||||
t.transform.position = newBounds.center; |
|
||||||
newBounds.center = Vector3.zero; |
|
||||||
|
|
||||||
t.pageBounds = newBounds; |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
Binary file not shown.
@ -1,4 +0,0 @@ |
|||||||
fileFormatVersion: 2 |
|
||||||
guid: dcca71ea1c47741ce882a7c9dea90719 |
|
||||||
NativeFormatImporter: |
|
||||||
userData: |
|
Binary file not shown.
Binary file not shown.
@ -1,4 +0,0 @@ |
|||||||
fileFormatVersion: 2 |
|
||||||
guid: ec557b5a76ab94961964394b8511fc9b |
|
||||||
NativeFormatImporter: |
|
||||||
userData: |
|
Binary file not shown.
Binary file not shown.
@ -1,757 +0,0 @@ |
|||||||
using UnityEngine; |
|
||||||
using System; |
|
||||||
using System.Collections; |
|
||||||
using System.Collections.Generic; |
|
||||||
|
|
||||||
namespace Fungus |
|
||||||
{ |
|
||||||
/** |
|
||||||
* Command classes have their own namespace to prevent them popping up in code completion |
|
||||||
*/ |
|
||||||
namespace Command |
|
||||||
{ |
|
||||||
/** |
|
||||||
* Call a delegate method on execution. |
|
||||||
* This command can be used to schedule arbitrary script code. |
|
||||||
*/ |
|
||||||
public class CallCommand : CommandQueue.Command |
|
||||||
{ |
|
||||||
Action callAction; |
|
||||||
|
|
||||||
public CallCommand(Action _callAction) |
|
||||||
{ |
|
||||||
if (_callAction == null) |
|
||||||
{ |
|
||||||
Debug.LogError("Action must not be null."); |
|
||||||
return; |
|
||||||
} |
|
||||||
|
|
||||||
callAction = _callAction; |
|
||||||
} |
|
||||||
|
|
||||||
public override void Execute(CommandQueue commandQueue, Action onComplete) |
|
||||||
{ |
|
||||||
if (callAction != null) |
|
||||||
{ |
|
||||||
callAction(); |
|
||||||
} |
|
||||||
|
|
||||||
// Execute next command |
|
||||||
onComplete(); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Wait for a period of time. |
|
||||||
*/ |
|
||||||
public class WaitCommand : CommandQueue.Command |
|
||||||
{ |
|
||||||
float duration; |
|
||||||
|
|
||||||
public WaitCommand(float _duration) |
|
||||||
{ |
|
||||||
duration = _duration; |
|
||||||
} |
|
||||||
|
|
||||||
public override void Execute(CommandQueue commandQueue, Action onComplete) |
|
||||||
{ |
|
||||||
Game.GetInstance().waiting = true; |
|
||||||
commandQueue.StartCoroutine(WaitCoroutine(duration, onComplete)); |
|
||||||
} |
|
||||||
|
|
||||||
IEnumerator WaitCoroutine(float duration, Action onComplete) |
|
||||||
{ |
|
||||||
yield return new WaitForSeconds(duration); |
|
||||||
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(); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Sets the currently active view immediately. |
|
||||||
* The main camera snaps to the active view. |
|
||||||
*/ |
|
||||||
public class SetViewCommand : CommandQueue.Command |
|
||||||
{ |
|
||||||
View view; |
|
||||||
|
|
||||||
public SetViewCommand(View _view) |
|
||||||
{ |
|
||||||
if (_view == null) |
|
||||||
{ |
|
||||||
Debug.LogError("View must not be null"); |
|
||||||
} |
|
||||||
|
|
||||||
view = _view; |
|
||||||
} |
|
||||||
|
|
||||||
public override void Execute(CommandQueue commandQueue, Action onComplete) |
|
||||||
{ |
|
||||||
Game game = Game.GetInstance(); |
|
||||||
|
|
||||||
game.cameraController.SnapToView(view); |
|
||||||
game.activeView = view; |
|
||||||
|
|
||||||
// Set the first page component found (if any) as the active page |
|
||||||
Page page = view.gameObject.GetComponentInChildren<Page>(); |
|
||||||
if (page != null) |
|
||||||
{ |
|
||||||
Game.GetInstance().activePage = page; |
|
||||||
} |
|
||||||
|
|
||||||
if (onComplete != null) |
|
||||||
{ |
|
||||||
onComplete(); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Sets the currently active page for text rendering. |
|
||||||
*/ |
|
||||||
public class SetPageCommand : CommandQueue.Command |
|
||||||
{ |
|
||||||
Page page; |
|
||||||
|
|
||||||
public SetPageCommand(Page _page) |
|
||||||
{ |
|
||||||
page = _page; |
|
||||||
} |
|
||||||
|
|
||||||
public override void Execute(CommandQueue commandQueue, Action onComplete) |
|
||||||
{ |
|
||||||
Game.GetInstance().activePage = page; |
|
||||||
if (onComplete != null) |
|
||||||
{ |
|
||||||
onComplete(); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Sets the currently active Page Style for rendering Pages. |
|
||||||
*/ |
|
||||||
public class SetPageStyleCommand : CommandQueue.Command |
|
||||||
{ |
|
||||||
PageStyle pageStyle; |
|
||||||
|
|
||||||
public SetPageStyleCommand(PageStyle _pageStyle) |
|
||||||
{ |
|
||||||
pageStyle = _pageStyle; |
|
||||||
} |
|
||||||
|
|
||||||
public override void Execute(CommandQueue commandQueue, Action onComplete) |
|
||||||
{ |
|
||||||
Game.GetInstance().activePageStyle = pageStyle; |
|
||||||
if (onComplete != null) |
|
||||||
{ |
|
||||||
onComplete(); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Sets the header text displayed at the top of the active page. |
|
||||||
*/ |
|
||||||
public class HeaderCommand : CommandQueue.Command |
|
||||||
{ |
|
||||||
string titleText; |
|
||||||
|
|
||||||
public HeaderCommand(string _titleText) |
|
||||||
{ |
|
||||||
titleText = _titleText; |
|
||||||
} |
|
||||||
|
|
||||||
public override void Execute(CommandQueue commandQueue, Action onComplete) |
|
||||||
{ |
|
||||||
Page page = Game.GetInstance().activePage; |
|
||||||
if (page == null) |
|
||||||
{ |
|
||||||
Debug.LogError("Active page must not be null"); |
|
||||||
} |
|
||||||
else |
|
||||||
{ |
|
||||||
page.SetHeader(titleText); |
|
||||||
} |
|
||||||
if (onComplete != null) |
|
||||||
{ |
|
||||||
onComplete(); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Sets the footer text displayed at the top of the active page. |
|
||||||
*/ |
|
||||||
public class FooterCommand : CommandQueue.Command |
|
||||||
{ |
|
||||||
string titleText; |
|
||||||
|
|
||||||
public FooterCommand(string _titleText) |
|
||||||
{ |
|
||||||
titleText = _titleText; |
|
||||||
} |
|
||||||
|
|
||||||
public override void Execute(CommandQueue commandQueue, Action onComplete) |
|
||||||
{ |
|
||||||
Page page = Game.GetInstance().activePage; |
|
||||||
if (page == null) |
|
||||||
{ |
|
||||||
Debug.LogError("Active page must not be null"); |
|
||||||
} |
|
||||||
else |
|
||||||
{ |
|
||||||
page.SetFooter(titleText); |
|
||||||
} |
|
||||||
if (onComplete != null) |
|
||||||
{ |
|
||||||
onComplete(); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Writes story text to the currently active page. |
|
||||||
* A 'continue' button is displayed when the text has fully appeared. |
|
||||||
*/ |
|
||||||
public class SayCommand : CommandQueue.Command |
|
||||||
{ |
|
||||||
string storyText; |
|
||||||
|
|
||||||
public SayCommand(string _storyText) |
|
||||||
{ |
|
||||||
storyText = _storyText; |
|
||||||
} |
|
||||||
|
|
||||||
public override void Execute(CommandQueue commandQueue, Action onComplete) |
|
||||||
{ |
|
||||||
Page page = Game.GetInstance().activePage; |
|
||||||
if (page == null) |
|
||||||
{ |
|
||||||
Debug.LogError("Active page must not be null"); |
|
||||||
} |
|
||||||
else |
|
||||||
{ |
|
||||||
page.Say(storyText, onComplete); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Adds an option button to the current list of options. |
|
||||||
* Use the Choose command to display added options. |
|
||||||
*/ |
|
||||||
public class AddOptionCommand : CommandQueue.Command |
|
||||||
{ |
|
||||||
string optionText; |
|
||||||
Action optionAction; |
|
||||||
|
|
||||||
public AddOptionCommand(string _optionText, Action _optionAction) |
|
||||||
{ |
|
||||||
optionText = _optionText; |
|
||||||
optionAction = _optionAction; |
|
||||||
} |
|
||||||
|
|
||||||
public override void Execute(CommandQueue commandQueue, Action onComplete) |
|
||||||
{ |
|
||||||
Page page = Game.GetInstance().activePage; |
|
||||||
if (page == null) |
|
||||||
{ |
|
||||||
Debug.LogError("Active page must not be null"); |
|
||||||
} |
|
||||||
else |
|
||||||
{ |
|
||||||
page.AddOption(optionText, optionAction); |
|
||||||
} |
|
||||||
if (onComplete != null) |
|
||||||
{ |
|
||||||
onComplete(); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Displays all previously added options. |
|
||||||
*/ |
|
||||||
public class ChooseCommand : CommandQueue.Command |
|
||||||
{ |
|
||||||
string chooseText; |
|
||||||
|
|
||||||
public ChooseCommand(string _chooseText) |
|
||||||
{ |
|
||||||
chooseText = _chooseText; |
|
||||||
} |
|
||||||
|
|
||||||
public override void Execute(CommandQueue commandQueue, Action onComplete) |
|
||||||
{ |
|
||||||
Page page = Game.GetInstance().activePage; |
|
||||||
if (page == null) |
|
||||||
{ |
|
||||||
Debug.LogError("Active page must not be null"); |
|
||||||
} |
|
||||||
else |
|
||||||
{ |
|
||||||
page.Choose(chooseText); |
|
||||||
} |
|
||||||
// Choose always clears commandQueue, so no need to call onComplete() |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Changes the active room to a different room |
|
||||||
*/ |
|
||||||
public class MoveToRoomCommand : CommandQueue.Command |
|
||||||
{ |
|
||||||
Room room; |
|
||||||
|
|
||||||
public MoveToRoomCommand(Room _room) |
|
||||||
{ |
|
||||||
if (_room == null) |
|
||||||
{ |
|
||||||
Debug.LogError("Room must not be null."); |
|
||||||
return; |
|
||||||
} |
|
||||||
|
|
||||||
room = _room; |
|
||||||
} |
|
||||||
|
|
||||||
public override void Execute(CommandQueue commandQueue, Action onComplete) |
|
||||||
{ |
|
||||||
Game game = Game.GetInstance(); |
|
||||||
|
|
||||||
game.waiting = true; |
|
||||||
|
|
||||||
// Fade out screen |
|
||||||
game.cameraController.Fade(0f, game.roomFadeDuration / 2f, delegate { |
|
||||||
|
|
||||||
game.activeRoom = room; |
|
||||||
|
|
||||||
// Notify room script that the Room is being entered |
|
||||||
// Calling private method on Room to hide implementation |
|
||||||
game.activeRoom.gameObject.SendMessage("Enter"); |
|
||||||
|
|
||||||
// Fade in screen |
|
||||||
game.cameraController.Fade(1f, game.roomFadeDuration / 2f, delegate { |
|
||||||
game.waiting = false; |
|
||||||
}); |
|
||||||
}); |
|
||||||
// MoveToRoom always resets the command queue so no need to call onComplete |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Sets a globally accessible game value |
|
||||||
*/ |
|
||||||
public class SetValueCommand : CommandQueue.Command |
|
||||||
{ |
|
||||||
string key; |
|
||||||
int value; |
|
||||||
|
|
||||||
public SetValueCommand(string _key, int _value) |
|
||||||
{ |
|
||||||
key = _key; |
|
||||||
value = _value; |
|
||||||
} |
|
||||||
|
|
||||||
public override void Execute(CommandQueue commandQueue, Action onComplete) |
|
||||||
{ |
|
||||||
Game.GetInstance().SetGameValue(key, value); |
|
||||||
if (onComplete != null) |
|
||||||
{ |
|
||||||
onComplete(); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Fades a sprite to a given alpha value over a period of time |
|
||||||
*/ |
|
||||||
public class FadeSpriteCommand : CommandQueue.Command |
|
||||||
{ |
|
||||||
SpriteRenderer spriteRenderer; |
|
||||||
Color targetColor; |
|
||||||
float fadeDuration; |
|
||||||
Vector2 slideOffset = Vector2.zero; |
|
||||||
|
|
||||||
public FadeSpriteCommand(SpriteRenderer _spriteRenderer, |
|
||||||
Color _targetColor, |
|
||||||
float _fadeDuration, |
|
||||||
Vector2 _slideOffset) |
|
||||||
{ |
|
||||||
if (_spriteRenderer == null) |
|
||||||
{ |
|
||||||
Debug.LogError("Sprite renderer must not be null."); |
|
||||||
return; |
|
||||||
} |
|
||||||
|
|
||||||
spriteRenderer = _spriteRenderer; |
|
||||||
targetColor = _targetColor; |
|
||||||
fadeDuration = _fadeDuration; |
|
||||||
slideOffset = _slideOffset; |
|
||||||
} |
|
||||||
|
|
||||||
public override void Execute(CommandQueue commandQueue, Action onComplete) |
|
||||||
{ |
|
||||||
SpriteFader.FadeSprite(spriteRenderer, targetColor, fadeDuration, slideOffset); |
|
||||||
|
|
||||||
// Fade is asynchronous, but command completes immediately. |
|
||||||
// If you need to wait for the fade to complete, just use an additional Wait() command |
|
||||||
if (onComplete != null) |
|
||||||
{ |
|
||||||
onComplete(); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Sets an animator trigger to change the animator state for an animated sprite |
|
||||||
*/ |
|
||||||
public class SetAnimatorTriggerCommand : CommandQueue.Command |
|
||||||
{ |
|
||||||
Animator animator; |
|
||||||
string triggerName; |
|
||||||
|
|
||||||
public SetAnimatorTriggerCommand(Animator _animator, |
|
||||||
string _triggerName) |
|
||||||
{ |
|
||||||
if (_animator == null) |
|
||||||
{ |
|
||||||
Debug.LogError("Animator must not be null."); |
|
||||||
return; |
|
||||||
} |
|
||||||
|
|
||||||
animator = _animator; |
|
||||||
triggerName = _triggerName; |
|
||||||
} |
|
||||||
|
|
||||||
public override void Execute(CommandQueue commandQueue, Action onComplete) |
|
||||||
{ |
|
||||||
animator.SetTrigger(triggerName); |
|
||||||
|
|
||||||
if (onComplete != null) |
|
||||||
{ |
|
||||||
onComplete(); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Display a button and set the method to be called when player clicks. |
|
||||||
*/ |
|
||||||
public class ShowButtonCommand : CommandQueue.Command |
|
||||||
{ |
|
||||||
Button button; |
|
||||||
bool visible; |
|
||||||
Action buttonAction; |
|
||||||
|
|
||||||
public ShowButtonCommand(Button _button, |
|
||||||
bool _visible, |
|
||||||
Action _buttonAction) |
|
||||||
{ |
|
||||||
if (_button == null) |
|
||||||
{ |
|
||||||
Debug.LogError("Button must not be null."); |
|
||||||
return; |
|
||||||
} |
|
||||||
|
|
||||||
button = _button; |
|
||||||
visible = _visible; |
|
||||||
buttonAction = _buttonAction; |
|
||||||
} |
|
||||||
|
|
||||||
public override void Execute(CommandQueue commandQueue, Action onComplete) |
|
||||||
{ |
|
||||||
button.Show(visible, buttonAction); |
|
||||||
|
|
||||||
if (onComplete != null) |
|
||||||
{ |
|
||||||
onComplete(); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Pans the camera to a view over a period of time. |
|
||||||
*/ |
|
||||||
public class PanToViewCommand : CommandQueue.Command |
|
||||||
{ |
|
||||||
View view; |
|
||||||
float duration; |
|
||||||
|
|
||||||
public PanToViewCommand(View _view, |
|
||||||
float _duration) |
|
||||||
{ |
|
||||||
if (_view == null) |
|
||||||
{ |
|
||||||
Debug.LogError("View must not be null."); |
|
||||||
return; |
|
||||||
} |
|
||||||
|
|
||||||
view = _view; |
|
||||||
duration = _duration; |
|
||||||
} |
|
||||||
|
|
||||||
public override void Execute(CommandQueue commandQueue, Action onComplete) |
|
||||||
{ |
|
||||||
Game game = Game.GetInstance(); |
|
||||||
|
|
||||||
game.waiting = true; |
|
||||||
|
|
||||||
game.cameraController.PanToView(view, duration, delegate { |
|
||||||
|
|
||||||
game.activeView = view; |
|
||||||
game.waiting = false; |
|
||||||
|
|
||||||
// Try to find a page that is a child of the active view. |
|
||||||
// If there are multiple child pages then it is the client's responsibility |
|
||||||
// to set the correct active page in the room script. |
|
||||||
Page defaultPage = view.gameObject.GetComponentInChildren<Page>(); |
|
||||||
if (defaultPage) |
|
||||||
{ |
|
||||||
game.activePage = defaultPage; |
|
||||||
} |
|
||||||
|
|
||||||
if (onComplete != null) |
|
||||||
{ |
|
||||||
onComplete(); |
|
||||||
} |
|
||||||
}); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Pans the camera through a sequence of views over a period of time. |
|
||||||
*/ |
|
||||||
public class PanToPathCommand : CommandQueue.Command |
|
||||||
{ |
|
||||||
View[] views; |
|
||||||
float duration; |
|
||||||
|
|
||||||
public PanToPathCommand(View[] _views, |
|
||||||
float _duration) |
|
||||||
{ |
|
||||||
if (_views.Length == 0) |
|
||||||
{ |
|
||||||
Debug.LogError("View list must not be empty."); |
|
||||||
return; |
|
||||||
} |
|
||||||
|
|
||||||
views = _views; |
|
||||||
duration = _duration; |
|
||||||
} |
|
||||||
|
|
||||||
public override void Execute(CommandQueue commandQueue, Action onComplete) |
|
||||||
{ |
|
||||||
Game game = Game.GetInstance(); |
|
||||||
|
|
||||||
game.waiting = true; |
|
||||||
|
|
||||||
game.cameraController.PanToPath(views, duration, delegate { |
|
||||||
|
|
||||||
if (views.Length > 0) |
|
||||||
{ |
|
||||||
game.activeView = views[views.Length - 1]; |
|
||||||
game.waiting = false; |
|
||||||
|
|
||||||
// Try to find a page that is a child of the active view. |
|
||||||
// If there are multiple child pages then it is the client's responsibility |
|
||||||
// to set the correct active page in the room script. |
|
||||||
Page defaultPage = game.activeView.gameObject.GetComponentInChildren<Page>(); |
|
||||||
if (defaultPage) |
|
||||||
{ |
|
||||||
game.activePage = defaultPage; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
if (onComplete != null) |
|
||||||
{ |
|
||||||
onComplete(); |
|
||||||
} |
|
||||||
}); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Fades the camera to a view over a period of time. |
|
||||||
*/ |
|
||||||
public class FadeToViewCommand : CommandQueue.Command |
|
||||||
{ |
|
||||||
View view; |
|
||||||
float duration; |
|
||||||
|
|
||||||
public FadeToViewCommand(View _view, |
|
||||||
float _duration) |
|
||||||
{ |
|
||||||
if (_view == null) |
|
||||||
{ |
|
||||||
Debug.LogError("View must not be null."); |
|
||||||
return; |
|
||||||
} |
|
||||||
|
|
||||||
view = _view; |
|
||||||
duration = _duration; |
|
||||||
} |
|
||||||
|
|
||||||
public override void Execute(CommandQueue commandQueue, Action onComplete) |
|
||||||
{ |
|
||||||
Game game = Game.GetInstance(); |
|
||||||
|
|
||||||
game.waiting = true; |
|
||||||
|
|
||||||
game.cameraController.FadeToView(view, duration, delegate { |
|
||||||
|
|
||||||
game.activeView = view; |
|
||||||
game.waiting = false; |
|
||||||
|
|
||||||
// Try to find a page that is a child of the active view. |
|
||||||
// If there are multiple child pages then it is the client's responsibility |
|
||||||
// to set the correct active page in the room script. |
|
||||||
Page defaultPage = view.gameObject.GetComponentInChildren<Page>(); |
|
||||||
if (defaultPage) |
|
||||||
{ |
|
||||||
game.activePage = defaultPage; |
|
||||||
} |
|
||||||
|
|
||||||
if (onComplete != null) |
|
||||||
{ |
|
||||||
onComplete(); |
|
||||||
} |
|
||||||
}); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Plays a music clip |
|
||||||
*/ |
|
||||||
public class PlayMusicCommand : CommandQueue.Command |
|
||||||
{ |
|
||||||
AudioClip audioClip; |
|
||||||
|
|
||||||
public PlayMusicCommand(AudioClip _audioClip) |
|
||||||
{ |
|
||||||
if (_audioClip == null) |
|
||||||
{ |
|
||||||
Debug.LogError("Audio clip must not be null."); |
|
||||||
return; |
|
||||||
} |
|
||||||
|
|
||||||
audioClip = _audioClip; |
|
||||||
} |
|
||||||
|
|
||||||
public override void Execute(CommandQueue commandQueue, Action onComplete) |
|
||||||
{ |
|
||||||
Game game = Game.GetInstance(); |
|
||||||
|
|
||||||
game.audio.clip = audioClip; |
|
||||||
game.audio.Play(); |
|
||||||
|
|
||||||
if (onComplete != null) |
|
||||||
{ |
|
||||||
onComplete(); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Stops a music clip |
|
||||||
*/ |
|
||||||
public class StopMusicCommand : CommandQueue.Command |
|
||||||
{ |
|
||||||
public override void Execute(CommandQueue commandQueue, Action onComplete) |
|
||||||
{ |
|
||||||
Game game = Game.GetInstance(); |
|
||||||
game.audio.Stop(); |
|
||||||
|
|
||||||
if (onComplete != null) |
|
||||||
{ |
|
||||||
onComplete(); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Fades music volume to required level over a period of time |
|
||||||
*/ |
|
||||||
public class SetMusicVolumeCommand : CommandQueue.Command |
|
||||||
{ |
|
||||||
float musicVolume; |
|
||||||
float duration; |
|
||||||
|
|
||||||
public SetMusicVolumeCommand(float _musicVolume, float _duration) |
|
||||||
{ |
|
||||||
musicVolume = _musicVolume; |
|
||||||
duration = _duration; |
|
||||||
} |
|
||||||
|
|
||||||
public override void Execute(CommandQueue commandQueue, Action onComplete) |
|
||||||
{ |
|
||||||
Game game = Game.GetInstance(); |
|
||||||
iTween.AudioTo(game.gameObject, musicVolume, 1f, duration); |
|
||||||
|
|
||||||
if (onComplete != null) |
|
||||||
{ |
|
||||||
onComplete(); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Plays a sound effect once |
|
||||||
*/ |
|
||||||
public class PlaySoundCommand : CommandQueue.Command |
|
||||||
{ |
|
||||||
AudioClip audioClip; |
|
||||||
float volume; |
|
||||||
|
|
||||||
public PlaySoundCommand(AudioClip _audioClip, float _volume) |
|
||||||
{ |
|
||||||
audioClip = _audioClip; |
|
||||||
volume = _volume; |
|
||||||
} |
|
||||||
|
|
||||||
public override void Execute(CommandQueue commandQueue, Action onComplete) |
|
||||||
{ |
|
||||||
Game game = Game.GetInstance(); |
|
||||||
game.audio.PlayOneShot(audioClip, volume); |
|
||||||
|
|
||||||
if (onComplete != null) |
|
||||||
{ |
|
||||||
onComplete(); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
@ -0,0 +1,5 @@ |
|||||||
|
fileFormatVersion: 2 |
||||||
|
guid: ed31c7843a16b49bb918643ab98b7f67 |
||||||
|
folderAsset: yes |
||||||
|
DefaultImporter: |
||||||
|
userData: |
@ -0,0 +1,113 @@ |
|||||||
|
using UnityEngine; |
||||||
|
using System; |
||||||
|
using System.Collections; |
||||||
|
|
||||||
|
namespace Fungus |
||||||
|
{ |
||||||
|
/** |
||||||
|
* Command classes have their own namespace to prevent them popping up in code completion |
||||||
|
*/ |
||||||
|
namespace Command |
||||||
|
{ |
||||||
|
/** |
||||||
|
* Plays a music clip |
||||||
|
*/ |
||||||
|
public class PlayMusic : CommandQueue.Command |
||||||
|
{ |
||||||
|
AudioClip audioClip; |
||||||
|
|
||||||
|
public PlayMusic(AudioClip _audioClip) |
||||||
|
{ |
||||||
|
if (_audioClip == null) |
||||||
|
{ |
||||||
|
Debug.LogError("Audio clip must not be null."); |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
audioClip = _audioClip; |
||||||
|
} |
||||||
|
|
||||||
|
public override void Execute(CommandQueue commandQueue, Action onComplete) |
||||||
|
{ |
||||||
|
Game game = Game.GetInstance(); |
||||||
|
|
||||||
|
game.audio.clip = audioClip; |
||||||
|
game.audio.Play(); |
||||||
|
|
||||||
|
if (onComplete != null) |
||||||
|
{ |
||||||
|
onComplete(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Stops a music clip |
||||||
|
*/ |
||||||
|
public class StopMusic : CommandQueue.Command |
||||||
|
{ |
||||||
|
public override void Execute(CommandQueue commandQueue, Action onComplete) |
||||||
|
{ |
||||||
|
Game game = Game.GetInstance(); |
||||||
|
game.audio.Stop(); |
||||||
|
|
||||||
|
if (onComplete != null) |
||||||
|
{ |
||||||
|
onComplete(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Fades music volume to required level over a period of time |
||||||
|
*/ |
||||||
|
public class SetMusicVolume : CommandQueue.Command |
||||||
|
{ |
||||||
|
float musicVolume; |
||||||
|
float duration; |
||||||
|
|
||||||
|
public SetMusicVolume(float _musicVolume, float _duration) |
||||||
|
{ |
||||||
|
musicVolume = _musicVolume; |
||||||
|
duration = _duration; |
||||||
|
} |
||||||
|
|
||||||
|
public override void Execute(CommandQueue commandQueue, Action onComplete) |
||||||
|
{ |
||||||
|
Game game = Game.GetInstance(); |
||||||
|
iTween.AudioTo(game.gameObject, musicVolume, 1f, duration); |
||||||
|
|
||||||
|
if (onComplete != null) |
||||||
|
{ |
||||||
|
onComplete(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Plays a sound effect once |
||||||
|
*/ |
||||||
|
public class PlaySound : CommandQueue.Command |
||||||
|
{ |
||||||
|
AudioClip audioClip; |
||||||
|
float volume; |
||||||
|
|
||||||
|
public PlaySound(AudioClip _audioClip, float _volume) |
||||||
|
{ |
||||||
|
audioClip = _audioClip; |
||||||
|
volume = _volume; |
||||||
|
} |
||||||
|
|
||||||
|
public override void Execute(CommandQueue commandQueue, Action onComplete) |
||||||
|
{ |
||||||
|
Game game = Game.GetInstance(); |
||||||
|
game.audio.PlayOneShot(audioClip, volume); |
||||||
|
|
||||||
|
if (onComplete != null) |
||||||
|
{ |
||||||
|
onComplete(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -1,5 +1,5 @@ |
|||||||
fileFormatVersion: 2 |
fileFormatVersion: 2 |
||||||
guid: b5c35620ec53b405a8d00dcb285cd260 |
guid: bc443341450b64de790b66416177cca7 |
||||||
MonoImporter: |
MonoImporter: |
||||||
serializedVersion: 2 |
serializedVersion: 2 |
||||||
defaultReferences: [] |
defaultReferences: [] |
@ -0,0 +1,273 @@ |
|||||||
|
using UnityEngine; |
||||||
|
using System; |
||||||
|
using System.Collections; |
||||||
|
|
||||||
|
namespace Fungus |
||||||
|
{ |
||||||
|
/** |
||||||
|
* Command classes have their own namespace to prevent them popping up in code completion. |
||||||
|
*/ |
||||||
|
namespace Command |
||||||
|
{ |
||||||
|
/** |
||||||
|
* Sets the currently active view immediately. |
||||||
|
* The main camera snaps to the active view. |
||||||
|
*/ |
||||||
|
public class SetView : CommandQueue.Command |
||||||
|
{ |
||||||
|
View view; |
||||||
|
|
||||||
|
public SetView(View _view) |
||||||
|
{ |
||||||
|
if (_view == null) |
||||||
|
{ |
||||||
|
Debug.LogError("View must not be null"); |
||||||
|
} |
||||||
|
|
||||||
|
view = _view; |
||||||
|
} |
||||||
|
|
||||||
|
public override void Execute(CommandQueue commandQueue, Action onComplete) |
||||||
|
{ |
||||||
|
Game game = Game.GetInstance(); |
||||||
|
|
||||||
|
game.cameraController.PanToPosition(view.transform.position, view.viewSize, 0, null); |
||||||
|
|
||||||
|
if (onComplete != null) |
||||||
|
{ |
||||||
|
onComplete(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Pans the camera to a target position & size over a period of time. |
||||||
|
*/ |
||||||
|
public class PanToPosition : CommandQueue.Command |
||||||
|
{ |
||||||
|
Vector3 targetPosition; |
||||||
|
float targetSize; |
||||||
|
float duration; |
||||||
|
|
||||||
|
public PanToPosition(Vector3 _targetPosition, float _targetSize, float _duration) |
||||||
|
{ |
||||||
|
targetPosition = _targetPosition; |
||||||
|
targetSize = _targetSize; |
||||||
|
duration = _duration; |
||||||
|
} |
||||||
|
|
||||||
|
public override void Execute(CommandQueue commandQueue, Action onComplete) |
||||||
|
{ |
||||||
|
Game game = Game.GetInstance(); |
||||||
|
|
||||||
|
game.waiting = true; |
||||||
|
|
||||||
|
game.cameraController.PanToPosition(targetPosition, targetSize, duration, delegate { |
||||||
|
|
||||||
|
game.waiting = false; |
||||||
|
|
||||||
|
if (onComplete != null) |
||||||
|
{ |
||||||
|
onComplete(); |
||||||
|
} |
||||||
|
}); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Pans the camera through a sequence of views over a period of time. |
||||||
|
*/ |
||||||
|
public class PanToPath : CommandQueue.Command |
||||||
|
{ |
||||||
|
View[] views; |
||||||
|
float duration; |
||||||
|
|
||||||
|
public PanToPath(View[] _views, float _duration) |
||||||
|
{ |
||||||
|
if (_views.Length == 0) |
||||||
|
{ |
||||||
|
Debug.LogError("View list must not be empty."); |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
views = _views; |
||||||
|
duration = _duration; |
||||||
|
} |
||||||
|
|
||||||
|
public override void Execute(CommandQueue commandQueue, Action onComplete) |
||||||
|
{ |
||||||
|
Game game = Game.GetInstance(); |
||||||
|
|
||||||
|
game.waiting = true; |
||||||
|
|
||||||
|
game.cameraController.PanToPath(views, duration, delegate { |
||||||
|
|
||||||
|
if (views.Length > 0) |
||||||
|
{ |
||||||
|
game.waiting = false; |
||||||
|
} |
||||||
|
|
||||||
|
if (onComplete != null) |
||||||
|
{ |
||||||
|
onComplete(); |
||||||
|
} |
||||||
|
}); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Fades the camera to a view over a period of time. |
||||||
|
*/ |
||||||
|
public class FadeToView : CommandQueue.Command |
||||||
|
{ |
||||||
|
View view; |
||||||
|
float duration; |
||||||
|
|
||||||
|
public FadeToView(View _view, float _duration) |
||||||
|
{ |
||||||
|
if (_view == null) |
||||||
|
{ |
||||||
|
Debug.LogError("View must not be null."); |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
view = _view; |
||||||
|
duration = _duration; |
||||||
|
} |
||||||
|
|
||||||
|
public override void Execute(CommandQueue commandQueue, Action onComplete) |
||||||
|
{ |
||||||
|
Game game = Game.GetInstance(); |
||||||
|
|
||||||
|
game.waiting = true; |
||||||
|
|
||||||
|
game.cameraController.FadeToView(view, duration, delegate { |
||||||
|
|
||||||
|
game.waiting = false; |
||||||
|
|
||||||
|
if (onComplete != null) |
||||||
|
{ |
||||||
|
onComplete(); |
||||||
|
} |
||||||
|
}); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Switches on manual pan mode. |
||||||
|
* This allows the player to swipe the screen to pan around a region defined by 2 views. |
||||||
|
*/ |
||||||
|
public class StartManualPan : CommandQueue.Command |
||||||
|
{ |
||||||
|
View viewA; |
||||||
|
View viewB; |
||||||
|
float duration; |
||||||
|
|
||||||
|
public StartManualPan(View _viewA, View _viewB, float _duration) |
||||||
|
{ |
||||||
|
if (_viewA == null || |
||||||
|
_viewB == null) |
||||||
|
{ |
||||||
|
Debug.LogError("Views must not be null."); |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
viewA = _viewA; |
||||||
|
viewB = _viewB; |
||||||
|
duration = _duration; |
||||||
|
} |
||||||
|
|
||||||
|
public override void Execute(CommandQueue commandQueue, Action onComplete) |
||||||
|
{ |
||||||
|
Game game = Game.GetInstance(); |
||||||
|
|
||||||
|
game.waiting = true; |
||||||
|
|
||||||
|
game.cameraController.StartManualPan(viewA, viewB, duration, delegate { |
||||||
|
|
||||||
|
game.waiting = false; |
||||||
|
|
||||||
|
if (onComplete != null) |
||||||
|
{ |
||||||
|
onComplete(); |
||||||
|
} |
||||||
|
}); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Switches off manual pan mode. |
||||||
|
*/ |
||||||
|
public class StopManualPan : CommandQueue.Command |
||||||
|
{ |
||||||
|
public override void Execute(CommandQueue commandQueue, Action onComplete) |
||||||
|
{ |
||||||
|
Game game = Game.GetInstance(); |
||||||
|
|
||||||
|
game.cameraController.StopManualPan(); |
||||||
|
|
||||||
|
if (onComplete != null) |
||||||
|
{ |
||||||
|
onComplete(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Stores the current camera position |
||||||
|
*/ |
||||||
|
public class StoreView : CommandQueue.Command |
||||||
|
{ |
||||||
|
string viewName; |
||||||
|
|
||||||
|
public StoreView(string _viewName) |
||||||
|
{ |
||||||
|
viewName = _viewName; |
||||||
|
} |
||||||
|
|
||||||
|
public override void Execute(CommandQueue commandQueue, Action onComplete) |
||||||
|
{ |
||||||
|
Game game = Game.GetInstance(); |
||||||
|
|
||||||
|
game.cameraController.StoreView(viewName); |
||||||
|
|
||||||
|
if (onComplete != null) |
||||||
|
{ |
||||||
|
onComplete(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Pans the camera to a view over a period of time. |
||||||
|
*/ |
||||||
|
public class PanToStoredView : CommandQueue.Command |
||||||
|
{ |
||||||
|
float duration; |
||||||
|
string viewName; |
||||||
|
|
||||||
|
public PanToStoredView(string _viewName, float _duration) |
||||||
|
{ |
||||||
|
viewName = _viewName; |
||||||
|
duration = _duration; |
||||||
|
} |
||||||
|
|
||||||
|
public override void Execute(CommandQueue commandQueue, Action onComplete) |
||||||
|
{ |
||||||
|
Game game = Game.GetInstance(); |
||||||
|
|
||||||
|
game.waiting = true; |
||||||
|
|
||||||
|
game.cameraController.PanToStoredView(viewName, duration, delegate { |
||||||
|
|
||||||
|
game.waiting = false; |
||||||
|
|
||||||
|
if (onComplete != null) |
||||||
|
{ |
||||||
|
onComplete(); |
||||||
|
} |
||||||
|
}); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -1,5 +1,5 @@ |
|||||||
fileFormatVersion: 2 |
fileFormatVersion: 2 |
||||||
guid: dce33924cf6804b2c94d17784a6037d1 |
guid: 48a11d9857cef47caad512a6e89998d3 |
||||||
MonoImporter: |
MonoImporter: |
||||||
serializedVersion: 2 |
serializedVersion: 2 |
||||||
defaultReferences: [] |
defaultReferences: [] |
@ -0,0 +1,168 @@ |
|||||||
|
using UnityEngine; |
||||||
|
using System; |
||||||
|
using System.Collections; |
||||||
|
|
||||||
|
namespace Fungus |
||||||
|
{ |
||||||
|
/** |
||||||
|
* Command classes have their own namespace to prevent them popping up in code completion. |
||||||
|
*/ |
||||||
|
namespace Command |
||||||
|
{ |
||||||
|
/** |
||||||
|
* Call a delegate method on execution. |
||||||
|
* This command can be used to schedule arbitrary script code. |
||||||
|
*/ |
||||||
|
public class Call : CommandQueue.Command |
||||||
|
{ |
||||||
|
Action callAction; |
||||||
|
|
||||||
|
public Call(Action _callAction) |
||||||
|
{ |
||||||
|
if (_callAction == null) |
||||||
|
{ |
||||||
|
Debug.LogError("Action must not be null."); |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
callAction = _callAction; |
||||||
|
} |
||||||
|
|
||||||
|
public override void Execute(CommandQueue commandQueue, Action onComplete) |
||||||
|
{ |
||||||
|
if (callAction != null) |
||||||
|
{ |
||||||
|
callAction(); |
||||||
|
} |
||||||
|
|
||||||
|
// Execute next command |
||||||
|
onComplete(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Wait for a period of time. |
||||||
|
*/ |
||||||
|
public class Wait : CommandQueue.Command |
||||||
|
{ |
||||||
|
float duration; |
||||||
|
|
||||||
|
public Wait(float _duration) |
||||||
|
{ |
||||||
|
duration = _duration; |
||||||
|
} |
||||||
|
|
||||||
|
public override void Execute(CommandQueue commandQueue, Action onComplete) |
||||||
|
{ |
||||||
|
Game.GetInstance().waiting = true; |
||||||
|
commandQueue.StartCoroutine(WaitCoroutine(duration, onComplete)); |
||||||
|
} |
||||||
|
|
||||||
|
IEnumerator WaitCoroutine(float duration, Action onComplete) |
||||||
|
{ |
||||||
|
yield return new WaitForSeconds(duration); |
||||||
|
if (onComplete != null) |
||||||
|
{ |
||||||
|
Game.GetInstance().waiting = false; |
||||||
|
onComplete(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Wait for a player tap/click/key press |
||||||
|
*/ |
||||||
|
public class WaitForInput : 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(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Changes the active room to a different room |
||||||
|
*/ |
||||||
|
public class MoveToRoom : CommandQueue.Command |
||||||
|
{ |
||||||
|
Room room; |
||||||
|
|
||||||
|
public MoveToRoom(Room _room) |
||||||
|
{ |
||||||
|
if (_room == null) |
||||||
|
{ |
||||||
|
Debug.LogError("Room must not be null."); |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
room = _room; |
||||||
|
} |
||||||
|
|
||||||
|
public override void Execute(CommandQueue commandQueue, Action onComplete) |
||||||
|
{ |
||||||
|
Game game = Game.GetInstance(); |
||||||
|
|
||||||
|
game.waiting = true; |
||||||
|
|
||||||
|
// Fade out screen |
||||||
|
game.cameraController.Fade(0f, game.roomFadeDuration / 2f, delegate { |
||||||
|
|
||||||
|
game.activeRoom = room; |
||||||
|
|
||||||
|
// Notify room script that the Room is being entered |
||||||
|
// Calling private method on Room to hide implementation |
||||||
|
game.activeRoom.gameObject.SendMessage("Enter"); |
||||||
|
|
||||||
|
// Fade in screen |
||||||
|
game.cameraController.Fade(1f, game.roomFadeDuration / 2f, delegate { |
||||||
|
game.waiting = false; |
||||||
|
}); |
||||||
|
}); |
||||||
|
// MoveToRoom always resets the command queue so no need to call onComplete |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Sets a globally accessible game value |
||||||
|
*/ |
||||||
|
public class SetValue : CommandQueue.Command |
||||||
|
{ |
||||||
|
string key; |
||||||
|
int value; |
||||||
|
|
||||||
|
public SetValue(string _key, int _value) |
||||||
|
{ |
||||||
|
key = _key; |
||||||
|
value = _value; |
||||||
|
} |
||||||
|
|
||||||
|
public override void Execute(CommandQueue commandQueue, Action onComplete) |
||||||
|
{ |
||||||
|
Game.GetInstance().SetGameValue(key, value); |
||||||
|
if (onComplete != null) |
||||||
|
{ |
||||||
|
onComplete(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -1,5 +1,5 @@ |
|||||||
fileFormatVersion: 2 |
fileFormatVersion: 2 |
||||||
guid: c82cac70434cd411b973a4c590386c63 |
guid: 83105d98d4aed45f9b25b7ba66e83a29 |
||||||
MonoImporter: |
MonoImporter: |
||||||
serializedVersion: 2 |
serializedVersion: 2 |
||||||
defaultReferences: [] |
defaultReferences: [] |
@ -0,0 +1,243 @@ |
|||||||
|
using UnityEngine; |
||||||
|
using System; |
||||||
|
using System.Collections; |
||||||
|
|
||||||
|
namespace Fungus |
||||||
|
{ |
||||||
|
/** |
||||||
|
* Command classes have their own namespace to prevent them popping up in code completion. |
||||||
|
*/ |
||||||
|
namespace Command |
||||||
|
{ |
||||||
|
/** |
||||||
|
* Sets the display rect for the active Page using a PageBounds object. |
||||||
|
*/ |
||||||
|
public class SetPageBounds : CommandQueue.Command |
||||||
|
{ |
||||||
|
PageBounds pageBounds; |
||||||
|
Page.Layout pageLayout; |
||||||
|
|
||||||
|
public SetPageBounds(PageBounds _pageBounds, Page.Layout _pageLayout) |
||||||
|
{ |
||||||
|
pageBounds = _pageBounds; |
||||||
|
pageLayout = _pageLayout; |
||||||
|
} |
||||||
|
|
||||||
|
public override void Execute(CommandQueue commandQueue, Action onComplete) |
||||||
|
{ |
||||||
|
if (pageBounds != null) |
||||||
|
{ |
||||||
|
pageBounds.UpdatePageRect(); |
||||||
|
Game.GetInstance().activePage.layout = pageLayout; |
||||||
|
} |
||||||
|
|
||||||
|
if (onComplete != null) |
||||||
|
{ |
||||||
|
onComplete(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Sets the display rect for the active Page using normalized screen space coords. |
||||||
|
*/ |
||||||
|
public class SetPageRect : CommandQueue.Command |
||||||
|
{ |
||||||
|
float x1; |
||||||
|
float y1; |
||||||
|
float x2; |
||||||
|
float y2; |
||||||
|
Page.Layout layout; |
||||||
|
|
||||||
|
public SetPageRect(float _x1, float _y1, float _x2, float _y2, Page.Layout _layout) |
||||||
|
{ |
||||||
|
x1 = _x1; |
||||||
|
y1 = _y1; |
||||||
|
x2 = _x2; |
||||||
|
y2 = _y2; |
||||||
|
layout = _layout; |
||||||
|
} |
||||||
|
|
||||||
|
public override void Execute(CommandQueue commandQueue, Action onComplete) |
||||||
|
{ |
||||||
|
Page page = Game.GetInstance().activePage; |
||||||
|
page.SetPageRect(x1, y1, x2, y2); |
||||||
|
page.layout = layout; |
||||||
|
|
||||||
|
if (onComplete != null) |
||||||
|
{ |
||||||
|
onComplete(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Sets the currently active Page Style for rendering Pages. |
||||||
|
*/ |
||||||
|
public class SetPageStyle : CommandQueue.Command |
||||||
|
{ |
||||||
|
PageStyle pageStyle; |
||||||
|
|
||||||
|
public SetPageStyle(PageStyle _pageStyle) |
||||||
|
{ |
||||||
|
pageStyle = _pageStyle; |
||||||
|
} |
||||||
|
|
||||||
|
public override void Execute(CommandQueue commandQueue, Action onComplete) |
||||||
|
{ |
||||||
|
Game.GetInstance().activePageStyle = pageStyle; |
||||||
|
if (onComplete != null) |
||||||
|
{ |
||||||
|
onComplete(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Sets the header text displayed at the top of the active page. |
||||||
|
*/ |
||||||
|
public class SetHeader : CommandQueue.Command |
||||||
|
{ |
||||||
|
string titleText; |
||||||
|
|
||||||
|
public SetHeader(string _titleText) |
||||||
|
{ |
||||||
|
titleText = _titleText; |
||||||
|
} |
||||||
|
|
||||||
|
public override void Execute(CommandQueue commandQueue, Action onComplete) |
||||||
|
{ |
||||||
|
Page page = Game.GetInstance().activePage; |
||||||
|
if (page == null) |
||||||
|
{ |
||||||
|
Debug.LogError("Active page must not be null"); |
||||||
|
} |
||||||
|
else |
||||||
|
{ |
||||||
|
page.SetHeader(titleText); |
||||||
|
} |
||||||
|
if (onComplete != null) |
||||||
|
{ |
||||||
|
onComplete(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Sets the footer text displayed at the top of the active page. |
||||||
|
*/ |
||||||
|
public class SetFooter : CommandQueue.Command |
||||||
|
{ |
||||||
|
string titleText; |
||||||
|
|
||||||
|
public SetFooter(string _titleText) |
||||||
|
{ |
||||||
|
titleText = _titleText; |
||||||
|
} |
||||||
|
|
||||||
|
public override void Execute(CommandQueue commandQueue, Action onComplete) |
||||||
|
{ |
||||||
|
Page page = Game.GetInstance().activePage; |
||||||
|
if (page == null) |
||||||
|
{ |
||||||
|
Debug.LogError("Active page must not be null"); |
||||||
|
} |
||||||
|
else |
||||||
|
{ |
||||||
|
page.SetFooter(titleText); |
||||||
|
} |
||||||
|
if (onComplete != null) |
||||||
|
{ |
||||||
|
onComplete(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Writes story text to the currently active page. |
||||||
|
* A 'continue' icon is displayed when the text has fully appeared. |
||||||
|
*/ |
||||||
|
public class Say : CommandQueue.Command |
||||||
|
{ |
||||||
|
string storyText; |
||||||
|
|
||||||
|
public Say(string _storyText) |
||||||
|
{ |
||||||
|
storyText = _storyText; |
||||||
|
} |
||||||
|
|
||||||
|
public override void Execute(CommandQueue commandQueue, Action onComplete) |
||||||
|
{ |
||||||
|
Page page = Game.GetInstance().activePage; |
||||||
|
if (page == null) |
||||||
|
{ |
||||||
|
Debug.LogError("Active page must not be null"); |
||||||
|
} |
||||||
|
else |
||||||
|
{ |
||||||
|
page.Say(storyText, onComplete); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Adds an option button to the current list of options. |
||||||
|
* Use the Choose command to display added options. |
||||||
|
*/ |
||||||
|
public class AddOption : CommandQueue.Command |
||||||
|
{ |
||||||
|
string optionText; |
||||||
|
Action optionAction; |
||||||
|
|
||||||
|
public AddOption(string _optionText, Action _optionAction) |
||||||
|
{ |
||||||
|
optionText = _optionText; |
||||||
|
optionAction = _optionAction; |
||||||
|
} |
||||||
|
|
||||||
|
public override void Execute(CommandQueue commandQueue, Action onComplete) |
||||||
|
{ |
||||||
|
Page page = Game.GetInstance().activePage; |
||||||
|
if (page == null) |
||||||
|
{ |
||||||
|
Debug.LogError("Active page must not be null"); |
||||||
|
} |
||||||
|
else |
||||||
|
{ |
||||||
|
page.AddOption(optionText, optionAction); |
||||||
|
} |
||||||
|
if (onComplete != null) |
||||||
|
{ |
||||||
|
onComplete(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Displays all previously added options. |
||||||
|
*/ |
||||||
|
public class Choose : CommandQueue.Command |
||||||
|
{ |
||||||
|
string chooseText; |
||||||
|
|
||||||
|
public Choose(string _chooseText) |
||||||
|
{ |
||||||
|
chooseText = _chooseText; |
||||||
|
} |
||||||
|
|
||||||
|
public override void Execute(CommandQueue commandQueue, Action onComplete) |
||||||
|
{ |
||||||
|
Page page = Game.GetInstance().activePage; |
||||||
|
if (page == null) |
||||||
|
{ |
||||||
|
Debug.LogError("Active page must not be null"); |
||||||
|
} |
||||||
|
else |
||||||
|
{ |
||||||
|
page.Choose(chooseText); |
||||||
|
} |
||||||
|
// Choose always clears commandQueue, so no need to call onComplete() |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,8 @@ |
|||||||
|
fileFormatVersion: 2 |
||||||
|
guid: ae90082ad9904474ebe8554e864a0539 |
||||||
|
MonoImporter: |
||||||
|
serializedVersion: 2 |
||||||
|
defaultReferences: [] |
||||||
|
executionOrder: 0 |
||||||
|
icon: {instanceID: 0} |
||||||
|
userData: |
@ -0,0 +1,119 @@ |
|||||||
|
using UnityEngine; |
||||||
|
using System; |
||||||
|
using System.Collections; |
||||||
|
|
||||||
|
namespace Fungus |
||||||
|
{ |
||||||
|
/** |
||||||
|
* Command classes have their own namespace to prevent them popping up in code completion. |
||||||
|
*/ |
||||||
|
namespace Command |
||||||
|
{ |
||||||
|
/** |
||||||
|
* Fades a sprite to a given alpha value over a period of time |
||||||
|
*/ |
||||||
|
public class FadeSprite : CommandQueue.Command |
||||||
|
{ |
||||||
|
SpriteRenderer spriteRenderer; |
||||||
|
Color targetColor; |
||||||
|
float fadeDuration; |
||||||
|
Vector2 slideOffset = Vector2.zero; |
||||||
|
|
||||||
|
public FadeSprite(SpriteRenderer _spriteRenderer, |
||||||
|
Color _targetColor, |
||||||
|
float _fadeDuration, |
||||||
|
Vector2 _slideOffset) |
||||||
|
{ |
||||||
|
if (_spriteRenderer == null) |
||||||
|
{ |
||||||
|
Debug.LogError("Sprite renderer must not be null."); |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
spriteRenderer = _spriteRenderer; |
||||||
|
targetColor = _targetColor; |
||||||
|
fadeDuration = _fadeDuration; |
||||||
|
slideOffset = _slideOffset; |
||||||
|
} |
||||||
|
|
||||||
|
public override void Execute(CommandQueue commandQueue, Action onComplete) |
||||||
|
{ |
||||||
|
SpriteFader.FadeSprite(spriteRenderer, targetColor, fadeDuration, slideOffset); |
||||||
|
|
||||||
|
// Fade is asynchronous, but command completes immediately. |
||||||
|
// If you need to wait for the fade to complete, just use an additional Wait() command |
||||||
|
if (onComplete != null) |
||||||
|
{ |
||||||
|
onComplete(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Sets an animator trigger to change the animator state for an animated sprite |
||||||
|
*/ |
||||||
|
public class SetAnimatorTrigger : CommandQueue.Command |
||||||
|
{ |
||||||
|
Animator animator; |
||||||
|
string triggerName; |
||||||
|
|
||||||
|
public SetAnimatorTrigger(Animator _animator, |
||||||
|
string _triggerName) |
||||||
|
{ |
||||||
|
if (_animator == null) |
||||||
|
{ |
||||||
|
Debug.LogError("Animator must not be null."); |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
animator = _animator; |
||||||
|
triggerName = _triggerName; |
||||||
|
} |
||||||
|
|
||||||
|
public override void Execute(CommandQueue commandQueue, Action onComplete) |
||||||
|
{ |
||||||
|
animator.SetTrigger(triggerName); |
||||||
|
|
||||||
|
if (onComplete != null) |
||||||
|
{ |
||||||
|
onComplete(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Display a button and set the method to be called when player clicks. |
||||||
|
*/ |
||||||
|
public class ShowButton : CommandQueue.Command |
||||||
|
{ |
||||||
|
Button button; |
||||||
|
bool visible; |
||||||
|
Action buttonAction; |
||||||
|
|
||||||
|
public ShowButton(Button _button, |
||||||
|
bool _visible, |
||||||
|
Action _buttonAction) |
||||||
|
{ |
||||||
|
if (_button == null) |
||||||
|
{ |
||||||
|
Debug.LogError("Button must not be null."); |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
button = _button; |
||||||
|
visible = _visible; |
||||||
|
buttonAction = _buttonAction; |
||||||
|
} |
||||||
|
|
||||||
|
public override void Execute(CommandQueue commandQueue, Action onComplete) |
||||||
|
{ |
||||||
|
button.Show(visible, buttonAction); |
||||||
|
|
||||||
|
if (onComplete != null) |
||||||
|
{ |
||||||
|
onComplete(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,8 @@ |
|||||||
|
fileFormatVersion: 2 |
||||||
|
guid: bb89d5e15bc734221b9d8fe9ae8e8153 |
||||||
|
MonoImporter: |
||||||
|
serializedVersion: 2 |
||||||
|
defaultReferences: [] |
||||||
|
executionOrder: 0 |
||||||
|
icon: {instanceID: 0} |
||||||
|
userData: |
@ -1,48 +0,0 @@ |
|||||||
using UnityEngine; |
|
||||||
using System.Collections; |
|
||||||
|
|
||||||
public class ContinueStyle : MonoBehaviour |
|
||||||
{ |
|
||||||
/** |
|
||||||
* Text to use on 'Continue' buttons. |
|
||||||
*/ |
|
||||||
public string continueText = "Continue"; |
|
||||||
|
|
||||||
/// Continue font size as a fraction of screen height. |
|
||||||
public float continueFontScale = 1f / 30f; |
|
||||||
|
|
||||||
/// Style for continue button |
|
||||||
public GUIStyle style; |
|
||||||
|
|
||||||
/** |
|
||||||
* If true, places the continue button on the active page. |
|
||||||
* If false, places the continue button on the screen. |
|
||||||
*/ |
|
||||||
public bool onPage; |
|
||||||
|
|
||||||
/** |
|
||||||
* Specifies continue button position in normalized screen coordinates. |
|
||||||
* This setting is ignored if onPage == true |
|
||||||
* (0,0) is top left of screen. |
|
||||||
* (1,1) is bottom right of screen |
|
||||||
*/ |
|
||||||
public Vector2 screenPosition = new Vector2(1,1); |
|
||||||
|
|
||||||
/** |
|
||||||
* Padding distance between button and edge of the screen in pixels. |
|
||||||
*/ |
|
||||||
public Vector2 padding = new Vector2(4,4); |
|
||||||
|
|
||||||
/** |
|
||||||
* Returns the style for the Continue button. |
|
||||||
* Overrides the font size to compensate for varying device resolution. |
|
||||||
* Font size is calculated as a fraction of the current screen height. |
|
||||||
*/ |
|
||||||
public GUIStyle GetScaledContinueStyle() |
|
||||||
{ |
|
||||||
GUIStyle guiStyle; |
|
||||||
guiStyle = new GUIStyle(style); |
|
||||||
guiStyle.fontSize = Mathf.RoundToInt((float)Screen.height * continueFontScale); |
|
||||||
return guiStyle; |
|
||||||
} |
|
||||||
} |
|
Loading…
Reference in new issue