Ejemplo n.º 1
0
        public static UnityType FindTypeByName(string name)
        {
            UnityType result = null;

            UnityType.ms_nameToTypeInfo.TryGetValue(name, out result);
            return(result);
        }
 public static void GenerateRegisterClassesForStripping(HashSet <UnityType> nativeClassesAndBaseClasses, TextWriter output)
 {
     output.WriteLine("template <typename T> void RegisterClass();");
     output.WriteLine("template <typename T> void RegisterStrippedTypeInfo(int, const char*, const char*);");
     output.WriteLine();
     foreach (UnityType current in UnityType.GetTypes())
     {
         if (current.baseClass != null && !current.isEditorOnly)
         {
             if (current.hasNativeNamespace)
             {
                 output.WriteLine("class {0};", current.name);
             }
             else
             {
                 output.WriteLine("namespace {0} {{ class {1}; }}", current.nativeNamespace, current.name);
             }
             output.WriteLine();
         }
     }
     output.Write("void RegisterAllClasses() \n{\n");
     output.WriteLine("\tvoid RegisterBuiltinTypes();");
     output.WriteLine("\tRegisterBuiltinTypes();");
     output.WriteLine("\t// Non stripped classes");
     foreach (UnityType current2 in UnityType.GetTypes())
     {
         if (current2.baseClass != null && !current2.isEditorOnly && nativeClassesAndBaseClasses.Contains(current2))
         {
             output.WriteLine("\tRegisterClass<{0}>();", current2.qualifiedName);
         }
     }
     output.WriteLine();
     output.Write("\n}\n");
 }
Ejemplo n.º 3
0
        public static UnityType FindTypeByPersistentTypeID(int id)
        {
            UnityType result = null;

            UnityType.ms_idToTypeInfo.TryGetValue(id, out result);
            return(result);
        }
Ejemplo n.º 4
0
        public static void GenerateDependencies2(string strippedAssemblyDir, bool doStripping, out HashSet <UnityType> nativeClasses,
                                                 out HashSet <string> nativeModules)
        {
            var dataFromLinker = AssemblyStripper.ReadLinkerToEditorData(strippedAssemblyDir);

            nativeClasses = doStripping ? new HashSet <UnityType>() : null;
            nativeModules = new HashSet <string>();
            foreach (var module in dataFromLinker.report.modules)
            {
                nativeModules.Add(module.name);

                if (doStripping)
                {
                    foreach (var dependency in module.dependencies)
                    {
                        var unityType = UnityType.FindTypeByName(dependency.name);

                        if (unityType != null)
                        {
                            nativeClasses.Add(unityType);
                        }
                    }
                }
            }
        }
Ejemplo n.º 5
0
 static UnityType()
 {
     UnityType.UnityTypeTransport[] array = UnityType.Internal_GetAllTypes();
     UnityType.ms_types          = new UnityType[array.Length];
     UnityType.ms_idToTypeInfo   = new Dictionary <int, UnityType>();
     UnityType.ms_nameToTypeInfo = new Dictionary <string, UnityType>();
     for (int i = 0; i < array.Length; i++)
     {
         UnityType baseClass = null;
         if ((ulong)array[i].baseClassIndex < (ulong)((long)array.Length))
         {
             baseClass = UnityType.ms_types[(int)((UIntPtr)array[i].baseClassIndex)];
         }
         UnityType unityType = new UnityType
         {
             runtimeTypeIndex = array[i].runtimeTypeIndex,
             descendantCount  = array[i].descendantCount,
             name             = array[i].className,
             nativeNamespace  = array[i].classNamespace,
             persistentTypeID = array[i].persistentTypeID,
             baseClass        = baseClass,
             flags            = (UnityTypeFlags)array[i].flags
         };
         UnityType.ms_types[i]      = unityType;
         UnityType.ms_typesReadOnly = new ReadOnlyCollection <UnityType>(UnityType.ms_types);
         UnityType.ms_idToTypeInfo[unityType.persistentTypeID] = unityType;
         UnityType.ms_nameToTypeInfo[unityType.name]           = unityType;
     }
 }
Ejemplo n.º 6
0
        public static UnityType FindTypeByPersistentTypeID(int persistentTypeId)
        {
            UnityType result = null;

            ms_idToType.TryGetValue(persistentTypeId, out result);
            return(result);
        }
