Skip to content

Commit

Permalink
Update 0.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Nebby1999 committed Nov 9, 2021
1 parent f410a6e commit 7ab5ad0
Show file tree
Hide file tree
Showing 17 changed files with 641 additions and 22 deletions.
2 changes: 1 addition & 1 deletion RoR2EditorKit/Assets/RoR2EditorKit.asset
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,5 @@ MonoBehaviour:
Name: RoR2EditorKit
Description: RoR2EditorKit is a toolkit built around developing mods for Risk of
Rain 2
Version: 0.0.2
Version: 0.1.1
Dependencies: []
Original file line number Diff line number Diff line change
@@ -1,14 +1,30 @@
using RoR2EditorKit.Common;
using RoR2EditorKit.Core.Inspectors;
using System;
using System.Collections.Generic;
using System.Linq;
using ThunderKit.Core.Data;
using ThunderKit.Core.Manifests;
using ThunderKit.Markdown;
using UnityEditor;
using UnityEditor.Experimental.UIElements;
using UnityEngine;
using UnityEngine.Experimental.UIElements;

namespace RoR2EditorKit.Settings
{
public class RoR2EditorKitSettings : ThunderKitSetting
{
[Serializable]
public class InspectorSetting
{
public string inspectorName;

[HideInInspector]
public string typeReference;

public bool isEnabled;
}
const string MarkdownStylePath = "Packages/com.passivepicasso.thunderkit/Documentation/uss/markdown.uss";
const string DocumentationStylePath = "Packages/com.passivepicasso.thunderkit/uss/thunderkit_style.uss";

Expand All @@ -22,7 +38,9 @@ static void SetupSettings()

public string TokenPrefix;

public bool EditorWindowsEnabled = true;
public Manifest MainManifest;

public List<InspectorSetting> EnabledInspectors = new List<InspectorSetting>();

public bool CloseWindowWhenAssetIsCreated = true;

Expand All @@ -48,18 +66,42 @@ public override void CreateSettingsUI(VisualElement rootElement)

rootElement.Add(CreateStandardField(nameof(TokenPrefix)));

var enableEditorWindows = CreateStandardField(nameof(EditorWindowsEnabled));
enableEditorWindows.tooltip = $"Uncheck this to disable the {Constants.RoR2EditorKit} custom inspectors";
rootElement.Add(enableEditorWindows);
var mainManifest = CreateStandardField(nameof(MainManifest));
mainManifest.tooltip = $"The main manifest of this unity project, used for certain windows and utilities";
rootElement.Add(mainManifest);

var enabledInspectors = CreateStandardField(nameof(EnabledInspectors));
enabledInspectors.tooltip = $"Which Inspectors that use RoR2EditorKit systems are enabled.";
rootElement.Add(enabledInspectors);

var assetCreatorCloses = CreateStandardField(nameof(CloseWindowWhenAssetIsCreated));
assetCreatorCloses.tooltip = $"By default, when an asset creator window creates an asset, it closes, uncheck this so it doesnt close.";
assetCreatorCloses.tooltip = $"By default, when an asset creator window creates an asset, it closes, uncheck this so it doesnt closes.";
rootElement.Add(assetCreatorCloses);

if (ror2EditorKitSettingsSO == null)
ror2EditorKitSettingsSO = new SerializedObject(this);

rootElement.Bind(ror2EditorKitSettingsSO);
}

public InspectorSetting GetOrCreateInspectorSetting(Type type)
{
var setting = EnabledInspectors.Find(x => x.typeReference == type.AssemblyQualifiedName);
if (setting != null)
{
return setting;
}
else
{
setting = new InspectorSetting
{
inspectorName = type.Name,
typeReference = type.AssemblyQualifiedName,
isEnabled = true
};
EnabledInspectors.Add(setting);
return setting;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,10 @@ public static NullReferenceException ThrowNullTokenPrefix()
{
return new NullReferenceException($"Your TokenPrefix in the RoR2EditorKit settings is Empty or Null");
}

public static NullReferenceException ThrowNullMainManifest()
{
return new NullReferenceException($"Your Main Manifest in the RoR2EditorKit Settings is Empty");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,49 @@
using RoR2EditorKit.Settings;
using UnityEditor;
using System.Linq;
using UnityEngine;

namespace RoR2EditorKit.Core.Inspectors
{
public class ExtendedInspector : Editor
public abstract class ExtendedInspector : Editor
{
public RoR2EditorKitSettings Settings { get => RoR2EditorKitSettings.GetOrCreateSettings<RoR2EditorKitSettings>(); }
public static bool enableInspectors = true;
public static RoR2EditorKitSettings Settings { get => RoR2EditorKitSettings.GetOrCreateSettings<RoR2EditorKitSettings>(); }

public RoR2EditorKitSettings.InspectorSetting InspectorSetting
{
get
{
if(_inspectorSetting == null)
{
var setting = Settings.GetOrCreateInspectorSetting(GetType());
_inspectorSetting = setting;
}
return _inspectorSetting;
}
set
{
if(_inspectorSetting != value)
{
var index = Settings.EnabledInspectors.IndexOf(_inspectorSetting);
Settings.EnabledInspectors[index] = value;
}
_inspectorSetting = value;
}
}

private RoR2EditorKitSettings.InspectorSetting _inspectorSetting;

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

private void OnEnable()
{
InspectorEnabled = InspectorSetting.isEnabled;
}
public override void OnInspectorGUI()
{
enableInspectors = Settings.EditorWindowsEnabled;
if (!enableInspectors)
InspectorEnabled = EditorGUILayout.Toggle("Enable Inspector", InspectorEnabled);
GUILayout.Space(10);
if (!InspectorEnabled)
{
DrawDefaultInspector();
}
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,27 @@
using RoR2EditorKit.Settings;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEditor;
using UnityEngine;

namespace RoR2EditorKit.Core.PropertyDrawers
{
[CustomPropertyDrawer(typeof(RoR2EditorKitSettings.InspectorSetting))]
public class InspectorSettingPropertyDrawer : PropertyDrawer
{
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
EditorGUI.BeginProperty(position, label, property);

var isEnabled = property.FindPropertyRelative("isEnabled");
var displayName = property.FindPropertyRelative("inspectorName");

EditorGUI.PropertyField(position, isEnabled, new GUIContent(ObjectNames.NicifyVariableName(displayName.stringValue)));

EditorGUI.EndProperty();
}
}
}

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 @@ -7,7 +7,6 @@ namespace RoR2EditorKit.Core.Windows
public abstract class CreateRoR2ScriptableObjectWindow<T> : ExtendedEditorWindow where T : ScriptableObject
{
public T ScriptableObject { get; private set; }
public RoR2EditorKitSettings Settings { get => RoR2EditorKitSettings.GetOrCreateSettings<RoR2EditorKitSettings>(); }

protected string nameField;
protected string actualName;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using UnityEditor;
using RoR2EditorKit.Settings;
using UnityEditor;
using UnityEngine;

namespace RoR2EditorKit.Core.Windows
Expand All @@ -15,6 +16,8 @@ public class ExtendedEditorWindow : EditorWindow
/// </summary>
protected SerializedObject mainSerializedObject;

public static RoR2EditorKitSettings Settings { get => RoR2EditorKitSettings.GetOrCreateSettings<RoR2EditorKitSettings>(); }

public static void OpenEditorWindow<T>(Object unityObject, string windowName) where T : ExtendedEditorWindow
{
T window = GetWindow<T>(windowName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class EntityStateConfigCustomEditor : ExtendedInspector
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
if (!enableInspectors)
if (!InspectorEnabled)
{
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class SerializableContentPackCustomEditor : ExtendedInspector
[OnOpenAsset]
public static bool OpenEditor(int instanceID, int line)
{
if (enableInspectors)
if (Settings.GetOrCreateInspectorSetting(typeof(SerializableContentPackCustomEditor)).isEnabled)
{
SerializableContentPack obj = EditorUtility.InstanceIDToObject(instanceID) as SerializableContentPack;
if (obj != null)
Expand All @@ -28,7 +28,7 @@ public static bool OpenEditor(int instanceID, int line)
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
if (enableInspectors && GUILayout.Button("Open Editor"))
if (InspectorEnabled && GUILayout.Button("Open Editor"))
{
ExtendedEditorWindow.OpenEditorWindow<SerializableContentPackEditorWindow>(target, "Serializable Content Pack Window");
}
Expand Down
Loading

0 comments on commit 7ab5ad0

Please sign in to comment.