Skip to content

Commit 593d5cf

Browse files
authored
Merge pull request #30 from arimger/develop
Develop - 0.10.6
2 parents 29f34f6 + 88f002f commit 593d5cf

29 files changed

+341
-89
lines changed

Assets/Editor Toolbox/CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
## 0.10.6 [30.11.2021]
2+
3+
### Added:
4+
- DynamicRangeSliderAttribute
5+
- SerializedDateTime
6+
7+
### Changed:
8+
- Fix disposing inlined Editors in ScriptableObjects-based Inspectors
9+
- Fix disabling "Edit" button when inlined Editor is disabled
10+
- Fix relative path when ToolboxEditorSettings is created manually
11+
112
## 0.10.4 [27.10.2021]
213

314
### Added:
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System;
2+
using UnityEditor;
3+
using UnityEngine;
4+
5+
namespace Toolbox.Editor.Drawers
6+
{
7+
[CustomPropertyDrawer(typeof(SerializedDateTime))]
8+
public class SerializedDateTimeDrawer : PropertyDrawerBase
9+
{
10+
protected override void OnGUISafe(Rect position, SerializedProperty property, GUIContent label)
11+
{
12+
label = EditorGUI.BeginProperty(position, label, property);
13+
var fieldPosition = EditorGUI.PrefixLabel(position, label);
14+
var ticksProperty = property.FindPropertyRelative("ticks");
15+
DateTime dateTime = new DateTime(ticksProperty.longValue);
16+
EditorGUI.BeginChangeCheck();
17+
var dateTimeString = EditorGUI.DelayedTextField(fieldPosition, dateTime.ToString());
18+
if (EditorGUI.EndChangeCheck())
19+
{
20+
if (DateTime.TryParse(dateTimeString, out var newDateTime))
21+
{
22+
ticksProperty.serializedObject.Update();
23+
ticksProperty.longValue = newDateTime.Ticks;
24+
ticksProperty.serializedObject.ApplyModifiedProperties();
25+
}
26+
}
27+
28+
EditorGUI.EndProperty();
29+
}
30+
}
31+
}

Assets/Editor Toolbox/Editor/Drawers/Regular/SerializedDateTimeDrawer.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.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using System;
2+
3+
using UnityEditor;
4+
using UnityEngine;
5+
6+
namespace Toolbox.Editor.Drawers
7+
{
8+
public abstract class DynamicMinMaxBaseDrawer<T> : ToolboxSelfPropertyDrawer<T> where T : DynamicMinMaxBaseAttribute
9+
{
10+
protected override void OnGuiSafe(SerializedProperty property, GUIContent label, T attribute)
11+
{
12+
var minValueSource = attribute.MinValueSource;
13+
var maxValueSource = attribute.MaxValueSource;
14+
if (!ValueExtractionHelper.TryGetValue(minValueSource, property, out var minValueCandidate, out _) ||
15+
!ValueExtractionHelper.TryGetValue(maxValueSource, property, out var maxValueCandidate, out _))
16+
{
17+
ToolboxEditorLog.MemberNotFoundWarning(attribute, property,
18+
string.Format("{0} or {1}", minValueSource, maxValueSource));
19+
base.OnGuiSafe(property, label, attribute);
20+
return;
21+
}
22+
23+
float minValue;
24+
float maxValue;
25+
try
26+
{
27+
minValue = Convert.ToSingle(minValueCandidate);
28+
maxValue = Convert.ToSingle(maxValueCandidate);
29+
}
30+
catch (Exception e) when (e is InvalidCastException || e is FormatException)
31+
{
32+
ToolboxEditorLog.AttributeUsageWarning(attribute, property,
33+
string.Format("Invalid source types, cannot convert them to {0}", typeof(float)));
34+
base.OnGuiSafe(property, label, attribute);
35+
return;
36+
}
37+
38+
OnGuiSafe(property, label, minValue, maxValue);
39+
}
40+
41+
protected abstract void OnGuiSafe(SerializedProperty property, GUIContent label, float minValue, float maxValue);
42+
}
43+
}

Assets/Editor Toolbox/Editor/Drawers/Toolbox/PropertySelfDrawers/DynamicMinMaxBaseDrawer.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.

Assets/Editor Toolbox/Editor/Drawers/Toolbox/PropertySelfDrawers/DynamicMinMaxSliderAttributeDrawer.cs

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,12 @@
1-
using System;
2-
31
using UnityEditor;
42
using UnityEngine;
53

