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 #120 from techno-dwarf-works/bug/serialized-type
Browse files Browse the repository at this point in the history
Fix Serialize reference
  • Loading branch information
uurha authored Apr 22, 2024
2 parents 3023dba + a9b77ea commit dcd56e4
Show file tree
Hide file tree
Showing 11 changed files with 78 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,12 @@ public override void PreDraw(Rect position, GUIContent label)
{
if (!string.IsNullOrEmpty(_tooltipAttribute.Tooltip) && !string.IsNullOrEmpty(label.text))
{
label.tooltip = _tooltipAttribute.Tooltip;
label.tooltip = _tooltipAttribute.Tooltip;
var addingSymbol = _tooltipAttribute.TooltipSymbol == default ? Asterisk : _tooltipAttribute.TooltipSymbol;
label.text += addingSymbol.ToString();
}
}

public override void DrawField(Rect rect, GUIContent label)
{
EditorGUI.PropertyField(rect, _property, label);
}

public override void PostDraw()
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@ public override void PreDraw(Rect position, GUIContent label)
ExtendedGUIUtility.HelpBox(copy, _helpBoxContent);
}

public override void DrawField(Rect rect, GUIContent label)
{
EditorGUI.PropertyField(rect, _property, label, true);
}

public override void PostDraw()
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Better.Attributes.Runtime.Misc;
using Better.Commons.EditorAddons.Drawers.Caching;
using Better.Commons.EditorAddons.Drawers.Utility;
using Better.Commons.EditorAddons.Utility;
using UnityEditor;
using UnityEngine;

Expand All @@ -15,7 +16,6 @@ public abstract class MiscWrapper : UtilityWrapper

public override void Deconstruct()
{

}

public virtual void SetProperty(SerializedProperty property, FieldInfo fieldInfo, MiscAttribute attribute)
Expand All @@ -26,7 +26,12 @@ public virtual void SetProperty(SerializedProperty property, FieldInfo fieldInfo
}

public abstract void PreDraw(Rect position, GUIContent label);
public abstract void DrawField(Rect rect, GUIContent label);

public virtual void DrawField(Rect rect, GUIContent label)
{
EditorGUI.PropertyField(rect, _property, label, true);
}

public abstract void PostDraw();
public abstract HeightCacheValue GetHeight(GUIContent label);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,14 @@ protected override WrapperCollection<BaseSelectWrapper> GenerateCollection()

protected override void DrawField(Rect position, SerializedProperty property, GUIContent label)
{
var rect = PreparePropertyRect(position);
if (_setupStrategy.SkipFieldDraw())
{
var rect = PreparePropertyRect(position);
// rect.height = value.Wrapper.GetHeight().Value;
EditorGUI.LabelField(rect, label);
return;
}

base.DrawField(position, property, label);
_setupStrategy.DrawField(rect, property, label);
}

