Skip to content

Instantly share code, notes, and snippets.

@Agent40infinity
Last active March 22, 2023 00:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Agent40infinity/9f73fae377c84dad66cb84d1934071d5 to your computer and use it in GitHub Desktop.
Save Agent40infinity/9f73fae377c84dad66cb84d1934071d5 to your computer and use it in GitHub Desktop.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using RotaryHeart.Lib.SerializableDictionary;
[CreateAssetMenu(menuName = "Context")]
public class SnapshotEditor : ScriptableObject
{
[SerializeField, ID("id")] public NestedStringDictionary data;
}
[System.Serializable]
public class Container
{
public StringDictionary data;
}
[System.Serializable]
public class NestedStringDictionary : SerializableDictionaryBase<string, Container> { }
[System.Serializable]
public class StringDictionary : SerializableDictionaryBase<string, string> { }
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.Linq;
using Newtonsoft.Json;
public class SnapshotEditorWindow : EditorWindow
{
public static SnapshotEditorWindow window;
protected GUISkin skin;
protected Vector2 scrollPosition;
protected string snapshotCache;
protected SerializedObject serializedObject;
protected SerializedProperty property;
protected SnapshotEditor snapshot;
[MenuItem("Snapshot/Snapshot Editor")]
protected static void ShowWindow()
{
window = GetWindow<SnapshotEditorWindow>("Snapshot Editor");
}
private void OnEnable()
{
skin = (GUISkin)Resources.Load("SnapshotEditorGUI");
}
private void OnGUI()
{
EditorGUILayout.BeginVertical("box", GUILayout.ExpandHeight(true));
DisplayLoadedSnapshot();
ShortcutHotkeys();
EditorGUILayout.EndVertical();
}
private void DisplayLoadedSnapshot()
{
EditorGUILayout.LabelField("Loaded Snapshot", skin.customStyles.ToList().Find(x => x.name == "Header"));
if (snapshot == null)
{
snapshot = ScriptableObject.CreateInstance<SnapshotEditor>();
snapshot.data = ConvertDictionaryToString();
}
snapshot.data = ConvertDictionaryToString();
serializedObject = new SerializedObject(snapshot);
property = serializedObject.FindProperty("data");
EditorGUILayout.PropertyField(property, true);
}
private NestedStringDictionary ConvertDictionaryToString()
{
var temp = new NestedStringDictionary();
temp.Add("test", new Container());
return temp;
}
public void ShortcutHotkeys()
{
GUILayout.Space(20);
EditorGUILayout.BeginHorizontal();
GUILayout.Space(15);
if (GUILayout.Button(new GUIContent("Capture", "Capture a new Snapshot.")))
CaptureSnapshot();
if (GUILayout.Button(new GUIContent("Load", "Capture a new Snapshot.")))
LoadSnapshot();
if (GUILayout.Button(new GUIContent("Delete", "Deletes the current Snapshot to allow for a new file to replace it.")))
{ }
GUILayout.Space(15);
EditorGUILayout.EndHorizontal();
}
[MenuItem("Snapshot/Capture Snapshot")]
public static void CaptureSnapshot()
{
if (SnapshotManagerCheck())
return;
SnapshotManager.instance.Save();
}
[MenuItem("Snapshot/Load Capture")]
public static void LoadSnapshot()
{
if (SnapshotManagerCheck())
return;
SnapshotManager.instance.Load();
}
public static bool SnapshotManagerCheck()
{
return SnapshotManager.instance == null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment