-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ScriptableLogic FieldTypeからFlagsAttributeを取得してMaskFieldに自動的に切り替…
…わるように修正
- Loading branch information
Showing
5 changed files
with
123 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
Packages/uGUI-Skinner/Editor/SkinnerAttributeExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
using System; | ||
using Object = UnityEngine.Object; | ||
using System.Reflection; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace Pspkurara.UI.Skinner | ||
{ | ||
|
||
/// <summary> | ||
/// <see cref="Attribute"/>関係の拡張関数群 | ||
/// </summary> | ||
public static class SkinnerAttributeExtensions | ||
{ | ||
|
||
/// <summary> | ||
/// <see cref="Attribute.IsDefined"/>を親クラスも含めて行う | ||
/// </summary> | ||
public static bool IsDefinedWithBaseType(this Type element, bool inherit = true) | ||
{ | ||
return IsDefinedWithBaseType(element, typeof(Attribute), inherit); | ||
} | ||
|
||
/// <summary> | ||
/// <see cref="Attribute.IsDefined"/>を親クラスも含めて行う | ||
/// </summary> | ||
public static bool IsDefinedWithBaseType(this Type element, Type attributeType, bool inherit = true) | ||
{ | ||
if (element == null) return false; | ||
if (element.IsDefined(attributeType, inherit)) | ||
{ | ||
return true; | ||
} | ||
return element.IsDefinedWithBaseType(attributeType.BaseType, inherit); | ||
} | ||
|
||
/// <summary> | ||
/// <see cref="Attribute.GetCustomAttribute"/>を親クラスも含めて行う | ||
/// </summary> | ||
public static Attribute[] GetCustomAttributesWithBaseType(this Type element, bool inherit = true) | ||
{ | ||
return GetCustomAttributesWithBaseType(element, typeof(Attribute), inherit); | ||
} | ||
|
||
/// <summary> | ||
/// <see cref="Attribute.GetCustomAttribute"/>を親クラスも含めて行う | ||
/// </summary> | ||
public static Attribute[] GetCustomAttributesWithBaseType(this Type element, Type attributeType, bool inherit = true) | ||
{ | ||
if (element == null) return Array.Empty<Attribute>(); | ||
HashSet<Attribute> attributeList = new HashSet<Attribute>(); | ||
if (attributeType == null) attributeType = typeof(Attribute); | ||
AccumulationAttributesWithBaseType(element, attributeList, attributeType, inherit); | ||
return attributeList.ToArray(); | ||
} | ||
|
||
/// <summary> | ||
/// <see cref="GetCustomAttributesWithBaseType(Type, Type, bool)"/>の内部処理 | ||
/// </summary> | ||
private static void AccumulationAttributesWithBaseType(Type element, HashSet<Attribute> attributeList, Type attributeType, bool inherit) | ||
{ | ||
if (element == null) return; | ||
attributeList.UnionWith(element.GetCustomAttributes(attributeType, inherit).Cast<Attribute>()); | ||
AccumulationAttributesWithBaseType(element.BaseType, attributeList, attributeType, inherit); | ||
} | ||
|
||
} | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
Packages/uGUI-Skinner/Editor/SkinnerAttributeExtensions.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters