Skip to content

Commit

Permalink
Update README.md and LICENSE
Browse files Browse the repository at this point in the history
  • Loading branch information
uurha committed Aug 12, 2024
0 parents commit 524386b
Show file tree
Hide file tree
Showing 360 changed files with 8,600 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Editor.meta

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

21 changes: 21 additions & 0 deletions Editor/BetterAttributes.Editor.asmdef
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "BetterAttributes.Editor",
"rootNamespace": "Better.Attributes.EditorAddons",
"references": [
"GUID:35101f455c979e94c9a0a4793484b7fd",
"GUID:01df13aca8d01e24a911bcc3e8277031",
"GUID:8bd4b41f8da90144d9006c4d926c9679",
"GUID:55fbe2a01ca11514f94a66e7102c8895"
],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}
7 changes: 7 additions & 0 deletions Editor/BetterAttributes.Editor.asmdef.meta

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

3 changes: 3 additions & 0 deletions Editor/EditorAddons.meta

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

3 changes: 3 additions & 0 deletions Editor/EditorAddons/Comparers.meta

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

23 changes: 23 additions & 0 deletions Editor/EditorAddons/Comparers/AnyTypeComparer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using Better.Commons.Runtime.Comparers;

namespace Better.Attributes.EditorAddons.Comparers
{
public class AnyTypeComparer : BaseComparer<AnyTypeComparer,Type>, IEqualityComparer<Type>
{
public bool Equals(Type x, Type y)
{
if (ReferenceEquals(x, y)) return true;
if (ReferenceEquals(x, null)) return false;
if (ReferenceEquals(y, null)) return false;
if (x.IsAssignableFrom(y) || x == y) return true;
return x == typeof(Type);
}

public int GetHashCode(Type obj)
{
return 0;
}
}
}
3 changes: 3 additions & 0 deletions Editor/EditorAddons/Comparers/AnyTypeComparer.cs.meta

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

3 changes: 3 additions & 0 deletions Editor/EditorAddons/CustomEditors.meta

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

108 changes: 108 additions & 0 deletions Editor/EditorAddons/CustomEditors/ButtonsEditor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Better.Attributes.Runtime;
using Better.Commons.EditorAddons.CustomEditors.Attributes;
using Better.Commons.EditorAddons.CustomEditors.Base;
using Better.Commons.EditorAddons.Extensions;
using Better.Commons.EditorAddons.Utility;
using Better.Commons.Runtime.Extensions;
using UnityEditor;
using UnityEngine;
using UnityEngine.UIElements;
using Object = UnityEngine.Object;

namespace Better.Attributes.EditorAddons.CustomEditors
{
[MultiEditor(typeof(Object), true, Order = 999)]
public class ButtonsEditor : ExtendedEditor
{
private Dictionary<int, IEnumerable<KeyValuePair<MethodInfo, EditorButtonAttribute>>> _methodButtonsAttributes =
new Dictionary<int, IEnumerable<KeyValuePair<MethodInfo, EditorButtonAttribute>>>();

public ButtonsEditor(Object target, SerializedObject serializedObject) : base(target, serializedObject)
{
}

public override void OnDisable()
{
}

public override void OnEnable()
{
var type = _target.GetType();
_methodButtonsAttributes = EditorButtonUtility.GetSortedMethodAttributes(type);
}

private Button DrawButton(MethodInfo methodInfo, EditorButtonAttribute attribute)
{
var button = new Button
{
text = attribute.GetDisplayName(methodInfo.PrettyMemberName()),
name = methodInfo.PrettyMemberName()
};
button.style.FlexGrow(StyleDefinition.OneStyleFloat);
button.RegisterCallback<ClickEvent, (MethodInfo, EditorButtonAttribute)>(OnClick, (methodInfo, attribute));
return button;
}

private void OnClick(ClickEvent clickEvent, (MethodInfo methodInfo, EditorButtonAttribute attribute) data)
{
_serializedObject.Update();
data.methodInfo.Invoke(_target, data.attribute.InvokeParams);
EditorUtility.SetDirty(_target);
_serializedObject.ApplyModifiedProperties();
}


private VisualElement DrawButtons(Dictionary<int, IEnumerable<KeyValuePair<MethodInfo, EditorButtonAttribute>>> buttons)
{
var container = new VisualElement();

foreach (var button in buttons)
{
if (button.Key == -1)
{
var grouped = button.Value.GroupBy(key => key.Key, pair => pair.Value,
(info, attributes) => new KeyValuePair<MethodInfo, IEnumerable<EditorButtonAttribute>>(info, attributes));
var verticalElement = VisualElementUtility.CreateVerticalGroup();
container.Add(verticalElement);

foreach (var group in grouped)
{
var horizontalElement = VisualElementUtility.CreateHorizontalGroup();
verticalElement.Add(horizontalElement);

foreach (var attribute in group.Value)
{
var buttonElement = DrawButton(group.Key, attribute);
horizontalElement.Add(buttonElement);
}
}
}
else
{
var horizontalElement = VisualElementUtility.CreateHorizontalGroup();
container.Add(horizontalElement);
foreach (var (key, value) in button.Value)
{
var element = DrawButton(key, value);
horizontalElement.Add(element);
}
}
}

return container;
}

public override VisualElement CreateInspectorGUI()
{
var buttons = DrawButtons(_methodButtonsAttributes);
return buttons;
}

public override void OnChanged(SerializedObject serializedObject)
{
}
}
}
11 changes: 11 additions & 0 deletions Editor/EditorAddons/CustomEditors/ButtonsEditor.cs.meta

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