Ejemplo n.º 7
0
 // When switching to explicitly defined clips, we must fix up the internalID's to not lose AnimationClip references.
 // When m_ClipAnimations is defined, the clips are identified by the clipName
 // When m_ClipAnimations is not defined, the clips are identified by the takeName
 void PatchDefaultClipTakeNamesToSplitClipNames()
 {
     foreach (TakeInfo takeInfo in singleImporter.importedTakeInfos)
     {
         UnityType animationClipType = UnityType.FindTypeByName("AnimationClip");
         ImportSettingInternalID.Rename(serializedObject, animationClipType, takeInfo.name, takeInfo.defaultClipName);
     }
 }
Ejemplo n.º 8
0
        public void AddNativeClassID(int ID)
        {
            string name = UnityType.FindTypeByPersistentTypeID(ID).name;

            if (name.Length > 0)
            {
                this.allNativeClasses[ID] = name;
            }
        }
Ejemplo n.º 9
0
        static void GetAnnotationIdAndClass(Type type, out int id, out string klass)
        {
            var unityType = UnityType.FindTypeByName(type.Name);

            id = unityType?.persistentTypeID ?? 0;
            // In AnnotationManager, if script name is null or empty the persistent ID is used. If not, the type is
            // assumed to be a built-in type.
            klass = unityType == null ? type.Name : null;
        }
Ejemplo n.º 10
0
        private static HashSet <UnityType> GenerateNativeClassList(RuntimeClassRegistry rcr, string directory, string[] rootAssemblies, StrippingInfo strippingInfo)
        {
            if (AssemblyStripper.UseUnityLinkerEngineModuleStripping)
            {
                throw new NotSupportedException("Don't want to rely on this method when UnityLinker EMS is used");
            }

            HashSet <UnityType> nativeClasses = CollectNativeClassListFromRoots(directory, rootAssemblies, strippingInfo);

            // List native classes found in scenes
            foreach (string klassName in rcr.GetAllNativeClassesIncludingManagersAsString())
            {
                UnityType klass = UnityType.FindTypeByName(klassName);
                if (klass != null && klass.baseClass != null)
                {
                    nativeClasses.Add(klass);
                    if (strippingInfo != null)
                    {
                        if (!klass.IsDerivedFrom(GameManagerTypeInfo))
                        {
                            var scenes = rcr.GetScenesForClass(klass.persistentTypeID);
                            if (scenes != null)
                            {
                                foreach (var scene in scenes)
                                {
                                    strippingInfo.RegisterDependency(klassName, scene);
                                    if (scene.EndsWith(".unity"))
                                    {
                                        strippingInfo.SetIcon(scene, "class/SceneAsset");
                                    }
                                    else
                                    {
                                        strippingInfo.SetIcon(scene, "class/AssetBundle");
                                    }
                                }
                            }
                        }
                    }
                }
            }

            // Always include base classes of derived native classes.
            HashSet <UnityType> nativeClassesAndBaseClasses = new HashSet <UnityType>();

            foreach (var klass in nativeClasses)
            {
                var current = klass;
                while (current.baseClass != null)
                {
                    nativeClassesAndBaseClasses.Add(current);
                    current = current.baseClass;
                }
            }

            return(nativeClassesAndBaseClasses);
        }
Ejemplo n.º 11
0
        private static HashSet <UnityType> CollectNativeClassListFromRoots(string directory, string[] rootAssemblies, StrippingInfo strippingInfo)
        {
            HashSet <string>        source     = CodeStrippingUtils.CollectManagedTypeReferencesFromRoots(directory, rootAssemblies, strippingInfo);
            IEnumerable <UnityType> collection = from name in source
                                                 select UnityType.FindTypeByName(name) into klass
                                                     where klass != null && klass.baseClass != null
                                                 select klass;

            return(new HashSet <UnityType>(collection));
        }
Ejemplo n.º 12
0
        private static UnityType FindTypeByNameChecked(string name, string msg)
        {
            UnityType result = UnityType.FindTypeByName(name);

            if (result == null)
            {
                throw new ArgumentException(string.Format("Could not map typename '{0}' to type info ({1})", name, msg ?? "no context"));
            }
            return(result);
        }
