public void GameOptionCreated(object sender, GameObjectCreatedEventArgs e) { if (heightSliders.Contains(e.Id)) { GameObject go = e.GameObject; GameObject slider = go.transform.Find("Slider").gameObject; slider.GetComponent <uGUI_SnappingSlider>().maxValue = MaxHeight; } }
public void Options_GameObjectCreated(object sender, GameObjectCreatedEventArgs e) { GameObject gameObject = e.GameObject; if (e.Id == "FlareTotalDuration") { GameObject slider = gameObject.transform.Find("Slider").gameObject; slider.AddComponent <CustomSliderValue>(); } }
public void Options_GameObjectCreated(object sender, GameObjectCreatedEventArgs e) { GameObject gameObject = e.GameObject; if (e.Id == "CraftingSpeed" || e.Id == "MinimumDuration") { GameObject slider = gameObject.transform.Find("Slider").gameObject; slider.AddComponent <StepSlider_001>(); return; } }
public void Options_GameObjectCreated(object sender, GameObjectCreatedEventArgs e) { GameObject gameObject = e.GameObject; if (e.Id == "CyclopsIdlingEnergyPerDay") { GameObject slider = gameObject.transform.Find("Slider").gameObject; slider.AddComponent <StepSlider_1>(); return; } if (e.Id == "CyclopsSilentRunningEnergyPerDay") { GameObject slider = gameObject.transform.Find("Slider").gameObject; slider.AddComponent <StepSlider_25>(); return; } }
// some optional and advanced stuff public void Options_GameObjectCreated(object sender, GameObjectCreatedEventArgs e) { GameObject go = e.GameObject; if (e.Id == "exampleChoice") { // adding tooltip to the choice's label GameObject label = go.GetComponentInChildren <Text>().gameObject; label.AddComponent <Tooltip>().tooltip = "This is tooltip for choice"; } else if (e.Id == "exampleSlider") { // adding custom value handler // if you need just custom value format, you don't need custom component, just add format to AddSliderOption params GameObject slider = go.transform.Find("Slider").gameObject; slider.AddComponent <CustomSliderValue>().ValueFormat = "{0:F2}"; // ValueFormat is optional } }
/// <summary> /// Generates tooltips for each <see cref="ModOption"/> with a specified <see cref="TooltipAttribute"/>, before /// invoking any relevant method(s) specified with <see cref="OnGameObjectCreatedAttribute"/>(s) and passes /// parameters when a <see cref="GameObject"/> is created in the options menu. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void HandleGameObjectCreated(object sender, GameObjectCreatedEventArgs e) { if (TryGetMetadata(e.Id, out ModOptionAttributeMetadata <T> modOptionMetadata)) { // Create a tooltip if there is a TooltipAttribute specified if (modOptionMetadata.ModOptionAttribute.Tooltip is string tooltip) { e.GameObject.GetComponentInChildren <Text>().gameObject.AddComponent <ModOptionTooltip>().Tooltip = tooltip; } if (modOptionMetadata.OnGameObjectCreatedMetadata == null) { return; // Skip attempting to invoke events if there are no OnGameObjectCreatedAttributes set for the member. } foreach (MemberInfoMetadata <T> onGameObjectCreatedMetadata in modOptionMetadata.OnGameObjectCreatedMetadata) { InvokeEvent(onGameObjectCreatedMetadata, sender, e); } } }
public void Options_GameObjectCreated(object sender, GameObjectCreatedEventArgs e) { GameObject gameObject = e.GameObject; if (e.Id == "SeaMothLightEnergyPerDay" || e.Id == "ExosuitLightEnergyPerDay" || e.Id == "BaseDefaultLightEnergyPerDay" || e.Id == "CyclopsFloodLightEnergyPerDay" || e.Id == "BaseEmergencyLightEnergyPerDay" || e.Id == "CyclopsCameraLightRange" || e.Id == "MapRoomCameraLightEnergyPerDay" || e.Id == "CyclopsCameraLightEnergyPerDay") { GameObject slider = gameObject.transform.Find("Slider").gameObject; slider.AddComponent <StepSlider_1>(); return; } if (e.Id == "BaseLightFadeDuration") { GameObject slider = gameObject.transform.Find("Slider").gameObject; slider.AddComponent <StepSlider_01>(); return; } }
public void Options_GameObjectCreated(object sender, GameObjectCreatedEventArgs e) { GameObject gameObject = e.GameObject; if (e.Id == "SolarPanelPowerModifier" || e.Id == "ThermalPlantPowerModifier" || e.Id == "BioReactorPowerModifier" || e.Id == "NuclearReactorPowerModifier") { GameObject slider = gameObject.transform.Find("Slider").gameObject; slider.AddComponent <MultiplierSliderValue>(); return; } if (e.Id == "SolarPanelMaxPower") { GameObject slider = gameObject.transform.Find("Slider").gameObject; slider.AddComponent <StepSlider_5>(); return; } if (e.Id == "ThermalPlantMaxPower") { GameObject slider = gameObject.transform.Find("Slider").gameObject; slider.AddComponent <StepSlider_25>(); return; } if (e.Id == "BioReactorMaxPower") { GameObject slider = gameObject.transform.Find("Slider").gameObject; slider.AddComponent <StepSlider_50>(); return; } if (e.Id == "NuclearReactorMaxPower") { GameObject slider = gameObject.transform.Find("Slider").gameObject; slider.AddComponent <StepSlider_100>(); return; } }
/// <summary> /// The method will be called whenever the <see cref="GameObject"/> for a member with a /// <see cref="OnGameObjectCreatedAttribute"/> referencing it by name is created. In this example, only the /// <see cref="MyButtonClickEvent(ButtonClickedEventArgs)"/> button is referencing it, so it will only be called whenever /// this button is created. /// </summary> /// <param name="e">The <see cref="GameObjectCreatedEventArgs"/> passed from the event, containing the id of the field /// as a string as well as the newly created <see cref="GameObject"/>.</param> private void MyGameObjectCreatedEvent(GameObjectCreatedEventArgs e) { Logger.Log(Logger.Level.Info, "GameObject was created"); Logger.Log(Logger.Level.Info, $"{e.Id}: {e.GameObject}"); }
public void ConfigOptions_GameObjectCreated(object sender, GameObjectCreatedEventArgs e) { GameObject go = e.GameObject; if (e.Id == "OpenDecorationsModConfigurator" && go != null) { uGUI_TabbedControlsPanel tcp = null; try { tcp = go.transform.parent.parent.parent.parent.parent.GetComponent <uGUI_TabbedControlsPanel>(); } catch { tcp = null; } if (tcp != null) { ICollection tabs = _tabsField.GetValue(tcp) as ICollection; if (tabs != null) { IEnumerator enumerator = tabs.GetEnumerator(); if (enumerator != null) { int i = 0; // Iterate through each panel tabs while (enumerator.MoveNext()) { object currentTab = enumerator.Current; GameObject pane = (GameObject)_paneField.GetValue(currentTab); GameObject tab = (GameObject)_tabField.GetValue(currentTab); OpenConfiguratorBtnContainer = (RectTransform)_containerField.GetValue(currentTab); if (pane != null && tab != null && OpenConfiguratorBtnContainer != null) { Text paneText = pane.GetComponentInChildren <Text>(); Text tabText = tab.GetComponentInChildren <Text>(); // If current panel is "QModManager" and current tab is "Mods" if (paneText != null && string.Compare(paneText.text, "QModManager", false, CultureInfo.InvariantCulture) == 0 && tabText != null && string.Compare(tabText.text, "Mods", false, CultureInfo.InvariantCulture) == 0) { // Detroy toggle GameObject.DestroyImmediate(go); // Add button tcp.AddButton(i, LanguageHelper.GetFriendlyWord("Config_OpenDecorationsModConfigurator"), new UnityEngine.Events.UnityAction(() => { ConfigSwitcher.OpenDecorationsModConfigurator = !ConfigSwitcher.OpenDecorationsModConfigurator; // If button state changed if (ConfigSwitcher.OpenConfiguratorLastState != ConfigSwitcher.OpenDecorationsModConfigurator) { // Update button state ConfigSwitcher.OpenConfiguratorLastState = ConfigSwitcher.OpenDecorationsModConfigurator; // Open configurator string configuratorPath = ConfiguratorPath(); if (File.Exists(configuratorPath)) { // Try launch configurator try { Configurator = Process.Start(new ProcessStartInfo { Arguments = "/C \"" + configuratorPath + "\"", FileName = "cmd", WindowStyle = ProcessWindowStyle.Hidden }); } catch (Exception ex) { // Cleanup any running instance on failure if (Configurator != null) { if (!Configurator.HasExited) { try { Configurator.CloseMainWindow(); } catch { } } try { Configurator.Close(); } catch { } } // Log error Logger.Log("ERROR: Unable to open configurator. Exception=[" + ex.ToString() + "]"); } } // Apply "deselected" style to button foreach (Transform tr in OpenConfiguratorBtnContainer) { // If current transform is GUI button if (tr != null && !string.IsNullOrEmpty(tr.name) && tr.name.StartsWith("uGUI_OptionButton")) { Text btnText = tr.GetComponentInChildren <Text>(); if (btnText != null && !string.IsNullOrEmpty(btnText.text) && (string.Compare(btnText.text, "Cliquez ici pour configurer", true, CultureInfo.InvariantCulture) == 0 || string.Compare(btnText.text, "Haga clic aquí para configurar", true, CultureInfo.InvariantCulture) == 0 || string.Compare(btnText.text, "Yapılandırmak için burayı tıklayın", true, CultureInfo.InvariantCulture) == 0 || string.Compare(btnText.text, "Klicken Sie hier zum Konfigurieren", true, CultureInfo.InvariantCulture) == 0 || string.Compare(btnText.text, "Нажмите здесь, чтобы настроить", true, CultureInfo.InvariantCulture) == 0 || string.Compare(btnText.text, "Click here to configure", true, CultureInfo.InvariantCulture) == 0)) { // Deselect button Button btn = tr.GetComponentInChildren <Button>(); if (btn != null) { btn.OnDeselect(null); } } } } } })); break; } } ++i; } } } } } }