mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
feat(Chat Example): Bidirectional sync of networkAddress
This commit is contained in:
parent
e1195391c6
commit
325cc15f5b
@ -2532,6 +2532,7 @@ MonoBehaviour:
|
|||||||
m_Script: {fileID: 11500000, guid: 7a77ca56c9d91af4b81b73a9907d6112, type: 3}
|
m_Script: {fileID: 11500000, guid: 7a77ca56c9d91af4b81b73a9907d6112, type: 3}
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
|
networkAddressInput: {fileID: 1027272349}
|
||||||
usernameInput: {fileID: 851154181}
|
usernameInput: {fileID: 851154181}
|
||||||
hostButton: {fileID: 1904406266}
|
hostButton: {fileID: 1904406266}
|
||||||
clientButton: {fileID: 1063265580}
|
clientButton: {fileID: 1063265580}
|
||||||
|
@ -6,6 +6,7 @@ namespace Mirror.Examples.Chat
|
|||||||
public class LoginUI : MonoBehaviour
|
public class LoginUI : MonoBehaviour
|
||||||
{
|
{
|
||||||
[Header("UI Elements")]
|
[Header("UI Elements")]
|
||||||
|
[SerializeField] internal InputField networkAddressInput;
|
||||||
[SerializeField] internal InputField usernameInput;
|
[SerializeField] internal InputField usernameInput;
|
||||||
[SerializeField] internal Button hostButton;
|
[SerializeField] internal Button hostButton;
|
||||||
[SerializeField] internal Button clientButton;
|
[SerializeField] internal Button clientButton;
|
||||||
@ -13,11 +14,34 @@ public class LoginUI : MonoBehaviour
|
|||||||
|
|
||||||
public static LoginUI instance;
|
public static LoginUI instance;
|
||||||
|
|
||||||
|
string originalNetworkAddress;
|
||||||
|
|
||||||
void Awake()
|
void Awake()
|
||||||
{
|
{
|
||||||
instance = this;
|
instance = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Start()
|
||||||
|
{
|
||||||
|
// if we don't have a networkAddress, set a default one.
|
||||||
|
if (string.IsNullOrWhiteSpace(NetworkManager.singleton.networkAddress))
|
||||||
|
NetworkManager.singleton.networkAddress = "localhost";
|
||||||
|
|
||||||
|
// cache the original networkAddress for resetting if blank.
|
||||||
|
originalNetworkAddress = NetworkManager.singleton.networkAddress;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Update()
|
||||||
|
{
|
||||||
|
// bidirectional sync of networkAddressInput and NetworkManager.networkAddress
|
||||||
|
// Order of operations is important here...Don't switch the order of these steps.
|
||||||
|
if (string.IsNullOrWhiteSpace(NetworkManager.singleton.networkAddress))
|
||||||
|
NetworkManager.singleton.networkAddress = originalNetworkAddress;
|
||||||
|
|
||||||
|
if (networkAddressInput.text != NetworkManager.singleton.networkAddress)
|
||||||
|
networkAddressInput.text = NetworkManager.singleton.networkAddress;
|
||||||
|
}
|
||||||
|
|
||||||
// Called by UI element UsernameInput.OnValueChanged
|
// Called by UI element UsernameInput.OnValueChanged
|
||||||
public void ToggleButtons(string username)
|
public void ToggleButtons(string username)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user