Skip to content

Commit

Permalink
Fix RectOffset drawn not correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
vanifatovvlad committed Feb 16, 2023
1 parent 10cb1fc commit 9895ce9
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
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

0 comments on commit 9895ce9

Please sign in to comment.