Ejemplo n.º 13
0
        private static HashSet <UnityType> CollectNativeClassListFromRoots(string directory, string[] rootAssemblies, StrippingInfo strippingInfo)
        {
            // Collect managed types
            HashSet <string> managedTypeNames = CollectManagedTypeReferencesFromRoots(directory, rootAssemblies, strippingInfo);

            // Extract native types from managed types
            var infos = managedTypeNames.Select(name => UnityType.FindTypeByName(name)).Where(klass => klass != null && klass.baseClass != null);

            return(new HashSet <UnityType>(infos));
        }
Ejemplo n.º 14
0
        public static void InjectCustomDependencies(BuildTarget target, StrippingInfo strippingInfo, HashSet <UnityType> nativeClasses,
                                                    HashSet <string> nativeModules)
        {
            // This function can be used to inject user-readable dependency information for specific classes which would not be obvious otherwise.
            // Can also be used to set up dependencies to modules which cannot be derived by the build pipeline without custom rules
            const string connectSettingsName         = "UnityConnectSettings";
            var          connectSettings             = UnityType.FindTypeByName(connectSettingsName);
            const string cloudWebServicesManagerName = "CloudWebServicesManager";
            var          cloudWebServicesManager     = UnityType.FindTypeByName(cloudWebServicesManagerName);

            if (nativeClasses.Contains(connectSettings) || nativeClasses.Contains(cloudWebServicesManager))
            {
                if (PlayerSettings.submitAnalytics)
                {
                    const string requiredMessage = "Required by HW Statistics (See Player Settings)";
                    strippingInfo.RegisterDependency(connectSettingsName, requiredMessage);
                    strippingInfo.RegisterDependency(cloudWebServicesManagerName, requiredMessage);
                    strippingInfo.SetIcon(requiredMessage, "class/PlayerSettings");
                }
            }

            const string analyticsManagerName = "UnityAnalyticsManager";
            var          analyticsManager     = UnityType.FindTypeByName(analyticsManagerName);

            if (nativeClasses.Contains(analyticsManager))
            {
                if (UnityEditor.Analytics.AnalyticsSettings.enabled)
                {
                    const string requiredMessage = "Required by Unity Analytics (See Services Window)";
                    strippingInfo.RegisterDependency(analyticsManagerName, requiredMessage);
                    strippingInfo.SetIcon(requiredMessage, "class/PlayerSettings");
                }
            }

            if (UnityEditorInternal.VR.VRModule.ShouldInjectVRDependenciesForBuildTarget(target))
            {
                const string moduleName      = "VR";
                const string requiredMessage = "Required because VR is enabled in PlayerSettings";
                nativeModules.Add(moduleName);
                strippingInfo.RegisterDependency(StrippingInfo.ModuleName(moduleName), requiredMessage);
                strippingInfo.SetIcon(requiredMessage, "class/PlayerSettings");
            }

            foreach (string module in ModuleMetadata.GetModuleNames())
            {
                if (!ModuleMetadata.IsStrippableModule(module))
                {
                    string requiredMessage = module + " is always required";
                    nativeModules.Add(module);
                    strippingInfo.AddModule(module);
                    strippingInfo.RegisterDependency(StrippingInfo.ModuleName(module), requiredMessage);
                    strippingInfo.SetIcon(requiredMessage, "class/DefaultAsset");
                }
            }
        }
Ejemplo n.º 15
0
 internal GizmoInfo(Annotation annotation)
 {
     m_GizmoEnabled = annotation.gizmoEnabled > 0;
     m_IconEnabled  = annotation.iconEnabled > 0;
     m_ClassID      = annotation.classID;
     m_ScriptClass  = annotation.scriptClass;
     m_Flags        = annotation.flags;
     m_Name         = string.IsNullOrEmpty(m_ScriptClass)
         ? UnityType.FindTypeByPersistentTypeID(m_ClassID).name
         : m_Name = m_ScriptClass;
 }
Ejemplo n.º 16
0
        public void AddNativeClassID(int ID)
        {
            string className = UnityType.FindTypeByPersistentTypeID(ID).name;

            ////System.Console.WriteLine("Looking for ID {0} name {1} --> is manager? {2}", ID, className, functionalityGroups.ContainsValue(className));

            // Native class found
            if (className.Length > 0)
            {
                allNativeClasses[ID] = className;
            }
        }
