IEnumerator _FetchAcatar(CSteamID id, RawImage ui)
        {
            var AvatarInt = SteamFriends.GetLargeFriendAvatar(id);

            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;
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        ///     Get your steam avatar.
        ///     Important:
        ///     The returned Texture2D object is NOT loaded using a ContentManager.
        ///     So it's your responsibility to dispose it at the end by calling <see cref="Texture2D.Dispose()" />.
        /// </summary>
        /// <param name="device">The GraphicsDevice</param>
        /// <returns>Your Steam Avatar Image as a Texture2D object</returns>
        private Texture2D GetSteamUserAvatar(GraphicsDevice device)
        {
            // Get the icon type as a integer.
            var icon = SteamFriends.GetMediumFriendAvatar(SteamUser.GetSteamID());

            // Check if we got an icon type.
            if (icon != 0)
            {
                uint width;
                uint height;
                var  ret = SteamUtils.GetImageSize(icon, out width, out height);

                if (ret && width > 0 && height > 0)
                {
                    var rgba = new byte[width * height * 4];
                    ret = SteamUtils.GetImageRGBA(icon, rgba, rgba.Length);
                    if (ret)
                    {
                        var texture = new Texture2D(device, (int)width, (int)height, false, SurfaceFormat.Color);
                        texture.SetData(rgba, 0, rgba.Length);
                        return(texture);
                    }
                }
            }
            return(null);
        }
Esempio n. 3
0
        private static Texture2D GetAvatar(CSteamID steamUser)
        {
            int  avatarInt = SteamFriends.GetLargeFriendAvatar(steamUser);
            bool success   = SteamUtils.GetImageSize(avatarInt, out uint imageWidth, out uint imageHeight);

            if (success && imageWidth > 0 && imageHeight > 0)
            {
                byte[]    Image         = new byte[imageWidth * imageHeight * 4];
                Texture2D returnTexture = new Texture2D((int)imageWidth, (int)imageHeight, TextureFormat.RGBA32, false, true);
                success = SteamUtils.GetImageRGBA(avatarInt, Image, (int)(imageWidth * imageHeight * 4));

                if (success)
                {
                    returnTexture.LoadRawTextureData(Image);
                    returnTexture.Apply();
                }

                return(returnTexture);
            }
            else
            {
                Debug.LogError("Couldn't get avatar.");
                return(new Texture2D(0, 0));
            }
        }
Esempio n. 4
0
    public static Texture2D GetAvatar(CSteamID user)
    {
        int  FriendAvatar = SteamFriends.GetLargeFriendAvatar(user);
        uint ImageWidth;
        uint ImageHeight;
        bool success = SteamUtils.GetImageSize(FriendAvatar, out ImageWidth, out ImageHeight);

        Debug.LogError("Loading avatar for " + user.m_SteamID);

        if (success && ImageWidth > 0 && ImageHeight > 0)
        {
            byte[]    Image         = new byte[ImageWidth * ImageHeight * 4];
            Texture2D returnTexture = new Texture2D((int)ImageWidth, (int)ImageHeight, TextureFormat.RGBA32, false, true);
            success = SteamUtils.GetImageRGBA(FriendAvatar, Image, (int)(ImageWidth * ImageHeight * 4));
            if (success)
            {
                returnTexture.LoadRawTextureData(Image);
                returnTexture.Apply();
                Debug.LogError("Loaded avatar!");
            }
            else
            {
                Debug.LogError("Avatar loading failed!");
            }
            return(returnTexture);
        }
        else
        {
            Debug.LogError("Couldn't get avatar.");
            return(new Texture2D(0, 0));
        }
    }
Esempio n. 5
0
        IEnumerator _GetAchivementIcon(string ID)
        {
            int iconInt = 0;
            int counter = 0;

            while (iconInt <= 0 && counter < retryCounter.Value)
            {
                iconInt = SteamUserStats.GetAchievementIcon(ID);
                counter++;
                yield return(null);
            }
            if (iconInt <= 0)
            {
                Fsm.Event(noImageFound);
                Finish();
            }
            else
            {
                SteamUtils.GetImageSize(iconInt, out icon_width, out icon_height);
                byte[] iconStream = new byte[4 * (int)icon_width * (int)icon_height];
                SteamUtils.GetImageRGBA(iconInt, iconStream, 4 * (int)icon_width * (int)icon_height);
                Texture2D downloadIcon = new Texture2D((int)icon_width, (int)icon_height, TextureFormat.RGBA32, false);
                downloadIcon.LoadRawTextureData(iconStream);
                downloadIcon.Apply();
                Sprite spriteTemp = Sprite.Create(downloadIcon, new Rect(0, 0, downloadIcon.width, downloadIcon.height), new Vector2(.5f, .5f));
                Debug.Log(downloadIcon.width + "+" + downloadIcon.height);
                icon.Value = (Sprite)spriteTemp;
                spriteTemp = null;
                Finish();
            }
        }
Esempio n. 6
0
    public static Texture2D BuildTexture(int i_Image)
    {
        if (!SteamManager.initializedMain)
        {
            return(null);
        }

        uint imageWidth;
        uint imageHeight;
        bool ret = SteamUtils.GetImageSize(i_Image, out imageWidth, out imageHeight);

        if (ret && imageWidth > 0 && imageHeight > 0)
        {
            byte[] image = new byte[imageWidth * imageHeight * 4];

            ret = SteamUtils.GetImageRGBA(i_Image, image, (int)(imageWidth * imageHeight * 4));

            Texture2D avatar = new Texture2D((int)imageWidth, (int)imageHeight, TextureFormat.RGBA32, false, true);
            avatar.LoadRawTextureData(image); // The image is upside down! "@ares_p: in Unity all texture data starts from "bottom" (OpenGL convention)"
            avatar.Apply();

            return(avatar);
        }

        return(null);
    }
Esempio n. 7
0
    private Texture2D GetSteamAvatar()
    {
        int  FriendAvatar = SteamFriends.GetMediumFriendAvatar(id);
        uint ImageWidth;
        uint ImageHeight;
        bool success = SteamUtils.GetImageSize(FriendAvatar, out ImageWidth, out ImageHeight);

        if (success && ImageWidth > 0 && ImageHeight > 0)
        {
            byte[]    Image         = new byte[ImageWidth * ImageHeight * 4];
            Texture2D returnTexture = new Texture2D((int)ImageWidth, (int)ImageHeight, TextureFormat.RGBA32, false, true);
            success = SteamUtils.GetImageRGBA(FriendAvatar, Image, (int)(ImageWidth * ImageHeight * 4));
            if (success)
            {
                returnTexture.LoadRawTextureData(Image);
                returnTexture.Apply();
            }
            return(returnTexture);
        }
        else
        {
            Debug.LogError("[Leaderboard] Couldn't get a steam avatar.");
            return(new Texture2D(0, 0));
        }
    }
Esempio n. 8
0
        private Texture2D GetSteamImageAsTexture2D(int p_imageID)
        {
            Texture2D texture = null;
            uint      imageWidth;
            uint      imageHeight;

            if (SteamUtils.GetImageSize(p_imageID, out imageWidth, out imageHeight))
            {
                byte[] imageBytes = new byte[imageWidth * imageHeight * 4];
                if (SteamUtils.GetImageRGBA(p_imageID, imageBytes, imageBytes.Length))
                {
                    // vertically mirror image
                    int    byteWidth         = (int)imageWidth * 4;
                    byte[] imageBytesFlipped = new byte[imageBytes.Length];
                    for (int i = 0, j = imageBytes.Length - byteWidth; i < imageBytes.Length; i += byteWidth, j -= byteWidth)
                    {
                        for (int k = 0; k < byteWidth; k++)
                        {
                            imageBytesFlipped[i + k] = imageBytes[j + k];
                        }
                    }
                    // create Unity Texture2D
                    texture = new Texture2D((int)imageWidth, (int)imageHeight, TextureFormat.RGBA32, false, true);
                    texture.LoadRawTextureData(imageBytesFlipped);
                    texture.Apply();
                }
            }

            return(texture);
        }
    void setAvatar()
    {
        uint width     = 0;
        uint height    = 0;
        int  avatarInt = SteamFriends.GetLargeFriendAvatar(SteamUser.GetSteamID());


        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();

            Playerimage.texture = downloadedAvatar;
            Playerimage.rectTransform.localScale = new Vector2(1, -1);
        }
        else
        {
            Debug.Log("Get Steam AvatarINT Error");
            needReLoad = true;
        }
    }
