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

Commit

Permalink
Merge pull request #128 from techno-dwarf-works/feature/refactoring
Browse files Browse the repository at this point in the history
Version 3.1.8
  • Loading branch information
uurha committed Aug 2, 2024
1 parent a05b948 commit df58891
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 91 deletions.
25 changes: 25 additions & 0 deletions Editor/EditorAddons/Drawers/Gizmo/GizmoElementBehaviour.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Better.Commons.EditorAddons.Drawers.BehavioredElements;
using Better.Commons.Runtime.Extensions;
using UnityEngine.UIElements;

namespace Better.Attributes.EditorAddons.Drawers.Gizmo
{
public class GizmoElementBehaviour : DefaultElementBehaviour<Button>
{
public override void OnLink(BehavioredElement<Button> behavioredElement)
{
base.OnLink(behavioredElement);
BehavioredElement.style
.FlexGrow(new StyleFloat(1f));
BehavioredElement.SubElement.style.FlexGrow(new StyleFloat(1f));
}

public override void OnAttach(VisualElement root)
{
if (root.Contains(BehavioredElement)) return;
BehavioredElement.RemoveFromHierarchy();

root.Add(BehavioredElement);
}
}
}

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,12 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Better.Attributes.Runtime.Select;
using Better.Commons.EditorAddons.Enums;
using Better.Commons.EditorAddons.Extensions;
using Better.Commons.Runtime.Extensions;
using UnityEditor.UIElements;
using UnityEngine;
using UnityEngine.UIElements;

namespace Better.Attributes.EditorAddons.Drawers.Select
{
Expand All @@ -21,7 +20,7 @@ public override void Update(object value)
var property = _container.SerializedProperty;
if (!property.Verify()) return;
var typeValue = (Type)value;
property.managedReferenceValue = typeValue == null ? null : Activator.CreateInstance(typeValue);
property.managedReferenceValue = typeValue == null ? null : Activator.CreateInstance(typeValue, true);

base.Update(value);
}
Expand All @@ -38,7 +37,9 @@ public override object GetCurrentValue()

protected override IEnumerable<Type> GetInheritedTypes(Type fieldType)
{
return fieldType.GetAllInheritedTypesWithoutUnityObject();
var inheritedTypes = fieldType.GetAllInheritedTypesWithoutUnityObject()
.Where(type => !type.IsGenericType && !type.IsGenericTypeDefinition);
return inheritedTypes;
}

public override bool IsSkippingFieldDraw()
Expand Down
2 changes: 1 addition & 1 deletion Editor/EditorAddons/Drawers/Select/SelectDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ protected override void PopulateContainer(ElementsContainer container)
container.SerializedPropertyChanged += UpdateElement;

handler.OnPopulateContainer();
container.RootElement.OnElementAppear<Label>(behavioredElement.Attach);
container.RootElement.OnElementAppear<Label>(behavioredElement.Attach).Until(null).Every(100).Resume();
}

private void OnReferenceTypeChange(ReferenceTypeChangeEvent changeEvent, ElementsContainer container)
Expand Down
19 changes: 19 additions & 0 deletions Editor/EditorAddons/Drawers/Select/SelectElementBehaviour.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Better.Commons.EditorAddons.Drawers.BehavioredElements;
using Better.Commons.EditorAddons.Enums;
using Better.Commons.EditorAddons.Extensions;
using Better.Commons.Runtime.Extensions;
using UnityEngine.UIElements;

namespace Better.Attributes.EditorAddons.Drawers.Select
{
public class SelectElementBehaviour : DefaultElementBehaviour<Button>
{
public override void OnLink(BehavioredElement<Button> behavioredElement)
{
base.OnLink(behavioredElement);

var icon = BehavioredElement.SubElement.AddIcon(IconType.GrayDropdown);
icon.style.AlignSelf(new StyleEnum<Align>(Align.FlexEnd));
}
}
}

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

160 changes: 76 additions & 84 deletions Samples~/TestSamples/Scripts/Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,20 @@ public class TestInner
[Serializable]
public class TestSerializableType : ITestSerializableType
{
[Select(typeof(ISomeInterface))]
[SerializeField]
[Select(typeof(ISomeInterface))] [SerializeField]
private List<SerializedType> serializedTypes;

protected TestSerializableType()
{
}
}

[Serializable]
public class TestSerializableType<T> : ITestSerializableType
{
protected TestSerializableType()
{
}
}

public interface ITestSerializableType
Expand All @@ -75,44 +86,36 @@ public interface ITestSerializableType

