예제 #1
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);
        }
예제 #2
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");
                }
            }
        }
예제 #3
0
 private static void AddNativeModuleInStrippingInfo(string moduleName, string requiredMessage, StrippingInfo strippingInfo, HashSet <string> nativeModules, string icon)
 {
     nativeModules.Add(moduleName);
     strippingInfo.AddModule(moduleName);
     strippingInfo.RegisterDependency(StrippingInfo.ModuleName(moduleName), requiredMessage);
     strippingInfo.SetIcon(requiredMessage, icon);
 }
        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");
                }
            }
        }
예제 #5
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");
                }
            }
        }
예제 #6
0
        private static void AddNativeModuleInStrippingInfo(string moduleName, string requiredMessage, StrippingInfo strippingInfo, HashSet <string> nativeModules, string icon)
        {
            if (AssemblyStripper.UseUnityLinkerEngineModuleStripping)
            {
                throw new NotSupportedException("Don't want to rely on this method when UnityLinker EMS is used");
            }

            nativeModules.Add(moduleName);
            strippingInfo.AddModule(moduleName);
            strippingInfo.RegisterDependency(StrippingInfo.ModuleName(moduleName), requiredMessage);
            strippingInfo.SetIcon(requiredMessage, icon);
        }
        internal static void UpdateBuildReport(LinkerToEditorData dataFromLinker, StrippingInfo strippingInfo)
        {
            foreach (var moduleInfo in dataFromLinker.report.modules)
            {
                strippingInfo.AddModule(moduleInfo.name);
                foreach (var moduleDependency in moduleInfo.dependencies)
                {
                    strippingInfo.RegisterDependency(StrippingInfo.ModuleName(moduleInfo.name), moduleDependency.name);

                    if (!string.IsNullOrEmpty(moduleDependency.icon))
                    {
                        strippingInfo.SetIcon(moduleDependency.name, moduleDependency.icon);
                    }

                    // Hacky way to match the existing behavior
                    if (moduleDependency.name == "UnityConnectSettings")
                    {
                        strippingInfo.RegisterDependency(moduleDependency.name, "Required by UnityAnalytics");
                    }

                    foreach (var scene in moduleDependency.scenes)
                    {
                        strippingInfo.RegisterDependency(moduleDependency.name, scene);

                        var klass = UnityType.FindTypeByName(moduleDependency.name);
                        if (klass != null && !klass.IsDerivedFrom(CodeStrippingUtils.GameManagerTypeInfo))
                        {
                            if (scene.EndsWith(".unity"))
                            {
                                strippingInfo.SetIcon(scene, "class/SceneAsset");
                            }
                            else
                            {
                                strippingInfo.SetIcon(scene, "class/AssetBundle");
                            }
                        }
                    }
                }
            }
        }
예제 #8
0
        public static void InjectCustomDependencies(BuildTarget target, StrippingInfo strippingInfo, HashSet <UnityType> nativeClasses,
                                                    HashSet <string> nativeModules)
        {
            if (AssemblyStripper.UseUnityLinkerEngineModuleStripping)
            {
                throw new NotSupportedException("Don't want to rely on this method when UnityLinker EMS is used");
            }

            // 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
            if (UnityEngine.Connect.UnityConnectSettings.enabled || UnityEditor.CrashReporting.CrashReportingSettings.enabled || UnityEngine.Analytics.PerformanceReporting.enabled || UnityEngine.Analytics.Analytics.enabled)
            {
                string       requiredMessage = "Required by HW Statistics (See Player Settings)";
                const string icon            = "class/PlayerSettings";
                if (UnityEngine.Analytics.Analytics.enabled || UnityEngine.Analytics.PerformanceReporting.enabled)
                {
                    requiredMessage = "Required by Analytics Performance Reporting (See Analytics Services Window)";
                    AddNativeModuleInStrippingInfo("PerformanceReporting", requiredMessage, strippingInfo, nativeModules, icon);
                }
                requiredMessage = "Required by UnityAnalytics (See Services Window)";
                AddNativeModuleInStrippingInfo("UnityAnalytics", requiredMessage, strippingInfo, nativeModules, icon);

                AddNativeModuleInStrippingInfo("UnityConnect", requiredMessage, strippingInfo, nativeModules, icon);
                strippingInfo.RegisterDependency("UnityConnectSettings", "Required by UnityAnalytics");
            }

            if (CrashReporting.CrashReportingSettings.enabled)
            {
                AddNativeModuleInStrippingInfo("CrashReporting", "Required by Crash Reporting Service (See Services Window)", strippingInfo, nativeModules, "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";
                    AddNativeModuleInStrippingInfo(module, requiredMessage, strippingInfo, nativeModules, "class/DefaultAsset");
                }
            }
        }
예제 #9
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");
            }
        }
        private static HashSet <UnityType> GenerateNativeClassList(RuntimeClassRegistry rcr, string directory, string[] rootAssemblies, StrippingInfo strippingInfo)
        {
            HashSet <UnityType> nativeClasses = CollectNativeClassListFromRoots(directory, rootAssemblies, strippingInfo);

            // Inject blacklisted native types
            foreach (var klass in BlackListNativeClasses)
            {
                nativeClasses.Add(klass);
            }

            foreach (var dependent in BlackListNativeClassesDependency.Keys)
            {
                if (nativeClasses.Contains(dependent))
                {
                    var provider = BlackListNativeClassesDependency[dependent];
                    nativeClasses.Add(provider);
                }
            }

            // 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);
        }
