Skip to content

Commit 8c7112e

Browse files
authored
Merge pull request #137 from arimger/develop
Develop - 0.14.1
2 parents ce91498 + 688f421 commit 8c7112e

File tree

13 files changed

+138
-49
lines changed

13 files changed

+138
-49
lines changed

Assets/Editor Toolbox/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
## 0.14.1 [22.04.2025]
2+
3+
### Changed:
4+
- Ability to define [EditorButton] position (below or above the target property)
5+
- Improvements to the SerializedScene class & linked drawer
6+
- Fix rare issue with nested layouts
7+
18
## 0.14.0 [23.02.2025]
29

310
### Added:

Assets/Editor Toolbox/Editor/Drawers/Regular/PropertyDrawerBase.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ public sealed override void OnGUI(Rect position, SerializedProperty property, GU
4848
}
4949

5050
ToolboxEditorLog.WrongAttributeUsageWarning(attribute, property);
51-
//create additional warning label based on the property name
52-
var warningContent = new GUIContent(property.displayName + " has invalid property drawer");
51+
var warningContent = new GUIContent($"{property.displayName} has invalid property drawer");
5352
ToolboxEditorGui.DrawEmptyProperty(position, property, warningContent);
5453
}
5554

Assets/Editor Toolbox/Editor/Drawers/Regular/SerializedSceneDrawer.cs

Lines changed: 46 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using UnityEditor;
1+
using Toolbox.Editor.Internal;
2+
using UnityEditor;
23
using UnityEngine;
34

45
namespace Toolbox.Editor.Drawers
@@ -28,29 +29,39 @@ private void OpenBuildSettings()
2829
EditorWindow.GetWindow(typeof(BuildPlayerWindow));
2930
}
3031

31-
32-
protected override float GetPropertyHeightSafe(SerializedProperty property, GUIContent label)
33-
{
34-
var lineHeight = EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
35-
return HasSceneDetails(property)
36-
? base.GetPropertyHeightSafe(property, label) + lineHeight * 2
37-
: base.GetPropertyHeightSafe(property, label);
38-
}
39-
4032
protected override void OnGUISafe(Rect position, SerializedProperty property, GUIContent label)
4133
{
34+
var hasDetails = HasSceneDetails(property);
4235
EditorGUI.BeginProperty(position, label, property);
4336
position.height = EditorGUIUtility.singleLineHeight;
44-
position = EditorGUI.PrefixLabel(position, label);
37+
if (hasDetails)
38+
{
39+
position.xMax -= Style.foldoutWidth;
40+
}
41+
4542
var sceneProperty = property.FindPropertyRelative("sceneReference");
46-
EditorGUI.ObjectField(position, sceneProperty, GUIContent.none);
43+
EditorGUI.ObjectField(position, sceneProperty, label);
4744
EditorGUI.EndProperty();
4845

49-
if (!HasSceneDetails(property))
46+
if (hasDetails)
47+
{
48+
var prevXMin = position.xMin;
49+
position.xMin = position.xMax;
50+
position.xMax += Style.foldoutWidth;
51+
using (new DisabledScope(true))
52+
{
53+
property.isExpanded = GUI.Toggle(position, property.isExpanded, Style.foldoutContent, Style.foldoutStyle);
54+
}
55+
56+
position.xMin = prevXMin;
57+
}
58+
59+
if (!hasDetails || !property.isExpanded)
5060
{
5161
return;
5262
}
5363

64+
EditorGUI.indentLevel++;
5465
var sceneData = SceneData.GetSceneDataFromIndex(property);
5566
var spacing = EditorGUIUtility.standardVerticalSpacing;
5667
position.y += EditorGUIUtility.singleLineHeight + spacing;
@@ -64,20 +75,21 @@ protected override void OnGUISafe(Rect position, SerializedProperty property, GU
6475
EditorGUI.LabelField(position, Style.notInBuildContent);
6576
position.y += EditorGUIUtility.singleLineHeight + spacing;
6677
EditorGUI.EndDisabledGroup();
67-
if (GUI.Button(position, Style.showDetailsContent))
78+
var buttonRect = EditorGUI.IndentedRect(position);
79+
if (GUI.Button(buttonRect, Style.showDetailsContent))
6880
{
6981
OpenBuildSettings();
7082
}
7183
}
72-
}
7384

85+
EditorGUI.indentLevel--;
86+
}
7487

7588
public override bool IsPropertyValid(SerializedProperty property)
7689
{
7790
return property.type == nameof(SerializedScene);
7891
}
7992