76 changes: 76 additions & 0 deletions Editor/EditorAddons/CustomEditors/GizmosEditor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
using System.Reflection;
using Better.Attributes.EditorAddons.Drawers.Gizmo;
using Better.Attributes.Runtime.Gizmo;
using Better.Commons.EditorAddons.CustomEditors.Attributes;
using Better.Commons.EditorAddons.CustomEditors.Base;
using Better.Commons.EditorAddons.Extensions;
using UnityEditor;
using UnityEngine;
using UnityEngine.UIElements;

namespace Better.Attributes.EditorAddons.CustomEditors
{
[MultiEditor(typeof(Object), true, Order = -999)]
public class GizmosEditor : ExtendedEditor
{
private HideTransformButtonHelper _hideTransformHelper;

public GizmosEditor(Object target, SerializedObject serializedObject) : base(target, serializedObject)
{
}

public override void OnDisable()
{
}

public override void OnEnable()
{
CheckAttribute();
}

private void CheckAttribute()
{
var attributeFound = IsAttributeFound();

if (attributeFound && !(_serializedObject.targetObject is ScriptableObject))
{
_hideTransformHelper = new HideTransformButtonHelper();
}
}

private bool IsAttributeFound()
{
var iterator = _serializedObject.GetIterator().Copy();
var attributeFound = false;
while (iterator.Next(true))
{
var data = iterator.GetFieldInfoAndStaticTypeFromProperty();
if (data == null)
{
continue;
}

if (data.FieldInfo.GetCustomAttribute<GizmoLocalAttribute>() == null && data.FieldInfo.GetCustomAttribute<GizmoAttribute>() == null) continue;
attributeFound = true;
break;
}

return attributeFound;
}

public override VisualElement CreateInspectorGUI()
{
if (_hideTransformHelper != null)
{
return _hideTransformHelper.DrawHideTransformButton();
}

return null;
}

public override void OnChanged(SerializedObject serializedObject)
{
CheckAttribute();
}
}
}
3 changes: 3 additions & 0 deletions Editor/EditorAddons/CustomEditors/GizmosEditor.cs.meta

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

8 changes: 8 additions & 0 deletions Editor/EditorAddons/Drawers.meta

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

8 changes: 8 additions & 0 deletions Editor/EditorAddons/Drawers/Decorators.meta

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

40 changes: 40 additions & 0 deletions Editor/EditorAddons/Drawers/Decorators/IconHeaderDrawer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using Better.Attributes.Runtime.Headers;
using UnityEditor;
using UnityEngine;

namespace Better.Attributes.EditorAddons.Drawers.Decorators
{
[CustomPropertyDrawer(typeof(IconHeaderAttribute))]
internal sealed class IconHeaderDrawer : DecoratorDrawer
{
private Texture _loadedTexture;
private float _height;

public override void OnGUI(Rect position)
{
position.yMin += EditorGUIUtility.singleLineHeight * 0.5f;
position = EditorGUI.IndentedRect(position);
if (!(attribute is IconHeaderAttribute iconHeaderAttribute)) return;
if (_loadedTexture == null)
{
var path = AssetDatabase.GUIDToAssetPath(iconHeaderAttribute.Guid);
_loadedTexture = AssetDatabase.LoadAssetAtPath<Texture>(path);
}

var texture = (Texture)Texture2D.whiteTexture;
if (_loadedTexture != null)
{
texture = _loadedTexture;
}

var imageAspect = texture.width / (float)texture.height;
_height = EditorGUIUtility.currentViewWidth / imageAspect;
GUI.DrawTexture(position, texture, ScaleMode.ScaleToFit, iconHeaderAttribute.UseTransparency, imageAspect);
}

public override float GetHeight()
{
return _height;
}
}
}

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

22 changes: 22 additions & 0 deletions Editor/EditorAddons/Drawers/Decorators/PrefabHeaderDrawer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Better.Attributes.Runtime.Headers;
using UnityEditor;
using UnityEngine;

namespace Better.Attributes.EditorAddons.Drawers.Decorators
{
[CustomPropertyDrawer(typeof(PrefabHeaderAttribute))]
internal sealed class PrefabHeaderDrawer : DecoratorDrawer
{
public override void OnGUI(Rect position)
{
position.yMin += EditorGUIUtility.singleLineHeight * 0.5f;
position = EditorGUI.IndentedRect(position);
GUI.Label(position, (attribute as HeaderAttribute)?.header, EditorStyles.boldLabel);
}

public override float GetHeight()
{
return EditorGUIUtility.singleLineHeight * 1.5f;
}
}
}

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

Loading

0 comments on commit 524386b

Please sign in to comment.