Skip to content

Commit c07f13c

Browse files
authored
Merge pull request #21 from arimger/develop
Develop
2 parents 4f54fd2 + 074d5e2 commit c07f13c

File tree

77 files changed

+1323
-399
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+1323
-399
lines changed

.vsconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"version": "1.0",
3+
"components": [
4+
"Microsoft.VisualStudio.Workload.ManagedGame"
5+
]
6+
}

Assets/Editor Toolbox/CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
## 0.9.0 [19.07.2021]
2+
3+
### Added:
4+
- FormattedNumberAttribute
5+
- SceneAsset picker for the SceneNameAttribute
6+
- Optional foldout for the ReorderableList and related attributes
7+
- GuiColorAttribute
8+
9+
### Changed:
10+
11+
- Remove obsolete attributes
12+
- Rename ToolboxCompositionAttribute class to ToolboxArchetypeAttribute
13+
114
## 0.8.13 [04.07.2021]
215

316
### Added:

Assets/Editor Toolbox/Editor/Drawers/Internal.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Editor Toolbox/Editor/Drawers/RegularDrawers/FolderDataDrawer.cs renamed to Assets/Editor Toolbox/Editor/Drawers/Internal/FolderDataDrawer.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ namespace Toolbox.Editor.Drawers
88
[CustomPropertyDrawer(typeof(FolderData))]
99
internal class FolderDataDrawer : PropertyDrawer
1010
{
11-
private const string selectorEventName = "ObjectSelectorUpdated";
12-
1311
private const int largeIconPickedId = 1001;
1412
private const int smallIconPickedId = 1002;
1513

@@ -81,15 +79,15 @@ public override float GetPropertyHeight(SerializedProperty property, GUIContent
8179
var pathProperty = property.FindPropertyRelative("path");
8280
var tooltipProperty = property.FindPropertyRelative("tooltip");
8381

84-
//check if type is path-based or name-based
85-
height += typeProperty.intValue == 0
86-
? EditorGUI.GetPropertyHeight(pathProperty)
87-
: EditorGUI.GetPropertyHeight(nameProperty);
8882
height += EditorGUI.GetPropertyHeight(tooltipProperty);
8983
height += Style.height;
9084
height += Style.height;
9185
height += Style.largeFolderHeight;
9286
height += Style.spacing * 4;
87+
//check if type is path-based or name-based
88+
height += typeProperty.intValue == 0
89+
? EditorGUI.GetPropertyHeight(pathProperty)
90+
: EditorGUI.GetPropertyHeight(nameProperty);
9391
return height;
9492
}
9593

@@ -210,7 +208,7 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten
210208
}
211209

