Skip to content

Commit

Permalink
5.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Nebby1999 committed Sep 7, 2024
1 parent 779d83e commit 1e6a3bf
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 2 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
### '5.0.3'

* Core Changes:
* Fixed ``SerializableShaderWrapperDrawer`` still using the old property names for finding the ``SerializedProperties``, causing null reference exceptions.
* Added back ``DrawCheckableProperty`` functionality to IMGUIUtil
* Added a ``SerializedProperty`` extension to generate it's GUIContent,

* ThunderKitSupport Changes:
* Re-Added the ``MarkdownUtility`` class

### '5.0.2'

* RoR2EditorScripts Changes:
Expand Down
54 changes: 54 additions & 0 deletions Editor/Core/IMGUIUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,60 @@ public static class IMGUIUtil
private static FieldDrawHandler _enumFlagsHandler;
private static FieldDrawHandler _enumTypeHandler;

/// <summary>
/// Draws <paramref name="property"/> within an <see cref="EditorGUI.BeginChangeCheck"/> and calls <paramref name="onValueChanged"/> when the <paramref name="property"/>'s value changes.
/// </summary>
/// <param name="property">The property to draw</param>
/// <param name="onValueChanged">The method to invoke when the value changes.</param>
public static void DrawCheckableProperty(SerializedProperty property, Action<SerializedProperty> onValueChanged)
{
DrawCheckableProperty(property, onValueChanged, property.GetGUIContent(), true);
}


/// <summary>
/// Draws <paramref name="property"/> within an <see cref="EditorGUI.BeginChangeCheck"/> and calls <paramref name="onValueChanged"/> when the <paramref name="property"/>'s value changes.
/// </summary>
/// <param name="property">The property to draw</param>
/// <param name="onValueChanged">The method to invoke when the value changes.</param>
/// <param name="drawChildren">Wether children of <paramref name="property"/> should be drawn too</param>
/// <returns>True if the property has children, is expanded, and drawChildren is set to false, otherwise false.</returns>
public static bool DrawCheckableProperty(SerializedProperty property, Action<SerializedProperty> onValueChanged, bool drawChildren)
{
return DrawCheckableProperty(property, onValueChanged, property.GetGUIContent(), drawChildren);
}

/// <summary>
/// Draws <paramref name="property"/> within an <see cref="EditorGUI.BeginChangeCheck"/> and calls <paramref name="onValueChanged"/> when the <paramref name="property"/>'s value changes.
/// </summary>
/// <param name="property">The property to draw</param>
/// <param name="onValueChanged">The method to invoke when the value changes.</param>
/// <param name="label">The label to display for the property</param>
public static void DrawCheckableProperty(SerializedProperty property, Action<SerializedProperty> onValueChanged, GUIContent label)
{
DrawCheckableProperty(property, onValueChanged, label, true);
}


/// <summary>
/// Draws <paramref name="property"/> within an <see cref="EditorGUI.BeginChangeCheck"/> and calls <paramref name="onValueChanged"/> when the <paramref name="property"/>'s value changes.
/// </summary>
/// <param name="property">The property to draw</param>
/// <param name="onValueChanged">The method to invoke when the value changes.</param>
/// <param name="label">The label to display for the property</param>
/// <param name="drawChildren">Wether children of <paramref name="property"/> should be drawn too</param>
/// <returns>True if the property has children, is expanded, and drawChildren is set to false, otherwise false.</returns>
public static bool DrawCheckableProperty(SerializedProperty property, Action<SerializedProperty> onValueChanged, GUIContent label, bool drawChildren)
{
EditorGUI.BeginChangeCheck();
var v = EditorGUILayout.PropertyField(property, label, drawChildren);
if(EditorGUI.EndChangeCheck())
{
onValueChanged(property);
}
return v;
}

/// <summary>
/// Draws the given property with a snug label, useful when grouping multiple property fields inside a horizontal group
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ internal class SerializableShaderWrapperDrawer : IMGUIPropertyDrawer<Serializabl
Object shaderObj = null;
protected override void DrawIMGUI(Rect position, SerializedProperty property, GUIContent label)
{
var shaderNameProp = property.FindPropertyRelative("shaderName");
var shaderGUIDProp = property.FindPropertyRelative("shaderGUID");
var shaderNameProp = property.FindPropertyRelative("_shaderName");
var shaderGUIDProp = property.FindPropertyRelative("_shaderGUID");

shaderObj = Shader.Find(shaderNameProp.stringValue);
if (!shaderObj)
Expand Down
7 changes: 7 additions & 0 deletions Editor/Core/R2EKExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;

namespace RoR2.Editor
{
Expand All @@ -25,5 +27,10 @@ public static void Deconstruct<TKey, TValue>(this KeyValuePair<TKey, TValue> kvp
key = kvp.Key;
value = kvp.Value;
}

public static GUIContent GetGUIContent(this SerializedProperty property)
{
return new GUIContent(property.displayName, property.tooltip);
}
}
}
25 changes: 25 additions & 0 deletions Editor/ThunderkitSupport/MarkdownUtility.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using UnityEditor;

namespace RoR2.Editor
{
/// <summary>
/// Markdown related utilities for usage with Thunderkit's Markdown Element.
/// </summary>
public static class MarkdownUtils
{
/// <summary>
/// Generates an AssetLink that points to the object specified.
/// </summary>
/// <param name="obj">The object to point towards</param>
/// <returns>A string that represents the object's location, using the asset's GUID to ensure stability.</returns>
public static string GenerateAssetLink(UnityEngine.Object obj) => GenerateAssetLink(obj.name, AssetDatabase.GetAssetPath(obj));

/// <summary>
/// Generates an AssetLink that points to a specified path.
/// </summary>
/// <param name="name">The name of the clickable link</param>
/// <param name="path">The path to the asset, needs to be relative to the project</param>
/// <returns>A string that represents the object's location, using the asset's GUID to ensure stability</returns>
public static string GenerateAssetLink(string name, string path) => $"[{name}](assetlink://{AssetDatabase.AssetPathToGUID(path)})";
}
}
11 changes: 11 additions & 0 deletions Editor/ThunderkitSupport/MarkdownUtility.cs.meta

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

0 comments on commit 1e6a3bf

Please sign in to comment.