Skip to content

Commit d6b1dba

Browse files
committed
Avatars receive from server
1 parent 6f7d472 commit d6b1dba

File tree

6 files changed

+32
-59
lines changed

6 files changed

+32
-59
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:8af35b7c1bc91aa204a78519c4be0024b29f2085bac95b5ad458f4ea36bd9f16
3-
size 19646
2+
oid sha256:a0a43e3ef5debe8151d5424cc7a2f9daf97e5cec99557ddd808f1241adca16a6
3+
size 19701

Assets/_Project/Scenes/tally-viz.unity

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2024,7 +2024,7 @@ MonoBehaviour:
20242024
m_HandleRect: {fileID: 489705913}
20252025
m_Direction: 2
20262026
m_Value: 0
2027-
m_Size: 1
2027+
m_Size: 0.83469206
20282028
m_NumberOfSteps: 0
20292029
m_OnValueChanged:
20302030
m_PersistentCalls:
@@ -2999,6 +2999,10 @@ PrefabInstance:
29992999
propertyPath: m_Name
30003000
value: PlayerPrefab
30013001
objectReference: {fileID: 0}
3002+
- target: {fileID: 9008334923571228613, guid: ecec1fc7bdc6441a691ca908dfadc8b4, type: 3}
3003+
propertyPath: m_IsActive
3004+
value: 0
3005+
objectReference: {fileID: 0}
30023006
m_RemovedComponents: []
30033007
m_SourcePrefab: {fileID: 100100000, guid: ecec1fc7bdc6441a691ca908dfadc8b4, type: 3}
30043008
--- !u!1 &1339374947
@@ -3372,7 +3376,7 @@ RectTransform:
33723376
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
33733377
m_AnchorMin: {x: 0, y: 1}
33743378
m_AnchorMax: {x: 1, y: 1}
3375-
m_AnchoredPosition: {x: 0, y: -59.999916}
3379+
m_AnchoredPosition: {x: 0, y: -60.000004}
33763380
m_SizeDelta: {x: 0, y: 0}
33773381
m_Pivot: {x: 0.5, y: 0.5}
33783382
--- !u!114 &1617634874

Assets/_Project/Scripts/Players/Player.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ public class Player : MonoBehaviour
77

88

99
public string username;
10+
public string avatarPath;
1011

1112

12-
public void Init(string username)
13+
public void Init(string username, string avatarPath)
1314
{
1415
this.username = username;
16+
this.avatarPath = avatarPath;
1517
}
1618

1719

Assets/_Project/Scripts/Players/PlayerAvaterController.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
using System.Collections;
22
using System.Collections.Generic;
33
using UnityEngine;
4+
using UnityEngine.Networking;
45

56
public class PlayerAvaterController : MonoBehaviour {
67

78

89
// temp sprites for assigning avatars
910
public SpriteRenderer spriteRenderer;
1011
public SpriteMask spriteMask;
11-
12+
public Player player;
1213

1314
void Start ()
1415
{
1516
spriteRenderer = GetComponent<SpriteRenderer> ();
17+
1618
// temp - choose random avatar
17-
spriteRenderer.sprite = PlayerManager.Instance.avatars [Random.Range (0, PlayerManager.Instance.avatars.Length - 1)];
19+
// spriteRenderer.sprite = PlayerManager.Instance.avatars [Random.Range (0, PlayerManager.Instance.avatars.Length - 1)];
20+
21+
StartCoroutine(DownloadImage("https://tallysavestheinternet.com/" + player.avatarPath));
1822

1923
// set random sorting order
2024
spriteRenderer.sortingOrder = Random.Range (100, 10000);
@@ -26,5 +30,17 @@ void Start ()
2630

2731
}
2832

33+
IEnumerator DownloadImage(string MediaUrl)
34+
{
35+
UnityWebRequest request = UnityWebRequestTexture.GetTexture(MediaUrl);
36+
yield return request.SendWebRequest();
37+
if (request.isNetworkError || request.isHttpError)
38+
Debug.Log(request.error + " " + MediaUrl);
39+
else
40+
{
41+
Texture2D onlineAvatar = ((DownloadHandlerTexture)request.downloadHandler).texture;
42+
spriteRenderer.sprite = Sprite.Create(onlineAvatar, new Rect(0, 0, onlineAvatar.width, onlineAvatar.height), new Vector2(0.5f, 0.5f));
43+
}
44+
}
2945

3046
}

