68 lines
1.9 KiB
C#
68 lines
1.9 KiB
C#
using System.IO;
|
|
using UnityEditor;
|
|
using UnityEditorInternal;
|
|
using UnityEngine;
|
|
|
|
public class KedrExtensionSettings : ScriptableObject
|
|
{
|
|
private static string SettingsPath => "ProjectSettings/KedrExtensionSettings.asset";
|
|
private static KedrExtensionSettings _instance;
|
|
|
|
public bool enableOpcodeShuffle = false;
|
|
|
|
public static KedrExtensionSettings Instance
|
|
{
|
|
get
|
|
{
|
|
if (_instance) return _instance;
|
|
var arr = InternalEditorUtility.LoadSerializedFileAndForget(SettingsPath);
|
|
|
|
if (arr.Length == 1 && arr[0] is KedrExtensionSettings settings)
|
|
{
|
|
_instance = settings;
|
|
}
|
|
else
|
|
{
|
|
_instance = CreateInstance<KedrExtensionSettings>();
|
|
}
|
|
|
|
return _instance;
|
|
}
|
|
}
|
|
|
|
public static void Save()
|
|
{
|
|
if (!_instance) return;
|
|
Directory.CreateDirectory(Path.GetDirectoryName(SettingsPath)!);
|
|
Object[] obj = { _instance };
|
|
InternalEditorUtility.SaveToSerializedFileAndForget(obj, SettingsPath, true);
|
|
}
|
|
}
|
|
|
|
public class KedrExtensionSettingsProvider : SettingsProvider
|
|
{
|
|
private SerializedObject _serializedObject;
|
|
|
|
[SettingsProvider]
|
|
public static SettingsProvider CreateProvider() => new KedrExtensionSettingsProvider();
|
|
|
|
private KedrExtensionSettingsProvider() : base("Project/KedrExtension", SettingsScope.Project)
|
|
{
|
|
}
|
|
|
|
public override void OnGUI(string searchContext)
|
|
{
|
|
_serializedObject ??= new SerializedObject(KedrExtensionSettings.Instance);
|
|
_serializedObject.Update();
|
|
|
|
EditorGUI.BeginChangeCheck();
|
|
|
|
EditorGUILayout.PropertyField(_serializedObject.FindProperty("enableOpcodeShuffle"));
|
|
|
|
if (EditorGUI.EndChangeCheck())
|
|
{
|
|
_serializedObject.ApplyModifiedProperties();
|
|
KedrExtensionSettings.Save();
|
|
}
|
|
}
|
|
} |