public class Test : MonoBehaviour
{
[HideLabel] [Select(typeof(ISomeInterface))]
[SerializeField]
[HideLabel] [Select(typeof(ISomeInterface))] [SerializeField]
private SerializedType serializedType;

[Select]
[SerializeReference]
private List<ITestSerializableType> serializedTypes;

[Select(typeof(ISomeInterface))]
[SerializeField]

[Select] [SerializeReference] private List<ITestSerializableType> serializedTypes;

[Select(typeof(ISomeInterface))] [SerializeField]
private SerializedType serializedType2;

[Select] [SerializeField] private KeyCode keyCode;


[DisableIf(nameof(keyCode), KeyCode.D)] [Select]
[SerializeField]

[DisableIf(nameof(keyCode), KeyCode.D)] [Select] [SerializeField]
private MyFlagEnum myFlagEnumTest;

[EnumButtons] [HideLabel]
[SerializeField]

[EnumButtons] [HideLabel] [SerializeField]
private TestEnum myEnumTest;

//
[ShowIf(nameof(keyCode), KeyCode.Backspace)] [Preview] [DrawInspector]
[SerializeField]
[ShowIf(nameof(keyCode), KeyCode.Backspace)] [Preview] [DrawInspector] [SerializeField]
private PreviewTest component;

[Preview] [CustomTooltip("Test tooltip")]
[SerializeField] private Texture2D texture;

[HelpBox("It's help box")] [DrawInspector]
[SerializeField] private List<TestScriptableObject> scriptableObjectList;

[DrawInspector]
[SerializeField] private TestScriptableObject[] scriptableObjectArray;
[DrawInspector]
[SerializeField] private TestScriptableObject scriptableObject;


[Preview] [CustomTooltip("Test tooltip")] [SerializeField]
private Texture2D texture;

[HelpBox("It's help box")] [DrawInspector] [SerializeField]
private List<TestScriptableObject> scriptableObjectList;

[DrawInspector] [SerializeField] private TestScriptableObject[] scriptableObjectArray;
[DrawInspector] [SerializeField] private TestScriptableObject scriptableObject;

[GizmoLocal] [SerializeField] private Vector3 vector3Local;
[SerializeField] private Vector3 vector3Local2;

Expand All @@ -136,58 +139,47 @@ [HideLabel] [Select(DisplayGrouping.GroupedFlat)] [SerializeReference]
[Dropdown("r:SingletonTest.Instance.GetIDs()")] [SerializeField]
private int testInt2;

[HideLabel]
[SerializeField] private TestInner _testInner;


[Select(typeof(ISomeInterface), DisplayGrouping.Grouped)]
[SerializeReference] private List<ISomeInterface> someInterfaces;

[GizmoLocal]
[SerializeField] private Bounds bounds;

[DisableInEditorMode]
[SerializeField] private List<Vector3> _vector3s;

[ShowInEditorMode]
[SerializeField] private int showInEditorMode;

[HideInEditorMode]
[SerializeField] private int hideInEditorMode;

[HideInPlayMode]
[SerializeField] private int hideInPlayMode;

[ShowInPlayMode]
[SerializeField] private int showInPlayMode;

[EnableInPlayMode]
[SerializeField] private int enableInPlayMode;

[DisableInEditorMode]
[SerializeField] private int disableInEditorMode;

[EnableInEditorMode]
[SerializeField] private int enableInEditorMode;

[DisableInPlayMode]
[SerializeField] private int disableInPlayMode;

[HelpBox("TestHelpBox()")]
[SerializeField] private bool boolField;

[ShowIf(nameof(boolField), true)]
[SerializeField] private int showIfBool;

[HideIf(nameof(boolField), true)]
[SerializeField] private int hideIfBool;

[DisableIf(nameof(boolField), true)]
[SerializeField] private int disableIfBool;

[EnableIf(nameof(boolField), true)]
[SerializeField] private int enableIfBool;

[HideLabel] [SerializeField] private TestInner _testInner;


[Select(typeof(ISomeInterface), DisplayGrouping.Grouped)] [SerializeReference]
private List<ISomeInterface> someInterfaces;

[GizmoLocal] [SerializeField] private Bounds bounds;

[DisableInEditorMode] [SerializeField] private List<Vector3> _vector3s;

[ShowInEditorMode] [SerializeField] private int showInEditorMode;

[HideInEditorMode] [SerializeField] private int hideInEditorMode;

[HideInPlayMode] [SerializeField] private int hideInPlayMode;

[ShowInPlayMode] [SerializeField] private int showInPlayMode;

[EnableInPlayMode] [SerializeField] private int enableInPlayMode;

[DisableInEditorMode] [SerializeField] private int disableInEditorMode;

[EnableInEditorMode] [SerializeField] private int enableInEditorMode;

[DisableInPlayMode] [SerializeField] private int disableInPlayMode;

[HelpBox("TestHelpBox()")] [SerializeField]
private bool boolField;

[ShowIf(nameof(boolField), true)] [SerializeField]
private int showIfBool;

[HideIf(nameof(boolField), true)] [SerializeField]
private int hideIfBool;

[DisableIf(nameof(boolField), true)] [SerializeField]
private int disableIfBool;

[EnableIf(nameof(boolField), true)] [SerializeField]
private int enableIfBool;


///Default usage of attribute.
[EditorButton]
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "com.uurha.betterattributes",
"displayName": "Better Attributes",
"version": "3.1.7",
"version": "3.1.8",
"unity": "2021.3",
"description": "Unity attributes, allows to serialize interfaces, draw handles for Vector3/Vector2/Quaternion/Bounds, create read only fields.",
"dependencies": {
"com.tdw.better.commons" : "0.0.26",
"com.tdw.better.commons" : "0.0.32",
"com.tdw.better.internal.core" : "0.0.2"
},
"author": {
Expand Down

0 comments on commit df58891

Please sign in to comment.