コード例 #1
0
    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);
    }
コード例 #2
0
        // Token: 0x0600151A RID: 5402 RVA: 0x0005A270 File Offset: 0x00058470
        private void OnSteamAvatarReceived(Facepunch.Steamworks.Image image)
        {
            if (!this)
            {
                return;
            }
            if (image == null)
            {
                return;
            }
            int width  = image.Width;
            int height = image.Height;

            this.BuildTexture(width, height);
            byte[]    data  = image.Data;
            Color32[] array = new Color32[data.Length / 4];
            for (int i = 0; i < height; i++)
            {
                int num = height - 1 - i;
                for (int j = 0; j < width; j++)
                {
                    int num2 = (i * width + j) * 4;
                    array[num * width + j] = new Color32(data[num2], data[num2 + 1], data[num2 + 2], data[num2 + 3]);
                }
            }
            if (this.generatedTexture)
            {
                this.generatedTexture.SetPixels32(array);
                this.generatedTexture.Apply();
            }
        }
コード例 #3
0
    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;
    }
コード例 #4
0
        // Token: 0x06001519 RID: 5401 RVA: 0x0005A214 File Offset: 0x00058414
        private void RefreshForSteam()
        {
            Client instance = Client.Instance;

            if (instance != null)
            {
                Facepunch.Steamworks.Image cachedAvatar = instance.Friends.GetCachedAvatar(this.avatarSize, this.userSteamId);
                if (cachedAvatar != null)
                {
                    this.OnSteamAvatarReceived(cachedAvatar);
                    return;
                }
                instance.Friends.GetAvatar(this.avatarSize, this.userSteamId, new Action <Facepunch.Steamworks.Image>(this.OnSteamAvatarReceived));
            }
        }
コード例 #5
0
ファイル: Utils.cs プロジェクト: thehult/unity_steam_template
    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);
    }
コード例 #6
0
    GameObject InsertFriend(SteamFriend friend)
    {
        GameObject go = Instantiate(friendPrefab);

        go.transform.SetParent(container.transform, false);
        Facepunch.Steamworks.Image image = friend.GetAvatar(Friends.AvatarSize.Small);

        var texture = Utils.ConvertSteamImage(image);

        var rawImage = go.GetComponentInChildren <RawImage>();

        if (rawImage != null)
        {
            rawImage.texture = texture;
        }
        go.GetComponentInChildren <Text>().text = friend.Name;
        go.name = "Friend_" + friend.Name;
        go.GetComponentInChildren <Button>().onClick.AddListener(delegate { InviteFriend(friend.Id); });
        return(go);
    }
コード例 #7
0
    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);
    }
コード例 #8
0
    private void OnImage(Facepunch.Steamworks.Image image, ulong steamid)
    {
        endTimestamp = Time.time;
        Debug.Log("End time:" + endTimestamp);
        Debug.Log("IMAGE HASHCODE: " + image.GetHashCode() + " id: " + image.Id);

        if (image.Id == 3)
        {
            hasNoPicture = true;
        }
        else
        {
            hasNoPicture = false;
        }
        if (image.Id == -1)
        {
            isStillLoading = true;
        }
        else
        {
            isStillLoading = false;
        }

        if (steamid != SteamId)
        {
            Debug.Log("STEAM ID MISMATCH");
            return;
        }

        if (image == null)
        {
            Debug.Log("Applied fallback");
            isTextureApplied = false;
            ApplyTexture(FallbackTexture);
            return;
        }


        Debug.Log("SHIT WORKS");

        thisAvatarImage = image;

        applyImage();

        /*
         * isTextureApplied = true;
         *
         * 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);
         */
    }