mirror of
https://github.com/Leahnaya/TheKingsRace.git
synced 2026-09-12 12:25:16 -05:00
Added Toggle Option to Use the MLAPI Relay
- Also cleaned up and merged title screen files into a single class
This commit is contained in:
51
Assets/Scripts/UI/Options/OptionsMenu.cs
Normal file
51
Assets/Scripts/UI/Options/OptionsMenu.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using MLAPI.Transports.UNET;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class OptionsMenu : MonoBehaviour {
|
||||
|
||||
[SerializeField]
|
||||
private Toggle useMLAPIRelayToggle;
|
||||
|
||||
void Start() {
|
||||
// Set the current values for options
|
||||
|
||||
// ** Use MLAPI Relay
|
||||
if (PlayerPrefs.GetInt("UseMLAPIRelay") == 0) {
|
||||
useMLAPIRelayToggle.isOn = false;
|
||||
} else {
|
||||
useMLAPIRelayToggle.isOn = true;
|
||||
}
|
||||
|
||||
// Add a listener to the toggle
|
||||
useMLAPIRelayToggle.onValueChanged.AddListener((isSelected) => {
|
||||
OnUseMLAPIRelayToggleChanged(isSelected);
|
||||
});
|
||||
|
||||
// ** Other options here
|
||||
}
|
||||
|
||||
private void OnUseMLAPIRelayToggleChanged(bool newState) {
|
||||
Debug.Log("New value: " + newState);
|
||||
if (newState) {
|
||||
useMLAPIRelayToggle.isOn = true;
|
||||
PlayerPrefs.SetInt("UseMLAPIRelay", 1);
|
||||
|
||||
// Don't forget to update the value on the network manager
|
||||
GameObject.FindGameObjectWithTag("NetworkManager").GetComponent<UNetTransport>().UseMLAPIRelay = true;
|
||||
} else {
|
||||
useMLAPIRelayToggle.isOn = false;
|
||||
PlayerPrefs.SetInt("UseMLAPIRelay", 0);
|
||||
|
||||
// Don't forget to update the value on the network manager
|
||||
GameObject.FindGameObjectWithTag("NetworkManager").GetComponent<UNetTransport>().UseMLAPIRelay = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnReturnToTitleClicked() {
|
||||
SceneManager.LoadScene("TitleScene");
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/UI/Options/OptionsMenu.cs.meta
Normal file
11
Assets/Scripts/UI/Options/OptionsMenu.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b3ca8c571992ca54dbe057215f42f055
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user