Browse Source

Merge branch 'master' into PlaygroundPhysics2D

master
desktop-maesty/steve 7 years ago
parent
commit
ec72430f6f
  1. 6
      Assets/Fungus/Scripts/Commands/SpawnObject.cs
  2. 2
      Assets/Fungus/Scripts/Components/Command.cs
  3. 53
      Assets/Fungus/Scripts/Components/SaveManager.cs
  4. 9
      Assets/Fungus/Scripts/Editor/CommandEditor.cs

6
Assets/Fungus/Scripts/Commands/SpawnObject.cs

@ -11,7 +11,11 @@ namespace Fungus
/// </summary>
[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

2
Assets/Fungus/Scripts/Components/Command.cs

@ -11,6 +11,8 @@ namespace Fungus
/// <summary>
/// Attribute class for Fungus commands.
/// </summary>
///
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
public class CommandInfoAttribute : Attribute
{
/// <summary>

53
Assets/Fungus/Scripts/Components/SaveManager.cs

@ -10,14 +10,34 @@ namespace Fungus
{
/// <summary>
/// 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
/// </summary>
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<SaveHistory>(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<SavePoint>();
var savePoints = UnityEngine.Object.FindObjectsOfType<SavePoint>();
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<SavePoint>();
var savePoints = UnityEngine.Object.FindObjectsOfType<SavePoint>();
for (int i = 0; i < savePoints.Length; i++)
{
var savePoint = savePoints[i];
@ -207,8 +237,16 @@ namespace Fungus
/// </summary>
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
}
/// <summary>
@ -216,8 +254,13 @@ namespace Fungus
/// </summary>
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
}
/// <summary>
/// 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
}
}

9
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()

Loading…
Cancel
Save