Skip to content

Commit

Permalink
Add UnityAssetUtility and UnityRectUtility
Browse files Browse the repository at this point in the history
  • Loading branch information
Exanite committed Mar 14, 2024
1 parent e90a1eb commit 074c37f
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 0 deletions.
29 changes: 29 additions & 0 deletions Utilities/UnityAssetUtility.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#if UNITY_EDITOR
using System;
using UnityEditor;
using Object = UnityEngine.Object;

namespace Exanite.Core.Utilities
{
public static class UnityAssetUtility
{
/// <summary>
/// Returns the override importer of an asset. Returns null when the provided
/// <see cref="Object"/> is not an asset or does not have an override importer.
/// </summary>
/// <remarks>
/// This is a wrapper around <see cref="AssetDatabase.GetImporterOverride"/> to make it easier to use.
/// </remarks>
public static Type GetOverrideImporter(this Object asset)
{
var path = AssetDatabase.GetAssetPath(asset);
if (string.IsNullOrEmpty(path))
{
return null;
}

return AssetDatabase.GetImporterOverride(path);
}
}
}
#endif
11 changes: 11 additions & 0 deletions Utilities/UnityAssetUtility.cs.meta

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

20 changes: 20 additions & 0 deletions Utilities/UnityRectUtility.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#if UNITY_2021_3_OR_NEWER
using UnityEngine;

namespace Exanite.Core.Utilities
{
public static class UnityRectUtility
{
public static Rect WithInset(this Rect rect, float inset)
{
rect.xMin += inset;
rect.yMin += inset;

rect.xMax -= inset;
rect.yMax -= inset;

return rect;
}
}
}
#endif
3 changes: 3 additions & 0 deletions Utilities/UnityRectUtility.cs.meta

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

0 comments on commit 074c37f

Please sign in to comment.