70 lines
2.4 KiB
C#
70 lines
2.4 KiB
C#
using System;
|
|
using System.Linq;
|
|
using Streamingle.Utils.LerpConstraints;
|
|
using UnityEditor;
|
|
using UnityEngine;
|
|
|
|
namespace Streamingle.Utils.LerpConstraintsEditor
|
|
{
|
|
[InitializeOnLoad]
|
|
internal static class LerpConstraintIconInstaller
|
|
{
|
|
private const string IconDirectory = "Packages/com.streamingle.utilities/Editor/Constraints/Icons";
|
|
|
|
private static readonly IconDefinition[] IconDefinitions =
|
|
{
|
|
new IconDefinition(typeof(LerpAimConstraint), "LerpAimConstraintIcon"),
|
|
new IconDefinition(typeof(LerpLookAtConstraint), "LerpLookAtConstraintIcon"),
|
|
new IconDefinition(typeof(LerpParentConstraint), "LerpParentConstraintIcon"),
|
|
new IconDefinition(typeof(LerpPositionConstraint), "LerpPositionConstraintIcon"),
|
|
new IconDefinition(typeof(LerpRotationConstraint), "LerpRotationConstraintIcon"),
|
|
new IconDefinition(typeof(LerpScaleConstraint), "LerpScaleConstraintIcon")
|
|
};
|
|
|
|
static LerpConstraintIconInstaller()
|
|
{
|
|
EditorApplication.delayCall += ApplyIcons;
|
|
}
|
|
|
|
private static void ApplyIcons()
|
|
{
|
|
string[] scriptGuids = AssetDatabase.FindAssets(
|
|
"t:MonoScript",
|
|
new[] { "Packages/com.streamingle.utilities/Runtime/Constraints" });
|
|
|
|
foreach (IconDefinition definition in IconDefinitions)
|
|
{
|
|
Texture2D icon = AssetDatabase.LoadAssetAtPath<Texture2D>(
|
|
$"{IconDirectory}/{definition.IconName}.png");
|
|
if (icon == null)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
MonoScript script = scriptGuids
|
|
.Select(AssetDatabase.GUIDToAssetPath)
|
|
.Select(AssetDatabase.LoadAssetAtPath<MonoScript>)
|
|
.FirstOrDefault(candidate => candidate != null && candidate.GetClass() == definition.ConstraintType);
|
|
|
|
if (script != null)
|
|
{
|
|
EditorGUIUtility.SetIconForObject(script, icon);
|
|
}
|
|
}
|
|
}
|
|
|
|
private readonly struct IconDefinition
|
|
{
|
|
public IconDefinition(Type constraintType, string iconName)
|
|
{
|
|
ConstraintType = constraintType;
|
|
IconName = iconName;
|
|
}
|
|
|
|
public Type ConstraintType { get; }
|
|
|
|
public string IconName { get; }
|
|
}
|
|
}
|
|
}
|