Skip to content
This repository has been archived by the owner on Aug 24, 2024. It is now read-only.

Clean up #109

Merged
merged 2 commits into from
Mar 3, 2024
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
6 changes: 4 additions & 2 deletions Assets/BetterAttributes/Editor/BetterAttributes.Editor.asmdef
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
{
"name": "BetterAttributes.Editor",
"rootNamespace": "Better.Attributes",
"rootNamespace": "Better.Attributes.EditorAddons",
"references": [
"GUID:35101f455c979e94c9a0a4793484b7fd",
"GUID:28da8d3b12e3efa47928e0c9070f853d",
"GUID:19891d5296046644cbc12fcf3702cca3",
"GUID:443314a5a4e67c14a88ae223776b6554",
"GUID:a59e3daedde9ca94bba45364d4ead25f"
"GUID:a59e3daedde9ca94bba45364d4ead25f",
"GUID:01df13aca8d01e24a911bcc3e8277031",
"GUID:1ac867a6259e45a1856740fe8f7623aa"
],
"includePlatforms": [
"Editor"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Linq;
using System.Reflection;
using Better.Attributes.Runtime;
using Better.EditorTools.CustomEditors;
using Better.EditorTools.EditorAddons.CustomEditors;
using Better.Extensions.Runtime;
using UnityEditor;
using UnityEngine;
Expand All @@ -27,7 +27,7 @@ public override void OnDisable()
public override void OnEnable()
{
var type = _target.GetType();
_methodButtonsAttributes = type.GetSortedMethodAttributes();
_methodButtonsAttributes = EditorButtonUtility.GetSortedMethodAttributes(type);
}

private void DrawButton(KeyValuePair<MethodInfo, EditorButtonAttribute> button, GUIStyle guiStyle)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System.Reflection;
using Better.Attributes.EditorAddons.Drawers.Gizmo;
using Better.Attributes.Runtime.Gizmo;
using Better.EditorTools;
using Better.EditorTools.CustomEditors;
using Better.EditorTools.EditorAddons.CustomEditors;
using Better.Extensions.EditorAddons;
using UnityEditor;
using UnityEngine;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
using System;
using System.Reflection;
using System.Reflection;
using Better.Attributes.EditorAddons.Drawers.Utilities;
using Better.Attributes.EditorAddons.Drawers.WrapperCollections;
using Better.Attributes.Runtime.DrawInspector;
using Better.EditorTools.Attributes;
using Better.EditorTools.Drawers.Base;
using Better.EditorTools.Helpers;
using Better.Tools.Runtime.Attributes;
using Better.EditorTools.EditorAddons.Attributes;
using Better.EditorTools.EditorAddons.Drawers.Base;
using Better.EditorTools.EditorAddons.Helpers;
using Better.EditorTools.Runtime.Attributes;
using UnityEditor;
using UnityEngine;

Expand Down Expand Up @@ -56,15 +55,15 @@ protected override bool PreDraw(ref Rect position, SerializedProperty property,
return true;
}

protected override HeightCache GetPropertyHeight(SerializedProperty property, GUIContent label)
protected override HeightCacheValue GetPropertyHeight(SerializedProperty property, GUIContent label)
{
var additionalHeight = 0f;
if (Collection != null && Collection.IsOpen(property))
{
additionalHeight = Collection.GetHeight(property);
}

return HeightCache.GetAdditive(additionalHeight);
return HeightCacheValue.GetAdditive(additionalHeight);
}

protected override Rect PreparePropertyRect(Rect original)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using Better.EditorTools.Helpers;
using Better.EditorTools.Utilities;
using Better.EditorTools.EditorAddons.Helpers;
using Better.EditorTools.EditorAddons.Utilities;
using UnityEditor;
using UnityEngine;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
using System;
using System.Reflection;
using System.Text.RegularExpressions;
using Better.Attributes.EditorAddons.Drawers.Utilities;
using Better.EditorTools;
using Better.EditorTools.Drawers.Base;
using Better.EditorTools.Utilities;
using Better.EditorTools.EditorAddons.Drawers.Base;
using Better.EditorTools.EditorAddons.Utilities;
using Better.Extensions.EditorAddons;
using Better.Extensions.Runtime;
using UnityEditor;
using UnityEngine;
using Object = UnityEngine.Object;
#if UNITY_2022_1_OR_NEWER
using GizmoUtility = Better.Attributes.EditorAddons.Drawers.Utilities.GizmoUtility;
#endif
Expand Down Expand Up @@ -105,7 +103,7 @@ private protected void SetValueAndApply(object value)
else if (_fieldType.IsEquivalentTo(typeof(Quaternion)))
_serializedProperty.quaternionValue = (Quaternion)value;
else
throw new ArgumentOutOfRangeException();
DebugUtility.LogException<ArgumentOutOfRangeException>();

_serializedProperty.serializedObject.ApplyModifiedProperties();
}
Expand All @@ -132,9 +130,9 @@ private protected virtual Vector3 GetPosition(Vector3 position, Quaternion rotat
sceneView.camera.transform.right * 0.2f * HandleUtility.GetHandleSize(position));
}