Assets/_Project/Scripts/Players/PlayerManager.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public void ResetPlayers ()
4949

5050
// loop through the feed and add players
5151
foreach (var feed in DataManager.feeds) {
52-
CreateNewPlayer (feed.username);
52+
CreateNewPlayer (feed.username, feed.avatarPath);
5353
}
5454

5555
// trigger data updated event
@@ -59,7 +59,7 @@ public void ResetPlayers ()
5959
/**
6060
* Create a new player
6161
*/
62-
public void CreateNewPlayer (string username)
62+
public void CreateNewPlayer (string username, string avatarPath)
6363
{
6464
// make sure the player doesn't already exist
6565
if (playerDict.ContainsKey (username)) return;
@@ -79,7 +79,7 @@ public void CreateNewPlayer (string username)
7979
// instantiate prefab @ spawn position
8080
GameObject obj = (GameObject)Instantiate (playerPrefab, spawnPosition, spawnRotation);
8181
// call Init() on Player
82-
obj.GetComponent<Player> ().Init (username);
82+
obj.GetComponent<Player> ().Init (username, avatarPath);
8383
// set name in Unity Editor
8484
obj.name = username;
8585
// parent under PlayerManger
@@ -166,6 +166,4 @@ public static Vector3 RandomPointInBounds (Bounds bounds)
166166
);
167167
}
168168

169-
170-
171169
}

Packages/packages-lock.json

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,5 @@
11
{
22
"dependencies": {
3-
"com.unity.2d.animation": {
4-
"version": "4.2.6",
5-
"depth": 1,
6-
"source": "registry",
7-
"dependencies": {
8-
"com.unity.2d.common": "3.0.1",
9-
"com.unity.mathematics": "1.1.0",
10-
"com.unity.2d.sprite": "1.0.0",
11-
"com.unity.modules.animation": "1.0.0",
12-
"com.unity.modules.uielements": "1.0.0"
13-
},
14-
"url": "https://packages.unity.com"
15-
},
16-
"com.unity.2d.common": {
17-
"version": "3.0.1",
18-
"depth": 1,
19-
"source": "registry",
20-
"dependencies": {
21-
"com.unity.2d.sprite": "1.0.0",
22-
"com.unity.modules.uielements": "1.0.0"
23-
},
24-
"url": "https://packages.unity.com"
25-
},
26-
"com.unity.2d.psdimporter": {
27-
"version": "3.1.6",
28-
"depth": 0,
29-
"source": "registry",
30-
"dependencies": {
31-
"com.unity.2d.common": "3.0.1",
32-
"com.unity.2d.animation": "4.2.6",
33-
"com.unity.2d.sprite": "1.0.0"
34-
},
35-
"url": "https://packages.unity.com"
36-
},
37-
"com.unity.2d.sprite": {
38-
"version": "1.0.0",
39-
"depth": 1,
40-
"source": "builtin",
41-
"dependencies": {}
42-
},
433
"com.unity.collab-proxy": {
444
"version": "1.3.8",
455
"depth": 0,
@@ -77,13 +37,6 @@
7737
"dependencies": {},
7838
"url": "https://packages.unity.com"
7939
},
80-
"com.unity.mathematics": {
81-
"version": "1.1.0",
82-
"depth": 2,
83-
"source": "registry",
84-
"dependencies": {},
85-
"url": "https://packages.unity.com"
86-
},
8740
"com.unity.render-pipelines.core": {
8841
"version": "8.2.0",
8942
"depth": 1,

0 commit comments

Comments
 (0)