Skip to content

Commit

Permalink
Fixed #22
Browse files Browse the repository at this point in the history
  • Loading branch information
yasirkula committed Jul 9, 2020
1 parent 364909b commit 3614029
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ MonoBehaviour:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 0, g: 0, b: 0, a: 0.5019608}
m_RaycastTarget: 0
m_RaycastTarget: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
Expand Down Expand Up @@ -541,7 +541,9 @@ MonoBehaviour:
visibleArea: {fileID: 114198838805767348}
background: {fileID: 114405046876110564}
dropdownArrow: {fileID: 114098797441886034}
templateTransform: {fileID: 224281342250994130}
templateRoot: {fileID: 224854286026678716}
templateContentTransform: {fileID: 224281342250994130}
templateItemTransform: {fileID: 224767493225950242}
templateBackground: {fileID: 114403854879612838}
templateCheckmark: {fileID: 114317618226792586}
templateText: {fileID: 114253684249676600}
Expand Down Expand Up @@ -877,8 +879,8 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: -2, y: 0}
m_SizeDelta: {x: 0, y: -2}
m_AnchoredPosition: {x: -0.5, y: 0}
m_SizeDelta: {x: -1, y: -2}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!224 &224125497233420464
RectTransform:
Expand All @@ -895,9 +897,9 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0.5}
m_AnchorMax: {x: 0, y: 0.5}
m_AnchoredPosition: {x: 10, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 20, y: 20}
m_Pivot: {x: 0.5, y: 0.5}
m_Pivot: {x: 0, y: 0.5}
--- !u!224 &224275561588672442
RectTransform:
m_ObjectHideFlags: 1
Expand Down Expand Up @@ -1066,9 +1068,9 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 5, y: -0.5}
m_SizeDelta: {x: -30, y: -3}
m_Pivot: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: -5, y: -0.5}
m_SizeDelta: {x: -25, y: -3}
m_Pivot: {x: 1, y: 0.5}
--- !u!224 &224673874819871544
RectTransform:
m_ObjectHideFlags: 1
Expand All @@ -1084,9 +1086,9 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: -7.5, y: 0}
m_AnchoredPosition: {x: 10, y: 0}
m_SizeDelta: {x: -35, y: -4}
m_Pivot: {x: 0.5, y: 0.5}
m_Pivot: {x: 0, y: 0.5}
--- !u!224 &224688293831919758
RectTransform:
m_ObjectHideFlags: 1
Expand Down Expand Up @@ -1139,11 +1141,11 @@ RectTransform:
m_Father: {fileID: 224485359870051676}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 1, y: 0}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: -15, y: 0}
m_SizeDelta: {x: 20, y: -4}
m_Pivot: {x: 0.5, y: 0.5}
m_AnchorMin: {x: 1, y: 0.5}
m_AnchorMax: {x: 1, y: 0.5}
m_AnchoredPosition: {x: -5, y: 0}
m_SizeDelta: {x: 20, y: 20}
m_Pivot: {x: 1, y: 0.5}
--- !u!224 &224854286026678716
RectTransform:
m_ObjectHideFlags: 1
Expand Down
9 changes: 5 additions & 4 deletions Plugins/RuntimeInspector/Scripts/RuntimeInspector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -325,10 +325,11 @@ public void Refresh()

// Refreshes the Inspector in the next Update. Called by most of the InspectorDrawers
// when their values have changed. If a drawer is bound to a property whose setter
// may modify the input data, the drawer's BoundInputFields will still show the unmodified
// input data until the next Refresh. That is because BoundInputFields don't have access
// to the fields/properties they are modifying, there is no way for the BoundInputFields to
// know whether or not the property has modified the input data.
// may modify the input data (e.g. when input data is 20 but the setter clamps it to 10),
// the drawer's BoundInputFields will still show the unmodified input data (20) until the
// next Refresh. That is because BoundInputFields don't have access to the fields/properties
// they are modifying, there is no way for the BoundInputFields to know whether or not
// the property has modified the input data (changed it from 20 to 10).
//
// Why not refresh only the changed InspectorDrawers? Because changing a property may affect
// multiple fields/properties that are bound to other drawers, we don't know which
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@ public class EnumField : InspectorField
private Image dropdownArrow;