public virtual HeightCache GetHeight(GUIContent label)
public virtual HeightCacheValue GetHeight(GUIContent label)
{
return HeightCache.GetAdditive(0f);
return HeightCacheValue.GetAdditive(0f);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
using System.Reflection;
using Better.Attributes.EditorAddons.Drawers.WrapperCollections;
using Better.Attributes.Runtime.Gizmo;
using Better.EditorTools;
using Better.EditorTools.Attributes;
using Better.EditorTools.Drawers.Base;
using Better.EditorTools.Helpers;
using Better.EditorTools.Utilities;
using Better.Tools.Runtime.Attributes;
using Better.EditorTools.EditorAddons.Attributes;
using Better.EditorTools.EditorAddons.Drawers.Base;
using Better.EditorTools.EditorAddons.Helpers;
using Better.EditorTools.Runtime.Attributes;
using UnityEditor;
using UnityEngine;

Expand Down Expand Up @@ -148,14 +146,14 @@ private Rect PrepareButtonRect(Rect original)
return copy;
}

protected override HeightCache GetPropertyHeight(SerializedProperty property, GUIContent label)
protected override HeightCacheValue GetPropertyHeight(SerializedProperty property, GUIContent label)
{
var fieldType = GetFieldOrElementType();
if (!GizmoUtility.Instance.IsSupported(fieldType))
{
var message = DrawersHelper.NotSupportedMessage(property.name, fieldType, _attribute.GetType());
var additive = DrawersHelper.GetHelpBoxHeight(EditorGUIUtility.currentViewWidth, message, IconType.WarningMessage);
return HeightCache.GetAdditive(additive + DrawersHelper.SpaceHeight * 2);
return HeightCacheValue.GetAdditive(additive + DrawersHelper.SpaceHeight * 2);
}

return Collection.GetHeight(property, label);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ public class HideTransformButtonUtility
{
public void DrawHideTransformButton()
{
var text = UnityEditor.Tools.hidden ? "Show" : "Hide";
var text = Tools.hidden ? "Show" : "Hide";
if (GUILayout.Button($"{text} Transform handles"))
{
UnityEditor.Tools.hidden = !UnityEditor.Tools.hidden;
Tools.hidden = !Tools.hidden;
SceneView.RepaintAll();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Better.EditorTools;
using Better.Extensions.Runtime.MathfExtensions;
using Better.Extensions.EditorAddons;
using Better.Extensions.Runtime;
using UnityEditor;
using UnityEngine;

Expand All @@ -20,7 +20,7 @@ public override void Apply(SceneView sceneView)
ValidateSize(size);
Handles.DrawWireCube(worldPosition, size);

if (!Vector3Math.Approximately(_bounds.center, center) || !Vector3Math.Approximately(_bounds.size, size))
if (!Vector3Utility.Approximately(_bounds.center, center) || !Vector3Utility.Approximately(_bounds.size, size))
{
_bounds.center = center;
_bounds.size = size;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using Better.EditorTools;
using Better.EditorTools.Drawers.Base;
using Better.Extensions.Runtime.MathfExtensions;
using Better.EditorTools.EditorAddons.Drawers.Base;
using Better.Extensions.EditorAddons;
using Better.Extensions.Runtime;
using UnityEditor;
using UnityEngine;

Expand All @@ -20,14 +20,19 @@ public override void Apply(SceneView sceneView)
var transform = component.transform;
var rotation = transform.rotation;
var position = transform.position;
var worldRotation = Vector3Math.Validate(rotation * _quaternion);
var worldRotation = (rotation * _quaternion);
if (!worldRotation.IsNormalized())
{
worldRotation = Quaternion.identity;
}

DrawLabel($"Local {GetName()}:\n{_quaternion.eulerAngles}", position, worldRotation, sceneView);
var buffer = Quaternion.Inverse(rotation) * Handles.RotationHandle(worldRotation, position);

Handles.ArrowHandleCap(GUIUtility.GetControlID(FocusType.Passive), position, worldRotation, Size * HandleUtility.GetHandleSize(position),
EventType.Repaint);

if (!Vector3Math.Approximately(_quaternion, buffer))
if (!_quaternion.Approximately(buffer))
{
_quaternion = buffer;
SetValueAndApply(_quaternion);
Expand All @@ -52,9 +57,9 @@ public override void DrawField(Rect position, GUIContent label)
}
}

public override HeightCache GetHeight(GUIContent label)
public override HeightCacheValue GetHeight(GUIContent label)
{
return HeightCache.GetFull(EditorGUIUtility.singleLineHeight);
return HeightCacheValue.GetFull(EditorGUIUtility.singleLineHeight);
}

public override void SetProperty(SerializedProperty property, Type fieldType)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using Better.EditorTools;
using Better.Extensions.Runtime.MathfExtensions;
using Better.Extensions.EditorAddons;
using Better.Extensions.Runtime;
using UnityEditor;
using UnityEngine;

Expand All @@ -20,7 +20,7 @@ public override void Apply(SceneView sceneView)
DrawLabel($"Local {GetName()}:\n{_vector2}", _vector2, _defaultRotation, sceneView);
var buffer = transform.InverseTransformPoint(Handles.PositionHandle(worldPosition, _defaultRotation));

if (!Vector3Math.Approximately(_vector2, (Vector2)buffer))
if (!_vector2.Approximately(buffer))
{
_vector2 = buffer;
SetValueAndApply(_vector2);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using Better.EditorTools;
using Better.Extensions.Runtime.MathfExtensions;
using Better.Extensions.EditorAddons;
using Better.Extensions.Runtime;
using UnityEditor;
using UnityEngine;

Expand All @@ -20,7 +20,7 @@ public override void Apply(SceneView sceneView)
DrawLabel($"Local {GetName()}:\n{_vector3}", worldPosition, _defaultRotation, sceneView);
var buffer = transform.InverseTransformPoint(Handles.PositionHandle(worldPosition, _defaultRotation));

if (!Vector3Math.Approximately(_vector3, buffer))
if (!_vector3.Approximately(buffer))
{
_vector3 = buffer;
SetValueAndApply(_vector3);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Better.Extensions.Runtime.MathfExtensions;
using Better.Extensions.Runtime;
using UnityEditor;

namespace Better.Attributes.EditorAddons.Drawers.Gizmo
Expand All @@ -14,7 +14,7 @@ public override void Apply(SceneView sceneView)
ValidateSize(size);
Handles.DrawWireCube(center, size);

if (!Vector3Math.Approximately(_bounds.center, center) || !Vector3Math.Approximately(_bounds.size, size))
if (!_bounds.center.Approximately(center) || !_bounds.size.Approximately(size))
{
_bounds.center = center;
_bounds.size = size;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using Better.EditorTools.Drawers.Base;
using Better.Extensions.Runtime.MathfExtensions;
using Better.EditorTools.EditorAddons.Drawers.Base;
using Better.Extensions.Runtime;
using UnityEditor;
using UnityEngine;

Expand All @@ -15,19 +15,23 @@ public override void Apply(SceneView sceneView)
{
if (!ShowInSceneView) return;
DrawLabel($"{GetName()}:\n{_quaternion.eulerAngles}", _defaultPosition, _quaternion, sceneView);
_quaternion = Vector3Math.Validate(_quaternion);
if (!_quaternion.IsNormalized())
{
_quaternion = Quaternion.identity;
}

var buffer = Handles.RotationHandle(_quaternion, _defaultPosition);

Handles.ArrowHandleCap(GUIUtility.GetControlID(FocusType.Passive), _defaultPosition, buffer, Size * HandleUtility.GetHandleSize(_defaultPosition),
EventType.Repaint);

if (!Vector3Math.Approximately(_quaternion, buffer))
if (!_quaternion.Approximately(buffer))
{
_quaternion = buffer;
SetValueAndApply(_quaternion);
}
}

public override void DrawField(Rect position, GUIContent label)
{
using (var change = new EditorGUI.ChangeCheckScope())
Expand All @@ -41,9 +45,9 @@ public override void DrawField(Rect position, GUIContent label)
}
}

public override HeightCache GetHeight(GUIContent label)
public override HeightCacheValue GetHeight(GUIContent label)
{
return HeightCache.GetFull(EditorGUIUtility.singleLineHeight);
return HeightCacheValue.GetFull(EditorGUIUtility.singleLineHeight);
}

public override void SetProperty(SerializedProperty property, Type fieldType)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System;
using Better.Extensions.Runtime.MathfExtensions;
using Better.Extensions.Runtime;
using UnityEditor;
using UnityEngine;

Expand All @@ -14,8 +14,8 @@ public override void Apply(SceneView sceneView)
if (!ShowInSceneView) return;
DrawLabel($"{GetName()}:\n{_vector2}", _vector2, _defaultRotation, sceneView);
var buffer = Handles.PositionHandle(_vector2, _defaultRotation);
if (!Vector3Math.Approximately(_vector2, (Vector2)buffer))

if (!_vector2.Approximately(buffer))
{
_vector2 = buffer;
SetValueAndApply(_vector2);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System;
using Better.Extensions.Runtime.MathfExtensions;
using Better.Extensions.Runtime;
using UnityEditor;
using UnityEngine;

Expand All @@ -15,7 +15,7 @@ public override void Apply(SceneView sceneView)
DrawLabel($"{GetName()}:\n{_vector3}", _vector3, _defaultRotation, sceneView);
var buffer = Handles.PositionHandle(_vector3, _defaultRotation);

if (!Vector3Math.Approximately(_vector3, buffer))
if (!_vector3.Approximately(buffer))
{
_vector3 = buffer;
SetValueAndApply(_vector3);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
using Better.Attributes.EditorAddons.Drawers.Manipulation.Wrappers;
using Better.Attributes.EditorAddons.Drawers.Utilities;
using Better.Attributes.Runtime.Manipulation;
using Better.EditorTools.Attributes;
using Better.EditorTools.Drawers.Base;
using Better.Tools.Runtime.Attributes;
using Better.EditorTools.EditorAddons.Attributes;
using Better.EditorTools.EditorAddons.Drawers.Base;
using Better.EditorTools.Runtime.Attributes;
using UnityEditor;
using UnityEngine;

Expand Down Expand Up @@ -42,7 +42,7 @@ protected override Rect PreparePropertyRect(Rect original)
return original;
}

protected override HeightCache GetPropertyHeight(SerializedProperty property, GUIContent label)
protected override HeightCacheValue GetPropertyHeight(SerializedProperty property, GUIContent label)
{
var wrapper = GetWrapper(property);
return wrapper.GetHeight();
Expand Down
Loading
Loading