From 15740faf9fe9fe4be08965098bbf2947e096aeeb Mon Sep 17 00:00:00 2001 From: chai Date: Wed, 14 Aug 2019 22:50:43 +0800 Subject: +Unity Runtime code --- Runtime/Export/AttributeHelperEngine.cs | 84 +++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 Runtime/Export/AttributeHelperEngine.cs (limited to 'Runtime/Export/AttributeHelperEngine.cs') diff --git a/Runtime/Export/AttributeHelperEngine.cs b/Runtime/Export/AttributeHelperEngine.cs new file mode 100644 index 0000000..d8188e0 --- /dev/null +++ b/Runtime/Export/AttributeHelperEngine.cs @@ -0,0 +1,84 @@ +using UnityEngine; +using System; +using System.Collections; +using System.Collections.Generic; +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + + +namespace AOT +{ + // Mono AOT compiler detects this attribute by name and generates required wrappers for + // native->managed callbacks. Works only for static methods. + [System.AttributeUsage(System.AttributeTargets.Method)] + public class MonoPInvokeCallbackAttribute : Attribute + { + public MonoPInvokeCallbackAttribute (Type type) {} + } +} + +namespace UnityEngine +{ + +internal class WrapperlessIcall : System.Attribute { + public WrapperlessIcall () { + } +} + +class AttributeHelperEngine +{ + static Type[] GetRequiredComponents (Type klass) + { + // Generate an array for all required components + // .NET doesnt give us multiple copies of the same attribute on derived classes + // Thus we do it manually + List required = null; + while (klass != null && klass != typeof (MonoBehaviour)) + { + object[] attrs = klass.GetCustomAttributes(typeof(RequireComponent), false); + + + for (int i=0;i(); + + if (attri.m_Type0 != null) + required.Add(attri.m_Type0); + if (attri.m_Type1 != null) + required.Add(attri.m_Type1); + if (attri.m_Type2 != null) + required.Add(attri.m_Type2); + } + } + + klass = klass.BaseType; + } + if (required == null) + return null; + else + return required.ToArray(); + } + + static bool CheckIsEditorScript (Type klass) + { + while (klass != null && klass != typeof (MonoBehaviour)) + { + object[] attrs = klass.GetCustomAttributes(typeof(ExecuteInEditMode), false); + if (attrs.Length != 0) + return true; + klass = klass.BaseType; + } + return false; + } +} +} \ No newline at end of file -- cgit v1.1-26-g67d0