Skip to content

Commit ffc6b30

Browse files
authored
Merge pull request #124 from FishingCactus/feature/add_inspector_utilities
feature/add inspector utilities
2 parents 0811fc9 + 331cc0d commit ffc6b30

File tree

5 files changed

+85
-1
lines changed

5 files changed

+85
-1
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog
22

3+
## [2.4.0] - 2025-05-09
4+
### Added
5+
- Add utility functions for the inspector:
6+
- InspectorUtils.SetIndentScope: use EditorGUI.IndentScope to set the editor GUI indent level
7+
- InspectorUtils.DrawHelpbox: draw a helpbox with the specified message and severity at given position
8+
- Add RectExtensions class: provides extensions functions for Rect
9+
310
## [2.3.2] - 2025-04-18
411
### Updated
512
- Update SubAssetPicker drawer to display mixed values and disable picker when multiple objects with different values are selected

Editor/Utilities/InspectorUtils.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,38 @@
11
using System;
22
using System.Reflection;
33
using UnityEditor;
4+
using UnityEngine;
45

56
namespace FishingCactus.CommonCode
67
{
78
public static class InspectorUtils
89
{
10+
public static EditorGUI.IndentLevelScope SetIndentScope(
11+
int indent
12+
)
13+
{
14+
return new EditorGUI.IndentLevelScope( indent - EditorGUI.indentLevel );
15+
}
16+
17+
public static void DrawHelpbox(
18+
Rect position,
19+
GUIContent content,
20+
MessageType message_type,
21+
out float total_height,
22+
float min_height = 40f,
23+
float top_margin = 2f,
24+
float bottom_margin = 2f
25+
)
26+
{
27+
total_height = GUI.skin.GetStyle( "helpbox" ).CalcHeight( content, position.width );
28+
total_height += top_margin + bottom_margin;
29+
total_height = Mathf.Max( total_height, min_height + ( top_margin + bottom_margin ) );
30+
31+
position.y += top_margin;
32+
position.height = total_height - ( top_margin + bottom_margin );
33+
EditorGUI.HelpBox( position, content.text, message_type );
34+
}
35+
936
public static Type GetPropertyType(
1037
SerializedProperty property
1138
)
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using UnityEngine;
2+
3+
namespace FishingCactus.CommonCode
4+
{
5+
public static class RectExtensions
6+
{
7+
public static Rect WithX(
8+
this Rect rect,
9+
float new_x
10+
)
11+
{
12+
return new Rect( new_x, rect.y, rect.width, rect.height );
13+
}
14+
15+
public static Rect WithY(
16+
this Rect rect,
17+
float new_y
18+
)
19+
{
20+
return new Rect( rect.x, new_y, rect.width, rect.height );
21+
}
22+
23+
public static Rect WithWidth(
24+
this Rect rect,
25+
float new_width
26+
)
27+
{
28+
return new Rect( rect.x, rect.y, new_width, rect.height );
29+
}
30+
31+
public static Rect WithHeight(
32+
this Rect rect,
33+
float new_height
34+
)
35+
{
36+
return new Rect( rect.x, rect.y, rect.width, new_height );
37+
}
38+
}
39+
}

Runtime/Extensions/RectExtensions.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.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "com.fishingcactus.common-code",
3-
"version": "2.3.2",
3+
"version": "2.4.0",
44
"displayName": "FC - Common Code",
55
"description": "Code, Extensions and extra features for Fishing Cactus Games.",
66
"unity": "2020.3",

0 commit comments

Comments
 (0)