212210
//catch object selection event and assign it to proper property
213-
if (Event.current.commandName == selectorEventName)
211+
if (Event.current.commandName == "ObjectSelectorUpdated")
214212
{
215213
//get proper action id by removing unique property hash code
216214
var rawPickId = EditorGUIUtility.GetObjectPickerControlID();

Assets/Editor Toolbox/Editor/Drawers/RegularDrawers/ClampAttributeDrawer.cs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,25 @@ protected override void OnGUISafe(Rect position, SerializedProperty property, GU
1515
{
1616
var minValue = Attribute.MinValue;
1717
var maxValue = Attribute.MaxValue;
18-
19-
if (property.propertyType == SerializedPropertyType.Float)
18+
if (property.hasMultipleDifferentValues)
2019
{
21-
property.floatValue = Mathf.Clamp(property.floatValue, minValue, maxValue);
20+
EditorGUI.PropertyField(position, property, label);
21+
return;
2222
}
23-
else
23+
24+
switch (property.propertyType)
2425
{
25-
property.intValue = Mathf.Clamp(property.intValue, (int)minValue, (int)maxValue);
26+
case SerializedPropertyType.Float:
27+
property.floatValue = Mathf.Clamp(property.floatValue, minValue, maxValue);
28+
break;
29+
case SerializedPropertyType.Integer:
30+
property.intValue = (int)Mathf.Clamp(property.intValue, minValue, maxValue);
31+
break;
32+
default:
33+
break;
2634
}
2735

28-
EditorGUI.PropertyField(position, property, label, property.isExpanded);
36+
EditorGUI.PropertyField(position, property, label);
2937
}
3038

3139

Assets/Editor Toolbox/Editor/Drawers/RegularDrawers/DirectoryAttributeDrawer.cs

Lines changed: 50 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,48 @@ private static bool IsPathValid(string propertyPath, string assetRelativePath)
1717
return Directory.Exists(targetPath);
1818
}
1919

20+
private Rect DrawWarningMessage(Rect position)
21+
{
22+
position = new Rect(position.x,
23+
position.y,
24+
position.width, Style.boxHeight);
25+
EditorGUI.HelpBox(position, "Provided directory does not exist.", MessageType.Warning);
26+
return position;
27+
}
28+
29+
private void UseDirectoryPicker(SerializedProperty property, string relativePath)
30+
{
31+
var baseDataPath = Application.dataPath;
32+
var baseOpenPath = Path.GetFileName(baseDataPath);
33+
if (!string.IsNullOrEmpty(relativePath))
34+
{
35+
baseDataPath = Path.Combine(baseDataPath, relativePath);
36+
baseOpenPath = Path.Combine(baseOpenPath, relativePath);
37+
}
38+
39+
var selectedPath = EditorUtility.OpenFolderPanel("Pick directory", baseOpenPath, "");
40+
if (!string.IsNullOrEmpty(selectedPath))
41+
{
42+
//Unity's API always returns slash
43+
baseDataPath = baseDataPath.Replace('\\', '/');
44+
selectedPath = selectedPath.Replace(baseDataPath, "");
45+
selectedPath = selectedPath.Remove(0, 1);
46+
47+
property.serializedObject.Update();
48+
property.stringValue = selectedPath;
49+
property.serializedObject.ApplyModifiedProperties();
50+
}
51+
52+
//NOTE: we have to exit GUI since the EditorUtility.OpenFolderPanel method will break the layouting system
53+
GUIUtility.ExitGUI();
54+
}
55+
2056

2157
protected override float GetPropertyHeightSafe(SerializedProperty property, GUIContent label)
2258
{
2359
//validate property type and serialized path
24-
return IsPathValid(property.stringValue, Attribute.RelativePath)
25-
? base.GetPropertyHeightSafe(property, label)
60+
return IsPathValid(property.stringValue, Attribute.RelativePath)
61+
? base.GetPropertyHeightSafe(property, label)
2662
: base.GetPropertyHeightSafe(property, label) + Style.boxHeight + Style.spacing * 2;
2763
}
2864

@@ -31,47 +67,20 @@ protected override void OnGUISafe(Rect position, SerializedProperty property, GU
3167
//validate currently serialized path value
3268
if (!IsPathValid(property.stringValue, Attribute.RelativePath))
3369
{
34-
var helpBoxRect = new Rect(position.x,
35-
position.y,
36-
position.width, Style.boxHeight);
37-
EditorGUI.HelpBox(helpBoxRect, "Provided directory does not exist.", MessageType.Warning);
38-
position.y += Style.boxHeight + Style.spacing + Style.spacing;
70+
position = DrawWarningMessage(position);
71+
position.yMin = position.yMax + Style.spacing;
72+
position.yMax = position.yMin + Style.rowHeight;
3973
}
4074

41-
position.height = Style.rowHeight;
42-
position.width -= Style.directoryButtonWidth + Style.spacing;
43-
//draw the default string property field
75+
position.xMax -= Style.pickerWidth + Style.spacing;
4476
EditorGUI.PropertyField(position, property, label);
45-
position.x = position.xMax + Style.spacing;
46-
position.width = Style.directoryButtonWidth;
77+
position.xMax += Style.pickerWidth + Style.spacing;
78+
position.xMin = position.xMax - Style.pickerWidth;
4779

4880
//create additional pick directory button
49-
if (GUI.Button(position, Style.directoryButtonContent, EditorStyles.miniButton))
81+
if (GUI.Button(position, Style.pickerContent, EditorStyles.miniButton))
5082
{
51-
var relativePath = Attribute.RelativePath;
52-
var baseDataPath = Application.dataPath;
53-
var baseOpenPath = "Assets";
54-
if (!string.IsNullOrEmpty(relativePath))
55-
{
56-
baseDataPath = Path.Combine(baseDataPath, relativePath);
57-
baseOpenPath = Path.Combine(baseOpenPath, relativePath);
58-
}
59-
60-
var selectedPath = EditorUtility.OpenFolderPanel("Pick directory", baseOpenPath, "");
61-
if (!string.IsNullOrEmpty(selectedPath))
62-
{
63-
//Unity's API always returns slash
64-
baseDataPath = baseDataPath.Replace('\\', '/');
65-
selectedPath = selectedPath.Replace(baseDataPath, "");
66-
selectedPath = selectedPath.Remove(0, 1);
67-
68-
property.serializedObject.Update();
69-
property.stringValue = selectedPath;
70-
property.serializedObject.ApplyModifiedProperties();
71-
}
72-
73-
//NOTE: we have to exit GUI since the EditorUtility.OpenFolderPanel method will break the layouting system
74-
GUIUtility.ExitGUI();
83+
UseDirectoryPicker(property, Attribute.RelativePath);
7584
}
7685
}
7786

@@ -94,13 +103,14 @@ private static class Style
94103
internal static readonly float boxHeight = EditorGUIUtility.singleLineHeight * 2.5f;
95104
#endif
96105
internal static readonly float spacing = EditorGUIUtility.standardVerticalSpacing;
97-
internal static readonly float directoryButtonWidth = 30.0f;
106+
internal static readonly float pickerWidth = 30.0f;
98107

99-
internal static readonly GUIContent directoryButtonContent;
108+
internal static readonly GUIContent pickerContent;
100109

101110
static Style()
102111
{
103-
directoryButtonContent = new GUIContent(EditorGUIUtility.FindTexture("Folder Icon"), "Pick directory");
112+
pickerContent = EditorGUIUtility.IconContent("Folder Icon");
113+
pickerContent.tooltip = "Pick directory";
104114
}
105115
}
106116
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
using System;
2+
using System.Globalization;
3+
4+
using UnityEditor;
5+
using UnityEngine;
6+
7+
namespace Toolbox.Editor.Drawers
8+
{
9+
[CustomPropertyDrawer(typeof(FormattedNumberAttribute))]
10+
public class FormattedNumberAttributeDrawer : ToolboxNativePropertyDrawer
11+
{
12+
private readonly NumberFormatInfo formatInfo = new NumberFormatInfo()
13+
{
14+
NumberGroupSeparator = " ",
15+
CurrencySymbol = "$",
16+
CurrencyDecimalSeparator = "."
17+
};
18+
19+
20+
private void ApplyControlName(string propertyKey)
21+
{
22+
GUI.SetNextControlName(propertyKey);
23+
}
24+
25+
private bool IsControlEditing(string propertyKey)
26+
{
27+
return EditorGUIUtility.editingTextField && GUI.GetNameOfFocusedControl() == propertyKey;
28+
}
29+
30+
private Single GetSingle(SerializedProperty property)
31+
{
32+
return property.propertyType == SerializedPropertyType.Integer
33+
? property.intValue
34+
: property.floatValue;
35+
}
36+
37+
private string GetFormat(SerializedProperty property, FormattedNumberAttribute attribute)
38+
{
39+
var isInt = property.propertyType == SerializedPropertyType.Integer;
40+
return string.Format("{0}{1}", attribute.Format, isInt ? 0 : attribute.DecimalsToShow);
41+
}
42+
43+
44+
protected override void OnGUISafe(Rect position, SerializedProperty property, GUIContent label)
45+
{
46+
var key = property.GetPropertyHashKey();
47+
ApplyControlName(key);
48+
EditorGUI.PropertyField(position, property, label);
49+
if (IsControlEditing(key))
50+
{
51+
position.width = 0;
52+
position.height = 0;
53+
}
54+
else
55+
{
56+
position.xMin += EditorGUIUtility.labelWidth + EditorGUIUtility.standardVerticalSpacing;
57+
}
58+
59+
var targetAttribute = attribute as FormattedNumberAttribute;
60+
var single = GetSingle(property);
61+
var format = GetFormat(property, targetAttribute);
62+
63+
try
64+
{
65+
EditorGUI.TextField(position, single.ToString(format, formatInfo));
66+
}
67+
catch (FormatException)
68+
{
69+
ToolboxEditorLog.AttributeUsageWarning(attribute, property, string.Format("{0} format is not supported.", format));
70+
}
71+
}
72+
73+
74+
public override bool IsPropertyValid(SerializedProperty property)
75+
{
76+
return property.propertyType == SerializedPropertyType.Integer ||
77+
property.propertyType == SerializedPropertyType.Float;
78+
}
79+
}
80+
}

Assets/Editor Toolbox/Scripts/Attributes/RegularAttributes/IndentAttribute.cs.meta renamed to Assets/Editor Toolbox/Editor/Drawers/RegularDrawers/FormattedNumberAttributeDrawer.cs.meta

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Editor Toolbox/Editor/Drawers/RegularDrawers/LabelByChildAttributeDrawer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,12 @@ protected override void OnGUISafe(Rect position, SerializedProperty property, GU
8888
//validate availability of the child property
8989
if (childProperty != null)
9090
{
91-
//set new label if found (unknown values will be ignored)
91+
//set new label if found (unknown types will be ignored)
9292
label = GetLabelByValue(childProperty, label);
9393
}
9494
else
9595
{
96-
ToolboxEditorLog.AttributeUsageWarning(attribute, property, propertyName + " does not exists.");
96+
ToolboxEditorLog.AttributeUsageWarning(attribute, property, string.Format("{0} does not exists.", propertyName));
9797
}
9898

9999
EditorGUI.PropertyField(position, property, label, property.isExpanded);

0 commit comments

Comments
 (0)