Exemplo n.º 1
0
        private void drawVRSectionGUI(BuildSetupEntry b)
        {
            #if UNITY_2017_2_OR_NEWER
            var targetGroup = BuildPipeline.GetBuildTargetGroup(b.target);
            if (VRUtils.targetGroupSupportsVirtualReality(targetGroup))
            {
                b.supportsVR = EditorGUILayout.Toggle("VR Support", b.supportsVR);
                if (b.supportsVR)
                {
                    b.guiShowVROptions = EditorGUILayout.Foldout(b.guiShowVROptions, "VR Options");
                    if (b.guiShowVROptions)
                    {
                        EditorGUI.indentLevel++;

                        var vrSdks = VRUtils.getAvailableVRSdks(targetGroup);
                        if (vrSdks.Length > 0)
                        {
                            b.vrSdkFlags = EditorGUILayout.MaskField("VR SDKs", b.vrSdkFlags, vrSdks);
                        }
                        else
                        {
                            GUILayout.Label("No VR SDK available for the current build target.");
                        }

                        EditorGUI.indentLevel--;
                    }
                }
            }
            #endif
        }
        public static void Build(BuildSetup buildSetup)
        {
            var defaultScenes = ScenesUtils.getDefaultScenesAsArray();

            string path = buildSetup.rootDirectory;

            var playerSettingsSnapshot = new PlayerSettingsSnapshot();

            var setupList = buildSetup.entriesList;

            for (var i = 0; i < setupList.Count; i++)
            {
                var setup = setupList[i];
                if (setup.enabled)
                {
                    var target      = setup.target;
                    var targetGroup = BuildPipeline.GetBuildTargetGroup(target);

                    playerSettingsSnapshot.takeSnapshot(targetGroup);

                    PlayerSettings.SetScriptingBackend(targetGroup, setup.scriptingBackend);
                    PlayerSettings.SetScriptingDefineSymbolsForGroup(targetGroup, setup.scriptingDefineSymbols);

#if UNITY_2018_3_OR_NEWER
                    PlayerSettings.SetManagedStrippingLevel(targetGroup, setup.strippingLevel);
#endif

#if UNITY_2017_2_OR_NEWER
                    if (VRUtils.targetGroupSupportsVirtualReality(targetGroup))
                    {
                        PlayerSettings.SetVirtualRealitySupported(targetGroup, setup.supportsVR);
                        if (setup.supportsVR)
                        {
                            var vrSdks = VRUtils.getSelectedVRSdksFromFlags(targetGroup, setup.vrSdkFlags);
                            PlayerSettings.SetVirtualRealitySDKs(targetGroup, vrSdks);
                        }
                    }
                    else
                    {
                        PlayerSettings.SetVirtualRealitySupported(targetGroup, false);
                    }
#endif

                    if (target == BuildTarget.Android)
                    {
                        #if UNITY_2017_4_OR_NEWER
                        EditorUserBuildSettings.buildAppBundle     = setup.androidAppBundle;
                        PlayerSettings.Android.targetArchitectures = setup.androidArchitecture;
                        #endif
                    }

                    if (target == BuildTarget.PS4)
                    {
                        EditorUserBuildSettings.ps4HardwareTarget = setup.ps4HardwareTarget;
                        EditorUserBuildSettings.ps4BuildSubtarget = setup.ps4BuildSubtarget;
                    }

#if ADDRESSABLES
                    if (setup.rebuildAddressables)
                    {
                        AddressableAssetSettings.CleanPlayerContent(AddressableAssetSettingsDefaultObject.Settings.ActivePlayerDataBuilder);
                        AddressableAssetSettings.BuildPlayerContent();
                    }
#endif

                    var buildPlayerOptions = BuildUtils.getBuildPlayerOptionsFromBuildSetupEntry(setup, path, defaultScenes);

#if UNITY_2018_1_OR_NEWER
                    BuildReport  report       = BuildPipeline.BuildPlayer(buildPlayerOptions);
                    BuildSummary buildSummary = report.summary;
                    var          success      = (buildSummary.result == BuildResult.Succeeded);
                    UnityEngine.Debug.Log("Build " + setup.buildName + " ended with Status: " + buildSummary.result);
#else
                    var result  = BuildPipeline.BuildPlayer(buildPlayerOptions);
                    var success = string.IsNullOrEmpty(result);
                    UnityEngine.Debug.Log("Build " + setup.buildName + " ended with Success: " + success);
#endif

                    // Revert group build player settings after building
                    playerSettingsSnapshot.applySnapshot();

                    if (!success && buildSetup.abortBatchOnFailure)
                    {
                        UnityEngine.Debug.LogError("Failure - Aborting remaining builds from batch");
                        break;
                    }
                }
                else
                {
                    UnityEngine.Debug.Log("Skipping Build " + setup.buildName);
                }
            }
        }