Skip to content

Commit

Permalink
Merge pull request #84 from arimger/develop
Browse files Browse the repository at this point in the history
Develop - 0.12.4
  • Loading branch information
arimger authored Jul 31, 2023
2 parents 454c045 + c72f7f5 commit 1f2c62a
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 22 deletions.
9 changes: 9 additions & 0 deletions Assets/Editor Toolbox/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## 0.12.4 [31.07.2023]

### Changed:
- Fix SceneView selection tool behaviour when selecting nested prefabs
- Fix InvalidOperationException when ExitGUIException is thrown inside PropertyScope
- Minor SerializedScene index calculation performance improvements
- Fix SearchablePopup styles initialization in Unity 2022+
- Minor visual improvements on how ReferencePicker label is rendered

## 0.12.3 [17.06.2023]

### Changed:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,16 @@ private void UpdateTypeProperty(SerializedProperty property, Type referenceType)
property.serializedObject.ApplyModifiedProperties();
}

private Rect PrepareTypePropertyPosition(in Rect labelPosition, in Rect inputPosition, bool isPropertyExpanded)
private Rect PrepareTypePropertyPosition(bool hasLabel, in Rect labelPosition, in Rect inputPosition, bool isPropertyExpanded)
{
var position = new Rect(inputPosition);
var baseLabelWidth = EditorGUIUtility.labelWidth + labelWidthOffset;
var realLabelWidth = labelPosition.width;
var labelWidth = Mathf.Max(baseLabelWidth, realLabelWidth);
if (!hasLabel)
{
position.xMin += EditorGUIUtility.standardVerticalSpacing;
return position;
}

//skip row only if label exists
if (isPropertyExpanded)
{
//property is expanded and we have place to move it to the next row
Expand All @@ -94,23 +98,28 @@ private Rect PrepareTypePropertyPosition(in Rect labelPosition, in Rect inputPos
return position;
}

var baseLabelWidth = EditorGUIUtility.labelWidth + labelWidthOffset;
var realLabelWidth = labelPosition.width;
//adjust position to already rendered label
position.xMin += labelWidth;
position.xMin += Mathf.Max(baseLabelWidth, realLabelWidth);
return position;
}


protected override void OnGuiSafe(SerializedProperty property, GUIContent label, ReferencePickerAttribute attribute)
{
using (var propertyScope = new PropertyScope(property, label))
//NOTE: we want to close scope manually because ExitGUIException can interrupt drawing and SerializedProperties stack
using (var propertyScope = new PropertyScope(property, label, closeManually: true))
{
UpdateContexts(attribute);

var isPropertyExpanded = propertyScope.IsVisible;
EditorGUI.indentLevel++;
var labelRect = propertyScope.LabelRect;
var inputRect = propertyScope.InputRect;
var position = PrepareTypePropertyPosition(in labelRect, in inputRect, isPropertyExpanded);

var hasLabel = !string.IsNullOrEmpty(label.text);
var position = PrepareTypePropertyPosition(hasLabel, in labelRect, in inputRect, isPropertyExpanded);

var parentType = GetParentType(property, attribute);
CreateTypeProperty(position, property, parentType);
Expand All @@ -120,6 +129,7 @@ protected override void OnGuiSafe(SerializedProperty property, GUIContent label,
}

EditorGUI.indentLevel--;
propertyScope.Close();
}
}

Expand Down
22 changes: 20 additions & 2 deletions Assets/Editor Toolbox/Editor/Internal/PropertyScope.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,18 @@ namespace Toolbox.Editor.Internal
internal class PropertyScope : IDisposable
{
private readonly SerializedProperty property;
private readonly bool closeManually;
private bool isClosed;

public PropertyScope(SerializedProperty property, GUIContent label) : this(property, label, false)
{ }

public PropertyScope(SerializedProperty property, GUIContent label)
public PropertyScope(SerializedProperty property, GUIContent label, bool closeManually)
{
this.property = property;
this.closeManually = closeManually;
isClosed = false;

ToolboxEditorGui.BeginProperty(property, ref label, out var rect);
HandleEvents(rect);
TryDrawLabel(rect, label);
Expand Down Expand Up @@ -50,9 +57,20 @@ private void TryDrawLabel(Rect rect, GUIContent label)
}


public void Dispose()
public void Close()
{
ToolboxEditorGui.CloseProperty();
isClosed = true;
}

public void Dispose()
{
if (closeManually || isClosed)
{
return;
}

Close();
}


Expand Down
6 changes: 6 additions & 0 deletions Assets/Editor Toolbox/Editor/Internal/SearchablePopup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -316,9 +316,15 @@ static Style()
toolbarStyle = new GUIStyle(EditorStyles.toolbar);
scrollbarStyle = new GUIStyle(GUI.skin.verticalScrollbar);
selectionStyle = new GUIStyle("SelectionRect");
#if UNITY_2022_1_OR_NEWER
searchBoxStyle = new GUIStyle("ToolbarSearchTextField");
showCancelButtonStyle = new GUIStyle("ToolbarSearchCancelButton");
hideCancelButtonStyle = new GUIStyle("ToolbarSearchCancelButtonEmpty");
#else
searchBoxStyle = new GUIStyle("ToolbarSeachTextField");
showCancelButtonStyle = new GUIStyle("ToolbarSeachCancelButton");
hideCancelButtonStyle = new GUIStyle("ToolbarSeachCancelButtonEmpty");
#endif
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#if UNITY_EDITOR
using UnityEditor;
#endif
using UnityEngine.SceneManagement;

namespace Toolbox.Serialization
{
Expand Down Expand Up @@ -40,37 +41,30 @@ internal static void ConfirmCache()
internal static void RefreshCache()
{
cachedScenes.Clear();
var buildIndex = -1;
foreach (var scene in EditorBuildSettings.scenes)
{
if (string.IsNullOrEmpty(scene.path))
var path = scene.path;
if (string.IsNullOrEmpty(path))
{
continue;
}

var sceneAsset = EditorGUIUtility.Load(scene.path) as SceneAsset;
var sceneAsset = EditorGUIUtility.Load(path) as SceneAsset;
if (sceneAsset == null)
{
continue;
}

var sceneIndex = InvalidSceneIndex;
if (scene.enabled)
{
buildIndex++;
sceneIndex = buildIndex;
}

if (cachedScenes.ContainsKey(sceneAsset))
{
continue;
}

cachedScenes.Add(sceneAsset, new SceneData()
{
BuildIndex = sceneIndex,
BuildIndex = SceneUtility.GetBuildIndexByScenePath(path),
SceneName = sceneAsset.name,
ScenePath = scene.path
ScenePath = path
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion Assets/Editor Toolbox/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "com.browar.editor-toolbox",
"displayName": "Editor Toolbox",
"version": "0.12.3",
"version": "0.12.4",
"unity": "2018.1",
"description": "Tools, custom attributes, drawers, hierarchy overlay, and other extensions for the Unity Editor.",
"keywords": [
Expand Down

0 comments on commit 1f2c62a

Please sign in to comment.