public override void OnInspectorGUI()
        {
            if (style == null)
            {
                style = new BuildConfigEditorStyle();
            }

            if (allWorkers == null)
            {
                try
                {
                    var guids    = AssetDatabase.FindAssets("WorkerMenu");
                    var textFile = guids.Select(AssetDatabase.GUIDToAssetPath)
                                   .FirstOrDefault(f => Path.GetExtension(f) == ".txt");
                    if (string.IsNullOrEmpty(textFile))
                    {
                        throw new Exception("Could not find WorkerMenu.txt - you may need to regenerate code.");
                    }

                    allWorkers = File.ReadAllLines(Path.Combine(Application.dataPath, "..", textFile));
                }
                catch (Exception e)
                {
                    allWorkers = new string[0];
                    Debug.LogException(e);
                }
            }

            // Clean up state when drag events end.
            if (sourceDragState != null && Event.current.type == EventType.DragExited)
            {
                sourceDragState.SourceItemIndex = -1;
                sourceDragState = null;
                Repaint();
            }

            var workerConfiguration = (BuildConfig)target;

            BuildConfigEditorStyle.DrawHorizontalLine();

            var configs = workerConfiguration.WorkerBuildConfigurations;

            for (var index = 0; index < configs.Count; index++)
            {
                var workerConfig = configs[index];
                if (!DrawWorkerConfiguration(workerConfig))
                {
                    RecordUndo($"Remove '{workerConfig.WorkerType}'");

                    configs.RemoveAt(index);
                    index--;
                }

                BuildConfigEditorStyle.DrawHorizontalLine();
            }

            using (new EditorGUI.DisabledScope(workerConfiguration.WorkerBuildConfigurations.Count ==
                                               allWorkers.Length))
                using (new GUILayout.HorizontalScope())
                {
                    GUILayout.FlexibleSpace();
                    if (GUILayout.Button("Add new worker type"))
                    {
                        workerChooser = new WorkerChoicePopup(addWorkerButtonRect, workerConfiguration, allWorkers);
                        PopupWindow.Show(addWorkerButtonRect, workerChooser);
                    }

                    if (Event.current.type == EventType.Repaint)
                    {
                        addWorkerButtonRect = GUILayoutUtility.GetLastRect();

                        // Only add the new worker during the Repaint phase - otherwise you'll see errors due to adding new content at the wrong point of the GUI lifecycle.
                        if (workerChooser != null && workerChooser.Choice != -1)
                        {
                            RecordUndo("Add '{Choices[i]}'");

                            var config = new WorkerBuildConfiguration
                            {
                                WorkerType       = workerChooser.Choices[workerChooser.Choice],
                                LocalBuildConfig = new BuildEnvironmentConfig(WorkerBuildData.LocalBuildTargets,
                                                                              WorkerBuildData.GetCurrentBuildTargetConfig()),
                                CloudBuildConfig = new BuildEnvironmentConfig(WorkerBuildData.AllBuildTargets,
                                                                              WorkerBuildData.GetLinuxBuildTargetConfig())
                            };
                            workerConfiguration.WorkerBuildConfigurations.Add(config);
                            workerChooser = null;
                        }
                    }

                    GUILayout.FlexibleSpace();
                }

            if (invalidateCachedContent > 0)
            {
                invalidateCachedContent--;
            }
        }
        private void DrawBuildTargets(BuildEnvironmentConfig env, int hash)
        {
            // Init cached UI state.
            var selectedBuildTarget = stateManager.GetStateObjectOrDefault <BuildTargetState>(hash ^ typeof(BuildTargetState).GetHashCode());

            if (selectedBuildTarget.Choices == null || invalidateCachedContent > 0)
            {
                selectedBuildTarget.Choices = env.BuildTargets.Select(GetBuildTargetGuiContents).ToArray();
            }

            // Draw available build targets.
            using (new EditorGUIUtility.IconSizeScope(SmallIconSize))
            {
                selectedBuildTarget.Index =
                    GUILayout.Toolbar(selectedBuildTarget.Index, selectedBuildTarget.Choices);
            }

            // Draw selected build target.
            var buildTarget    = env.BuildTargets[selectedBuildTarget.Index];
            var canBuildTarget = WorkerBuildData.BuildTargetsThatCanBeBuilt[buildTarget.Target];

            var options  = buildTarget.Options;
            var enabled  = buildTarget.Enabled;
            var required = buildTarget.Required;

            using (var check = new EditorGUI.ChangeCheckScope())
                using (new EditorGUILayout.VerticalScope(GUILayout.ExpandWidth(true)))
                {
                    BuildConfigEditorStyle.DrawHorizontalLine();
                    EditorGUILayout.Space();

                    enabled = EditorGUILayout.Toggle("Build", enabled);

                    if (!enabled)
                    {
                        required = false;
                    }

                    using (new EditorGUI.DisabledScope(!buildTarget.Enabled))
                    {
                        required = EditorGUILayout.Toggle("Required", required);

                        switch (buildTarget.Target)
                        {
                        case BuildTarget.StandaloneOSX:
                            options = ConfigureOSX(buildTarget);
                            break;

                        case BuildTarget.StandaloneWindows:
                            options = ConfigureWindows(buildTarget);
                            break;

                        case BuildTarget.iOS:
                            options = ConfigureIOS(buildTarget);
                            break;

                        case BuildTarget.Android:
                            options = ConfigureAndroid(buildTarget);
                            break;

                        case BuildTarget.StandaloneWindows64:
                            options = ConfigureWindows(buildTarget);
                            break;

                        case BuildTarget.StandaloneLinux64:
                            options = ConfigureLinux(buildTarget);
                            break;
                        }

                        options = ConfigureCompression(options);
                    }

                    if (!canBuildTarget)
                    {
                        EditorGUILayout.HelpBox(
                            $"Your Unity Editor is missing build support for {buildTarget.Target.ToString()}.\n" +
                            "Please add the missing build support options to your Unity Editor",
                            buildTarget.Required ? MessageType.Error : MessageType.Warning);
                    }

                    if (check.changed)
                    {
                        RecordUndo("Worker build options");

                        env.BuildTargets[selectedBuildTarget.Index] =
                            new BuildTargetConfig(buildTarget.Target, options, enabled, required);

                        selectedBuildTarget.Choices = null;
                    }
                }
        }
