void OnGUI() { var config = GameObject.Find("ConfiguratorSettings")?.GetComponent <CoinConfigurator>(); if (!config) { return; } if (config.GameConfig != null) { int count = 0; bool began = false; foreach (var coin in config.GameConfig.Coins) { if (count % 3 == 0) { if (began) { GUILayout.EndHorizontal(); } GUILayout.BeginHorizontal(); began = true; } count++; if (GUILayout.Button(coin.Sprite.texture, GUILayout.Width(100), GUILayout.Height(100))) { SpawnCoin(config.SpawnArea.bounds, config.CoinPrefab, coin); } } GUILayout.EndHorizontal(); } Filename = EditorGUILayout.TextField("Filename:", Filename); TargetAmount = EditorGUILayout.IntField("Target amount:", TargetAmount); IsSolvable = EditorGUILayout.Toggle("Solvable:", IsSolvable); GUILayout.BeginHorizontal(); if (GUILayout.Button("Load Configuration")) { EditorGUIUtility.ShowObjectPicker <CoinSpawns>(null, true, "", EditorGUIUtility.GetControlID(FocusType.Passive) + 100); } if (Event.current.commandName == "ObjectSelectorClosed") { LoadConfiguration(config.GameConfig, config.CoinPrefab, EditorGUIUtility.GetObjectPickerObject()); } if (GUILayout.Button("Save Configuration")) { SaveConfiguration(); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); bool newConfig = false; if (GUILayout.Button("New Configuration")) { NewConfiguration(); newConfig = true; } if (GUILayout.Button("New Random Configuration")) { NewConfiguration(); var noDummies = config.GameConfig.Coins.Where(cfg => !cfg.IsDummy).ToList(); var coinConfigs = SolutionHelper.GenerateRandomValues(noDummies); foreach (var cfg in coinConfigs) { SpawnCoin(config.SpawnArea.bounds, config.CoinPrefab, cfg); } newConfig = true; } GUILayout.EndHorizontal(); if (newConfig || GUILayout.Button("Suggest sum")) { var coins = GameObject.FindObjectsOfType <Coin>(); var amounts = coins.Select(coin => coin.Config.Amount).ToList(); TargetAmount = SolutionHelper.PickSumFor(amounts); newConfig = true; } if (newConfig || GUILayout.Button("Update Solution Count: " + SolutionCount)) { // expensive to calculate without keeping a list of coins around var coins = GameObject.FindObjectsOfType <Coin>(); var amounts = coins.Select(coin => coin.Config.Amount).ToList(); SolutionCount = SolutionHelper.NumberSolutions(amounts, TargetAmount); IsSolvable = SolutionCount > 0; } }