Ejemplo n.º 1
0
        private static bool IsTypeAUserExtendedScript(AssemblyDefinition assembly, TypeReference type)
        {
            bool result;

            if (type == null)
            {
                result = false;
            }
            else if (type.FullName == "System.Object")
            {
                result = false;
            }
            else
            {
                Assembly assembly2 = null;
                if (type.Scope.Name == "UnityEngine")
                {
                    assembly2 = typeof(MonoBehaviour).Assembly;
                }
                else if (type.Scope.Name == "UnityEditor")
                {
                    assembly2 = typeof(EditorWindow).Assembly;
                }
                else if (type.Scope.Name == "UnityEngine.UI")
                {
                    assembly2 = AssemblyHelper.FindLoadedAssemblyWithName("UnityEngine.UI");
                }
                if (assembly2 != null)
                {
                    string name  = (!type.IsGenericInstance) ? type.FullName : (type.Namespace + "." + type.Name);
                    Type   type2 = assembly2.GetType(name);
                    if (type2 == typeof(MonoBehaviour) || type2.IsSubclassOf(typeof(MonoBehaviour)))
                    {
                        result = true;
                        return(result);
                    }
                    if (type2 == typeof(ScriptableObject) || type2.IsSubclassOf(typeof(ScriptableObject)))
                    {
                        result = true;
                        return(result);
                    }
                    if (type2 == typeof(ScriptedImporter) || type2.IsSubclassOf(typeof(ScriptedImporter)))
                    {
                        result = true;
                        return(result);
                    }
                }
                TypeDefinition typeDefinition = null;
                try
                {
                    typeDefinition = type.Resolve();
                }
                catch (AssemblyResolutionException)
                {
                }
                result = (typeDefinition != null && AssemblyHelper.IsTypeAUserExtendedScript(assembly, typeDefinition.BaseType));
            }
            return(result);
        }
Ejemplo n.º 2
0
        private static bool IsTypeMonoBehaviourOrScriptableObject(AssemblyDefinition assembly, TypeReference type)
        {
            if (type == null || type.get_FullName() == "System.Object")
            {
                return(false);
            }
            Assembly assembly1 = (Assembly)null;

            if (type.get_Scope().get_Name() == "UnityEngine")
            {
                assembly1 = typeof(MonoBehaviour).Assembly;
            }
            else if (type.get_Scope().get_Name() == "UnityEditor")
            {
                assembly1 = typeof(EditorWindow).Assembly;
            }
            else if (type.get_Scope().get_Name() == "UnityEngine.UI")
            {
                assembly1 = AssemblyHelper.FindLoadedAssemblyWithName("UnityEngine.UI");
            }
            if (assembly1 != null)
            {
                string      name  = !type.get_IsGenericInstance() ? type.get_FullName() : type.get_Namespace() + "." + type.get_Name();
                System.Type type1 = assembly1.GetType(name);
                if (type1 == typeof(MonoBehaviour) || type1.IsSubclassOf(typeof(MonoBehaviour)) || (type1 == typeof(ScriptableObject) || type1.IsSubclassOf(typeof(ScriptableObject))))
                {
                    return(true);
                }
            }
            TypeDefinition typeDefinition = (TypeDefinition)null;

            try
            {
                typeDefinition = type.Resolve();
            }
            catch (AssemblyResolutionException ex)
            {
            }
            if (typeDefinition != null)
            {
                return(AssemblyHelper.IsTypeMonoBehaviourOrScriptableObject(assembly, typeDefinition.get_BaseType()));
            }
            return(false);
        }