예제 #11
0
        private static HashSet <UnityType> GenerateNativeClassList(RuntimeClassRegistry rcr, string directory, string[] rootAssemblies, StrippingInfo strippingInfo)
        {
            HashSet <UnityType> hashSet = CodeStrippingUtils.CollectNativeClassListFromRoots(directory, rootAssemblies, strippingInfo);

            UnityType[] blackListNativeClasses = CodeStrippingUtils.BlackListNativeClasses;
            for (int i = 0; i < blackListNativeClasses.Length; i++)
            {
                UnityType item = blackListNativeClasses[i];
                hashSet.Add(item);
            }
            foreach (UnityType current in CodeStrippingUtils.BlackListNativeClassesDependency.Keys)
            {
                if (hashSet.Contains(current))
                {
                    UnityType item2 = CodeStrippingUtils.BlackListNativeClassesDependency[current];
                    hashSet.Add(item2);
                }
            }
            foreach (string current2 in rcr.GetAllNativeClassesIncludingManagersAsString())
            {
                UnityType unityType = UnityType.FindTypeByName(current2);
                if (unityType != null && unityType.baseClass != null)
                {
                    hashSet.Add(unityType);
                    if (strippingInfo != null)
                    {
                        if (!unityType.IsDerivedFrom(CodeStrippingUtils.GameManagerTypeInfo))
                        {
                            List <string> scenesForClass = rcr.GetScenesForClass(unityType.persistentTypeID);
                            if (scenesForClass != null)
                            {
                                foreach (string current3 in scenesForClass)
                                {
                                    strippingInfo.RegisterDependency(current2, current3);
                                    if (current3.EndsWith(".unity"))
                                    {
                                        strippingInfo.SetIcon(current3, "class/SceneAsset");
                                    }
                                    else
                                    {
                                        strippingInfo.SetIcon(current3, "class/AssetBundle");
                                    }
                                }
                            }
                        }
                    }
                }
            }
            HashSet <UnityType> hashSet2 = new HashSet <UnityType>();

            foreach (UnityType current4 in hashSet)
            {
                UnityType unityType2 = current4;
                while (unityType2.baseClass != null)
                {
                    hashSet2.Add(unityType2);
                    unityType2 = unityType2.baseClass;
                }
            }
            return(hashSet2);
        }
예제 #12
0
        public static void GenerateDependencies(string strippedAssemblyDir, string icallsListFile, RuntimeClassRegistry rcr, bool doStripping, out HashSet <UnityType> nativeClasses, out HashSet <string> nativeModules, IIl2CppPlatformProvider platformProvider)
        {
            StrippingInfo strippingInfo = (platformProvider != null) ? StrippingInfo.GetBuildReportData(platformProvider.buildReport) : null;

            string[] userAssemblies = CodeStrippingUtils.GetUserAssemblies(strippedAssemblyDir);
            nativeClasses = ((!doStripping) ? null : CodeStrippingUtils.GenerateNativeClassList(rcr, strippedAssemblyDir, userAssemblies, strippingInfo));
            if (nativeClasses != null)
            {
                CodeStrippingUtils.ExcludeModuleManagers(ref nativeClasses);
            }
            nativeModules = CodeStrippingUtils.GetNativeModulesToRegister(nativeClasses, strippingInfo);
            if (nativeClasses != null && icallsListFile != null)
            {
                HashSet <string> modulesFromICalls = CodeStrippingUtils.GetModulesFromICalls(icallsListFile);
                foreach (string current in modulesFromICalls)
                {
                    if (!nativeModules.Contains(current))
                    {
                        if (strippingInfo != null)
                        {
                            strippingInfo.RegisterDependency(StrippingInfo.ModuleName(current), "Required by Scripts");
                        }
                    }
                    UnityType[] moduleTypes = ModuleMetadata.GetModuleTypes(current);
                    UnityType[] array       = moduleTypes;
                    for (int i = 0; i < array.Length; i++)
                    {
                        UnityType unityType = array[i];
                        if (unityType.IsDerivedFrom(CodeStrippingUtils.GameManagerTypeInfo))
                        {
                            nativeClasses.Add(unityType);
                        }
                    }
                }
                nativeModules.UnionWith(modulesFromICalls);
            }
            bool flag = true;

            if (platformProvider != null)
            {
                while (flag)
                {
                    flag = false;
                    foreach (string current2 in nativeModules.ToList <string>())
                    {
                        string moduleWhitelist = CodeStrippingUtils.GetModuleWhitelist(current2, platformProvider.moduleStrippingInformationFolder);
                        if (File.Exists(moduleWhitelist))
                        {
                            foreach (string current3 in CodeStrippingUtils.GetDependentModules(moduleWhitelist))
                            {
                                if (!nativeModules.Contains(current3))
                                {
                                    nativeModules.Add(current3);
                                    flag = true;
                                }
                                if (strippingInfo != null)
                                {
                                    string text = StrippingInfo.ModuleName(current2);
                                    strippingInfo.RegisterDependency(StrippingInfo.ModuleName(current3), "Required by " + text);
                                    if (strippingInfo.icons.ContainsKey(text))
                                    {
                                        strippingInfo.SetIcon("Required by " + text, strippingInfo.icons[text]);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            AssemblyReferenceChecker assemblyReferenceChecker = new AssemblyReferenceChecker();

            assemblyReferenceChecker.CollectReferencesFromRoots(strippedAssemblyDir, userAssemblies, true, 0f, true);
            if (strippingInfo != null)
            {
                foreach (string current4 in nativeModules)
                {
                    strippingInfo.AddModule(StrippingInfo.ModuleName(current4));
                }
                strippingInfo.AddModule(StrippingInfo.ModuleName("Core"));
            }
            if (nativeClasses != null && strippingInfo != null)
            {
                CodeStrippingUtils.InjectCustomDependencies(platformProvider.target, strippingInfo, nativeClasses, nativeModules);
            }
        }