Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix RectOffset drawn not correctly #78

Merged
merged 1 commit into from
Feb 16, 2023
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
39 changes: 39 additions & 0 deletions Editor/TypeProcessors/TriRectOffsetTypeProcessor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using TriInspector;
using TriInspector.TypeProcessors;
using UnityEngine;

[assembly: RegisterTriTypeProcessor(typeof(TriRectOffsetTypeProcessor), 1)]

namespace TriInspector.TypeProcessors
{
public class TriRectOffsetTypeProcessor : TriTypeProcessor
{
private static readonly string[] DrawnProperties = new[]
{
"left",
"right",
"top",
"bottom",
};

public override void ProcessType(Type type, List<TriPropertyDefinition> properties)
{
if (type != typeof(RectOffset))
{
return;
}

for (var i = 0; i < DrawnProperties.Length; i++)
{
var propertyName = DrawnProperties[i];
var propertyInfo = type.GetProperty(propertyName, BindingFlags.Instance | BindingFlags.Public);
var propertyDef = TriPropertyDefinition.CreateForPropertyInfo(i, propertyInfo);

properties.Add(propertyDef);
}
}
}
}
3 changes: 3 additions & 0 deletions Editor/TypeProcessors/TriRectOffsetTypeProcessor.cs.meta

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

3 changes: 2 additions & 1 deletion Editor/Utilities/TriUnityInspectorUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ public class TriUnityInspectorUtilities

public static bool MustDrawWithUnity(TriProperty property)
{
if (property.FieldType == typeof(GUIStyle))
if (property.FieldType == typeof(GUIStyle) ||
property.FieldType == typeof(RectOffset))
{
return true;
}
Expand Down