mirror of
https://github.com/unity-atoms/unity-atoms.git
synced 2025-01-24 00:58:59 -05:00
32 lines
916 B
C#
32 lines
916 B
C#
|
using System;
|
||
|
using System.Linq;
|
||
|
using System.Collections.Generic;
|
||
|
using UnityEditor;
|
||
|
|
||
|
namespace UnityAtoms
|
||
|
{
|
||
|
/// <summary>
|
||
|
/// Assigner that enables the attribute AssignIcon.
|
||
|
/// </summary>
|
||
|
public class AttributeMonoScriptAssigner : IconAssigner<MonoScript>
|
||
|
{
|
||
|
protected override Func<MonoScript, List<IconData>, IconData> SelectIcon
|
||
|
{
|
||
|
get => (script, icons) =>
|
||
|
{
|
||
|
var type = script?.GetClass();
|
||
|
if (type != null)
|
||
|
{
|
||
|
var assignIcon = type.GetCustomAttributes(typeof(AssignIcon), true).FirstOrDefault() as AssignIcon;
|
||
|
if (assignIcon != null)
|
||
|
{
|
||
|
return icons.FirstOrDefault((icon) => icon.Name.Contains(assignIcon.IconName));
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return null;
|
||
|
};
|
||
|
}
|
||
|
}
|
||
|
}
|