80-
8193
private struct SceneData
8294
{
8395
public int index;
@@ -134,10 +146,28 @@ public static SceneData GetSceneDataFromScene(SerializedProperty property)
134146

135147
private static class Style
136148
{
149+
internal const float foldoutWidth = 50.0f;
150+
151+
internal static readonly GUIContent foldoutContent = new GUIContent("Details", "Show/Hide Scene Details");
137152
internal static readonly GUIContent buildIndexContent = new GUIContent("Build Index");
138153
internal static readonly GUIContent isEnabledContent = new GUIContent("Is Enabled");
139154
internal static readonly GUIContent notInBuildContent = new GUIContent("Not in Build");
140155
internal static readonly GUIContent showDetailsContent = new GUIContent("Open Build Settings");
156+
157+
internal static readonly GUIStyle foldoutStyle;
158+
159+
static Style()
160+
{
161+
foldoutStyle = new GUIStyle(EditorStyles.miniButton)
162+
{
163+
#if UNITY_2019_3_OR_NEWER
164+
fontSize = 10,
165+
#else
166+
fontSize = 9,
167+
#endif
168+
alignment = TextAnchor.MiddleCenter
169+
};
170+
}
141171
}
142172
}
143173
}

Assets/Editor Toolbox/Editor/Drawers/Toolbox/Decorator/EditorButtonAttributeDrawer.cs

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,31 @@ namespace Toolbox.Editor.Drawers
88
{
99
public class EditorButtonAttributeDrawer : ToolboxDecoratorDrawer<EditorButtonAttribute>
1010
{
11+
private void DrawButton(EditorButtonAttribute attribute)
12+
{
13+
var declaringObjects = GetDeclaringObjects();
14+
if (declaringObjects == null || declaringObjects.Length == 0)
15+
{
16+
//NOTE: something went really wrong, internal bug or OnGuiBeginSafe was called out of the Toolbox scope
17+
return;
18+
}
19+
20+
var disable = !IsClickable(attribute, declaringObjects);
21+
using (new EditorGUI.DisabledScope(disable))
22+
{
23+
var label = string.IsNullOrEmpty(attribute.ExtraLabel)
24+
? ObjectNames.NicifyVariableName(attribute.MethodName)
25+
: attribute.ExtraLabel;
26+
var tooltip = attribute.Tooltip;
27+
var content = new GUIContent(label, tooltip);
28+
29+
if (GUILayout.Button(content, Style.buttonStyle))
30+
{
31+
CallMethods(attribute, declaringObjects);
32+
}
33+
}
34+
}
35+
1136
private MethodInfo GetMethod(EditorButtonAttribute attribute, object[] targetObjects, string methodName)
1237
{
1338
var methodInfo = ReflectionUtility.GetMethod(methodName, targetObjects);
@@ -119,29 +144,25 @@ private void CallMethods(EditorButtonAttribute attribute, object[] targetObjects
119144
}
120145
}
121146

122-
protected override void OnGuiCloseSafe(EditorButtonAttribute attribute)
147+
protected override void OnGuiBeginSafe(EditorButtonAttribute attribute)
123148
{
124-
var declaringObjects = GetDeclaringObjects();
125-
if (declaringObjects == null || declaringObjects.Length == 0)
149+
if (attribute.PositionType != ButtonPositionType.Above)
126150
{
127-
//NOTE: something went really wrong, internal bug or OnGuiBeginSafe was called out of the Toolbox scope
128151
return;
129152
}
130153

131-
var disable = !IsClickable(attribute, declaringObjects);
132-
using (new EditorGUI.DisabledScope(disable))
133-
{
134-
var label = string.IsNullOrEmpty(attribute.ExtraLabel)
135-
? ObjectNames.NicifyVariableName(attribute.MethodName)
136-
: attribute.ExtraLabel;
137-
var tooltip = attribute.Tooltip;
138-
var content = new GUIContent(label, tooltip);
154+
DrawButton(attribute);
155+
}
139156

140-
if (GUILayout.Button(content, Style.buttonStyle))
141-
{
142-
CallMethods(attribute, declaringObjects);
143-
}
157+
protected override void OnGuiCloseSafe(EditorButtonAttribute attribute)
158+
{
159+
if (attribute.PositionType != ButtonPositionType.Default &&
160+
attribute.PositionType != ButtonPositionType.Below)
161+
{
162+
return;
144163
}
164+
165+
DrawButton(attribute);
145166
}
146167

147168
private static class Style

Assets/Editor Toolbox/Editor/Management/ToolboxManager.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,12 @@ void ReintializeProvider()
213213

214214
if (GUILayout.Button("Create a new settings file"))
215215
{
216-
var settingsInstance = ScriptableObject.CreateInstance(settingsType);
216+
var settingsInstance = ScriptableObject.CreateInstance<ToolboxEditorSettings>();
217+
if (settingsInstance == null)
218+
{
219+
ToolboxEditorLog.LogError($"Something went wrong. Cannot create a new Settings file.");
220+
return;
221+
}
217222

218223
var locationPath = EditorUtility.OpenFolderPanel("New Settings file location", "Assets", "");
219224
//validate returned path and create relative one if possible

Assets/Editor Toolbox/Editor/ToolboxEditorGui.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -528,12 +528,7 @@ public static void DrawPropertyChildren(SerializedProperty property, Action<Seri
528528
enterChildren = false;
529529
var childProperty = targetProperty.Copy();
530530
//handle current property using Toolbox features
531-
EditorGUI.BeginChangeCheck();
532531
drawElementAction(childProperty);
533-
if (EditorGUI.EndChangeCheck())
534-
{
535-
break;
536-
}
537532
}
538533
}
539534

Assets/Editor Toolbox/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ public int var1;
417417
![inspector](https://github.com/arimger/Unity-Editor-Toolbox/blob/develop/Docs/horizontal.png)
418418

419419
```csharp
420-
[EditorButton(nameof(MyMethod), "<b>My</b> Custom Label", activityType: ButtonActivityType.OnPlayMode, ValidateMethodName = nameof(ValidationMethod))]
420+
[EditorButton(nameof(MyMethod), "<b>My</b> Custom Label", activityType: ButtonActivityType.OnPlayMode, ValidateMethodName = nameof(ValidationMethod), PositionType = ButtonPositionType.Above)]
421421
public int var1;
422422

423423
private void MyMethod()

Assets/Editor Toolbox/Runtime/Attributes/Property/Toolbox/DecoratorAttributes/EditorButtonAttribute.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,15 @@ public EditorButtonAttribute(string methodName, string extraLabel = null, Button
2727
public string ValidateMethodName { get; set; }
2828
public string ExtraLabel { get; private set; }
2929
public string Tooltip { get; set; }
30-
public ButtonActivityType ActivityType { get; private set; }
30+
public ButtonActivityType ActivityType { get; set; }
31+
public ButtonPositionType PositionType { get; set; } = ButtonPositionType.Default;
32+
}
33+
34+
public enum ButtonPositionType
35+
{
36+
Default,
37+
Below,
38+
Above
3139
}
3240

3341
[Flags]

Assets/Editor Toolbox/Runtime/Serialization/SerializedScene.cs

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,42 @@ void ISerializationCallbackReceiver.OnBeforeSerialize()
3333
void ISerializationCallbackReceiver.OnAfterDeserialize()
3434
{ }
3535

36+
public void UpdateProperties()
37+
{
38+
UpdateProperties(out _);
39+
}
3640

37-
private void UpdateProperties()
41+
public void UpdateProperties(out bool anythingChanged)
3842
{
43+
anythingChanged = false;
3944
#if UNITY_EDITOR
4045
if (SceneSerializationUtility.TryGetSceneData(sceneReference, out var sceneData))
4146
{
42-
SceneName = sceneData.SceneName;
43-
ScenePath = sceneData.ScenePath;
44-
BuildIndex = sceneData.BuildIndex;
47+
if (SceneName != sceneData.SceneName)
48+
{
49+
SceneName = sceneData.SceneName;
50+
anythingChanged = true;
51+
}
52+
53+
if (ScenePath != sceneData.ScenePath)
54+
{
55+
ScenePath = sceneData.ScenePath;
56+
anythingChanged = true;
57+
}
58+
59+
if (BuildIndex != sceneData.BuildIndex)
60+
{
61+
BuildIndex = sceneData.BuildIndex;
62+
anythingChanged = true;
63+
}
4564
}
4665
else
4766
{
67+
if (!string.IsNullOrEmpty(sceneName))
68+
{
69+
anythingChanged = true;
70+
}
71+
4872
SceneName = string.Empty;
4973
ScenePath = string.Empty;
5074
BuildIndex = -1;

Assets/Editor Toolbox/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "com.browar.editor-toolbox",
33
"displayName": "Editor Toolbox",
4-
"version": "0.14.0",
4+
"version": "0.14.1",
55
"unity": "2018.1",
66
"description": "Tools, custom attributes, drawers, hierarchy overlay, and other extensions for the Unity Editor.",
77
"keywords": [

0 commit comments

Comments
 (0)