Skip to content

Commit d79263d

Browse files
committed
Inspector utils, new property drawer system, scriptableobject creation
1 parent 00e8761 commit d79263d

File tree

13 files changed

+616
-37
lines changed

13 files changed

+616
-37
lines changed

RoR2EditorKit/Assets/RoR2EditorKit.asset

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,5 +79,5 @@ MonoBehaviour:
7979
Name: RoR2EditorKit
8080
Description: RoR2EditorKit is a toolkit built around developing mods for Risk of
8181
Rain 2
82-
Version: 0.1.3
82+
Version: 0.2.1
8383
Dependencies: []

RoR2EditorKit/Assets/RoR2EditorKit/Editor/Core/Inspectors/ExtendedInspector.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,11 @@ public override void OnInspectorGUI()
5757
DrawDefaultInspector();
5858
}
5959
}
60+
61+
protected void DrawField(string propName) => EditorGUILayout.PropertyField(serializedObject.FindProperty(propName), true);
62+
protected void DrawField(SerializedProperty property, string propName) => EditorGUILayout.PropertyField(property.FindPropertyRelative(propName), true);
63+
protected void DrawField(SerializedProperty property) => EditorGUILayout.PropertyField(property, true);
64+
protected void Header(string label) => EditorGUILayout.LabelField(new GUIContent(label), EditorStyles.boldLabel);
65+
protected void Header(string label, string tooltip) => EditorGUILayout.LabelField(new GUIContent(label, tooltip), EditorStyles.boldLabel);
6066
}
6167
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using UnityEditor;
7+
using UnityEngine;
8+
9+
namespace RoR2EditorKit.Core.PropertyDrawers
10+
{
11+
/// <summary>
12+
/// Used for lazy creation of property drawer using editor gui layout instead of editor gui.
13+
///<para>This shouldnt be used unless you want a very simple property drawer that doesnt need to be all specific</para>
14+
///<para>May cause spamming in the unity editor console that's caused by using EditorGUILayout instead of EditorGUI.</para>
15+
/// </summary>
16+
public class EditorGUILayoutPropertyDrawer : PropertyDrawer
17+
{
18+
SerializedProperty serializedProperty;
19+
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
20+
{
21+
serializedProperty = property;
22+
EditorGUI.BeginProperty(position, label, property);
23+
DrawPropertyDrawer(property);
24+
EditorGUI.EndProperty();
25+
}
26+
27+
protected virtual void DrawPropertyDrawer(SerializedProperty property) { }
28+
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
29+
{
30+
return -2f;
31+
}
32+
33+
protected void DrawField(string propName) => EditorGUILayout.PropertyField(serializedProperty.FindPropertyRelative(propName), true);
34+
protected void DrawField(SerializedProperty property, string propName) => EditorGUILayout.PropertyField(property.FindPropertyRelative(propName), true);
35+
protected void DrawField(SerializedProperty property) => EditorGUILayout.PropertyField(property, true);
36+
protected void Header(string label) => EditorGUILayout.LabelField(new GUIContent(label), EditorStyles.boldLabel);
37+
protected void Header(string label, string tooltip) => EditorGUILayout.LabelField(new GUIContent(label, tooltip), EditorStyles.boldLabel);
38+
}
39+
}

RoR2EditorKit/Assets/RoR2EditorKit/Editor/Core/PropertyDrawers/EditorGUILayoutPropertyDrawer.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

