diff --git a/Assets/Fungus/Scripts/Commands/SpawnObject.cs b/Assets/Fungus/Scripts/Commands/SpawnObject.cs
index 5e101ca2..0cd17fbc 100644
--- a/Assets/Fungus/Scripts/Commands/SpawnObject.cs
+++ b/Assets/Fungus/Scripts/Commands/SpawnObject.cs
@@ -11,7 +11,11 @@ namespace Fungus
///
[CommandInfo("Scripting",
"Spawn Object",
- "Spawns a new object based on a reference to a scene or prefab game object.")]
+ "Spawns a new object based on a reference to a scene or prefab game object.",
+ Priority = 10)]
+ [CommandInfo("GameObject",
+ "Instantiate",
+ "Instantiate a game object")]
[AddComponentMenu("")]
[ExecuteInEditMode]
public class SpawnObject : Command
diff --git a/Assets/Fungus/Scripts/Components/Command.cs b/Assets/Fungus/Scripts/Components/Command.cs
index 64407984..0c63df11 100644
--- a/Assets/Fungus/Scripts/Components/Command.cs
+++ b/Assets/Fungus/Scripts/Components/Command.cs
@@ -11,6 +11,8 @@ namespace Fungus
///
/// Attribute class for Fungus commands.
///
+ ///
+ [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
public class CommandInfoAttribute : Attribute
{
///
diff --git a/Assets/Fungus/Scripts/Components/SaveManager.cs b/Assets/Fungus/Scripts/Components/SaveManager.cs
index 5ae5b3a7..6451a6f9 100644
--- a/Assets/Fungus/Scripts/Components/SaveManager.cs
+++ b/Assets/Fungus/Scripts/Components/SaveManager.cs
@@ -10,14 +10,34 @@ namespace Fungus
{
///
/// Manages the Save History (a list of Save Points) and provides a set of operations for saving and loading games.
+ ///
+ /// Note WebGL and Webplayer (deprecated) save using playerprefs instead of using a json file in persistent storage
+ /// -webgl would require additional js to force a sync of FS.syncfs
+ /// -webplayer does not implement system io
///
public class SaveManager : MonoBehaviour
{
protected static SaveHistory saveHistory = new SaveHistory();
+ public static string STORAGE_DIRECTORY { get { return Application.persistentDataPath + "/FungusSaves/"; } }
+
+ private static string GetFullFilePath(string saveDataKey)
+ {
+ return STORAGE_DIRECTORY + saveDataKey + ".json";
+ }
+
protected virtual bool ReadSaveHistory(string saveDataKey)
{
- var historyData = PlayerPrefs.GetString(saveDataKey);
+ var historyData = string.Empty;
+#if UNITY_WEBPLAYER || UNITY_WEBGL
+ historyData = PlayerPrefs.GetString(saveDataKey);
+#else
+ var fullFilePath = GetFullFilePath(saveDataKey);
+ if (System.IO.File.Exists(fullFilePath))
+ {
+ historyData = System.IO.File.ReadAllText(fullFilePath);
+ }
+#endif//UNITY_WEBPLAYER
if (!string.IsNullOrEmpty(historyData))
{
var tempSaveHistory = JsonUtility.FromJson(historyData);
@@ -36,8 +56,18 @@ namespace Fungus
var historyData = JsonUtility.ToJson(saveHistory, true);
if (!string.IsNullOrEmpty(historyData))
{
+#if UNITY_WEBPLAYER || UNITY_WEBGL
PlayerPrefs.SetString(saveDataKey, historyData);
PlayerPrefs.Save();
+#else
+ var fileLoc = GetFullFilePath(saveDataKey);
+
+ //make sure the dir exists
+ System.IO.FileInfo file = new System.IO.FileInfo(fileLoc);
+ file.Directory.Create();
+
+ System.IO.File.WriteAllText(fileLoc, historyData);
+#endif//UNITY_WEBPLAYER
return true;
}
@@ -57,7 +87,7 @@ namespace Fungus
SavePointLoaded.NotifyEventHandlers(savePointKey);
// Execute any block containing a SavePoint command matching the save key, with Resume On Load enabled
- var savePoints = Object.FindObjectsOfType();
+ var savePoints = UnityEngine.Object.FindObjectsOfType();
for (int i = 0; i < savePoints.Length; i++)
{
var savePoint = savePoints[i];
@@ -83,7 +113,7 @@ namespace Fungus
// Each scene should have one Save Point with the IsStartPoint property enabled.
// We automatically start execution from this command whenever the scene starts 'normally' (i.e. first play, restart or scene load via the Load Scene command or SceneManager.LoadScene).
- var savePoints = Object.FindObjectsOfType();
+ var savePoints = UnityEngine.Object.FindObjectsOfType();
for (int i = 0; i < savePoints.Length; i++)
{
var savePoint = savePoints[i];
@@ -207,8 +237,16 @@ namespace Fungus
///
public void Delete(string saveDataKey)
{
+#if UNITY_WEBPLAYER || UNITY_WEBGL
PlayerPrefs.DeleteKey(saveDataKey);
PlayerPrefs.Save();
+#else
+ var fullFilePath = GetFullFilePath(saveDataKey);
+ if (System.IO.File.Exists(fullFilePath))
+ {
+ System.IO.File.Delete(fullFilePath);
+ }
+#endif//UNITY_WEBPLAYER
}
///
@@ -216,8 +254,13 @@ namespace Fungus
///
public bool SaveDataExists(string saveDataKey)
{
+#if UNITY_WEBPLAYER || UNITY_WEBGL
return PlayerPrefs.HasKey(saveDataKey);
- }
+#else
+ var fullFilePath = GetFullFilePath(saveDataKey);
+ return System.IO.File.Exists(fullFilePath);
+#endif//UNITY_WEBPLAYER
+ }
///
/// Creates a new Save Point using a key and description, and adds it to the Save History.
@@ -275,7 +318,7 @@ namespace Fungus
return saveHistory.GetDebugInfo();
}
- #endregion
+#endregion
}
}
diff --git a/Assets/Fungus/Scripts/Editor/CommandEditor.cs b/Assets/Fungus/Scripts/Editor/CommandEditor.cs
index 4f9f43f1..05ae1e17 100644
--- a/Assets/Fungus/Scripts/Editor/CommandEditor.cs
+++ b/Assets/Fungus/Scripts/Editor/CommandEditor.cs
@@ -16,17 +16,22 @@ namespace Fungus.EditorUtils
public static CommandInfoAttribute GetCommandInfo(System.Type commandType)
{
+ CommandInfoAttribute retval = null;
+
object[] attributes = commandType.GetCustomAttributes(typeof(CommandInfoAttribute), false);
foreach (object obj in attributes)
{
CommandInfoAttribute commandInfoAttr = obj as CommandInfoAttribute;
if (commandInfoAttr != null)
{
- return commandInfoAttr;
+ if (retval == null)
+ retval = commandInfoAttr;
+ else if (retval.Priority < commandInfoAttr.Priority)
+ retval = commandInfoAttr;
}
}
- return null;
+ return retval;
}
public virtual void DrawCommandInspectorGUI()