两个页面接入完成
This commit is contained in:
48
Assets/Script/Util/WebRTCUtil.cs
Normal file
48
Assets/Script/Util/WebRTCUtil.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using Stary.Evo;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using Random = UnityEngine.Random;
|
||||
|
||||
namespace Script.Util
|
||||
{
|
||||
public static class WebRTCUtil
|
||||
{
|
||||
public static Color GetRandomColor()
|
||||
{
|
||||
return new Color(
|
||||
Random.Range(0.2f, 0.8f),
|
||||
Random.Range(0.2f, 0.8f),
|
||||
Random.Range(0.2f, 0.8f),
|
||||
1f
|
||||
);
|
||||
}
|
||||
|
||||
public static 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}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Script/Util/WebRTCUtil.cs.meta
Normal file
3
Assets/Script/Util/WebRTCUtil.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4decb134134b44de9674419f4b392d6e
|
||||
timeCreated: 1779180377
|
||||
Reference in New Issue
Block a user