Browse Source

Remove Room class

master
chrisgregan 11 years ago
parent
commit
c38d113433
  1. 44
      Assets/Fungus/Editor/GameEditor.cs
  2. 8
      Assets/Fungus/Editor/GameEditor.cs.meta
  3. 16
      Assets/Fungus/Editor/RoomEditor.cs
  4. 8
      Assets/Fungus/Editor/RoomEditor.cs.meta
  5. 11
      Assets/Fungus/Scripts/AnimationListener.cs
  6. 7
      Assets/Fungus/Scripts/GUIButton.cs
  7. 13
      Assets/Fungus/Scripts/Game.cs
  8. 35
      Assets/Fungus/Scripts/Parallax.cs
  9. 169
      Assets/Fungus/Scripts/Room.cs
  10. 8
      Assets/Fungus/Scripts/Room.cs.meta
  11. 39
      Assets/Fungus/Scripts/RoomTemplate.cs
  12. 8
      Assets/Fungus/Scripts/RoomTemplate.cs.meta
  13. 7
      Assets/Fungus/Scripts/SceneLoader.cs
  14. 5
      Assets/Fungus/Tests.meta
  15. 5
      Assets/Fungus/Tests/Sequence.meta
  16. BIN
      Assets/Fungus/Tests/Sequence/SequenceTest.unity
  17. 4
      Assets/Fungus/Tests/Sequence/SequenceTest.unity.meta
  18. 38
      Assets/Fungus/Tests/Sequence/SequenceTestRoom.cs
  19. 8
      Assets/Fungus/Tests/Sequence/SequenceTestRoom.cs.meta
  20. BIN
      Assets/Shuttle/ShuttleGame.unity

44
Assets/Fungus/Editor/GameEditor.cs

@ -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();
}
}
}

8
Assets/Fungus/Editor/GameEditor.cs.meta

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: 5464e5745a4da462795a6f6f5b112962
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

16
Assets/Fungus/Editor/RoomEditor.cs

@ -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();
}
}
}

8
Assets/Fungus/Editor/RoomEditor.cs.meta

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: 0314fe408508a4b25afa76f65378a427
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

11
Assets/Fungus/Scripts/AnimationListener.cs

@ -19,16 +19,7 @@ namespace Fungus
*/ */
void CallRoomMethod(string methodName) void CallRoomMethod(string methodName)
{ {
Room room = Game.GetInstance().activeRoom; // TODO: Execute a FungusScript sequence
if (room == null)
{
return;
}
/*
CommandQueue commandQueue = Game.GetInstance().commandQueue;
commandQueue.CallCommandMethod(room.gameObject, methodName);
*/
} }
} }
} }

7
Assets/Fungus/Scripts/GUIButton.cs

@ -101,12 +101,7 @@ namespace Fungus
Application.OpenURL(actionParameter); Application.OpenURL(actionParameter);
break; break;
case ClickAction.SendMessage: case ClickAction.SendMessage:
// Send the message to all Room objects in the scene // TODO: Execute a sequence
Room[] allRooms = GameObject.FindObjectsOfType<Room>();
foreach (Room room in allRooms)
{
room.SendMessage(actionParameter, SendMessageOptions.DontRequireReceiver);
}
break; break;
} }
} }

13
Assets/Fungus/Scripts/Game.cs

@ -19,12 +19,6 @@ namespace Fungus
[RequireComponent(typeof(CameraController))] [RequireComponent(typeof(CameraController))]
public class Game : MonoBehaviour public class Game : MonoBehaviour
{ {
/**
* The currently active Room.
*/
[Tooltip("The currently active Room.")]
public Room activeRoom;
/** /**
* Show links between Rooms in scene view. * Show links between Rooms in scene view.
*/ */
@ -100,15 +94,8 @@ namespace Fungus
cameraController = gameObject.GetComponent<CameraController>(); cameraController = gameObject.GetComponent<CameraController>();
// Auto-hide buttons should be visible at start of game // Auto-hide buttons should be visible at start of game
autoHideButtonTimer = autoHideButtonDuration; autoHideButtonTimer = autoHideButtonDuration;
if (activeRoom == null)
{
// Pick first room found if none is specified
activeRoom = GameObject.FindObjectOfType(typeof(Room)) as Room;
}
} }
public virtual void Update() public virtual void Update()

