private void OnImage(Facepunch.Steamworks.Image image, ulong steamid) { if (steamid != SteamId) { return; } if (image == null) { Debug.LogWarning("Failed to get avatar."); ApplyTexture(FallbackTexture); return; } var texture = new Texture2D(image.Width, image.Height); for (int x = 0; x < image.Width; x++) { for (int y = 0; y < image.Height; y++) { var p = image.GetPixel(x, y); texture.SetPixel(x, image.Height - y, new UnityEngine.Color(p.r / 255.0f, p.g / 255.0f, p.b / 255.0f, p.a / 255.0f)); } } texture.Apply(); ApplyTexture(texture); }
public void Awake() { // Do not destroy on scene change. DontDestroyOnLoad(gameObject); // Tell unity what we are running on; Windows, Mac, Console, Potato... Config.ForUnity(Application.platform.ToString()); new Client(AppID); if (Client.Instance == null) { // Failed to 'start steam'. Debug.LogError("Failed to create client instance!"); return; } ServerRequest = Client.Instance.ServerList.Internet(); Client.Instance.Achievements.Refresh(); Client.Instance.Friends.Refresh(); Client.Instance.Screenshots.Trigger(); Client.Instance.Overlay.OpenProfile(Client.Instance.SteamId); SteamFriend first = null; foreach (SteamFriend f in Client.Instance.Friends.AllFriends) { if (first == null || Random.value < 0.2f) { first = f; } Debug.Log(f.Name + ": " + (f.IsOnline ? "Online" : "Offline") + ", playing: " + f.CurrentAppId); } Debug.Log("Avatar for " + first.Name); Facepunch.Steamworks.Image image = Client.Instance.Friends.GetAvatar(Friends.AvatarSize.Small, first.Id); Debug.Log(image.Width + "x" + image.Height + ": " + image.IsLoaded); Texture2D tex = new Texture2D(image.Width, image.Height); for (int x = 0; x < image.Width; x++) { for (int y = 0; y < image.Height; y++) { var c = image.GetPixel(x, (image.Height - 1) - y); tex.SetPixel(x, y, new UnityEngine.Color((float)(c.r / 255f), (float)(c.g / 255f), (float)(c.b / 255f), 1f)); } } tex.Apply(); Image.material.mainTexture = tex; }
public static Texture ConvertSteamImage(Facepunch.Steamworks.Image image) { var texture = new Texture2D(image.Width, image.Height); for (int x = 0; x < image.Width; x++) { for (int y = 0; y < image.Height; y++) { var p = image.GetPixel(x, y); texture.SetPixel(x, image.Height - y, new UnityEngine.Color(p.r / 255.0f, p.g / 255.0f, p.b / 255.0f, p.a / 255.0f)); } } texture.Apply(); return(texture); }
private void applyImage() { isTextureApplied = true; var texture = new Texture2D(thisAvatarImage.Width, thisAvatarImage.Height); for (int x = 0; x < thisAvatarImage.Width; x++) { for (int y = 0; y < thisAvatarImage.Height; y++) { var p = thisAvatarImage.GetPixel(x, y); texture.SetPixel(x, thisAvatarImage.Height - y, new UnityEngine.Color(p.r / 255.0f, p.g / 255.0f, p.b / 255.0f, p.a / 255.0f)); } } texture.Apply(); ApplyTexture(texture); }
private void OnImage(Facepunch.Steamworks.Image image) { if (image == null) { ApplyTexture(FallbackTexture); return; } var texture = new Texture2D(image.Width, image.Height); for (int x = 0; x < image.Width; x++) { for (int y = 0; y < image.Height; y++) { var p = image.GetPixel(x, y); texture.SetPixel(x, image.Height - y, new UnityEngine.Color(p.r / 255.0f, p.g / 255.0f, p.b / 255.0f, p.a / 255.0f)); } } texture.Apply(); ApplyTexture(texture); }