Esempio n. 10
0
        // Remember to flip it
        public static Texture2D GetTexture(int id)
        {
            if (cache.TryGetValue(id, out Texture2D tex))
            {
                return(tex);
            }

            if (!SteamUtils.GetImageSize(id, out uint width, out uint height))
            {
                cache[id] = null;
                return(null);
            }

            uint sizeInBytes = width * height * 4;

            byte[] data = new byte[sizeInBytes];

            if (!SteamUtils.GetImageRGBA(id, data, (int)sizeInBytes))
            {
                cache[id] = null;
                return(null);
            }

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

            cache[id] = tex;

            return(tex);
        }
        public Texture2D getIcon(int id)
        {
            uint num;
            uint num2;

            if (id == -1 || !SteamUtils.GetImageSize(id, ref num, ref num2))
            {
                return(null);
            }
            Texture2D texture2D = new Texture2D((int)num, (int)num2, 4, false);

            texture2D.name      = "Steam_Community_Icon_Buffer";
            texture2D.hideFlags = 61;
            byte[] array = new byte[num * num2 * 4u];
            if (SteamUtils.GetImageRGBA(id, array, array.Length))
            {
                texture2D.LoadRawTextureData(array);
                texture2D.Apply();
                Texture2D texture2D2 = new Texture2D((int)num, (int)num2, 4, false, true);
                texture2D2.name      = "Steam_Community_Icon";
                texture2D2.hideFlags = 61;
                int num3 = 0;
                while ((long)num3 < (long)((ulong)num2))
                {
                    texture2D2.SetPixels(0, num3, (int)num, 1, texture2D.GetPixels(0, (int)(num2 - 1u - (uint)num3), (int)num, 1));
                    num3++;
                }
                texture2D2.Apply();
                Object.DestroyImmediate(texture2D);
                return(texture2D2);
            }
            Object.DestroyImmediate(texture2D);
            return(null);
        }
