Added new Game logic library to assist with game projects
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
namespace OmegaLeo.HelperLib.Game.Providers
|
||||
{
|
||||
#if GODOT
|
||||
public partial class GodotDelayedActionRunner : Node
|
||||
{
|
||||
private static GodotDelayedActionRunner _instance;
|
||||
public static DelayedActionManager Manager { get; private set; }
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
if (_instance == null)
|
||||
{
|
||||
_instance = this;
|
||||
Manager = new DelayedActionManager();
|
||||
}
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
Manager?.Update((float)delta);
|
||||
}
|
||||
|
||||
public override void _ExitTree()
|
||||
{
|
||||
if (_instance == this)
|
||||
{
|
||||
Manager?.CancelAll();
|
||||
_instance = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using System.IO;
|
||||
using OmegaLeo.HelperLib.Game.Interfaces;
|
||||
|
||||
namespace OmegaLeo.HelperLib.Game.Providers
|
||||
{
|
||||
#if GODOT
|
||||
public class GodotSaveFileProvider : ISaveFileProvider
|
||||
{
|
||||
private readonly string _saveFolder;
|
||||
|
||||
public GodotSaveFileProvider(string saveFolder = "Saves")
|
||||
{
|
||||
_saveFolder = saveFolder;
|
||||
}
|
||||
|
||||
public string GetSaveDirectory()
|
||||
{
|
||||
return Path.Combine("user://", _saveFolder);
|
||||
}
|
||||
|
||||
public string GetSavePath(string fileName)
|
||||
{
|
||||
if (!fileName.EndsWith(".json"))
|
||||
fileName += ".json";
|
||||
|
||||
return Path.Combine(GetSaveDirectory(), fileName);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
namespace OmegaLeo.HelperLib.Game.Providers
|
||||
{
|
||||
#if UNITY_EDITOR || UNITY_STANDALONE
|
||||
using UnityEngine;
|
||||
|
||||
namespace OmegaLeo.HelperLib.DelayedActions
|
||||
{
|
||||
public class UnityDelayedActionRunner : MonoBehaviour
|
||||
{
|
||||
private static UnityDelayedActionRunner _instance;
|
||||
public static DelayedActionManager Manager { get; private set; }
|
||||
|
||||
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
|
||||
private static void Initialize()
|
||||
{
|
||||
if (_instance == null)
|
||||
{
|
||||
var go = new GameObject("[DelayedActionRunner]");
|
||||
_instance = go.AddComponent<UnityDelayedActionRunner>();
|
||||
DontDestroyOnLoad(go);
|
||||
Manager = new DelayedActionManager();
|
||||
}
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
Manager?.Update(Time.deltaTime);
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
if (_instance == this)
|
||||
{
|
||||
Manager?.CancelAll();
|
||||
_instance = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
namespace OmegaLeo.HelperLib.Game.Providers
|
||||
{
|
||||
#if UNITY_EDITOR || UNITY_STANDALONE
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
|
||||
namespace OmegaLeo.HelperLib.SaveSystem
|
||||
{
|
||||
public class UnitySaveFileProvider : ISaveFileProvider
|
||||
{
|
||||
private readonly string _saveFolder;
|
||||
|
||||
public UnitySaveFileProvider(string saveFolder = "Saves")
|
||||
{
|
||||
_saveFolder = saveFolder;
|
||||
}
|
||||
|
||||
public string GetSaveDirectory()
|
||||
{
|
||||
return Path.Combine(Application.persistentDataPath, _saveFolder);
|
||||
}
|
||||
|
||||
public string GetSavePath(string fileName)
|
||||
{
|
||||
if (!fileName.EndsWith(".json"))
|
||||
fileName += ".json";
|
||||
|
||||
return Path.Combine(GetSaveDirectory(), fileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
Reference in New Issue
Block a user