Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Assets/Editor Toolbox/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
## 0.10.6 [30.11.2021]

### Added:
- DynamicRangeSliderAttribute
- SerializedDateTime

### Changed:
- Fix disposing inlined Editors in ScriptableObjects-based Inspectors
- Fix disabling "Edit" button when inlined Editor is disabled
- Fix relative path when ToolboxEditorSettings is created manually

## 0.10.4 [27.10.2021]

### Added:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;
using UnityEditor;
using UnityEngine;

namespace Toolbox.Editor.Drawers
{
[CustomPropertyDrawer(typeof(SerializedDateTime))]
public class SerializedDateTimeDrawer : PropertyDrawerBase
{
protected override void OnGUISafe(Rect position, SerializedProperty property, GUIContent label)
{
label = EditorGUI.BeginProperty(position, label, property);
var fieldPosition = EditorGUI.PrefixLabel(position, label);
var ticksProperty = property.FindPropertyRelative("ticks");
DateTime dateTime = new DateTime(ticksProperty.longValue);
EditorGUI.BeginChangeCheck();
var dateTimeString = EditorGUI.DelayedTextField(fieldPosition, dateTime.ToString());
if (EditorGUI.EndChangeCheck())
{
if (DateTime.TryParse(dateTimeString, out var newDateTime))
{
ticksProperty.serializedObject.Update();
ticksProperty.longValue = newDateTime.Ticks;
ticksProperty.serializedObject.ApplyModifiedProperties();
}
}

EditorGUI.EndProperty();
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System;

using UnityEditor;
using UnityEngine;

namespace Toolbox.Editor.Drawers
{
public abstract class DynamicMinMaxBaseDrawer<T> : ToolboxSelfPropertyDrawer<T> where T : DynamicMinMaxBaseAttribute
{
protected override void OnGuiSafe(SerializedProperty property, GUIContent label, T attribute)
{
var minValueSource = attribute.MinValueSource;
var maxValueSource = attribute.MaxValueSource;
if (!ValueExtractionHelper.TryGetValue(minValueSource, property, out var minValueCandidate, out _) ||
!ValueExtractionHelper.TryGetValue(maxValueSource, property, out var maxValueCandidate, out _))
{
ToolboxEditorLog.MemberNotFoundWarning(attribute, property,
string.Format("{0} or {1}", minValueSource, maxValueSource));
base.OnGuiSafe(property, label, attribute);
return;
}

float minValue;
float maxValue;
try
{
minValue = Convert.ToSingle(minValueCandidate);
maxValue = Convert.ToSingle(maxValueCandidate);
}
catch (Exception e) when (e is InvalidCastException || e is FormatException)
{
ToolboxEditorLog.AttributeUsageWarning(attribute, property,
string.Format("Invalid source types, cannot convert them to {0}", typeof(float)));
base.OnGuiSafe(property, label, attribute);
return;
}

OnGuiSafe(property, label, minValue, maxValue);
}

protected abstract void OnGuiSafe(SerializedProperty property, GUIContent label, float minValue, float maxValue);
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,38 +1,12 @@
using System;

using UnityEditor;
using UnityEngine;

namespace Toolbox.Editor.Drawers
{
public class DynamicMinMaxSliderAttributeDrawer : ToolboxSelfPropertyDrawer<DynamicMinMaxSliderAttribute>
public class DynamicMinMaxSliderAttributeDrawer : DynamicMinMaxBaseDrawer<DynamicMinMaxSliderAttribute>
{
protected override void OnGuiSafe(SerializedProperty property, GUIContent label, DynamicMinMaxSliderAttribute attribute)
protected override void OnGuiSafe(SerializedProperty property, GUIContent label, float minValue, float maxValue)
{
var minValueSource = attribute.MinValueSource;
var maxValueSource = attribute.MaxValueSource;
if (!ValueExtractionHelper.TryGetValue(minValueSource, property, out var minValueCandidate, out _) ||
!ValueExtractionHelper.TryGetValue(maxValueSource, property, out var maxValueCandidate, out _))
{
ToolboxEditorLog.MemberNotFoundWarning(attribute, property,
string.Format("{0} or {1}", minValueSource, maxValueSource));
base.OnGuiSafe(property, label, attribute);
return;
}

var maxValue = 0.0f;
var minValue = 0.0f;
try
{
minValue = Convert.ToSingle(minValueCandidate);
maxValue = Convert.ToSingle(maxValueCandidate);
}
catch (Exception e) when (e is InvalidCastException || e is FormatException)
{
ToolboxEditorLog.AttributeUsageWarning(attribute, property,
string.Format("Invalid source types, cannot convert them to {0}", typeof(float)));
}

var xValue = property.vector2Value.x;
var yValue = property.vector2Value.y;
ToolboxEditorGui.BeginProperty(property, ref label, out var position);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using UnityEditor;
using UnityEngine;

namespace Toolbox.Editor.Drawers
{
public class DynamicRangeAttributeDrawer : DynamicMinMaxBaseDrawer<DynamicRangeAttribute>
{
protected override void OnGuiSafe(SerializedProperty property, GUIContent label, float minValue, float maxValue)
{
ToolboxEditorGui.BeginProperty(property, ref label, out var position);
EditorGUI.BeginChangeCheck();
switch (property.propertyType)
{
case SerializedPropertyType.Integer:
var intValue = EditorGUI.IntSlider(position, label, property.intValue, (int)minValue, (int)maxValue);
if (EditorGUI.EndChangeCheck())
{
property.intValue = intValue;
}
break;
case SerializedPropertyType.Float:
var floatValue = EditorGUI.Slider(position, label, property.floatValue, minValue, maxValue);
if (EditorGUI.EndChangeCheck())
{
property.floatValue = floatValue;
}
break;
default:
break;
}

ToolboxEditorGui.CloseProperty();
}


public override bool IsPropertyValid(SerializedProperty property)
{
return property.propertyType == SerializedPropertyType.Integer ||
property.propertyType == SerializedPropertyType.Float;
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ private Editor GetTargetsEditor(SerializedProperty property, InLineEditorAttribu

private bool GetInspectorToggle(SerializedProperty property)
{
return GUILayout.Toggle(property.isExpanded, Style.foldoutContent, Style.foldoutStyle, Style.foldoutOptions);
using (new DisabledScope(true))
{
return GUILayout.Toggle(property.isExpanded, Style.foldoutContent, Style.foldoutStyle, Style.foldoutOptions);
}
}

private void DrawEditor(Editor editor, InLineEditorAttribute attribute)
Expand Down
14 changes: 6 additions & 8 deletions Assets/Editor Toolbox/Editor/ToolboxManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using UnityEditor;
using System.IO;
using UnityEditor;
using UnityEngine;

namespace Toolbox.Editor
Expand Down Expand Up @@ -36,8 +37,6 @@ private static void ManageProjectCore(IToolboxProjectSettings settings)
return;
}

var validateData = !IsInitialized;

//enable/disable the core GUI function
ToolboxEditorProject.IsOverlayAllowed = settings.UseToolboxProject;

Expand Down Expand Up @@ -160,15 +159,15 @@ void ReintializeProvider()

//rebuild the settings provider right after initialization
provider.OnDeactivate();
provider.OnActivate("", null);
provider.OnActivate(string.Empty, null);
}

provider.guiHandler = (searchContext) =>
{
if (globalSettingsEditor == null || globalSettingsEditor.serializedObject.targetObject == null)
{
EditorGUILayout.Space();
EditorGUILayout.LabelField("Cannot find " + settingsType + " file located in this Project");
EditorGUILayout.LabelField(string.Format("Cannot find {0} file located in this Project", settingsType));
EditorGUILayout.Space();

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

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

AssetDatabase.CreateAsset(settingsInstance, relativePath);
AssetDatabase.SaveAssets();
Expand Down
6 changes: 4 additions & 2 deletions Assets/Editor Toolbox/Editor/Utilities/InspectorUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ static InspectorUtility()
}


private static int lastCachedEditorId;
private static Editor lastCachedEditor;
private static readonly Stack<Editor> cachedEditors = new Stack<Editor>();


private static void OnBeginEditor(Editor editor)
{
lastCachedEditor = editor;
cachedEditors.Push(editor);
}

Expand All @@ -53,8 +53,10 @@ private static void OnCloseEditor(Editor editor)
private static void CheckReloads(Editor editor)
{
//NOTE: it means that last Editor was null or disposed, anyway we probably want to reload drawers-related cache
if (lastCachedEditor == null)
if (lastCachedEditor == null || lastCachedEditorId != lastCachedEditor.GetInstanceID())
{
lastCachedEditor = editor;
lastCachedEditorId = editor.GetInstanceID();
OnEditorReload?.Invoke();
}
}
Expand Down
1 change: 1 addition & 0 deletions Assets/Editor Toolbox/EditorSettings.asset
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ MonoBehaviour:
- classReference: Toolbox.Editor.Drawers.ShowWarningIfAttributeDrawer, Toolbox-Editor
selfPropertyDrawerHandlers:
- classReference: Toolbox.Editor.Drawers.DynamicMinMaxSliderAttributeDrawer, Toolbox-Editor
- classReference: Toolbox.Editor.Drawers.DynamicRangeAttributeDrawer, Toolbox-Editor
- classReference: Toolbox.Editor.Drawers.IgnoreParentAttributeDrawer, Toolbox-Editor
- classReference: Toolbox.Editor.Drawers.InLineEditorAttributeDrawer, Toolbox-Editor
- classReference: Toolbox.Editor.Drawers.RegexValueAttributeDrawer, Toolbox-Editor
Expand Down
4 changes: 4 additions & 0 deletions Assets/Editor Toolbox/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,10 @@ public void Usage()
#endif
```

#### SerializedDateTime

Allows to serialize DateTime.

![inspector](https://github.com/arimger/Unity-Editor-Toolbox/blob/develop/Docs/dictionary1.png)

![inspector](https://github.com/arimger/Unity-Editor-Toolbox/blob/develop/Docs/dictionary2.png)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace UnityEngine
{
public abstract class DynamicMinMaxBaseAttribute : ToolboxSelfPropertyAttribute
{
protected DynamicMinMaxBaseAttribute(string minValueSource, string maxValueSource)
{
MinValueSource = minValueSource;
MaxValueSource = maxValueSource;
}

public string MinValueSource { get; protected set; }

public string MaxValueSource { get; protected set; }
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,9 @@
namespace UnityEngine
{
[AttributeUsage(AttributeTargets.Field, AllowMultiple = false)]
public class DynamicMinMaxSliderAttribute : ToolboxSelfPropertyAttribute
public class DynamicMinMaxSliderAttribute : DynamicMinMaxBaseAttribute
{
public DynamicMinMaxSliderAttribute(string minValueSource, string maxValueSource)
{
MinValueSource = minValueSource;
MaxValueSource = maxValueSource;
}

public string MinValueSource { get; private set; }

public string MaxValueSource { get; private set; }
public DynamicMinMaxSliderAttribute(string minValueSource, string maxValueSource) : base(minValueSource, maxValueSource)
{ }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;

namespace UnityEngine
{
[AttributeUsage(AttributeTargets.Field, AllowMultiple = false)]
public class DynamicRangeAttribute : DynamicMinMaxBaseAttribute
{
public DynamicRangeAttribute(string minValueSource, string maxValueSource) : base(minValueSource, maxValueSource)
{ }
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading