基于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

posted @ 2018-03-28 16:42  三页菌  阅读(4067)  评论(0编辑  收藏  举报