update ConnectivityUI but not sure if its working

This commit is contained in:
alexiscatnip
2022-01-16 10:50:29 +08:00
parent 3f9d7f9f9d
commit 983be3ec73
+33 -11
View File
@@ -6,46 +6,68 @@ using Raindrop;
using UnityEngine;
using Raindrop.Netcom;
using Raindrop.ServiceLocator;
using UniRx;
using UnityEngine.UI;
using Logger = OpenMetaverse.Logger;
// change the color of the image to red or green based on connection to server.
[RequireComponent(typeof(Image))]
public class connectivityUI : MonoBehaviour
{
private ReactiveProperty<bool> isConnected = new ReactiveProperty<bool>();
private RaindropInstance instance => ServiceLocator.Instance.Get<RaindropInstance>();
void Start()
{
notConnected();
var _instance = ServiceLocator.Instance.Get<RaindropInstance>();
_instance.Netcom.ClientLoginStatus += NetcomOnClientLoginStatus;
_instance.Netcom.ClientLoggedOut += NetcomOnClientLoggedOut;
if (instance == null || instance.Netcom == null)
Logger.Log("raindrop instance/netcom not available", Helpers.LogLevel.Error);
isConnected.AsObservable().Subscribe(_ => updateConnectivityUI(_));
isConnected.Value = instance.Netcom.IsLoggedIn;
instance.Netcom.ClientLoginStatus += NetcomOnClientLoginStatus;
instance.Netcom.ClientLoggedOut += NetcomOnClientLoggedOut;
}
private void updateConnectivityUI(bool isConnected)
{
if (! isConnected)
{
show_notConnected();
}
else
{
show_isConnected();
}
}
#region Subscribe to backend connectivity events
private void NetcomOnClientLoggedOut(object sender, EventArgs e)
{
notConnected();
isConnected.Value = false;
}
private void NetcomOnClientLoginStatus(object sender, LoginProgressEventArgs e)
{
if (e.Status == LoginStatus.Success)
{
yesConnected();
{
isConnected.Value = true;
}
else if (e.Status == LoginStatus.Failed)
{
notConnected();
isConnected.Value = false;
}
}
#endregion
private void notConnected()
#region view
private void show_notConnected()
{
this.GetComponent<Image>().color = Color.red;
}
private void yesConnected()
private void show_isConnected()
{
this.GetComponent<Image>().color = Color.green;
}
#endregion
}