RoR2EditorKit/Assets/RoR2EditorKit/Editor/Core/PropertyDrawers/InspectorSettingPropertyDrawer.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,14 @@
1010
namespace RoR2EditorKit.Core.PropertyDrawers
1111
{
1212
[CustomPropertyDrawer(typeof(EnabledAndDisabledInspectorsSettings.InspectorSetting))]
13-
public class InspectorSettingPropertyDrawer : PropertyDrawer
13+
public class InspectorSettingPropertyDrawer : EditorGUILayoutPropertyDrawer
1414
{
15-
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
15+
protected override void DrawPropertyDrawer(SerializedProperty property)
1616
{
17-
EditorGUI.BeginProperty(position, label, property);
18-
1917
var isEnabled = property.FindPropertyRelative("isEnabled");
2018
var displayName = property.FindPropertyRelative("inspectorName");
2119

22-
EditorGUI.PropertyField(position, isEnabled, new GUIContent(ObjectNames.NicifyVariableName(displayName.stringValue)));
23-
24-
EditorGUI.EndProperty();
20+
EditorGUILayout.PropertyField(isEnabled, new GUIContent(ObjectNames.NicifyVariableName(displayName.stringValue)));
2521
}
2622
}
2723
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
using RoR2;
2+
using RoR2.Skills;
3+
using UnityEditor;
4+
using UnityEngine;
5+
6+
namespace RoR2EditorKit.RoR2
7+
{
8+
/// <summary>
9+
/// Creation of ScriptableObjects that are normally uncreatable in RoR2
10+
/// </summary>
11+
public static class ScriptableCreators
12+
{
13+
[MenuItem("Assets/Create/RoR2/UnlockableDef")]
14+
public static void CreateUnlockableDef()
15+
{
16+
var unlockableDef = ScriptableObject.CreateInstance<UnlockableDef>();
17+
unlockableDef.cachedName = "New UnlockableDef";
18+
Util.CreateAssetAtSelectionPath(unlockableDef);
19+
}
20+
21+
#region skilldefs
22+
[MenuItem("Assets/Create/RoR2/SkillDef/Captain/Orbital")]
23+
public static void CreateOrbital()
24+
{
25+
CreateSkill<CaptainOrbitalSkillDef>();
26+
}
27+
28+
[MenuItem("Assets/Create/RoR2/SkillDef/Captain/SupplyDrop")]
29+
public static void CreateSupplyDrop()
30+
{
31+
CreateSkill<CaptainSupplyDropSkillDef>();
32+
}
33+
34+
[MenuItem("Assets/Create/RoR2/SkillDef/Combo")]
35+
public static void CreateCombo()
36+
{
37+
CreateSkill<ComboSkillDef>();
38+
}
39+
40+
[MenuItem("Assets/Create/RoR2/SkillDef/Conditional")]
41+
public static void CreateConditional()
42+
{
43+
CreateSkill<ConditionalSkillDef>();
44+
}
45+
46+
[MenuItem("Assets/Create/RoR2/SkillDef/EngiMineDeployer")]
47+
public static void CreateEngiMineDeployer()
48+
{
49+
CreateSkill<EngiMineDeployerSkill>();
50+
}
51+
52+
[MenuItem("Assets/Create/RoR2/SkillDef/Grounded")]
53+
public static void CreateGrounded()
54+
{
55+
CreateSkill<GroundedSkillDef>();
56+
}
57+
58+
[MenuItem("Assets/Create/RoR2/SkillDef/LunarReplacements/Detonator")]
59+
public static void CreateDetonator()
60+
{
61+
CreateSkill<LunarDetonatorSkill>();
62+
}
63+
64+
[MenuItem("Assets/Create/RoR2/SkillDef/LunarReplacements/Primary")]
65+
public static void CreatePrimary()
66+
{
67+
CreateSkill<LunarPrimaryReplacementSkill>();
68+
}
69+
70+
[MenuItem("Assets/Create/RoR2/SkillDef/LunarReplacements/Secondary")]
71+
public static void CreateSecondary()
72+
{
73+
CreateSkill<LunarSecondaryReplacementSkill>();
74+
}
75+
76+
[MenuItem("Assets/Create/RoR2/SkillDef/Stepped")]
77+
public static void CreateStepped()
78+
{
79+
CreateSkill<SteppedSkillDef>();
80+
}
81+
82+
[MenuItem("Assets/Create/RoR2/SkillDef/ToolbotWeapon")]
83+
public static void CreateToolbotWeapon()
84+
{
85+
CreateSkill<ToolbotWeaponSkillDef>();
86+
}
87+
88+
private static void CreateSkill<T>() where T : SkillDef
89+
{
90+
var skillDef = ScriptableObject.CreateInstance<T>();
91+
var SO = skillDef as ScriptableObject;
92+
SO.name = $"New {typeof(T).Name}";
93+
skillDef = SO as T;
94+
95+
Util.CreateAssetAtSelectionPath(skillDef);
96+
}
97+
#endregion
98+
}
99+
}
File renamed without changes.

RoR2EditorKit/Assets/RoR2EditorKit/Editor/ScriptsForRoR2/UnlockableDefCreator.cs

Lines changed: 0 additions & 27 deletions
This file was deleted.

RoR2EditorKit/Assets/RoR2EditorKit/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,16 @@ RoR2EditorKit comes with special editor windows designed specifically for creati
4949

5050
## Changelog
5151

52+
### 0.2.1
53+
54+
* Renamed UnlockableDefCreator to ScriptableCreators
55+
* All the uncreatable skilldefs in the namespace RoR2.Skills can now be created thanks to the ScriptableCreator
56+
* Added an EditorGUILayoutProperyDrawer
57+
* Extends from property drawer.
58+
* Should only be used for extremely simple property drawer work.
59+
* It's not intended as a proper extension to the PropertyDrawer system.
60+
* Added Utility methods to the ExtendedInspector
61+
5262
### 0.2.0
5363

5464
* Added CreateRoR2PrefabWindow, used for creating prefabs.

0 commit comments

Comments
 (0)