Ejemplo n.º 17
0
        protected void AddNativeClassFromName(string className)
        {
            if (this.objectUnityType == null)
            {
                this.objectUnityType = UnityType.FindTypeByName("Object");
            }
            UnityType unityType = UnityType.FindTypeByName(className);

            if (unityType != null && unityType.persistentTypeID != this.objectUnityType.persistentTypeID)
            {
                this.nativeClasses[unityType.persistentTypeID] = className;
            }
        }
Ejemplo n.º 18
0
        public void AddNativeClassID(int ID)
        {
            string name = UnityType.FindTypeByPersistentTypeID(ID).name;

            if (name.Length > 0)
            {
                this.allNativeClasses[ID] = name;
                if (!this.functionalityGroups.ContainsValue(name))
                {
                    this.nativeClasses[ID] = name;
                }
            }
        }
Ejemplo n.º 19
0
 public static void ApplyManualStrippingOverrides(HashSet <UnityType> nativeClasses, HashSet <string> nativeModules, StrippingInfo strippingInfo)
 {
     string[] moduleNames = ModuleMetadata.GetModuleNames();
     for (int i = 0; i < moduleNames.Length; i++)
     {
         string text = moduleNames[i];
         ModuleIncludeSetting moduleIncludeSettingForModule = ModuleMetadata.GetModuleIncludeSettingForModule(text);
         if (moduleIncludeSettingForModule == ModuleIncludeSetting.ForceInclude)
         {
             nativeModules.Add(text);
             UnityType[] moduleTypes = ModuleMetadata.GetModuleTypes(text);
             UnityType[] array       = moduleTypes;
             for (int j = 0; j < array.Length; j++)
             {
                 UnityType unityType = array[j];
                 nativeClasses.Add(unityType);
                 if (strippingInfo != null)
                 {
                     strippingInfo.RegisterDependency(unityType.name, "Force included module");
                     strippingInfo.RegisterDependency(StrippingInfo.ModuleName(text), unityType.name);
                 }
             }
             if (strippingInfo != null)
             {
                 strippingInfo.RegisterDependency(StrippingInfo.ModuleName(text), "Force included module");
             }
         }
         else if (moduleIncludeSettingForModule == ModuleIncludeSetting.ForceExclude)
         {
             if (nativeModules.Contains(text))
             {
                 nativeModules.Remove(text);
                 UnityType[] moduleTypes2 = ModuleMetadata.GetModuleTypes(text);
                 UnityType[] array2       = moduleTypes2;
                 for (int k = 0; k < array2.Length; k++)
                 {
                     UnityType item = array2[k];
                     if (nativeClasses.Contains(item))
                     {
                         nativeClasses.Remove(item);
                     }
                 }
                 if (strippingInfo != null)
                 {
                     strippingInfo.modules.Remove(StrippingInfo.ModuleName(text));
                 }
             }
         }
     }
 }
Ejemplo n.º 20
0
        public void AddNativeClassFromName(string className)
        {
            if (objectUnityType == null)
            {
                objectUnityType = UnityType.FindTypeByName("Object");
            }

            var t = UnityType.FindTypeByName(className);

            ////System.Console.WriteLine("Looking for name {1}  ID {0}", classID, className);
            if (t != null && t.persistentTypeID != objectUnityType.persistentTypeID)
            {
                allNativeClasses[t.persistentTypeID] = className;
            }
        }
Ejemplo n.º 21
0
        private static HashSet <UnityType> CollectNativeClassListFromRoots(string directory, string[] rootAssemblies, StrippingInfo strippingInfo)
        {
            if (AssemblyStripper.UseUnityLinkerEngineModuleStripping)
            {
                throw new NotSupportedException("Don't want to rely on this method when UnityLinker EMS is used");
            }

            // Collect managed types
            HashSet <string> managedTypeNames = CollectManagedTypeReferencesFromRoots(directory, rootAssemblies, strippingInfo);

            // Extract native types from managed types
            var infos = managedTypeNames.Select(name => UnityType.FindTypeByName(name)).Where(klass => klass != null && klass.baseClass != null);

            return(new HashSet <UnityType>(infos));
        }
 public AInfo(bool gizmoEnabled, bool iconEnabled, int flags, int classID, string scriptClass)
 {
     m_GizmoEnabled = gizmoEnabled;
     m_IconEnabled  = iconEnabled;
     m_ClassID      = classID;
     m_ScriptClass  = scriptClass;
     m_Flags        = flags;
     if (m_ScriptClass == "")
     {
         m_DisplayText = UnityType.FindTypeByPersistentTypeID(m_ClassID).name;
     }
     else
     {
         m_DisplayText = m_ScriptClass;
     }
 }
