public static void _OnOpen_Prefix(UIEscMenu __instance) { // Disable save game button if you are a client in a multiplayer session Button saveGameWindowButton = __instance.button2; SetButtonEnableState(saveGameWindowButton, !Multiplayer.IsActive || Multiplayer.Session.LocalPlayer.IsHost); // Disable load game button if in a multiplayer session Button loadGameWindowButton = __instance.button3; SetButtonEnableState(loadGameWindowButton, !Multiplayer.IsActive); }
public static void _OnOpen_Prefix(UIEscMenu __instance) { // Disable save game button if you are a client in a multiplayer session Button saveGameWindowButton = AccessTools.Field(typeof(UIEscMenu), "button2").GetValue(__instance) as Button; SetButtonEnableState(saveGameWindowButton, !SimulatedWorld.Initialized || LocalPlayer.IsMasterClient); // Disable load game button if in a multiplayer session Button loadGameWindowButton = AccessTools.Field(typeof(UIEscMenu), "button3").GetValue(__instance) as Button; SetButtonEnableState(loadGameWindowButton, !SimulatedWorld.Initialized); }
public static void _OnOpen_Prefix(UIEscMenu __instance) { // Disable save game button if you are a client in a multiplayer session Button saveGameWindowButton = AccessTools.Field(typeof(UIEscMenu), "button2").GetValue(__instance) as Button; SetButtonEnableState(saveGameWindowButton, !SimulatedWorld.Initialized || LocalPlayer.IsMasterClient); // Disable load game button if in a multiplayer session Button loadGameWindowButton = AccessTools.Field(typeof(UIEscMenu), "button3").GetValue(__instance) as Button; SetButtonEnableState(loadGameWindowButton, !SimulatedWorld.Initialized); // If we are in a multiplayer game already make sure to hide the host game button if (SimulatedWorld.Initialized) { hostGameButton?.gameObject.SetActive(false); return; } if (hostGameButton != null) { hostGameButton.gameObject.SetActive(true); hostGameButton.GetComponentInChildren <Text>().text = "Host Game"; return; } RectTransform buttonTemplate = GameObject.Find("Esc Menu/button (6)").GetComponent <RectTransform>(); hostGameButton = Object.Instantiate(buttonTemplate, buttonTemplate.parent, false); hostGameButton.name = "button-host-game"; hostGameButton.anchoredPosition = new Vector2(buttonTemplate.anchoredPosition.x, buttonTemplate.anchoredPosition.y - buttonTemplate.sizeDelta.y * 2); hostGameButton.GetComponentInChildren <Text>().text = "Host Game"; hostGameButton.GetComponent <Button>().onClick.RemoveAllListeners(); hostGameButton.GetComponent <Button>().onClick.AddListener(new UnityAction(OnHostCurrentGameClick)); }