Esempio n. 12
0
        private static Friend getFriendFromId(CSteamID id)
        {
            Friend friend = new Friend();

            friend.id = id.m_SteamID;

            string name = SteamFriends.GetPlayerNickname(id);

            friend.displayName = (name == null || name == "") ? SteamFriends.GetFriendPersonaName(id) : name;

            int  handle = SteamFriends.GetMediumFriendAvatar(id);
            uint width = 0, height = 0;

            if (handle != 0 && SteamUtils.GetImageSize(handle, out width, out height))
            {
                byte[] pixels = new byte[width * height * 4];
                if (SteamUtils.GetImageRGBA(handle, pixels, (int)(width * height * 4)))
                {
                    friend.avatar = new Texture2D(Game1.graphics.GraphicsDevice, (int)width, (int)height);
                    friend.avatar.SetData(pixels);
                }
            }

            return(friend);
        }
    public Texture2D GetSteamProfileImage(CSteamID userID)
    {
        int FriendAvatar = SteamFriends.GetMediumFriendAvatar(userID);

        Texture2D m_MediumAvatar;

        if (DebugTextOn)
        {
            Debug.Log("SteamFriends.GetMediumFriendAvatar(" + userID + ") - " + FriendAvatar);
        }

        uint ImageWidth;
        uint ImageHeight;
        bool ret = SteamUtils.GetImageSize(FriendAvatar, out ImageWidth, out ImageHeight);

        if (ret && ImageWidth > 0 && ImageHeight > 0)
        {
            byte[] Image = new byte[ImageWidth * ImageHeight * 4];

            ret            = SteamUtils.GetImageRGBA(FriendAvatar, Image, (int)(ImageWidth * ImageHeight * 4));
            m_MediumAvatar = new Texture2D((int)ImageWidth, (int)ImageHeight, TextureFormat.RGBA32, false, true);
            m_MediumAvatar.LoadRawTextureData(Image);
            m_MediumAvatar.Apply();

            return(m_MediumAvatar);
        }

        //return null because Steam didn't give us an image
        return(null);
    }
Esempio n. 14
0
        /**
         * Creates a texture from a Steam image and returns the size.
         */
        public static Texture2D GetSteamImageAsTexture2D(int iImage, out Vector2 size)
        {
            Texture2D ret = null;
            uint      ImageWidth;
            uint      ImageHeight;
            bool      bIsValid = SteamUtils.GetImageSize(iImage, out ImageWidth, out ImageHeight);

            if (bIsValid)
            {
                byte[] Image = new byte[ImageWidth * ImageHeight * 4];

                bIsValid = SteamUtils.GetImageRGBA(iImage, Image, (int)(ImageWidth * ImageHeight * 4));
                if (bIsValid)
                {
                    Image = FlipVertical(Image, (int)ImageWidth, (int)ImageHeight);

                    ret = new Texture2D((int)ImageWidth, (int)ImageHeight, TextureFormat.RGBA32, false, true);
                    ret.LoadRawTextureData(Image);
                    ret.Apply();
                }
            }

            size.x = (int)ImageWidth;
            size.y = (int)ImageHeight;

            return(ret);
        }
        private Texture2D GetSmallAvatar(CSteamID user, bool dispatchReadyEvent = true)
        {
            int       FriendAvatar = SteamFriends.GetMediumFriendAvatar(user);
            uint      ImageWidth;
            uint      ImageHeight;
            bool      success       = SteamUtils.GetImageSize(FriendAvatar, out ImageWidth, out ImageHeight);
            Texture2D returnTexture = null;

            if (success && ImageWidth > 0 && ImageHeight > 0)
            {
                byte[] Image = new byte[ImageWidth * ImageHeight * 4];
                returnTexture = new Texture2D((int)ImageWidth, (int)ImageHeight, TextureFormat.RGBA32, false, true);
                success       = SteamUtils.GetImageRGBA(FriendAvatar, Image, (int)(ImageWidth * ImageHeight * 4));
                if (success)
                {
                    returnTexture.LoadRawTextureData(Image);
                    returnTexture.Apply();
                }
                if (dispatchReadyEvent)
                {
                    RaiseGameServiceEvent(new GameServiceEvent(GameServiceEventType.AvatarTextureReady, FlipTexture(returnTexture)));
                }
            }
            else
            {
                Debug.LogError("Couldn't get avatar.");
            }

            if (returnTexture != null)
            {
                returnTexture = FlipTexture(returnTexture);
            }

            return(returnTexture);
        }
Esempio n. 16
0
        private IEnumerator FetchAvatar()
        {
            var avatarInt = SteamFriends.GetLargeFriendAvatar(SteamUser.GetSteamID());

            while (avatarInt == -1)
            {
                yield return(null);
            }

            if (avatarInt > 0)
            {
                Debug.Log("Found avatar.");
                uint width, height;
                SteamUtils.GetImageSize(avatarInt, out width, out height);

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

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

                Rect    rect  = new Rect(0, 0, 184, 184);
                Vector2 pivot = new Vector2(.5f, .5f);
                _playerProfilePicture.sprite = Sprite.Create(downloadedAvatar, rect, pivot);
                Debug.Log("Updated avatar.");
            }
            else
            {
                Debug.LogWarning("Couldn't fetch player avatar.");
            }
        }
Esempio n. 17
0
        /// <summary>
        ///     Loads a user's avatar from steam
        /// </summary>
        /// <returns></returns>
        private static Texture2D LoadAvatar(ulong steamId)
        {
            // Get the icon type as a integer.
            var icon = SteamFriends.GetMediumFriendAvatar(new CSteamID(steamId));

            // Check if we got an icon type.
            if (icon != 0)
            {
                var ret = SteamUtils.GetImageSize(icon, out var width, out var height);

                if (ret && width > 0 && height > 0)
                {
                    var rgba = new byte[width * height * 4];
                    ret = SteamUtils.GetImageRGBA(icon, rgba, rgba.Length);
                    if (ret)
                    {
                        var texture = new Texture2D(GameBase.Game.GraphicsDevice, (int)width, (int)height, false, SurfaceFormat.Color);
                        texture.SetData(rgba, 0, rgba.Length);
                        return(texture);
                    }
                }
            }

            return(null);
        }
Esempio n. 18
0
        public Stream GetPicture()
        {
            int  img = SteamUserStats.GetAchievementIcon(Key);
            uint w, h;

            SteamUtils.GetImageSize(img, out w, out h);
            byte[] imgData = new byte[w * h * 4];
            SteamUtils.GetImageRGBA(img, imgData, imgData.Length);
            return(new MemoryStream(imgData));            // FIXME: Leak! -flibit
        }
Esempio n. 19
0
        /// <summary>
        /// Get image data from the Steam Api
        /// </summary>
        /// <param name="size">The image size to get from Steam</param>
        /// <param name="steamId">The steam id of the user to get the image for</param>
        /// <returns></returns>
        /// <exception cref="ArgumentException"></exception>
        /// <exception cref="SystemException"></exception>
        public SteamworksImage GetAvatarFromStreamApi(AvatarSize size, CSteamID steamId)
        {
            int imageHandle;

            switch (size)
            {
            case AvatarSize.Small:
                imageHandle = SteamFriends.GetSmallFriendAvatar(steamId);
                break;

            case AvatarSize.Medium:
                imageHandle = SteamFriends.GetMediumFriendAvatar(steamId);
                break;

            case AvatarSize.Large:
                imageHandle = SteamFriends.GetLargeFriendAvatar(steamId);
                break;

            default:
                throw new ArgumentException("Unknown Steam Avatar size!");
            }

            if (imageHandle == -1 || imageHandle == 0)
            {
                throw new SystemException("Invalid Steamworks image handle");
            }

            var image = new SteamworksImage();


            if (!SteamUtils.GetImageSize(imageHandle, out image.Width, out image.Height))
            {
                throw new SystemException("Couldn't get image size from Steamworks api");
            }

            uint imageSize = image.Width * image.Height * 4;

            var buffer = new byte[imageSize];

            if (!SteamUtils.GetImageRGBA(imageHandle, buffer, (int)imageSize))
            {
                throw new SystemException("Couldn't get image data  from Steamworks api");
            }

            image.imageData = new byte[imageSize];
            Array.Copy(buffer, 0, image.imageData, 0, imageSize);

            return(image);
        }
        internal void GetSmallAvatar(SteamPlayer player, bool raiseEvent)
        {
            var index = SteamFriends.GetSmallFriendAvatar(player.steamID);

            if (index < 1)
            {
                return;
            }
            uint w, h;

            if (SteamUtils.GetImageSize(index, out w, out h))
            {
                LoadPlayerAvatar(player, index, (int)w, (int)h, raiseEvent);
            }
        }
Esempio n. 21
0
    public static byte[] GetImageRGBA(int id)
    {
        uint w;
        uint h;

        if (!SteamUtils.GetImageSize(id, out w, out h))
        {
            return(null);
        }
        byte[] data = new byte[w * h * 4];
        if (!SteamUtils.GetImageRGBA(id, data, data.Length))
        {
            return(null);
        }
        return(data);
    }