Ejemplo n.º 23
0
 private static void ExcludeModuleManagers(ref HashSet <UnityType> nativeClasses)
 {
     string[] moduleNames = ModuleMetadata.GetModuleNames();
     string[] array       = moduleNames;
     for (int i = 0; i < array.Length; i++)
     {
         string moduleName = array[i];
         if (ModuleMetadata.GetModuleStrippable(moduleName))
         {
             UnityType[]         moduleTypes = ModuleMetadata.GetModuleTypes(moduleName);
             HashSet <UnityType> hashSet     = new HashSet <UnityType>();
             HashSet <UnityType> hashSet2    = new HashSet <UnityType>();
             UnityType[]         array2      = moduleTypes;
             for (int j = 0; j < array2.Length; j++)
             {
                 UnityType unityType = array2[j];
                 if (unityType.IsDerivedFrom(CodeStrippingUtils.GameManagerTypeInfo))
                 {
                     hashSet.Add(unityType);
                 }
                 else
                 {
                     hashSet2.Add(unityType);
                 }
             }
             if (hashSet2.Count != 0)
             {
                 if (!nativeClasses.Overlaps(hashSet2))
                 {
                     foreach (UnityType current in hashSet)
                     {
                         nativeClasses.Remove(current);
                     }
                 }
                 else
                 {
                     foreach (UnityType current2 in hashSet)
                     {
                         nativeClasses.Add(current2);
                     }
                 }
             }
         }
     }
 }
Ejemplo n.º 24
0
        public static void InjectCustomDependencies(StrippingInfo strippingInfo, HashSet <UnityType> nativeClasses)
        {
            UnityType item = UnityType.FindTypeByName("UnityAnalyticsManager");

            if (nativeClasses.Contains(item))
            {
                if (PlayerSettings.submitAnalytics)
                {
                    strippingInfo.RegisterDependency("UnityAnalyticsManager", "Required by HW Statistics (See Player Settings)");
                    strippingInfo.SetIcon("Required by HW Statistics (See Player Settings)", "class/PlayerSettings");
                }
                if (AnalyticsSettings.enabled)
                {
                    strippingInfo.RegisterDependency("UnityAnalyticsManager", "Required by Unity Analytics (See Services Window)");
                    strippingInfo.SetIcon("Required by Unity Analytics (See Services Window)", "class/PlayerSettings");
                }
            }
        }
Ejemplo n.º 25
0
        public static void InjectCustomDependencies(BuildTarget target, StrippingInfo strippingInfo, HashSet <UnityType> nativeClasses, HashSet <string> nativeModules)
        {
            UnityType item  = UnityType.FindTypeByName("UnityConnectSettings");
            UnityType item2 = UnityType.FindTypeByName("CloudWebServicesManager");

            if (nativeClasses.Contains(item) || nativeClasses.Contains(item2))
            {
                if (PlayerSettings.submitAnalytics)
                {
                    strippingInfo.RegisterDependency("UnityConnectSettings", "Required by HW Statistics (See Player Settings)");
                    strippingInfo.RegisterDependency("CloudWebServicesManager", "Required by HW Statistics (See Player Settings)");
                    strippingInfo.SetIcon("Required by HW Statistics (See Player Settings)", "class/PlayerSettings");
                }
            }
            UnityType item3 = UnityType.FindTypeByName("UnityAnalyticsManager");

            if (nativeClasses.Contains(item3))
            {
                if (AnalyticsSettings.enabled)
                {
                    strippingInfo.RegisterDependency("UnityAnalyticsManager", "Required by Unity Analytics (See Services Window)");
                    strippingInfo.SetIcon("Required by Unity Analytics (See Services Window)", "class/PlayerSettings");
                }
            }
            if (VRModule.ShouldInjectVRDependenciesForBuildTarget(target))
            {
                nativeModules.Add("VR");
                strippingInfo.RegisterDependency(StrippingInfo.ModuleName("VR"), "Required because VR is enabled in PlayerSettings");
                strippingInfo.SetIcon("Required because VR is enabled in PlayerSettings", "class/PlayerSettings");
            }
            string[] moduleNames = ModuleMetadata.GetModuleNames();
            for (int i = 0; i < moduleNames.Length; i++)
            {
                string text = moduleNames[i];
                if (!ModuleMetadata.IsStrippableModule(text))
                {
                    string text2 = text + " is always required";
                    nativeModules.Add(text);
                    strippingInfo.AddModule(text, true);
                    strippingInfo.RegisterDependency(StrippingInfo.ModuleName(text), text2);
                    strippingInfo.SetIcon(text2, "class/DefaultAsset");
                }
            }
        }
Ejemplo n.º 26
0
        static UnityType()
        {
            var types = UnityType.Internal_GetAllTypes();

            ms_types      = new UnityType[types.Length];
            ms_idToType   = new Dictionary <int, UnityType>();
            ms_nameToType = new Dictionary <string, UnityType>();

            for (int i = 0; i < types.Length; ++i)
            {
                // Types are sorted so base < derived and null baseclass is passed from native as 0xffffffff
                UnityType baseClass = null;
                if (types[i].baseClassIndex < types.Length)
                {
                    baseClass = ms_types[types[i].baseClassIndex];
                }

                var newType = new UnityType
                {
                    runtimeTypeIndex = types[i].runtimeTypeIndex,
                    descendantCount  = types[i].descendantCount,
                    name             = types[i].className,
                    nativeNamespace  = types[i].classNamespace,
                    module           = types[i].module,
                    persistentTypeID = types[i].persistentTypeID,
                    baseClass        = baseClass,
                    flags            = (UnityTypeFlags)types[i].flags
                };

                Debug.Assert(types[i].runtimeTypeIndex == i);

                ms_types[i]      = newType;
                ms_typesReadOnly = new ReadOnlyCollection <UnityType>(ms_types);
                ms_idToType[newType.persistentTypeID] = newType;
                ms_nameToType[newType.name]           = newType;
            }
        }
Ejemplo n.º 27
0
        public static void GenerateRegisterClassesForStripping(HashSet <UnityType> nativeClassesAndBaseClasses, TextWriter output)
        {
            output.WriteLine("template <typename T> void RegisterClass();");
            output.WriteLine("template <typename T> void RegisterStrippedTypeInfo(int, const char*, const char*);");
            output.WriteLine();
            foreach (UnityType type in UnityType.GetTypes())
            {
                if ((type.baseClass != null) && !type.isEditorOnly)
                {
                    if (!type.hasNativeNamespace)
                    {
                        output.WriteLine("class {0};", type.name);
                    }
                    else
                    {
                        output.WriteLine("namespace {0} {{ class {1}; }}", type.nativeNamespace, type.name);
                    }
                    output.WriteLine();
                }
            }
            output.Write("void RegisterAllClasses() \n{\n");
            output.WriteLine("\tvoid RegisterBuiltinTypes();");
            output.WriteLine("\tRegisterBuiltinTypes();");
            output.WriteLine("\t// {0} Non stripped classes", nativeClassesAndBaseClasses.Count);
            int num = 1;

            foreach (UnityType type2 in UnityType.GetTypes())
            {
                if (((type2.baseClass != null) && !type2.isEditorOnly) && nativeClassesAndBaseClasses.Contains(type2))
                {
                    output.WriteLine("\t// {0}. {1}\n", num++, type2.qualifiedName);
                    output.WriteLine("\tRegisterClass<{0}>();\n", type2.qualifiedName);
                }
            }
            output.WriteLine();
            output.Write("\n}\n");
        }