Exemplo n.º 3
0
        private void DrawBuildTargets(BuildEnvironmentConfig env, int hash)
        {
            // Build a mapping from the 'build target' position in the toolbar to it's position in the 'BuildTargets' array.
            // We do this since sometimes there are different number of targets in the BuildTargets array and those
            // in the toolbar as some targets are deprecated
            if (toolbarMapping.Count == 0)
            {
                var toolbarIndex = 0;
                for (var buildTargetIndex = 0; buildTargetIndex < env.BuildTargets.Count; buildTargetIndex++)
                {
                    if (!env.BuildTargets[buildTargetIndex].Deprecated)
                    {
                        toolbarMapping.Add(toolbarIndex++, buildTargetIndex);
                    }
                }
            }

            // Init cached UI state.
            var selectedBuildTarget = stateManager.GetStateObjectOrDefault <BuildTargetState>(hash ^ typeof(BuildTargetState).GetHashCode());

            if (selectedBuildTarget.Choices == null || invalidateCachedContent > 0)
            {
                selectedBuildTarget.Choices = env.BuildTargets
                                              .Where(c => !c.Deprecated)
                                              .Select(GetBuildTargetGuiContents)
                                              .ToArray();
            }


            // Draw available build targets.
            using (new EditorGUIUtility.IconSizeScope(SmallIconSize))
            {
                selectedBuildTarget.Index =
                    GUILayout.Toolbar(selectedBuildTarget.Index, selectedBuildTarget.Choices);
            }

            // Convert the index from the position selected in the toolbar to the position in the BuildTargets array
            var selectedTargetIndex = toolbarMapping[selectedBuildTarget.Index];

            // Draw selected build target.
            var buildTarget    = env.BuildTargets[selectedTargetIndex];
            var canBuildTarget = BuildSupportChecker.CanBuildTarget(buildTarget.Target);

            var options  = buildTarget.Options;
            var enabled  = buildTarget.Enabled;
            var required = buildTarget.Required;

            // Pick the current backend based on the current build target
            var scriptingImplementation = buildTarget.ScriptingImplementation;

            using (var check = new EditorGUI.ChangeCheckScope())
                using (new EditorGUILayout.VerticalScope(GUILayout.ExpandWidth(true)))
                {
                    BuildConfigEditorStyle.DrawHorizontalLine();
                    EditorGUILayout.Space();

                    enabled = EditorGUILayout.Toggle("Build", enabled);

                    if (!enabled)
                    {
                        required = false;
                    }

                    using (new EditorGUI.DisabledScope(!buildTarget.Enabled))
                    {
                        required = EditorGUILayout.Toggle("Required", required);

                        options = ConfigurePlatform(buildTarget.Target, options);

                        options = ConfigureCompression(options);

                        scriptingImplementation = ConfigureScriptingImplementation(scriptingImplementation, buildTarget.Target);
                    }

                    if (!canBuildTarget)
                    {
                        EditorGUILayout.HelpBox(
                            $"Your Unity Editor is missing build support for {buildTarget.Target.ToString()}.\n" +
                            "Please add the missing build support options to your Unity Editor",
                            buildTarget.Required ? MessageType.Error : MessageType.Warning);
                    }

                    if (check.changed)
                    {
                        RecordUndo("Worker build options");

                        env.BuildTargets[selectedTargetIndex] =
                            new BuildTargetConfig(buildTarget.Target, options, enabled, required, deprecated: false, scriptingImplementation);

                        selectedBuildTarget.Choices = null;
                    }
                }
        }