예제 #1
0
        private static void ExcludeModuleManagers(ref HashSet <UnityType> nativeClasses)
        {
            if (AssemblyStripper.UseUnityLinkerEngineModuleStripping)
            {
                throw new NotSupportedException("Don't want to rely on this method when UnityLinker EMS is used");
            }

            string[] moduleNames = ModuleMetadata.GetModuleNames();

            foreach (string module in moduleNames)
            {
                if (!ModuleMetadata.IsStrippableModule(module)) // Only handle strippable modules
                {
                    continue;
                }

                var moduleClasses = ModuleMetadata.GetModuleTypes(module);

                // Find (non-)manager classes
                HashSet <UnityType> managerClasses    = new HashSet <UnityType>();
                HashSet <UnityType> nonManagerClasses = new HashSet <UnityType>();
                foreach (var klass in moduleClasses)
                {
                    if (klass.IsDerivedFrom(GameManagerTypeInfo))
                    {
                        managerClasses.Add(klass);
                    }
                    else
                    {
                        nonManagerClasses.Add(klass);
                    }
                }

                // At least one non-manager class is required for the removal attempt
                if (nonManagerClasses.Count == 0)
                {
                    continue;
                }

                // Exclude manager classes if no non-manager classes are present
                if (!nativeClasses.Overlaps(nonManagerClasses))
                {
                    foreach (var klass in managerClasses)
                    {
                        nativeClasses.Remove(klass);
                    }
                }
                else
                {
                    foreach (var klass in managerClasses)
                    {
                        nativeClasses.Add(klass);
                    }
                }
            }
        }
예제 #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 HashSet <string> GetAllStrippableModules()
        {
            HashSet <string> nativeModules = new HashSet <string>();

            foreach (string module in ModuleMetadata.GetModuleNames())
            {
                if (ModuleMetadata.IsStrippableModule(module)) // Only handle strippable modules. Others are listed in RegisterStaticallyLinkedModulesGranular()
                {
                    nativeModules.Add(module);
                }
            }
            return(nativeModules);
        }
예제 #4
0
        private static void ExcludeModuleManagers(ref HashSet <UnityType> nativeClasses)
        {
            string[] moduleNames = ModuleMetadata.GetModuleNames();

            foreach (string module in moduleNames)
            {
                if (!ModuleMetadata.IsStrippableModule(module)) // Only handle strippable modules
                {
                    continue;
                }

                var moduleClasses = ModuleMetadata.GetModuleTypes(module);

                // Find (non-)manager classes
                HashSet <UnityType> managerClasses    = new HashSet <UnityType>();
                HashSet <UnityType> nonManagerClasses = new HashSet <UnityType>();
                foreach (var klass in moduleClasses)
                {
                    if (klass.IsDerivedFrom(GameManagerTypeInfo))
                    {
                        managerClasses.Add(klass);
                    }
                    else
                    {
                        nonManagerClasses.Add(klass);
                    }
                }

                // At least one non-manager class is required for the removal attempt
                if (nonManagerClasses.Count == 0)
                {
                    continue;
                }

                // Exclude manager classes if no non-manager classes are present
                if (!nativeClasses.Overlaps(nonManagerClasses))
                {
                    foreach (var klass in managerClasses)
                    {
                        nativeClasses.Remove(klass);
                    }
                }
                else
                {
                    foreach (var klass in managerClasses)
                    {
                        nativeClasses.Add(klass);
                    }
                }
            }
        }
예제 #5
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");
                }
            }
        }
예제 #6
0
        private static HashSet <string> GetAllStrippableModules()
        {
            HashSet <string> hashSet = new HashSet <string>();

            string[] moduleNames = ModuleMetadata.GetModuleNames();
            for (int i = 0; i < moduleNames.Length; i++)
            {
                string text = moduleNames[i];
                if (ModuleMetadata.IsStrippableModule(text))
                {
                    hashSet.Add(text);
                }
            }
            return(hashSet);
        }
예제 #7
0
        private static HashSet <string> GetRequiredStrippableModules(HashSet <UnityType> nativeClasses, StrippingInfo strippingInfo)
        {
            if (AssemblyStripper.UseUnityLinkerEngineModuleStripping)
            {
                throw new NotSupportedException("Don't want to rely on this method when UnityLinker EMS is used");
            }

            HashSet <UnityType> nativeClassesUsedInModules = new HashSet <UnityType>();
            HashSet <string>    nativeModules = new HashSet <string>();

            foreach (string module in ModuleMetadata.GetModuleNames())
            {
                if (ModuleMetadata.IsStrippableModule(module)) // Only handle strippable modules. Others are listed in RegisterStaticallyLinkedModulesGranular()
                {
                    var moduleClasses = new HashSet <UnityType>(ModuleMetadata.GetModuleTypes(module));
                    if (nativeClasses.Overlaps(moduleClasses)) // Include module if at least one of its classes is present
                    {
                        nativeModules.Add(module);
                        if (strippingInfo != null)
                        {
                            foreach (var klass in moduleClasses)
                            {
                                if (nativeClasses.Contains(klass))
                                {
                                    strippingInfo.RegisterDependency(StrippingInfo.ModuleName(module), klass.name);
                                    // Don't list GlobalGameManagers in a module will automatically be added if the module is added.
                                    nativeClassesUsedInModules.Add(klass);
                                }
                            }
                        }
                    }
                }
            }

            // Classes which have not been registered as belonging to a module belong to the Core module.
            if (strippingInfo != null)
            {
                foreach (var klass in nativeClasses)
                {
                    if (!nativeClassesUsedInModules.Contains(klass))
                    {
                        strippingInfo.RegisterDependency(StrippingInfo.ModuleName("Core"), klass.name);
                    }
                }
            }
            return(nativeModules);
        }
예제 #8
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.IsStrippableModule(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);
                     }
                 }
             }
         }
     }
 }
예제 #9
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");
                }
            }
        }
예제 #10
0
        private static HashSet <string> GetRequiredStrippableModules(HashSet <UnityType> nativeClasses, StrippingInfo strippingInfo)
        {
            HashSet <UnityType> hashSet  = new HashSet <UnityType>();
            HashSet <string>    hashSet2 = new HashSet <string>();

            string[] moduleNames = ModuleMetadata.GetModuleNames();
            for (int i = 0; i < moduleNames.Length; i++)
            {
                string text = moduleNames[i];
                if (ModuleMetadata.IsStrippableModule(text))
                {
                    HashSet <UnityType> hashSet3 = new HashSet <UnityType>(ModuleMetadata.GetModuleTypes(text));
                    if (nativeClasses.Overlaps(hashSet3))
                    {
                        hashSet2.Add(text);
                        if (strippingInfo != null)
                        {
                            foreach (UnityType current in hashSet3)
                            {
                                if (nativeClasses.Contains(current))
                                {
                                    strippingInfo.RegisterDependency(StrippingInfo.ModuleName(text), current.name);
                                    hashSet.Add(current);
                                }
                            }
                        }
                    }
                }
            }
            if (strippingInfo != null)
            {
                foreach (UnityType current2 in nativeClasses)
                {
                    if (!hashSet.Contains(current2))
                    {
                        strippingInfo.RegisterDependency(StrippingInfo.ModuleName("Core"), current2.name);
                    }
                }
            }
            return(hashSet2);
        }