Skip to content

Commit

Permalink
Inspector utils, new property drawer system, scriptableobject creation
Browse files Browse the repository at this point in the history
  • Loading branch information
Nebby1999 committed Nov 30, 2021
1 parent 00e8761 commit d79263d
Show file tree
Hide file tree
Showing 13 changed files with 616 additions and 37 deletions.
2 changes: 1 addition & 1 deletion RoR2EditorKit/Assets/RoR2EditorKit.asset
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,5 @@ MonoBehaviour:
Name: RoR2EditorKit
Description: RoR2EditorKit is a toolkit built around developing mods for Risk of
Rain 2
Version: 0.1.3
Version: 0.2.1
Dependencies: []
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,11 @@ public override void OnInspectorGUI()
DrawDefaultInspector();
}
}

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);
protected void Header(string label) => EditorGUILayout.LabelField(new GUIContent(label), EditorStyles.boldLabel);
protected void Header(string label, string tooltip) => EditorGUILayout.LabelField(new GUIContent(label, tooltip), EditorStyles.boldLabel);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEditor;
using UnityEngine;

namespace RoR2EditorKit.Core.PropertyDrawers
{
/// <summary>
/// Used for lazy creation of property drawer using editor gui layout instead of editor gui.
///<para>This shouldnt be used unless you want a very simple property drawer that doesnt need to be all specific</para>
///<para>May cause spamming in the unity editor console that's caused by using EditorGUILayout instead of EditorGUI.</para>
/// </summary>
public class EditorGUILayoutPropertyDrawer : PropertyDrawer
{
SerializedProperty serializedProperty;
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
serializedProperty = property;
EditorGUI.BeginProperty(position, label, property);
DrawPropertyDrawer(property);
EditorGUI.EndProperty();
}

protected virtual void DrawPropertyDrawer(SerializedProperty property) { }
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
return -2f;
}

protected void DrawField(string propName) => EditorGUILayout.PropertyField(serializedProperty.FindPropertyRelative(propName), true);
protected void DrawField(SerializedProperty property, string propName) => EditorGUILayout.PropertyField(property.FindPropertyRelative(propName), true);
protected void DrawField(SerializedProperty property) => EditorGUILayout.PropertyField(property, true);
protected void Header(string label) => EditorGUILayout.LabelField(new GUIContent(label), EditorStyles.boldLabel);
protected void Header(string label, string tooltip) => EditorGUILayout.LabelField(new GUIContent(label, tooltip), EditorStyles.boldLabel);
}
}

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 @@ -10,18 +10,14 @@
namespace RoR2EditorKit.Core.PropertyDrawers
{
[CustomPropertyDrawer(typeof(EnabledAndDisabledInspectorsSettings.InspectorSetting))]
public class InspectorSettingPropertyDrawer : PropertyDrawer
public class InspectorSettingPropertyDrawer : EditorGUILayoutPropertyDrawer
{
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
protected override void DrawPropertyDrawer(SerializedProperty property)
{
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();
EditorGUILayout.PropertyField(isEnabled, new GUIContent(ObjectNames.NicifyVariableName(displayName.stringValue)));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
using RoR2;
using RoR2.Skills;
using UnityEditor;
using UnityEngine;

namespace RoR2EditorKit.RoR2
{
/// <summary>
/// Creation of ScriptableObjects that are normally uncreatable in RoR2
/// </summary>
public static class ScriptableCreators
{
[MenuItem("Assets/Create/RoR2/UnlockableDef")]
public static void CreateUnlockableDef()
{
var unlockableDef = ScriptableObject.CreateInstance<UnlockableDef>();
unlockableDef.cachedName = "New UnlockableDef";
Util.CreateAssetAtSelectionPath(unlockableDef);
}

#region skilldefs
[MenuItem("Assets/Create/RoR2/SkillDef/Captain/Orbital")]
public static void CreateOrbital()
{
CreateSkill<CaptainOrbitalSkillDef>();
}

[MenuItem("Assets/Create/RoR2/SkillDef/Captain/SupplyDrop")]
public static void CreateSupplyDrop()
{
CreateSkill<CaptainSupplyDropSkillDef>();
}

[MenuItem("Assets/Create/RoR2/SkillDef/Combo")]
public static void CreateCombo()
{
CreateSkill<ComboSkillDef>();
}

[MenuItem("Assets/Create/RoR2/SkillDef/Conditional")]
public static void CreateConditional()
{
CreateSkill<ConditionalSkillDef>();
}

[MenuItem("Assets/Create/RoR2/SkillDef/EngiMineDeployer")]
public static void CreateEngiMineDeployer()
{
CreateSkill<EngiMineDeployerSkill>();
}

[MenuItem("Assets/Create/RoR2/SkillDef/Grounded")]
public static void CreateGrounded()
{
CreateSkill<GroundedSkillDef>();
}

[MenuItem("Assets/Create/RoR2/SkillDef/LunarReplacements/Detonator")]
public static void CreateDetonator()
{
CreateSkill<LunarDetonatorSkill>();
}

[MenuItem("Assets/Create/RoR2/SkillDef/LunarReplacements/Primary")]
public static void CreatePrimary()
{
CreateSkill<LunarPrimaryReplacementSkill>();
}

[MenuItem("Assets/Create/RoR2/SkillDef/LunarReplacements/Secondary")]
public static void CreateSecondary()
{
CreateSkill<LunarSecondaryReplacementSkill>();
}

[MenuItem("Assets/Create/RoR2/SkillDef/Stepped")]
public static void CreateStepped()
{
CreateSkill<SteppedSkillDef>();
}

[MenuItem("Assets/Create/RoR2/SkillDef/ToolbotWeapon")]
public static void CreateToolbotWeapon()
{
CreateSkill<ToolbotWeaponSkillDef>();
}

private static void CreateSkill<T>() where T : SkillDef
{
var skillDef = ScriptableObject.CreateInstance<T>();
var SO = skillDef as ScriptableObject;
SO.name = $"New {typeof(T).Name}";
skillDef = SO as T;

Util.CreateAssetAtSelectionPath(skillDef);
}
#endregion
}
}

This file was deleted.

10 changes: 10 additions & 0 deletions RoR2EditorKit/Assets/RoR2EditorKit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@ RoR2EditorKit comes with special editor windows designed specifically for creati

## Changelog

### 0.2.1

* Renamed UnlockableDefCreator to ScriptableCreators
* All the uncreatable skilldefs in the namespace RoR2.Skills can now be created thanks to the ScriptableCreator
* Added an EditorGUILayoutProperyDrawer
* Extends from property drawer.
* Should only be used for extremely simple property drawer work.
* It's not intended as a proper extension to the PropertyDrawer system.
* Added Utility methods to the ExtendedInspector

### 0.2.0

* Added CreateRoR2PrefabWindow, used for creating prefabs.
Expand Down
Loading

0 comments on commit d79263d

Please sign in to comment.