Esempio n. 22
0
            public void Load()
            {
                _imageId = SteamFriends.GetMediumFriendAvatar(new CSteamID(_steamid));
                if (_imageId <= 0)
                {
                    return;
                }

                uint w, h;

                if (!SteamUtils.GetImageSize(_imageId, out w, out h))
                {
                    return;
                }

                if (w != _texture.width && h != _texture.height)
                {
                    _avatarsLoading.Remove(this);
                    return;
                }

                int destBufferSize = (int)(4 * w * h);

                byte[] destBuffer = new byte[destBufferSize];

                if (!SteamUtils.GetImageRGBA(_imageId, destBuffer, destBufferSize))
                {
                    return;
                }

                for (int x = 0; x < w; x++)
                {
                    for (int y = 0; y < h; y++)
                    {
                        int  index = ((int)y * (int)w + (int)x) * 4;
                        byte r     = destBuffer[index + 0];
                        byte g     = destBuffer[index + 1];
                        byte b     = destBuffer[index + 2];
                        byte a     = destBuffer[index + 3];

                        _texture.SetPixel(x, (int)h - 1 - y, new Color32(r, g, b, a));
                    }
                }

                _texture.Apply();
                _avatarsLoading.Remove(this);
            }
Esempio n. 23
0
    public void SetPlayer(LeaderboardEntry_t player)
    {
        leaderboardEntry = player;

        if (positionInBoardText != null)
        {
            positionInBoardText.text = System.Convert.ToString(leaderboardEntry.m_nGlobalRank);
        }
        if (Nickname != null)
        {
            Nickname.text = SteamFriends.GetFriendPersonaName(leaderboardEntry.m_steamIDUser);
        }
        if (Score != null)
        {
            Score.text = System.Convert.ToString(leaderboardEntry.m_nScore);
        }

        if (avatarImage != null)
        {
            uint width     = 0;
            uint height    = 0;
            int  avatarInt = SteamFriends.GetMediumFriendAvatar(leaderboardEntry.m_steamIDUser);


            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);

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

                avatarImage.texture = TextureAvatar;
                avatarImage.rectTransform.localScale = new Vector2(1, -1);
            }
            else
            {
                Debug.Log("Get Steam AvatarINT Error");
            }
        }
    }
Esempio n. 24
0
    Texture2D GetTex(int handler)
    {
        uint width, height;

        if (SteamUtils.GetImageSize(handler, out width, out height))
        {
            byte[] data = new byte[width * height * 4];
            if (SteamUtils.GetImageRGBA(handler, data, data.Length))
            {
                Texture2D tex = new Texture2D((int)width, (int)height, TextureFormat.RGBA32, false);
                tex.LoadRawTextureData(data);
                tex.Apply();
                return(tex);
            }
        }
        return(null);
    }
Esempio n. 25
0
        /// <summary>
        /// This method gets the icon of the achievement as of the actual state (if needed to use on a menu
        /// option for instance)
        /// </summary>
        /// <param name="_achievementID"></param>
        /// <returns></returns>
        public static Sprite GetAchievementIcon(string _achievementID)
        {
            int  _iconInt;
            uint _width, _height;

            Texture2D _downloadedAvatar;

            Rect _rect = new Rect(0, 0, 184, 184);

            Vector2 _pivot = new Vector2(0.5f, 0.5f);

            _iconInt = SteamUserStats.GetAchievementIcon(_achievementID);

            //If the icon isn't downloaded yet
            if (_iconInt == -1)
            {
                //this is a delay necessary if the image is not loaded yet, may freeze a bit of the code
                for (int i = 0; i <= 2000; i++)
                {
                    Debug.Log("Icon not found");
                }
            }

            if (_iconInt > 0)
            {
                SteamUtils.GetImageSize(_iconInt, out _width, out _height);

                if (_width > 0 && _height > 0)
                {
                    byte[] _avatarStream = new byte[4 * (int)_width * (int)_height];

                    SteamUtils.GetImageRGBA(_iconInt, _avatarStream, 4 * (int)_width * (int)_height);

                    _downloadedAvatar = new Texture2D((int)_width, (int)_height, TextureFormat.RGBA32, false);
                    _downloadedAvatar.LoadRawTextureData(_avatarStream);
                    _downloadedAvatar.Apply();

                    return(Sprite.Create(_downloadedAvatar, _rect, _pivot));
                }
            }

            return(null);
        }
