OldBlueWater/BlueWater/Assets/Distant Lands/Cozy Weather/Contents/Scripts/Modules/CozySaveLoadModule.cs

105 lines
2.2 KiB
C#
Raw Normal View History

2024-01-03 06:34:33 +00:00
using DistantLands.Cozy.Data;
2023-09-13 05:07:40 +00:00
using System.Collections.Generic;
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace DistantLands.Cozy
{
2024-01-03 06:34:33 +00:00
public class CozySaveLoadModule : CozyModule
2023-09-13 05:07:40 +00:00
{
// Start is called before the first frame update
void Awake()
{
if (!enabled)
return;
2024-01-03 06:34:33 +00:00
InitializeModule();
2023-09-13 05:07:40 +00:00
}
public void Save()
{
if (weatherSphere == null)
2024-01-03 06:34:33 +00:00
InitializeModule();
2023-09-13 05:07:40 +00:00
string weatherJSON = JsonUtility.ToJson(weatherSphere);
PlayerPrefs.SetString("CZY_Properties", weatherJSON);
}
public void Load()
{
if (weatherSphere == null)
2024-01-03 06:34:33 +00:00
InitializeModule();
2023-09-13 05:07:40 +00:00
JsonUtility.FromJsonOverwrite(PlayerPrefs.GetString("CZY_Properties"), weatherSphere);
}
}
#if UNITY_EDITOR
2024-01-03 06:34:33 +00:00
[CustomEditor(typeof(CozySaveLoadModule))]
public class E_CozySaveLoad : E_CozyModule, IControlPanel
2023-09-13 05:07:40 +00:00
{
2024-01-03 06:34:33 +00:00
CozySaveLoadModule saveLoad;
2023-09-13 05:07:40 +00:00
void OnEnable()
{
2024-01-03 06:34:33 +00:00
saveLoad = (CozySaveLoadModule)target;
2023-09-13 05:07:40 +00:00
}
public override GUIContent GetGUIContent()
{
return new GUIContent(" Save & Load", (Texture)Resources.Load("Save"), "Manage save and load commands within the COZY system.");
}
2024-01-03 06:34:33 +00:00
public override void OpenDocumentationURL()
{
Application.OpenURL("https://distant-lands.gitbook.io/cozy-stylized-weather-documentation/how-it-works/modules/save-and-load-module");
}
2023-09-13 05:07:40 +00:00
public override void OnInspectorGUI()
{
}
public override void DisplayInCozyWindow()
{
EditorGUILayout.BeginHorizontal();
if (GUILayout.Button("Save"))
saveLoad.Save();
if (GUILayout.Button("Load"))
saveLoad.Load();
EditorGUILayout.EndHorizontal();
}
2024-01-03 06:34:33 +00:00
public void GetControlPanel()
{
if (GUILayout.Button("Save"))
saveLoad.Save();
if (GUILayout.Button("Load"))
saveLoad.Load();
}
2023-09-13 05:07:40 +00:00
}
#endif
}