mirror of
https://github.com/RaindropViewer/RaindropViewer.git
synced 2026-07-27 22:11:39 +00:00
update ConnectivityUI but not sure if its working
This commit is contained in:
+33
-11
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user