Skip to content

Commit

Permalink
Inspector Changes, HGButton inspector
Browse files Browse the repository at this point in the history
>Extended Inspector has been split into ScriptableObjectInspector and ComponentInspector. extended inspector still has the shorthand methods alongside having the main brains for getting and setting inspector settings
>SOInspector is used for ScriptableObject related inspectors. its used to draw the toggle setting on the Editor Header
>Component inspector is used for Component related inspectors, it's used to draw the toggle setting on the GUI itself.
  • Loading branch information
Nebby1999 committed Dec 8, 2021
1 parent d79263d commit dc21942
Show file tree
Hide file tree
Showing 13 changed files with 686 additions and 82 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using UnityEditor;

namespace RoR2EditorKit.Core.Inspectors
{
/// <summary>
/// Inherit from this class to make your own Component Inspectors.
/// </summary>
public abstract class ComponentInspector : ExtendedInspector
{
public override void OnInspectorGUI()
{
EditorGUILayout.BeginVertical("box");
InspectorEnabled = CreateEnableInsepctorToggle(target.GetType().Name);
EditorGUILayout.EndVertical();
base.OnInspectorGUI();
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@

namespace RoR2EditorKit.Core.Inspectors
{
/// <summary>
/// Base inspector for all the RoR2EditorKit Inspectors.
/// <para>If you want to make a Scriptable Object Inspector, you'll probably want to use the ScriptableInspector</para>
/// <para>If you want to make an Inspector for a Component, you'll probably want to use the ComponentInspector</para>
/// </summary>
public abstract class ExtendedInspector : Editor
{
public static RoR2EditorKitSettings Settings { get => RoR2EditorKitSettings.GetOrCreateSettings<RoR2EditorKitSettings>(); }
Expand Down Expand Up @@ -35,21 +40,6 @@ public EnabledAndDisabledInspectorsSettings.InspectorSetting InspectorSetting

public bool InspectorEnabled { get => InspectorSetting.isEnabled; set => InspectorSetting.isEnabled = value; }

private void OnEnable()
{
InspectorEnabled = InspectorSetting.isEnabled;
finishedDefaultHeaderGUI += DrawEnableToggle;
}
private void OnDisable() => finishedDefaultHeaderGUI -= DrawEnableToggle;

private void DrawEnableToggle(Editor obj)
{
if(obj is ExtendedInspector extendedInspector)
{
InspectorEnabled = EditorGUILayout.ToggleLeft($"Enable {ObjectNames.NicifyVariableName(extendedInspector.target.GetType().Name)} Inspector", InspectorEnabled);
}
}

public override void OnInspectorGUI()
{
if (!InspectorEnabled)
Expand All @@ -58,6 +48,7 @@ public override void OnInspectorGUI()
}
}

protected bool CreateEnableInsepctorToggle(string inspectorName) => EditorGUILayout.ToggleLeft($"Enable {ObjectNames.NicifyVariableName(target.GetType().Name)} Inspector", InspectorEnabled);
protected void DrawField(string propName) => EditorGUILayout.PropertyField(serializedObject.FindProperty(propName), true);
protected void DrawField(SerializedProperty property, string propName) => EditorGUILayout.PropertyField(property.FindPropertyRelative(propName), true);
protected void DrawField(SerializedProperty property) => EditorGUILayout.PropertyField(property, true);
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEditor;

namespace RoR2EditorKit.Core.Inspectors
{
/// <summary>
/// Inherit from this class to make your own Scriptable Object Inspectors.
/// </summary>
public abstract class ScriptableObjectInspector : ExtendedInspector
{
private void OnEnable()
{
InspectorEnabled = InspectorSetting.isEnabled;
finishedDefaultHeaderGUI += DrawEnableToggle;
}
private void OnDisable() => finishedDefaultHeaderGUI -= DrawEnableToggle;

private void DrawEnableToggle(Editor obj)
{
if (obj is ScriptableObjectInspector soInspector)
{
InspectorEnabled = CreateEnableInsepctorToggle(soInspector.target.GetType().Name);
}
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
namespace RoR2EditorKit.RoR2.Inspectors
{
[CustomEditor(typeof(EntityStateConfiguration))]
public class EntityStateConfigCustomEditor : ExtendedInspector
public class EntityStateConfigCustomEditor : ScriptableObjectInspector
{
private delegate object FieldDrawHandler(FieldInfo fieldInfo, object value);
private static readonly Dictionary<Type, FieldDrawHandler> typeDrawers = new Dictionary<Type, FieldDrawHandler>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
using RoR2.UI;
using RoR2EditorKit.Core;
using RoR2EditorKit.Core.Inspectors;
using UnityEditor;
using UnityEngine;
using UnityEngine.UI;
using UnityEditor.UI;
using RoR2EditorKit.Settings;

namespace RoR2EditorKit.RoR2.Inspectors
{
[CustomEditor(typeof(HGButton))]
public class HGButtonCustomEditor : ButtonEditor
{
public EnabledAndDisabledInspectorsSettings.InspectorSetting InspectorSetting
{
get
{
if (_inspectorSetting == null)
{
var setting = ExtendedInspector.Settings.InspectorSettings.GetOrCreateInspectorSetting(GetType());
_inspectorSetting = setting;
}
return _inspectorSetting;
}
set
{
if (_inspectorSetting != value)
{
var index = ExtendedInspector.Settings.InspectorSettings.EnabledInspectors.IndexOf(_inspectorSetting);
ExtendedInspector.Settings.InspectorSettings.EnabledInspectors[index] = value;
}
_inspectorSetting = value;
}
}

private EnabledAndDisabledInspectorsSettings.InspectorSetting _inspectorSetting;

public bool InspectorEnabled { get => InspectorSetting.isEnabled; set => InspectorSetting.isEnabled = value; }

public override void OnInspectorGUI()
{
EditorGUILayout.BeginVertical("box");
InspectorEnabled = EditorGUILayout.ToggleLeft($"Enable {ObjectNames.NicifyVariableName(target.GetType().Name)} Inspector", InspectorEnabled);
EditorGUILayout.EndVertical();
if (!InspectorEnabled)
{
base.OnInspectorGUI();
}
else
{
DrawCustomInspector();
}
}

private void DrawCustomInspector()
{
EditorGUILayout.BeginVertical("box");
Header("Button Settings");
base.OnInspectorGUI();
DrawField("onFindSelectableLeft");
DrawField("onFindSelectableRight");
DrawField("onSelect");
DrawField("onDeselect");
EditorGUILayout.EndVertical();

EditorGUILayout.BeginVertical("box");
Header("Control Options");
DrawField("allowAllEventSystems");
DrawField("submitOnPointerUp");
DrawField("disablePointerClick");
DrawField("disableGamepadClick");
EditorGUILayout.EndVertical();

EditorGUILayout.BeginVertical("box");
Header("Visual Properties");
DrawField("imageOnInteractable");
DrawField("showImageOnHover");
DrawField("imageOnHover");
DrawField("updateTextOnHover");
DrawField("hoverLanguageTextMeshController");
DrawField("hoverToken");
EditorGUILayout.EndVertical();

EditorGUILayout.BeginVertical("box");
Header("Misc Options");
DrawField("requiredTopLayer");
DrawField("defaultFallbackButton");
DrawField("uiClickSoundOverride");
EditorGUILayout.EndVertical();
}

private void Header(string label) => EditorGUILayout.LabelField(new GUIContent(label), EditorStyles.boldLabel);
private void Header(string label, string tooltip) => EditorGUILayout.LabelField(new GUIContent(label, tooltip), EditorStyles.boldLabel);
private void DrawField(SerializedProperty prop) => EditorGUILayout.PropertyField(prop, true);
private void DrawField(string prop) => EditorGUILayout.PropertyField(serializedObject.FindProperty(prop), true);
private void DrawField(SerializedProperty prop, string propName) => EditorGUILayout.PropertyField(prop.FindPropertyRelative(propName), true);
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace RoR2EditorKit.RoR2.Inspectors
{
[CustomEditor(typeof(SerializableContentPack))]
public class SerializableContentPackCustomEditor : ExtendedInspector
public class SerializableContentPackCustomEditor : ScriptableObjectInspector
{
[OnOpenAsset]
public static bool OpenEditor(int instanceID, int line)
Expand Down
4 changes: 1 addition & 3 deletions RoR2EditorKit/Assets/RoR2EditorKit/RoR2EditorKit.asmdef
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,5 @@
"Assembly-CSharp.dll"
],
"autoReferenced": true,
"defineConstraints": [
"UNITY_EDITOR"
]
"defineConstraints": []
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 13a56dfcde6dc7841a8bb1cbf89fc366, type: 3}
m_Name: SettingsWindowData
m_EditorClassIdentifier:
FirstLoad: 1
FirstLoad: 0
ShowOnStartup: 1
Loading

0 comments on commit dc21942

Please sign in to comment.