chrisgregan
11 years ago
20 changed files with 8 additions and 425 deletions
@ -1,44 +0,0 @@ |
|||||||
using UnityEditor; |
|
||||||
using UnityEngine; |
|
||||||
using System.Collections; |
|
||||||
|
|
||||||
namespace Fungus |
|
||||||
{ |
|
||||||
[CustomEditor (typeof(Game))] |
|
||||||
public class GameEditor : Editor |
|
||||||
{ |
|
||||||
private void OnSceneGUI() |
|
||||||
{ |
|
||||||
GameEditor.DrawRoomNames(); |
|
||||||
} |
|
||||||
|
|
||||||
static public void DrawRoomNames() |
|
||||||
{ |
|
||||||
Handles.color = Color.white; |
|
||||||
Handles.BeginGUI(); |
|
||||||
|
|
||||||
// Show labels for each room |
|
||||||
Room[] rooms = GameObject.FindObjectsOfType<Room>(); |
|
||||||
|
|
||||||
foreach (Room room in rooms) |
|
||||||
{ |
|
||||||
if (!room.renderer) |
|
||||||
{ |
|
||||||
continue; |
|
||||||
} |
|
||||||
|
|
||||||
Bounds bounds = room.renderer.bounds; |
|
||||||
Vector3 pos = new Vector3(bounds.min.x, bounds.max.y, 0); |
|
||||||
|
|
||||||
GUIStyle style = new GUIStyle(GUI.skin.label); |
|
||||||
style.normal.textColor = new Color(1,1,1); |
|
||||||
style.fontSize /= 2; |
|
||||||
Rect boxRect = HandleUtility.WorldPointToSizedRect(pos, new GUIContent(room.name), style); |
|
||||||
boxRect.y -= boxRect.height * 1.5f; |
|
||||||
GUI.Box(boxRect, room.name, style); |
|
||||||
} |
|
||||||
|
|
||||||
Handles.EndGUI(); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
@ -1,8 +0,0 @@ |
|||||||
fileFormatVersion: 2 |
|
||||||
guid: 5464e5745a4da462795a6f6f5b112962 |
|
||||||
MonoImporter: |
|
||||||
serializedVersion: 2 |
|
||||||
defaultReferences: [] |
|
||||||
executionOrder: 0 |
|
||||||
icon: {instanceID: 0} |
|
||||||
userData: |
|
@ -1,16 +0,0 @@ |
|||||||
using UnityEditor; |
|
||||||
using UnityEngine; |
|
||||||
using System.Collections; |
|
||||||
|
|
||||||
namespace Fungus |
|
||||||
{ |
|
||||||
[CustomEditor (typeof(Room), true)] |
|
||||||
[CanEditMultipleObjects] |
|
||||||
public class RoomEditor : Editor |
|
||||||
{ |
|
||||||
private void OnSceneGUI() |
|
||||||
{ |
|
||||||
GameEditor.DrawRoomNames(); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
@ -1,8 +0,0 @@ |
|||||||
fileFormatVersion: 2 |
|
||||||
guid: 0314fe408508a4b25afa76f65378a427 |
|
||||||
MonoImporter: |
|
||||||
serializedVersion: 2 |
|
||||||
defaultReferences: [] |
|
||||||
executionOrder: 0 |
|
||||||
icon: {instanceID: 0} |
|
||||||
userData: |
|
@ -1,169 +0,0 @@ |
|||||||
using UnityEngine; |
|
||||||
using System; |
|
||||||
using System.Collections; |
|
||||||
using System.Collections.Generic; |
|
||||||
using System.Reflection; |
|
||||||
using Fungus.Script; |
|
||||||
|
|
||||||
namespace Fungus |
|
||||||
{ |
|
||||||
/** |
|
||||||
* This is the primary base class for scripting Fungus games. |
|
||||||
* Each Room in your game should have a script component which inherits from Room. |
|
||||||
* The OnEnter() method is called when the player enters the room. |
|
||||||
* The GameController base class provides easy access to all Fungus functionality. |
|
||||||
*/ |
|
||||||
public abstract class Room : UnityEngine.MonoBehaviour |
|
||||||
{ |
|
||||||
string GetVisitVariableKey() |
|
||||||
{ |
|
||||||
return "_visits." + gameObject.name; |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Returns the number of times the player has visited this Room. |
|
||||||
* The Room game object name is used to track the visit count and so must be unique in the game. |
|
||||||
*/ |
|
||||||
public int GetVisitCount() |
|
||||||
{ |
|
||||||
return GlobalVariables.GetInteger(GetVisitVariableKey()); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Sets the number of times the player has visited this Room. |
|
||||||
*/ |
|
||||||
void SetVisitCount(int count) |
|
||||||
{ |
|
||||||
GlobalVariables.SetInteger(GetVisitVariableKey(), count); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Returns true if this is the first time the player has visited this room. |
|
||||||
*/ |
|
||||||
public bool IsFirstVisit() |
|
||||||
{ |
|
||||||
return GetVisitCount() == 0; |
|
||||||
} |
|
||||||
|
|
||||||
// Automatically draws arrows to other Rooms referenced in public properties |
|
||||||
void OnDrawGizmos() |
|
||||||
{ |
|
||||||
const BindingFlags flags = BindingFlags.Public | BindingFlags.Instance; |
|
||||||
FieldInfo[] fields = this.GetType().GetFields(flags); |
|
||||||
|
|
||||||
foreach (FieldInfo fieldInfo in fields) |
|
||||||
{ |
|
||||||
Room room = fieldInfo.GetValue(this) as Room; |
|
||||||
if (room != null) |
|
||||||
{ |
|
||||||
DrawLinkToRoom(room); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
void DrawLinkToRoom(Room room) |
|
||||||
{ |
|
||||||
if (!room) |
|
||||||
{ |
|
||||||
Gizmos.color = Color.red; |
|
||||||
Gizmos.DrawWireCube(transform.position, renderer.bounds.size * 1.1f); |
|
||||||
return; |
|
||||||
} |
|
||||||
|
|
||||||
if (!Game.GetInstance().showLinks) |
|
||||||
{ |
|
||||||
return; |
|
||||||
} |
|
||||||
|
|
||||||
Gizmos.color = Color.green; |
|
||||||
Vector3 posA = transform.position; |
|
||||||
Vector3 posB = room.transform.position; |
|
||||||
|
|
||||||
Ray toA = new Ray(posB, posA - posB); |
|
||||||
Ray toB = new Ray(posA, posB - posA); |
|
||||||
|
|
||||||
float tA = 0; |
|
||||||
if (renderer) |
|
||||||
{ |
|
||||||
if (renderer.bounds.IntersectRay(toA, out tA)) |
|
||||||
{ |
|
||||||
posA = toA.GetPoint(tA * 0.95f); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
float tB = 0; |
|
||||||
if (room.gameObject.renderer) |
|
||||||
{ |
|
||||||
if (room.gameObject.renderer.bounds.IntersectRay(toB, out tB)) |
|
||||||
{ |
|
||||||
posB = toB.GetPoint(tB * 0.95f); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
Gizmos.DrawLine(posA, posB); |
|
||||||
|
|
||||||
float arrowHeadSize = 0.25f; |
|
||||||
|
|
||||||
Vector3 arrowPosA = posB; |
|
||||||
Vector3 arrowPosB = arrowPosA; |
|
||||||
Vector3 arrowPosC = arrowPosA; |
|
||||||
|
|
||||||
arrowPosB.x += toB.direction.y * arrowHeadSize; |
|
||||||
arrowPosB.y -= toB.direction.x * arrowHeadSize; |
|
||||||
arrowPosB -= toB.direction * arrowHeadSize; |
|
||||||
Gizmos.DrawLine(arrowPosA, arrowPosB); |
|
||||||
|
|
||||||
arrowPosC.x -= toB.direction.y * arrowHeadSize; |
|
||||||
arrowPosC.y += toB.direction.x * arrowHeadSize; |
|
||||||
arrowPosC -= toB.direction * arrowHeadSize; |
|
||||||
Gizmos.DrawLine(arrowPosA, arrowPosC); |
|
||||||
} |
|
||||||
|
|
||||||
// Called by Game when player enters the room |
|
||||||
void Enter() |
|
||||||
{ |
|
||||||
Game game = Game.GetInstance(); |
|
||||||
CameraController cameraController = game.gameObject.GetComponent<CameraController>(); |
|
||||||
|
|
||||||
// Pick first view found in the room and snap to camera to this view. |
|
||||||
// It is allowed for a room to not have any views. |
|
||||||
// In this case the camera will attempt to snap to the room sprite. |
|
||||||
View view = gameObject.GetComponentInChildren<View>(); |
|
||||||
if (view == null) |
|
||||||
{ |
|
||||||
// No view defined for this room, try to center on room sprite |
|
||||||
SpriteRenderer spriteRenderer = GetComponent<SpriteRenderer>(); |
|
||||||
if (spriteRenderer != null) |
|
||||||
{ |
|
||||||
cameraController.CenterOnSprite(spriteRenderer); |
|
||||||
} |
|
||||||
else |
|
||||||
{ |
|
||||||
Debug.LogError("Failed to set camera view when entering room."); |
|
||||||
} |
|
||||||
} |
|
||||||
else |
|
||||||
{ |
|
||||||
// Snap to new view |
|
||||||
cameraController.PanToPosition(view.transform.position, view.transform.rotation, view.viewSize, 0, null); |
|
||||||
} |
|
||||||
|
|
||||||
// Hide all buttons in the room before entering |
|
||||||
// Buttons must always be made visible using a ShowButton() command |
|
||||||
Button[] buttons = game.activeRoom.GetComponentsInChildren<Button>(); |
|
||||||
foreach (Button button in buttons) |
|
||||||
{ |
|
||||||
button.SetAlpha(0f); |
|
||||||
} |
|
||||||
|
|
||||||
// Rooms may have multiple child views and page. |
|
||||||
// It is the responsibility of the client room script to set the desired active view & page in the OnEnter method. |
|
||||||
// game.commandQueue.CallCommandMethod(game.activeRoom.gameObject, "OnEnter"); |
|
||||||
|
|
||||||
// Increment visit count for this Room |
|
||||||
int visitCount = GetVisitCount(); |
|
||||||
visitCount++; |
|
||||||
SetVisitCount(visitCount); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
@ -1,8 +0,0 @@ |
|||||||
fileFormatVersion: 2 |
|
||||||
guid: 0f9670668ba24460ab0f64b121ec7d51 |
|
||||||
MonoImporter: |
|
||||||
serializedVersion: 2 |
|
||||||
defaultReferences: [] |
|
||||||
executionOrder: 0 |
|
||||||
icon: {instanceID: 0} |
|
||||||
userData: |
|
@ -1,39 +0,0 @@ |
|||||||
using UnityEngine; |
|
||||||
using System.Collections; |
|
||||||
|
|
||||||
/** |
|
||||||
* We recommend placing your room code in the Fungus namespace to avoid class name conflicts with other Unity libraries. |
|
||||||
*/ |
|
||||||
namespace Fungus |
|
||||||
{ |
|
||||||
/** |
|
||||||
* This class is a template to use as a starting point for your own Room scripts. |
|
||||||
* 1. Select this script in the Project window in Unity3D |
|
||||||
* 2. Choose Edit > Duplicate from the menu. A copy of the file will be created. |
|
||||||
* 3. Rename the file to match the name of your room (e.g. DungeonRoom) |
|
||||||
* 4. Edit the script and rename the class to match the file name (e.g. public class RoomTemplate => public class DungeonRoom) |
|
||||||
* 5. Save the script and add it as a component to your Room game object in Unity 3D. |
|
||||||
*/ |
|
||||||
public class RoomTemplate : Room |
|
||||||
{ |
|
||||||
// Add public properties here. |
|
||||||
// These will appear in the inspector window in Unity so you can connect them to objects in your scene |
|
||||||
|
|
||||||
// Some common examples: |
|
||||||
// public View mainView; |
|
||||||
// public Dialog otherDialog; |
|
||||||
// public Room otherRoom; |
|
||||||
// public SpriteRenderer characterSprite; |
|
||||||
// public Animator characterAnim; |
|
||||||
// public AudioClip musicSound; |
|
||||||
|
|
||||||
/** |
|
||||||
* OnEnter() is always called when the player enters the room |
|
||||||
*/ |
|
||||||
void OnEnter() |
|
||||||
{ |
|
||||||
// Add any sequence of Fungus commands you want here. |
|
||||||
// See FungusExample/Scripts for examples |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
@ -1,8 +0,0 @@ |
|||||||
fileFormatVersion: 2 |
|
||||||
guid: 4c04fb21e6b82447da36d145d0c35c18 |
|
||||||
MonoImporter: |
|
||||||
serializedVersion: 2 |
|
||||||
defaultReferences: [] |
|
||||||
executionOrder: 0 |
|
||||||
icon: {instanceID: 0} |
|
||||||
userData: |
|
@ -1,5 +0,0 @@ |
|||||||
fileFormatVersion: 2 |
|
||||||
guid: 3d934f071cde745c4b765174311a8a71 |
|
||||||
folderAsset: yes |
|
||||||
DefaultImporter: |
|
||||||
userData: |
|
@ -1,5 +0,0 @@ |
|||||||
fileFormatVersion: 2 |
|
||||||
guid: 84ac7916d4a1e49b79780733895b5fd2 |
|
||||||
folderAsset: yes |
|
||||||
DefaultImporter: |
|
||||||
userData: |
|
Binary file not shown.
@ -1,4 +0,0 @@ |
|||||||
fileFormatVersion: 2 |
|
||||||
guid: 5eb4cf18a4b5a440ba6e04861135daba |
|
||||||
DefaultImporter: |
|
||||||
userData: |
|
@ -1,38 +0,0 @@ |
|||||||
using UnityEngine; |
|
||||||
using System.Collections; |
|
||||||
using Fungus; |
|
||||||
using Fungus.Script; |
|
||||||
|
|
||||||
public class SequenceTestRoom : Room |
|
||||||
{ |
|
||||||
public FungusScript fungusScript; |
|
||||||
|
|
||||||
void OnEnter() |
|
||||||
{ |
|
||||||
fungusScript.Execute(); |
|
||||||
|
|
||||||
/* |
|
||||||
Sequence s = GetComponent<Sequence>(); |
|
||||||
|
|
||||||
s.Add(new Say("New sequencer 1")); |
|
||||||
s.Add(new AddOption("Button 1", Clicked)); |
|
||||||
//s.Add(new AddOption("Button 2", Clicked)); |
|
||||||
//s.Add(new AddOption("Button 3", Clicked)); |
|
||||||
s.Add(new Say("New sequencer 2")); |
|
||||||
s.Add(new Say("New sequencer 3")); |
|
||||||
|
|
||||||
s.Execute(); |
|
||||||
*/ |
|
||||||
} |
|
||||||
|
|
||||||
void Clicked() |
|
||||||
{ |
|
||||||
/* |
|
||||||
Sequence s = GetComponent<Sequence>(); |
|
||||||
|
|
||||||
s.Clear(); |
|
||||||
s.Add(new Say("You have clicked")); |
|
||||||
s.Execute(); |
|
||||||
*/ |
|
||||||
} |
|
||||||
} |
|
@ -1,8 +0,0 @@ |
|||||||
fileFormatVersion: 2 |
|
||||||
guid: ef19cdad7345445e28e7e646ad7a6c56 |
|
||||||
MonoImporter: |
|
||||||
serializedVersion: 2 |
|
||||||
defaultReferences: [] |
|
||||||
executionOrder: 0 |
|
||||||
icon: {instanceID: 0} |
|
||||||
userData: |
|
Binary file not shown.
Loading…
Reference in new issue