public SelectDrawer(FieldInfo fieldInfo, MultiPropertyAttribute attribute) : base(fieldInfo, attribute)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ private Rect GetPopupPosition(Rect currentPosition, GUIContent label)
{
var popupPosition = new Rect(currentPosition);
var width = label.GetMaxWidth();

popupPosition.width -= width;
popupPosition.x += width;
popupPosition.height = EditorGUIUtility.singleLineHeight;
Expand All @@ -135,6 +136,7 @@ private void ShowDropDown(SerializedProperty serializedProperty, Rect popupPosit
{
var copy = popupPosition;
copy.y += EditorGUIUtility.singleLineHeight;

var popup = DropdownWindow.ShowWindow(GUIUtility.GUIToScreenRect(copy), _setupStrategy.GenerateHeader());
var items = GenerateItemsTree(serializedProperty, currentValue);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,13 @@
using Better.Attributes.Runtime.Select;
using Better.Commons.Runtime.Extensions;
using Better.Commons.Runtime.Utility;
using UnityEditor;
using UnityEngine;

namespace Better.Attributes.EditorAddons.Drawers.Select.SetupStrategies
{
public class SelectSerializedTypeStrategy : SetupStrategy
{
public override bool SkipFieldDraw()
{
return true;
}

public SelectSerializedTypeStrategy(FieldInfo fieldInfo, object propertyContainer, SelectAttributeBase selectAttributeBase) : base(fieldInfo, propertyContainer,
selectAttributeBase)
{
Expand All @@ -43,6 +39,11 @@ protected static bool ValidateInternal(Type type)
return constructor != null;
}

public override bool SkipFieldDraw()
{
return true;
}

public override bool Validate(object item)
{
if (item == null)
Expand All @@ -60,7 +61,7 @@ public override bool Validate(object item)

public override bool CheckSupported()
{
return false;
return true;
}

public override GUIContent GenerateHeader()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
using System.Collections.Generic;
using System.Reflection;
using Better.Attributes.Runtime.Select;
using Better.Commons.EditorAddons.Utility;
using Better.Commons.Runtime.Extensions;
using UnityEditor;
using UnityEngine;

namespace Better.Attributes.EditorAddons.Drawers.Select.SetupStrategies
Expand Down Expand Up @@ -43,5 +45,10 @@ public virtual Type GetFieldOrElementType()
return fieldType.GetCollectionElementType();
return fieldType;
}

public virtual void DrawField(Rect position, SerializedProperty property, GUIContent label)
{
EditorGUI.PropertyField(position, property, label, true);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ public override void Update(object value)
}
}

protected override float GetPropertyHeight(SerializedProperty copy)
{
return EditorGUIUtility.singleLineHeight;
}

public override object GetCurrentValue()
{
var objectOfProperty = _property.GetValue();
Expand Down
8 changes: 8 additions & 0 deletions Assets/BetterAttributes/Samples~.meta

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

88 changes: 38 additions & 50 deletions Assets/BetterAttributes/Samples~/TestSamples/Scenes/Sample.unity
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,30 @@ GameObject:
serializedVersion: 6
m_Component:
- component: {fileID: 123298862}
- component: {fileID: 123298861}
- component: {fileID: 123298863}
m_Layer: 0
m_Name: TestObject
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &123298861
--- !u!4 &123298862
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 123298860}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 4.66, z: 1.96}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &123298863
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
Expand All @@ -153,17 +168,19 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
serializedType:
_fullQualifiedName: Samples.Models.SomeInterfaceImplementation21, Assembly-CSharp,
Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
keyCode: 8
myFlagEnumTest: 2
_fullQualifiedName:
serializedTypeTest:
- _type:
_fullQualifiedName: Samples.OtherModels.SomeInterfaceImplementation1, Assembly-CSharp,
Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
keyCode: 0
myFlagEnumTest: 0
myEnumTest: 0
component: {fileID: -745862845828164141, guid: 8929c6f090ecb854da923536f6ace092, type: 3}
texture: {fileID: 2800000, guid: 78b772f3f305147419de3cc97ca72bd7, type: 3}
component: {fileID: 0}
texture: {fileID: 0}
scriptableObjectList:
- {fileID: 0}
scriptableObjectArray:
- {fileID: 0}
- {fileID: 11400000, guid: ac831e4d15607c1468b51a2ca7a39284, type: 2}
scriptableObjectArray: []
scriptableObject: {fileID: 0}
vector3Local: {x: 0, y: 0, z: 0}
quaternion: {x: 0, y: 0, z: 0, w: 1}
Expand All @@ -174,25 +191,22 @@ MonoBehaviour:
intField3: 0
intField4: 0
someClass:
intField: 53
intField: 0
intField1: 0
intField2: 0
intField3: 0
intField4: 203
intField4: 0
someFloat: 0
someInterface:
rid: 0
rid: -2
someAbstractClass:
rid: 1
rid: -2
someAbstractClasses: []
someInterfaces:
- rid: 2
someInterfaces: []
bounds:
m_Center: {x: 0, y: -3.7256675, z: 0}
m_Extent: {x: 1.0894362, y: 1.2339233, z: 3.5291336}
_vector3s:
- {x: 0, y: -2.0571938, z: 6.2717056}
- {x: 0, y: -2.9847207, z: -7.380436}
m_Center: {x: 0, y: 0, z: 0}
m_Extent: {x: 0.05, y: 0.05, z: 0.05}
_vector3s: []
showInEditorMode: 0
hideInEditorMode: 0
hideInPlayMode: 0
Expand All @@ -209,34 +223,8 @@ MonoBehaviour:
references:
version: 2
RefIds:
- rid: 0
type: {class: SomeInterfaceImplementation14, ns: Samples.OtherModels, asm: Assembly-CSharp}
data:
intField: 0
- rid: 1
type: {class: SomeAbstractClassImplementation2, ns: Samples.Models, asm: Assembly-CSharp}
data:
baseIntField: 0
boolField: 0
- rid: 2
type: {class: SomeInterfaceImplementation21, ns: Samples.Models, asm: Assembly-CSharp}
data:
intField: 0
--- !u!4 &123298862
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 123298860}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 4.66, z: 1.96}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
- rid: -2
type: {class: , ns: , asm: }
--- !u!1 &705507993
GameObject:
m_ObjectHideFlags: 0
Expand Down
2 changes: 1 addition & 1 deletion Assets/BetterAttributes/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "com.uurha.betterattributes",
"displayName": "Better Attributes",
"version": "3.1.1",
"version": "3.1.2",
"unity": "2021.3",
"description": "Unity attributes, allows to serialize interfaces, draw handles for Vector3/Vector2/Quaternion/Bounds, create read only fields.",
"dependencies": {
Expand Down

0 comments on commit dcd56e4

Please sign in to comment.