两个页面接入完成
This commit is contained in:
@@ -2,10 +2,10 @@ using System;
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
using RenderStreaming;
|
||||
using Script.Util;
|
||||
using Stary.Evo;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using Random = UnityEngine.Random;
|
||||
|
||||
namespace Script
|
||||
{
|
||||
@@ -20,7 +20,7 @@ namespace Script
|
||||
private MeetingContacts _meetingContacts;
|
||||
private Transform _messageText;
|
||||
private Transform _nameText;
|
||||
private MeetingContacts.UsersItem _usersItem;
|
||||
private MainPanel.UsersItem _usersItem;
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
@@ -33,14 +33,14 @@ namespace Script
|
||||
return MainArchitecture.Interface;
|
||||
}
|
||||
|
||||
public void SetData(MeetingContacts.UsersItem item, MeetingContacts meetingContactsController)
|
||||
public void SetData(MainPanel.UsersItem item, MeetingContacts meetingContactsController)
|
||||
{
|
||||
_usersItem = item;
|
||||
_meetingContacts = meetingContactsController;
|
||||
///头像赋值
|
||||
if (string.IsNullOrEmpty(item.avatar))
|
||||
{
|
||||
var randomColor = GetRandomColor();
|
||||
var randomColor = WebRTCUtil.GetRandomColor();
|
||||
_background = transform.Find("headBackground");
|
||||
if (_background != null)
|
||||
{
|
||||
@@ -62,7 +62,7 @@ namespace Script
|
||||
if (_background != null)
|
||||
{
|
||||
var imageComponent = _background.GetComponent<Image>();
|
||||
if (imageComponent != null) DownloadAndSetAvatar(item.avatar, imageComponent);
|
||||
if (imageComponent != null) WebRTCUtil.DownloadAndSetAvatar(item.avatar, imageComponent);
|
||||
}
|
||||
|
||||
_backgroundName = _background.transform.Find("Name");
|
||||
@@ -161,41 +161,5 @@ namespace Script
|
||||
_confirmButton.interactable = true;
|
||||
_confirmBtnTime.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
private Color GetRandomColor()
|
||||
{
|
||||
return new Color(
|
||||
Random.Range(0.2f, 0.8f),
|
||||
Random.Range(0.2f, 0.8f),
|
||||
Random.Range(0.2f, 0.8f),
|
||||
1f
|
||||
);
|
||||
}
|
||||
|
||||
private async void DownloadAndSetAvatar(string avatarUrl, Image targetImage)
|
||||
{
|
||||
try
|
||||
{
|
||||
var tempPath = Path.Combine(Application.temporaryCachePath, $"avatar_{Guid.NewGuid()}.png");
|
||||
var result = await WebRequestSystem.GetFile(avatarUrl, tempPath);
|
||||
|
||||
if (result.code == 200)
|
||||
{
|
||||
var bytes = File.ReadAllBytes(tempPath);
|
||||
var texture = new Texture2D(2, 2);
|
||||
texture.LoadImage(bytes);
|
||||
|
||||
var sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height),
|
||||
Vector2.one * 0.5f);
|
||||
targetImage.sprite = sprite;
|
||||
|
||||
File.Delete(tempPath);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogError($"下载头像失败: {e.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user