Browse Source

LoadScene command

master
chrisgregan 11 years ago
parent
commit
62f6e11043
  1. 33
      Assets/Fungus/FungusScript/Commands/LoadScene.cs
  2. 8
      Assets/Fungus/FungusScript/Commands/LoadScene.cs.meta
  3. 15
      Assets/Fungus/FungusScript/Scripts/SceneLoader.cs
  4. 12
      Assets/Fungus/Legacy/Scripts/Game.cs
  5. BIN
      Assets/Shuttle/ShuttleGame.unity
  6. BIN
      ProjectSettings/EditorBuildSettings.asset

33
Assets/Fungus/FungusScript/Commands/LoadScene.cs

@ -0,0 +1,33 @@
using UnityEngine;
using System;
using System.Collections;
namespace Fungus.Script
{
[HelpText("Loads a new scene and displays an optional loading image. This is useful " +
"for splitting a large game across multiple scene files to reduce peak memory " +
"usage. All previously loaded assets (including textures and audio) will be released." +
"The scene to be loaded must be added to the scene list in Build Settings.")]
public class LoadScene : FungusCommand
{
public string sceneName = "";
public Texture2D loadingImage;
public override void OnEnter()
{
SceneLoader.LoadScene(sceneName, loadingImage);
}
public override string GetSummary()
{
if (sceneName.Length == 0)
{
return "Error: No scene name selected";
}
return sceneName;
}
}
}

8
Assets/Fungus/FungusScript/Commands/LoadScene.cs.meta

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

15
Assets/Fungus/FungusScript/Scripts/SceneLoader.cs

@ -15,15 +15,13 @@ namespace Fungus
Texture2D loadingTexture;
string sceneToLoad;
bool displayedImage;
bool saveCheckpoint;
/**
* Asynchronously load a new scene.
* @param _sceneToLoad The name of the scene to load. Scenes must be added in project build settings.
* @param _loadingTexture Loading image to display while loading the new scene.
* @param _saveCheckpoint Automatically save a checkpoint once the new scene has loaded.
*/
static public void LoadScene(string _sceneToLoad, Texture2D _loadingTexture, bool _saveCheckpoint)
static public void LoadScene(string _sceneToLoad, Texture2D _loadingTexture)
{
// Unity does not provide a way to check if the named scene actually exists in the project.
GameObject go = new GameObject("SceneLoader");
@ -32,7 +30,6 @@ namespace Fungus
SceneLoader sceneLoader = go.AddComponent<SceneLoader>();
sceneLoader.sceneToLoad = _sceneToLoad;
sceneLoader.loadingTexture = _loadingTexture;
sceneLoader.saveCheckpoint = _saveCheckpoint;
}
void Start()
@ -71,16 +68,6 @@ namespace Fungus
// Clean up any remaining unused assets
Resources.UnloadUnusedAssets();
// Save a checkpoint if required
if (saveCheckpoint)
{
Game game = Game.GetInstance();
if (game != null)
{
// Game.Save();
}
}
// We're now finished with the SceneLoader
Destroy(gameObject);
}

12
Assets/Fungus/Legacy/Scripts/Game.cs

@ -116,18 +116,6 @@ namespace Fungus
return false;
}
/**
* Loads a new scene and displays an optional loading image.
* This is useful for splitting a large Fungus game across multiple scene files to reduce peak memory usage.
* All previously loaded assets (including textures and audio) will be released.
* @param sceneName The filename of the scene to load.
* @param saveGame Automatically save the current game state as a checkpoint.
*/
public void LoadScene(string sceneName, bool saveGame)
{
SceneLoader.LoadScene(sceneName, loadingImage, saveGame);
}
/**
* Save the current game variables to persistant storage using a save game name.
* Stores the currently loaded scene name so that Game.LoadGame() can automatically move to the appropriate scene.

BIN
Assets/Shuttle/ShuttleGame.unity

Binary file not shown.

BIN
ProjectSettings/EditorBuildSettings.asset

Binary file not shown.
Loading…
Cancel
Save