Ejemplo n.º 28
0
        public static void InjectCustomDependencies(BuildTarget target, StrippingInfo strippingInfo, HashSet <UnityType> nativeClasses, HashSet <string> nativeModules)
        {
            UnityType item = UnityType.FindTypeByName("UnityAnalyticsManager");

            if (nativeClasses.Contains(item))
            {
                if (PlayerSettings.submitAnalytics)
                {
                    strippingInfo.RegisterDependency("UnityAnalyticsManager", "Required by HW Statistics (See Player Settings)");
                    strippingInfo.SetIcon("Required by HW Statistics (See Player Settings)", "class/PlayerSettings");
                }
                if (AnalyticsSettings.enabled)
                {
                    strippingInfo.RegisterDependency("UnityAnalyticsManager", "Required by Unity Analytics (See Services Window)");
                    strippingInfo.SetIcon("Required by Unity Analytics (See Services Window)", "class/PlayerSettings");
                }
            }
            if (CodeStrippingUtils.IsVRModuleUsed(target))
            {
                nativeModules.Add("VR");
                strippingInfo.RegisterDependency("VR", "Required by Scripts");
                strippingInfo.SetIcon("Required because VR is enabled in PlayerSettings", "class/PlayerSettings");
            }
        }
Ejemplo n.º 29
0
 public bool IsDerivedFrom(UnityType baseClass)
 {
     return(this.runtimeTypeIndex - baseClass.runtimeTypeIndex < baseClass.descendantCount);
 }
Ejemplo n.º 30
0
        private static void WriteStaticallyLinkedModuleClassRegistration(TextWriter w, HashSet <UnityType> nativeClasses, HashSet <UnityType> classesToSkip)
        {
            w.WriteLine("template <typename T> void RegisterUnityClass(const char*);");
            w.WriteLine("template <typename T> void RegisterStrippedType(int, const char*, const char*);");
            w.WriteLine();

            WriteFunctionInvokeRegisterStaticallyLinkedModuleClasses(w, nativeClasses);

            // Forward declare types
            if (nativeClasses != null)
            {
                foreach (var type in UnityType.GetTypes())
                {
                    if (type.baseClass == null || type.isEditorOnly || classesToSkip.Contains(type))
                    {
                        continue;
                    }

                    if (type.hasNativeNamespace)
                    {
                        w.Write("namespace {0} {{ class {1}; }} ", type.nativeNamespace, type.name);
                    }
                    else
                    {
                        w.Write("class {0}; ", type.name);
                    }

                    if (nativeClasses.Contains(type))
                    {
                        w.WriteLine("template <> void RegisterUnityClass<{0}>(const char*);", type.qualifiedName);
                    }
                    else
                    {
                        w.WriteLine();
                    }
                }
                w.WriteLine();
            }

            // Class registration function
            w.WriteLine("void RegisterAllClasses()");
            w.WriteLine("{");

            if (nativeClasses == null)
            {
                w.WriteLine("\tvoid RegisterAllClassesGranular();");
                w.WriteLine("\tRegisterAllClassesGranular();");
            }
            else
            {
                w.WriteLine("void RegisterBuiltinTypes();");
                w.WriteLine("RegisterBuiltinTypes();");
                w.WriteLine("\t//Total: {0} non stripped classes", nativeClasses.Count);

                int index = 0;
                foreach (var klass in nativeClasses)
                {
                    w.WriteLine("\t//{0}. {1}", index, klass.qualifiedName);
                    if (classesToSkip.Contains(klass) || (klass.baseClass == null))
                    {
                        w.WriteLine("\t//Skipping {0}", klass.qualifiedName);
                    }
                    else
                    {
                        w.WriteLine("\tRegisterUnityClass<{0}>(\"{1}\");", klass.qualifiedName, klass.module);
                    }
                    ++index;
                }
                w.WriteLine();

                // Register stripped classes

                // TODO (ulfj ) 2016-08-15 : Right now we cannot deal with types that are compiled into the editor
                // but not the player due to other defines than UNITY_EDITOR in them module definition file
                // (for example WorldAnchor only being there if ENABLE_HOLOLENS_MODULE_API). Doing this would
                // require either some non trivial changes to the module registration macros or a way for these
                // conditionals to be included in the RTTI so we can emit them when generating the code, so we
                // disabling the registration of stripped classes for now and will get back to this when we have
                // landed the remaining changes to the type system.

                //w.WriteLine("\t//Stripped classes");
                //foreach (var type in UnityType.GetTypes())
                //{
                //  if (type.baseClass == null || type.isEditorOnly || classesToSkip.Contains(type) || nativeClasses.Contains(type))
                //      continue;

                //  w.WriteLine("\tRegisterStrippedType<{0}>({1}, \"{2}\", \"{3}\");", type.qualifiedName, type.persistentTypeID, type.name, type.nativeNamespace);
                //}
            }
            w.WriteLine("}");
        }