35
Assets/Fungus/Scripts/Parallax.cs

@ -35,52 +35,25 @@ namespace Fungus
public float accelerometerScale = 0.5f; public float accelerometerScale = 0.5f;
Vector3 startPosition; Vector3 startPosition;
Vector3 startScale; // Vector3 startScale;
Vector3 acceleration; Vector3 acceleration;
Vector3 velocity; Vector3 velocity;
Room parentRoom;
void Start () void Start ()
{ {
// Store the starting position and scale of the sprite object // Store the starting position and scale of the sprite object
startPosition = transform.position; startPosition = transform.position;
startScale = transform.localScale; // startScale = transform.localScale;
// Store a reference to the parent Room object
Transform ancestor = transform.parent;
while (ancestor != null)
{
Room room = ancestor.GetComponent<Room>();
if (room != null)
{
parentRoom = room;
break;
}
ancestor = ancestor.transform.parent;
}
} }
void Update () void Update ()
{ {
if (parentRoom == null)
{
// Don't apply offset if the sprite is not a child of a Room
return;
}
if (Game.GetInstance().activeRoom != parentRoom)
{
// Early out if this sprite is not in the currently active Room
return;
}
Vector3 translation = Vector3.zero; Vector3 translation = Vector3.zero;
// Apply parallax translation based on camera position relative to Room // Apply parallax translation based on camera position relative to Room
{ {
Vector3 a = parentRoom.transform.position; Vector3 a = startPosition;
Vector3 b = Camera.main.transform.position; Vector3 b = Camera.main.transform.position;
translation = (a - b); translation = (a - b);
translation.x *= parallaxScale.x; translation.x *= parallaxScale.x;
@ -101,10 +74,12 @@ namespace Fungus
transform.position = startPosition + translation; transform.position = startPosition + translation;
// Set new scale for sprite // Set new scale for sprite
/*
float roomSize = parentRoom.renderer.bounds.extents.y; float roomSize = parentRoom.renderer.bounds.extents.y;
float t = Camera.main.orthographicSize / roomSize ; float t = Camera.main.orthographicSize / roomSize ;
float scale = Mathf.Lerp (zoomedInScale, zoomedOutScale, t); float scale = Mathf.Lerp (zoomedInScale, zoomedOutScale, t);
transform.localScale = startScale * scale; transform.localScale = startScale * scale;
*/
} }
} }
} }

169
Assets/Fungus/Scripts/Room.cs

@ -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);
}
}
}

8
Assets/Fungus/Scripts/Room.cs.meta

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: 0f9670668ba24460ab0f64b121ec7d51
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

39
Assets/Fungus/Scripts/RoomTemplate.cs

@ -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
}
}
}

8
Assets/Fungus/Scripts/RoomTemplate.cs.meta

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: 4c04fb21e6b82447da36d145d0c35c18
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

7
Assets/Fungus/Scripts/SceneLoader.cs

@ -49,12 +49,7 @@ namespace Fungus
yield return new WaitForEndOfFrame(); yield return new WaitForEndOfFrame();
} }
// Destroy all Room objects to release references to most game assets // TODO: Destroy all objects to release references to most game assets
Room[] rooms = GameObject.FindObjectsOfType<Room>();
foreach (Room room in rooms)
{
Destroy(room.gameObject);
}
// Wait for objects to actually be destroyed at end of run loop // Wait for objects to actually be destroyed at end of run loop
yield return new WaitForEndOfFrame(); yield return new WaitForEndOfFrame();

5
Assets/Fungus/Tests.meta

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

5
Assets/Fungus/Tests/Sequence.meta

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

BIN
Assets/Fungus/Tests/Sequence/SequenceTest.unity

Binary file not shown.

4
Assets/Fungus/Tests/Sequence/SequenceTest.unity.meta

@ -1,4 +0,0 @@
fileFormatVersion: 2
guid: 5eb4cf18a4b5a440ba6e04861135daba
DefaultImporter:
userData:

38
Assets/Fungus/Tests/Sequence/SequenceTestRoom.cs

@ -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();
*/
}
}

8
Assets/Fungus/Tests/Sequence/SequenceTestRoom.cs.meta

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: ef19cdad7345445e28e7e646ad7a6c56
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

BIN
Assets/Shuttle/ShuttleGame.unity

Binary file not shown.
Loading…
Cancel
Save