Esempio n. 26
0
        string GetSteamImageAsTexture2D(int iImage)
        {
            uint ImageWidth;
            uint ImageHeight;
            bool bIsValid = SteamUtils.GetImageSize(iImage, out ImageWidth, out ImageHeight);

            if (bIsValid)
            {
                byte[] Image = new byte[ImageWidth * ImageHeight * 4];

                bIsValid = SteamUtils.GetImageRGBA(iImage, Image, (int)(ImageWidth * ImageHeight * 4));
                if (bIsValid)
                {
                    string result = Convert.ToBase64String(Image);
                    return("data:image/jpeg;base64," + result);
                }
            }

            return(null);
        }
Esempio n. 27
0
        /// <summary>
        /// This method fetches an avatar from a certain user (CSteamID)
        /// </summary>
        /// <param name="_steamID"></param>
        /// <returns></returns>
        public static Sprite FetchAvatar(CSteamID _steamID)
        {
            int  _avatarInt;
            uint _width, _height;

            Texture2D _downloadedAvatar;

            Rect _rect = new Rect(0, 0, 184, 184);

            Vector2 _pivot = new Vector2(0.5f, 0.5f);

            _avatarInt = SteamFriends.GetLargeFriendAvatar(_steamID);

            if (_avatarInt == -1)
            {
                for (int i = 0; i <= 2000; i++)
                {
                    Debug.Log("avatar not found");
                }
            }

            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();

                    return(Sprite.Create(_downloadedAvatar, _rect, _pivot));
                }
            }

            return(null);
        }
Esempio n. 28
0
    private Texture2D GetSteamImageAsTexture(int iImage)
    {
        Texture2D texture = null;

        bool isValid = SteamUtils.GetImageSize(iImage, out uint width, out uint height);

        if (isValid)
        {
            byte[] image = new byte[width * height * 4];

            isValid = SteamUtils.GetImageRGBA(iImage, image, (int)(width * height * 4));

            if (isValid)
            {
                texture = new Texture2D((int)width, (int)height, TextureFormat.RGBA32, false, true);
                texture.LoadRawTextureData(image);
                texture.Apply();
            }
        }
        return(texture);
    }
Esempio n. 29
0
 IEnumerator SteamAvatar()
 {
     _avatarInt = SteamFriends.GetLargeFriendAvatar(SteamUser.GetSteamID());
     while (_avatarInt == -1)
     {
         yield return(null);
     }
     if (_avatarInt > 0)
     {
         SteamUtils.GetImageSize(_avatarInt, out width, out height);
         if (width > 0 && height > 0)
         {
             byte[] avatarSteam = new byte[4 * (int)width * (int)height];
             SteamUtils.GetImageRGBA(_avatarInt, avatarSteam, 4 * (int)width * (int)height);
             dowloadedAvatar = new Texture2D((int)width, (int)height, TextureFormat.RGBA32, false);
             dowloadedAvatar.LoadRawTextureData(avatarSteam);
             dowloadedAvatar.Apply();
             _steamAvatar.sprite = Sprite.Create(dowloadedAvatar, rect, pivot);
         }
     }
 }
Esempio n. 30
0
        void GetAvatar(int iImage)
        {
            uint ImageWidth, ImageHeight;
            bool success = SteamUtils.GetImageSize(iImage, out ImageWidth, out ImageHeight);

            if (!success)
            {
                Fsm.Event(noAvatar);
            }
            else
            {
                byte[] Image = new byte[ImageWidth * ImageHeight * 4];
                success = SteamUtils.GetImageRGBA(iImage, Image, (int)(ImageWidth * ImageHeight * 4));
                if (success)
                {
                    Texture2D ret = null;
                    ret = new Texture2D((int)ImageWidth, (int)ImageHeight, TextureFormat.RGBA32, false, true);
                    ret.LoadRawTextureData(Image);
                    ret.Apply();
                    avatar.Value = ret;
                }
            }
        }