mirror of
https://github.com/codewriter-packages/Tri-Inspector.git
synced 2025-01-22 00:08:51 -05:00
Add settings page in ProjectSettings
This commit is contained in:
parent
967481dd04
commit
aa9df5a6b6
@ -3,9 +3,11 @@ using UnityEngine;
|
||||
|
||||
namespace TriInspector.Editors
|
||||
{
|
||||
#if TRI_INSPECTOR
|
||||
[CanEditMultipleObjects]
|
||||
[CustomEditor(typeof(MonoBehaviour), true, isFallback = true)]
|
||||
internal sealed class MonoBehaviourEditor : TriEditor
|
||||
{
|
||||
}
|
||||
#endif
|
||||
}
|
@ -3,9 +3,11 @@ using UnityEngine;
|
||||
|
||||
namespace TriInspector.Editors
|
||||
{
|
||||
#if TRI_INSPECTOR
|
||||
[CanEditMultipleObjects]
|
||||
[CustomEditor(typeof(ScriptableObject), true, isFallback = true)]
|
||||
internal sealed class ScriptableObjectEditor : TriEditor
|
||||
{
|
||||
}
|
||||
#endif
|
||||
}
|
94
Editor/Editors/TriSettingsProvider.cs
Normal file
94
Editor/Editors/TriSettingsProvider.cs
Normal file
@ -0,0 +1,94 @@
|
||||
using System.Linq;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace TriInspector.Editors
|
||||
{
|
||||
public class TriSettingsProvider : SettingsProvider
|
||||
{
|
||||
private class Styles
|
||||
{
|
||||
public static readonly GUIContent Mode = new GUIContent("Tri Inspector Mode");
|
||||
}
|
||||
|
||||
public TriSettingsProvider()
|
||||
: base("Project/Tri Inspector", SettingsScope.Project)
|
||||
{
|
||||
}
|
||||
|
||||
public override void OnGUI(string searchContext)
|
||||
{
|
||||
EditorGUI.BeginDisabledGroup(EditorApplication.isCompiling);
|
||||
|
||||
base.OnGUI(searchContext);
|
||||
|
||||
DrawModeButton();
|
||||
|
||||
EditorGUI.EndDisabledGroup();
|
||||
}
|
||||
|
||||
private void DrawModeButton()
|
||||
{
|
||||
GUILayout.BeginHorizontal();
|
||||
|
||||
EditorGUILayout.PrefixLabel(Styles.Mode);
|
||||
|
||||
var targetGroup = EditorUserBuildSettings.selectedBuildTargetGroup;
|
||||
var isFull = HasScriptingDefine(targetGroup, "TRI_INSPECTOR");
|
||||
var isCompact = !isFull;
|
||||
|
||||
if (isCompact != GUILayout.Toggle(isCompact, "Compact", EditorStyles.miniButtonLeft) && !isCompact)
|
||||
{
|
||||
UpdateScriptingDefine(targetGroup, toRemove: "TRI_INSPECTOR");
|
||||
}
|
||||
|
||||
if (isFull != GUILayout.Toggle(isFull, "Full", EditorStyles.miniButtonRight) && !isFull)
|
||||
{
|
||||
UpdateScriptingDefine(targetGroup, toAdd: "TRI_INSPECTOR");
|
||||
}
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
private static bool HasScriptingDefine(BuildTargetGroup targetGroup, string define)
|
||||
{
|
||||
return PlayerSettings
|
||||
.GetScriptingDefineSymbolsForGroup(targetGroup)
|
||||
.Split(';')
|
||||
.Contains(define);
|
||||
}
|
||||
|
||||
private static void UpdateScriptingDefine(BuildTargetGroup targetGroup,
|
||||
string toAdd = null, string toRemove = null)
|
||||
{
|
||||
var defines = PlayerSettings
|
||||
.GetScriptingDefineSymbolsForGroup(targetGroup)
|
||||
.Split(';')
|
||||
.ToList();
|
||||
|
||||
if (toAdd != null && !defines.Contains(toAdd))
|
||||
{
|
||||
defines.Add(toAdd);
|
||||
}
|
||||
|
||||
if (toRemove != null && defines.Contains(toRemove))
|
||||
{
|
||||
defines.Remove(toRemove);
|
||||
}
|
||||
|
||||
var definesString = string.Join(";", defines);
|
||||
PlayerSettings.SetScriptingDefineSymbolsForGroup(targetGroup, definesString);
|
||||
}
|
||||
|
||||
[SettingsProvider]
|
||||
public static SettingsProvider CreateTriInspectorSettingsProvider()
|
||||
{
|
||||
var provider = new TriSettingsProvider
|
||||
{
|
||||
keywords = GetSearchKeywordsFromGUIContentProperties<Styles>(),
|
||||
};
|
||||
|
||||
return provider;
|
||||
}
|
||||
}
|
||||
}
|
3
Editor/Editors/TriSettingsProvider.cs.meta
Normal file
3
Editor/Editors/TriSettingsProvider.cs.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e21ace13982a498283f60e3271c86551
|
||||
timeCreated: 1651644353
|
Loading…
Reference in New Issue
Block a user