[SerializeField]
private RectTransform templateTransform;
private RectTransform templateRoot;

[SerializeField]
private RectTransform templateContentTransform;

[SerializeField]
private RectTransform templateItemTransform;

[SerializeField]
private Image templateBackground;
Expand Down Expand Up @@ -78,6 +84,23 @@ protected override void OnBound( MemberInfo variable )
input.AddOptions( currEnumNames );
}

protected override void OnInspectorChanged()
{
base.OnInspectorChanged();
OnTransformParentChanged();
}

private void OnTransformParentChanged()
{
if( Inspector && Skin )
{
// Dropdown's list should be able to expand as much as possible when necessary
Vector2 templateRootSizeDelta = templateRoot.sizeDelta;
templateRootSizeDelta.y = ( ( (RectTransform) Inspector.Canvas.transform ).rect.height - Skin.LineHeight ) * 0.5f;
templateRoot.sizeDelta = templateRootSizeDelta;
}
}

private void OnValueChanged( int input )
{
Value = currEnumValues[input];
Expand All @@ -87,10 +110,28 @@ private void OnValueChanged( int input )
protected override void OnSkinChanged()
{
base.OnSkinChanged();

Vector2 templateSizeDelta = templateTransform.sizeDelta;
templateSizeDelta.y = Skin.LineHeight;
templateTransform.sizeDelta = templateSizeDelta;
OnTransformParentChanged();

Vector2 templateContentSizeDelta = templateContentTransform.sizeDelta;
templateContentSizeDelta.y = Skin.LineHeight + 6f; // Padding at top and bottom edges
templateContentTransform.sizeDelta = templateContentSizeDelta;

Vector2 templateItemSizeDelta = templateItemTransform.sizeDelta;
templateItemSizeDelta.y = Skin.LineHeight;
templateItemTransform.sizeDelta = templateItemSizeDelta;

// Resize the checkmark icon
float templateCheckmarkSize = Skin.LineHeight * 0.66f;
Vector2 templateTextSizeDelta = templateText.rectTransform.sizeDelta;
templateTextSizeDelta.x -= templateCheckmarkSize - templateCheckmark.rectTransform.sizeDelta.x;
templateText.rectTransform.sizeDelta = templateTextSizeDelta;
templateCheckmark.rectTransform.sizeDelta = new Vector2( templateCheckmarkSize, templateCheckmarkSize );

// Resize the dropdown arrow
Vector2 dropdownTextSizeDelta = input.captionText.rectTransform.sizeDelta;
dropdownTextSizeDelta.x -= templateCheckmarkSize - dropdownArrow.rectTransform.sizeDelta.x;
input.captionText.rectTransform.sizeDelta = dropdownTextSizeDelta;
dropdownArrow.rectTransform.sizeDelta = new Vector2( templateCheckmarkSize, templateCheckmarkSize );

background.color = Skin.InputFieldNormalBackgroundColor;
dropdownArrow.color = Skin.TextColor.Tint( 0.1f );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,14 @@ protected override void OnUnbound()
ClearElements();
}

protected override void OnInspectorChanged()
{
base.OnInspectorChanged();

for( int i = 0; i < elements.Count; i++ )
elements[i].Inspector = Inspector;
}

protected override void OnSkinChanged()
{
base.OnSkinChanged();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Reflection;
using System.Collections.Generic;
using UnityEngine;

namespace RuntimeInspectorNamespace
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "com.yasirkula.runtimeinspector",
"displayName": "Runtime Inspector & Hierarchy",
"version": "1.5.0",
"version": "1.5.1",
"description": "This is a simple yet powerful runtime Inspector and Hierarchy solution for Unity 3D that should work on pretty much any platform that Unity supports, including mobile platforms.",
"hideInEditor": false
}

0 comments on commit 3614029

Please sign in to comment.