Skip to content

Instantly share code, notes, and snippets.

@giacomelli
Last active February 26, 2021 09:17
Show Gist options
  • Save giacomelli/623de59997fa6f2aaeeb231a2a789933 to your computer and use it in GitHub Desktop.
Save giacomelli/623de59997fa6f2aaeeb231a2a789933 to your computer and use it in GitHub Desktop.
using UnityEngine;
namespace Giacomelli.Framework
{
public class FrameworkSettings : ScriptableObject
{
[SerializeField]
bool _entityLogEnabled;
[SerializeField]
bool _notificationsLogEnabled;
public static bool EntityLogEnabled { get; private set; }
public static bool NotificationsLogEnabled { get; private set; }
private void OnEnable()
{
Refresh(this);
}
public static void Refresh(FrameworkSettings instance)
{
EntityLogEnabled = instance._entityLogEnabled;
NotificationsLogEnabled = instance._notificationsLogEnabled;
}
}
}
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
namespace Giacomelli.Framework
{
public static class FrameworkSettingsRegister
{
const string SettingsPath = "Assets/Editor/Giacomelli.Framework.Settings.asset";
[SettingsProvider]
public static SettingsProvider CreateSettingsProvider()
{
var logFoldout = true;
return new SettingsProvider("Project/Giacomelli.Framework", SettingsScope.Project)
{
guiHandler = (searchContext) =>
{
var settings = Load();
var serialized = new SerializedObject(settings);
EditorGUI.BeginChangeCheck();
logFoldout = EditorGUILayout.BeginFoldoutHeaderGroup(logFoldout, "Logging");
if (logFoldout)
{
EditorGUILayout.PropertyField(serialized.FindProperty("_entityLogEnabled"), new GUIContent("Entity"));
EditorGUILayout.PropertyField(serialized.FindProperty("_notificationsLogEnabled"), new GUIContent("Notifications"));
EditorGUILayout.HelpBox("Those log messages will appear on console with the prefix [ENTITY] or [NOTIFICATIONS]", MessageType.Info);
}
EditorGUILayout.EndFoldoutHeaderGroup();
if (EditorGUI.EndChangeCheck())
{
serialized.ApplyModifiedProperties();
FrameworkSettings.Refresh(settings);
}
},
keywords = new HashSet<string>(new[] { "Entity log enabled", "Notifications log enabled" })
};
}
static FrameworkSettings Load()
{
var settings = AssetDatabase.LoadAssetAtPath<FrameworkSettings>(SettingsPath);
if (settings == null)
{
settings = ScriptableObject.CreateInstance<FrameworkSettings>();
AssetDatabase.CreateAsset(settings, SettingsPath);
AssetDatabase.SaveAssets();
}
return settings;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment