Hello guys, i was following a tutorial about steam and unity. Everything is ok except the steam avatar. The avatar is not loading to the rawImage. I tried to print out the ImageID value and it prints as 0.
public class PlayerListItemScript : MonoBehaviour
{
public string PlayerName;
public int ConnectionId;
public ulong PlayerSteamId;
private bool avatarRecieved;
public TMP_Text playerNameText;
public RawImage playerAvatar;
protected Callback<AvatarImageLoaded_t> AvatarImageLoaded;
private void Start()
{
AvatarImageLoaded = Callback<AvatarImageLoaded_t>.Create(OnImageLoaded);
}
private void GetPlayerIcon()
{
int ImageID = SteamFriends.GetLargeFriendAvatar((CSteamID)PlayerSteamId);
print(ImageID);
if (ImageID == -1)
{
return;
}
}
public void SetPlayerValues()
{
playerNameText.text = PlayerName;
if (!avatarRecieved)
{
GetPlayerIcon();
}
}
private void OnImageLoaded(AvatarImageLoaded_t callback)
{
if (callback.m_steamID.m_SteamID == PlayerSteamId)
{
playerAvatar.texture = GetSteamImageAsTexture(callback.m_iImage);
}
}
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();
}
}
avatarRecieved = true;
return texture;
}
}