Skip to content

Add support to Windows Store #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 23 additions & 9 deletions ComponentAttribute/Assets/ComponentAttribute/ComponentAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,15 @@ public static class CAExtensions {
private const string NO_WRITE = "Component Loader: Unable to write {0} on {1}";
private const string NO_WRITE_ERROR = "Component Loader: Unable to write {0} on {1}, disabling it on {2}";

static bool HasAttribute<T>(this MemberInfo m) where T : Attribute
{
#if UNITY_WSA && !UNITY_EDITOR
return m.CustomAttributes.Any(o => o.AttributeType.Equals(typeof (T)));
#else
return Attribute.IsDefined(m, typeof(T));
#endif
}

public static void LoadComponents( this MonoBehaviour behaviour ) {
var bGameObject = behaviour.gameObject;
var bType = behaviour.GetType();
Expand All @@ -102,14 +111,19 @@ public static void LoadComponents( this MonoBehaviour behaviour ) {
if ( TypeMembers.ContainsKey( bType ) ) {
members = TypeMembers[bType];
} else {
members = bType.GetMembers( BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic )
.Where( m =>
( m.MemberType == MemberTypes.Field || m.MemberType == MemberTypes.Property )
&& m.GetMemberType().IsSubclassOf( mType )
&& m.GetCustomAttributes( cType, true ).Length == 1 ).ToList();

members.OrderBy( m => m.MemberType ).ThenBy( m => m.Name );
TypeMembers.Add( bType, members );
#if UNITY_WSA && !UNITY_EDITOR
var fields = bType.GetTypeInfo().DeclaredFields.Where(o => o.HasAttribute<ComponentAttribute>()).ToArray();
var props = bType.GetTypeInfo().DeclaredProperties.Where(o => o.HasAttribute<ComponentAttribute>()).ToArray();
#else
var fields = bType.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).Where(o => o.HasAttribute<ComponentAttribute>()).ToArray();
var props = bType.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).Where(o => o.HasAttribute<ComponentAttribute>()).ToArray();
#endif

members = new List<MemberInfo>();
members.AddRange(fields);
members.AddRange(props);

TypeMembers.Add(bType, members);
}

foreach ( var item in members ) {
Expand Down Expand Up @@ -225,4 +239,4 @@ public ComponentAttribute( string gameObject, bool addComponentIfMissing, bool d
DisableComponentOnError = disableComponentOnError;
GameObject = gameObject;
}
}
}