基於steamworks獲取steam用戶頭像


查看官網api,使用c++寫的,轉成c#之后,有個問題就是,圖片顯示問題

我們可以獲取到一個含有圖片信息的byte[]

然后

private Texture2D downloadedAvatar;
public RawImage image;


downloadedAvatar = new Texture2D((int) width, (int) height, TextureFormat.RGBA32, false);
                    downloadedAvatar.LoadRawTextureData(avatarStream);
                    downloadedAvatar.Apply();

                    image.texture = downloadedAvatar;
Texture2D先load,然后Apply就行了



【完整源碼】
    IEnumerator _FetchAcatar(CSteamID id, RawImage ui)
    {
        //獲取中等圖片,如果獲取的是大圖片的話,可能獲取不到
        var AvatarInt = SteamFriends.GetMediumFriendAvatar(id);
        Debug.Log("AvatarInt" + AvatarInt);
        while (AvatarInt == -1)
        {
            yield return null;
        }
        if (AvatarInt > 0)
        {
            SteamUtils.GetImageSize(AvatarInt, out width, out height);

            if (width > 0 && height > 0)
            {
                byte[] avatarStream = new byte[4 * (int)width * (int)height];
                SteamUtils.GetImageRGBA(AvatarInt, avatarStream, 4 * (int)width * (int)height);

                downloadedAvatar = new Texture2D((int)width, (int)height, TextureFormat.RGBA32, false);
                downloadedAvatar.LoadRawTextureData(avatarStream);
                downloadedAvatar.Apply();

                ui.texture = downloadedAvatar;
            }
        }
    }

 

 

一個開源的unity+steam聯機方案

https://zhuanlan.zhihu.com/p/33601024

 

【steam用戶驗證】

https://api.steampowered.com/ISteamUser/CheckAppOwnership/v2/?key=A182BE6994FEE94C0880A2FB2759E311&format=json&steamid=76561198448857469&appid=776510


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM