1
This commit is contained in:
@@ -2,7 +2,8 @@
|
||||
"name": "BITKit.Extension.Steamwork",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:14fe60d984bf9f84eac55c6ea033a8f4"
|
||||
"GUID:14fe60d984bf9f84eac55c6ea033a8f4",
|
||||
"GUID:f51ebe6a0ceec4240a699833d6309b23"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
|
@@ -1,7 +1,9 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using UnityEngine;
|
||||
using Steamworks;
|
||||
using Cysharp.Threading.Tasks;
|
||||
namespace BITKit.Steamwork
|
||||
{
|
||||
/// <summary>
|
||||
@@ -25,6 +27,7 @@ namespace BITKit.Steamwork
|
||||
/// Steam客户端是否已经初始化
|
||||
/// </summary>
|
||||
bool IsInitialized { get; }
|
||||
UniTask<Texture2D> GetAvatarAsync(CancellationToken token);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -0,0 +1,34 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Steamworks.Data;
|
||||
using UnityEngine;
|
||||
|
||||
namespace BITKit.Steamwork
|
||||
{
|
||||
public static class SteamExtensions
|
||||
{
|
||||
public static Texture2D Covert( this Image image )
|
||||
{
|
||||
// Create a new Texture2D
|
||||
var avatar = new Texture2D( (int)image.Width, (int)image.Height, TextureFormat.ARGB32, false )
|
||||
{
|
||||
// Set filter type, or else its really blury
|
||||
filterMode = FilterMode.Trilinear
|
||||
};
|
||||
|
||||
// Flip image
|
||||
for ( int x = 0; x < image.Width; x++ )
|
||||
{
|
||||
for ( int y = 0; y < image.Height; y++ )
|
||||
{
|
||||
var p = image.GetPixel( x, y );
|
||||
avatar.SetPixel( x, (int)image.Height - y, new UnityEngine.Color( p.r / 255.0f, p.g / 255.0f, p.b / 255.0f, p.a / 255.0f ) );
|
||||
}
|
||||
}
|
||||
|
||||
avatar.Apply();
|
||||
return avatar;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -1,8 +1,11 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using Steamworks;
|
||||
using Steamworks.Data;
|
||||
using UnityEditor.XR;
|
||||
|
||||
namespace BITKit.Steamwork
|
||||
@@ -16,6 +19,13 @@ namespace BITKit.Steamwork
|
||||
public ulong SteamId => SteamClient.SteamId;
|
||||
public string Name => SteamClient.Name;
|
||||
public bool IsInitialized=>SteamClient.IsValid&&SteamClient.IsLoggedOn;
|
||||
public async UniTask<Texture2D> GetAvatarAsync(CancellationToken token)
|
||||
{
|
||||
var avatar =await SteamFriends.GetLargeAvatarAsync(SteamClient.SteamId);
|
||||
var texture = new Texture2D(0, 0);
|
||||
return avatar.Value.Covert();
|
||||
}
|
||||
|
||||
public int Id => (int)SteamClient.SteamId.AccountId;
|
||||
|
||||
private bool initialized;
|
||||
@@ -48,6 +58,7 @@ namespace BITKit.Steamwork
|
||||
if (initialized)
|
||||
SteamClient.Shutdown();
|
||||
}
|
||||
|
||||
}
|
||||
[Serializable]
|
||||
public class SteamServiceSingleton:ISteamService
|
||||
@@ -57,5 +68,6 @@ namespace BITKit.Steamwork
|
||||
public ulong SteamId => _steamServiceImplementation.SteamId;
|
||||
public string Name => _steamServiceImplementation.Name;
|
||||
public bool IsInitialized=>_steamServiceImplementation.IsInitialized;
|
||||
public UniTask<Texture2D> GetAvatarAsync(CancellationToken token)=>_steamServiceImplementation.GetAvatarAsync(token);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user