Ejemplo n.º 1
0
 private void ResetToDefault()
 {
     WorkerBuildConfigurations = new List <WorkerBuildConfiguration>
     {
         new WorkerBuildConfiguration
         {
             WorkerType       = "UnityClient",
             LocalBuildConfig =
                 new BuildEnvironmentConfig(WorkerBuildData.LocalBuildTargets,
                                            WorkerBuildData.GetCurrentBuildTargetConfig()),
             CloudBuildConfig = new BuildEnvironmentConfig(
                 WorkerBuildData.AllBuildTargets,
                 new BuildTargetConfig(BuildTarget.StandaloneOSX, BuildOptions.Development, enabled: true, required: false),
                 new BuildTargetConfig(BuildTarget.StandaloneWindows64, BuildOptions.Development, enabled: true, required: false))
         },
         new WorkerBuildConfiguration
         {
             WorkerType       = "UnityGameLogic",
             LocalBuildConfig =
                 new BuildEnvironmentConfig(WorkerBuildData.LocalBuildTargets,
                                            WorkerBuildData.GetCurrentBuildTargetConfig()),
             CloudBuildConfig =
                 new BuildEnvironmentConfig(
                     WorkerBuildData.AllBuildTargets, WorkerBuildData.GetLinuxBuildTargetConfig())
         },
     };
     isInitialised = true;
 }
        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--;
            }
        }