Inital commit for the new UI page "avatar info"

This commit is contained in:
alexiscatnip
2022-01-16 10:56:41 +08:00
parent 84f7dd0b9e
commit ca5f5a137b
3 changed files with 133 additions and 3 deletions
@@ -0,0 +1,123 @@
using OpenMetaverse;
using OpenMetaverse.StructuredData;
using Raindrop;
using Raindrop.Netcom;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using UnityEngine;
using System;
using FMOD;
using OpenMetaverse.Assets;
using Raindrop.Services;
using Settings = Raindrop.Settings;
using UnityEngine.UI;
using UniRx;
using TMPro;
using static Raindrop.LoginUtils;
using Avatar = OpenMetaverse.Avatar;
using Logger = OpenMetaverse.Logger;
namespace Raindrop.Presenters
{
// show the avatar card and all the information.
public class AvatarInfoPresenter : MonoBehaviour
{
private RaindropInstance instance { get { return ServiceLocator.ServiceLocator.Instance.Get<RaindropInstance>(); } }
private RaindropNetcom netcom { get { return instance.Netcom; } }
private UIService uimanager => ServiceLocator.ServiceLocator.Instance.Get<UIService>();
#region UI elements - the 'view' in MVP
public RawImageView avatarImg;
public TMP_Text aviName;
#endregion
#region internal data representation
// public Avatar avatarShown;
public UUID aviID;
public UUID aviImgID { get; set; }
#endregion
void Start()
{
AddNetcomEvents();
}
private void UpdateAviName(string s)
{
aviName.text = s;
}
private void AddNetcomEvents()
{
netcom.ClientConnected += NetcomOnClientConnected;
}
private void NetcomOnClientConnected(object sender, EventArgs e)
{
instance.Client.Avatars.AvatarPropertiesReply += new EventHandler<AvatarPropertiesReplyEventArgs>(Avatars_AvatarPropertiesReply);
}
private void Avatars_AvatarPropertiesReply(object sender, AvatarPropertiesReplyEventArgs e)
{
if (e.AvatarID != aviID) return;
UnityMainThreadDispatcher.Instance().Enqueue(() =>
{
Avatars_AvatarPropertiesReply(sender, e);
});
UpdateAgentInfos(e);
}
//write UI. please do this on main thread.
private void UpdateAgentInfos(AvatarPropertiesReplyEventArgs e)
{
// ID.
this.aviID = e.AvatarID;
//Image UUID and image
this.aviImgID = e.Properties.ProfileImage;
instance.Client.Assets.RequestImage(e.AvatarID, ImageReady_Callback);
//UI - set name
this.aviName.text = instance.Names.Get(aviID);
}
private void ImageReady_Callback(TextureRequestState state, AssetTexture assettexture)
{
UnityMainThreadDispatcher.Instance().Enqueue(() =>
{
var ok = assettexture.Decode(); //call openjpg to decode j2k->managedimage
if (ok)
{
var img = assettexture.Image;
Texture2D t2d = img.ExportTex2D();
this.avatarImg.setRawImage(t2d);
}
else
{
Logger.Log("decoding texture failed!", Helpers.LogLevel.Error);
}
});
}
private void RemoveNetcomEvents()
{
netcom.ClientLoggingIn -= new EventHandler<OverrideEventArgs>(NetcomOnClientConnected);
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 602e6aee4d42474ba7008e70186f3139
timeCreated: 1642264242
+7 -3
View File
@@ -12,13 +12,17 @@ public class RawImageView : MonoBehaviour
public void setRawImage(Texture2D img)
{
//hack: delete old texture before loading new one
unloadRawImage();
this.GetComponent<RawImage>().texture = img;
}
public void unloadRawImage()
{
if (this.GetComponent<RawImage>().texture != null)
{
Object.Destroy(this.GetComponent<RawImage>().texture);
}
this.GetComponent<RawImage>().texture = img;
this.GetComponent<RawImage>().texture = Texture2D.grayTexture;
}
}