Esempio n. 1
0
        private (bool, SimulatedPlayerDeploymentConfig) DrawSimulatedConfig(int index, SimulatedPlayerDeploymentConfig config)
        {
            var copy         = config.DeepCopy();
            var foldoutState = stateManager.GetStateObjectOrDefault <bool>(config.Name.GetHashCode());

            using (var check = new EditorGUI.ChangeCheckScope())
            {
                using (new EditorGUILayout.HorizontalScope())
                {
                    foldoutState = EditorGUILayout.Foldout(foldoutState, new GUIContent($"Simulated Player Deployment {index + 1}"), true);

                    GUILayout.FlexibleSpace();

                    using (new EditorGUIUtility.IconSizeScope(style.SmallIconSize))
                    {
                        if (GUILayout.Button(style.RemoveSimPlayerDeploymentButtonContents, EditorStyles.miniButton))
                        {
                            return(true, null);
                        }
                    }
                }

                using (new EditorGUI.IndentLevelScope())
                    using (new EditorGUILayout.VerticalScope())
                    {
                        if (foldoutState)
                        {
                            RenderBaseDeploymentConfig(config, copy);
                            copy.FlagPrefix = EditorGUILayout.TextField("Flag Prefix", config.FlagPrefix);

                            if (!ValidAllWorkersList() && !RefreshAllWorkersList())
                            {
                                copy.WorkerTypeId = 0;
                                copy.WorkerType   = string.Empty;
                            }
                            else
                            {
                                copy.WorkerTypeId = EditorGUILayout.Popup(
                                    new GUIContent("Worker Type"),
                                    copy.WorkerTypeId,
                                    allWorkers);

                                copy.WorkerType = allWorkers[copy.WorkerTypeId];
                            }
                        }
                    }

                if (check.changed)
                {
                    stateManager.SetStateObject(copy.Name.GetHashCode(), foldoutState);
                }
            }

            return(false, copy);
        }
Esempio n. 2
0
        private (bool, DeploymentConfig) DrawDeploymentConfig(DeploymentConfig config)
        {
            var foldoutState = stateManager.GetStateObjectOrDefault <bool>(config.Deployment.Name.GetHashCode());
            var copy         = config.DeepCopy();

            var errors = copy.GetErrors();

            using (var check = new EditorGUI.ChangeCheckScope())
            {
                using (new EditorGUILayout.HorizontalScope())
                {
                    foldoutState = EditorGUILayout.Foldout(foldoutState, new GUIContent(config.Deployment.Name), true);

                    GUILayout.FlexibleSpace();

                    using (new EditorGUIUtility.IconSizeScope(style.SmallIconSize))
                    {
                        if (errors.Any())
                        {
                            GUILayout.Label(style.DeploymentConfigurationErrorContents);
                        }

                        if (GUILayout.Button(style.RemoveDeploymentConfigurationButtonContents, EditorStyles.miniButton))
                        {
                            return(true, null);
                        }
                    }
                }

                using (new EditorGUI.IndentLevelScope())
                    using (new EditorGUILayout.VerticalScope())
                    {
                        if (foldoutState)
                        {
                            copy.AssemblyName = EditorGUILayout.TextField("Assembly Name", config.AssemblyName);
                            RenderBaseDeploymentConfig(config.Deployment, copy.Deployment);

                            if (copy.Deployment.Name != config.Deployment.Name)
                            {
                                UpdateSimulatedDeploymentNames(copy);
                            }

                            GUILayout.Space(10);

                            EditorGUILayout.LabelField("Simulated Player Deployments");

                            for (var i = 0; i < copy.SimulatedPlayerDeploymentConfigs.Count; i++)
                            {
                                var simConfig = copy.SimulatedPlayerDeploymentConfigs[i];
                                var(shouldRemove, updated) = DrawSimulatedConfig(i, simConfig);

                                GUILayout.Space(5);

                                if (shouldRemove)
                                {
                                    copy.SimulatedPlayerDeploymentConfigs.RemoveAt(i);
                                    i--;
                                    UpdateSimulatedDeploymentNames(copy);
                                }
                                else
                                {
                                    copy.SimulatedPlayerDeploymentConfigs[i] = updated;
                                }
                            }
                        }
                    }

                using (new EditorGUILayout.HorizontalScope())
                {
                    if (foldoutState)
                    {
                        GUILayout.FlexibleSpace();

                        if (GUILayout.Button("Add simulated player deployment"))
                        {
                            var newSimPlayerDepl = new SimulatedPlayerDeploymentConfig();
                            newSimPlayerDepl.TargetDeploymentName = config.Deployment.Name;
                            newSimPlayerDepl.Name = $"{config.Deployment.Name}_sim{config.SimulatedPlayerDeploymentConfigs.Count + 1}";

                            copy.SimulatedPlayerDeploymentConfigs.Add(newSimPlayerDepl);
                        }
                    }
                }

                if (errors.Any())
                {
                    EditorGUILayout.HelpBox($"This deployment configuration has the following errors:\n\n{errors.FormatErrors()}", MessageType.Error);
                }

                if (check.changed)
                {
                    stateManager.SetStateObject(copy.Deployment.Name.GetHashCode(), foldoutState);
                }
            }

            CommonUIElements.DrawHorizontalLine(5, style.HorizontalLineColor);

            return(false, copy);
        }