64
namespace Toolbox.Editor.Drawers
75
{
8-
public class DynamicMinMaxSliderAttributeDrawer : ToolboxSelfPropertyDrawer<DynamicMinMaxSliderAttribute>
6+
public class DynamicMinMaxSliderAttributeDrawer : DynamicMinMaxBaseDrawer<DynamicMinMaxSliderAttribute>
97
{
10-
protected override void OnGuiSafe(SerializedProperty property, GUIContent label, DynamicMinMaxSliderAttribute attribute)
8+
protected override void OnGuiSafe(SerializedProperty property, GUIContent label, float minValue, float maxValue)
119
{
12-
var minValueSource = attribute.MinValueSource;
13-
var maxValueSource = attribute.MaxValueSource;
14-
if (!ValueExtractionHelper.TryGetValue(minValueSource, property, out var minValueCandidate, out _) ||
15-
!ValueExtractionHelper.TryGetValue(maxValueSource, property, out var maxValueCandidate, out _))
16-
{
17-
ToolboxEditorLog.MemberNotFoundWarning(attribute, property,
18-
string.Format("{0} or {1}", minValueSource, maxValueSource));
19-
base.OnGuiSafe(property, label, attribute);
20-
return;
21-
}
22-
23-
var maxValue = 0.0f;
24-
var minValue = 0.0f;
25-
try
26-
{
27-
minValue = Convert.ToSingle(minValueCandidate);
28-
maxValue = Convert.ToSingle(maxValueCandidate);
29-
}
30-
catch (Exception e) when (e is InvalidCastException || e is FormatException)
31-
{
32-
ToolboxEditorLog.AttributeUsageWarning(attribute, property,
33-
string.Format("Invalid source types, cannot convert them to {0}", typeof(float)));
34-
}
35-
3610
var xValue = property.vector2Value.x;
3711
var yValue = property.vector2Value.y;
3812
ToolboxEditorGui.BeginProperty(property, ref label, out var position);
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using UnityEditor;
2+
using UnityEngine;
3+
4+
namespace Toolbox.Editor.Drawers
5+
{
6+
public class DynamicRangeAttributeDrawer : DynamicMinMaxBaseDrawer<DynamicRangeAttribute>
7+
{
8+
protected override void OnGuiSafe(SerializedProperty property, GUIContent label, float minValue, float maxValue)
9+
{
10+
ToolboxEditorGui.BeginProperty(property, ref label, out var position);
11+
EditorGUI.BeginChangeCheck();
12+
switch (property.propertyType)
13+
{
14+
case SerializedPropertyType.Integer:
15+
var intValue = EditorGUI.IntSlider(position, label, property.intValue, (int)minValue, (int)maxValue);
16+
if (EditorGUI.EndChangeCheck())
17+
{
18+
property.intValue = intValue;
19+
}
20+
break;
21+
case SerializedPropertyType.Float:
22+
var floatValue = EditorGUI.Slider(position, label, property.floatValue, minValue, maxValue);
23+
if (EditorGUI.EndChangeCheck())
24+
{
25+
property.floatValue = floatValue;
26+
}
27+
break;
28+
default:
29+
break;
30+
}
31+
32+
ToolboxEditorGui.CloseProperty();
33+
}
34+
35+
36+
public override bool IsPropertyValid(SerializedProperty property)
37+
{
38+
return property.propertyType == SerializedPropertyType.Integer ||
39+
property.propertyType == SerializedPropertyType.Float;
40+
}
41+
}
42+
}

Assets/Editor Toolbox/Editor/Drawers/Toolbox/PropertySelfDrawers/DynamicRangeAttributeDrawer.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.

Assets/Editor Toolbox/Editor/Drawers/Toolbox/PropertySelfDrawers/InLineEditorAttributeDrawer.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ private Editor GetTargetsEditor(SerializedProperty property, InLineEditorAttribu
5252

5353
private bool GetInspectorToggle(SerializedProperty property)
5454
{
55-
return GUILayout.Toggle(property.isExpanded, Style.foldoutContent, Style.foldoutStyle, Style.foldoutOptions);
55+
using (new DisabledScope(true))
56+
{
57+
return GUILayout.Toggle(property.isExpanded, Style.foldoutContent, Style.foldoutStyle, Style.foldoutOptions);
58+
}
5659
}
5760

5861
private void DrawEditor(Editor editor, InLineEditorAttribute attribute)

Assets/Editor Toolbox/Editor/ToolboxManager.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using UnityEditor;
1+
using System.IO;
2+
using UnityEditor;
23
using UnityEngine;
34

45
namespace Toolbox.Editor
@@ -36,8 +37,6 @@ private static void ManageProjectCore(IToolboxProjectSettings settings)
3637
return;
3738
}
3839

39-
var validateData = !IsInitialized;
40-
4140
//enable/disable the core GUI function
4241
ToolboxEditorProject.IsOverlayAllowed = settings.UseToolboxProject;
4342

@@ -160,15 +159,15 @@ void ReintializeProvider()
160159

161160
//rebuild the settings provider right after initialization
162161
provider.OnDeactivate();
163-
provider.OnActivate("", null);
162+
provider.OnActivate(string.Empty, null);
164163
}
165164

166165
provider.guiHandler = (searchContext) =>
167166
{
168167
if (globalSettingsEditor == null || globalSettingsEditor.serializedObject.targetObject == null)
169168
{
170169
EditorGUILayout.Space();
171-
EditorGUILayout.LabelField("Cannot find " + settingsType + " file located in this Project");
170+
EditorGUILayout.LabelField(string.Format("Cannot find {0} file located in this Project", settingsType));
172171
EditorGUILayout.Space();
173172

174173
if (GUILayout.Button("Create a new settings file"))
@@ -182,9 +181,8 @@ void ReintializeProvider()
182181
return;
183182
}
184183

185-
var relativePath = locationPath
186-
.Substring(locationPath
187-
.IndexOf("Assets/")) + "/" + settingsType + ".asset";
184+
var assetName = string.Format("{0}.asset", settingsType);
185+
var relativePath = Path.Combine(FileUtil.GetProjectRelativePath(locationPath), assetName);
188186

189187
AssetDatabase.CreateAsset(settingsInstance, relativePath);
190188
AssetDatabase.SaveAssets();

0 commit comments

Comments
 (0)