Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Y
YGOProUnity_V2
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
perfectdicky
YGOProUnity_V2
Commits
0b54818d
Commit
0b54818d
authored
Aug 01, 2022
by
mercury233
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cache avatar & change url
parent
4856fc7f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
2 deletions
+18
-2
Assets/Scripts/MyCard.cs
Assets/Scripts/MyCard.cs
+18
-2
No files found.
Assets/Scripts/MyCard.cs
View file @
0b54818d
using
System
;
using
System.Collections.Generic
;
using
UnityEngine
;
using
UnityEngine.Networking
;
...
...
@@ -6,10 +7,23 @@ namespace DefaultNamespace
{
public
class
MyCard
{
private
static
Dictionary
<
string
,
Texture2D
>
cachedAvatars
=
new
Dictionary
<
string
,
Texture2D
>();
public
static
void
LoadAvatar
(
string
username
,
Action
<
Texture2D
>
callback
)
{
if
(
cachedAvatars
.
ContainsKey
(
username
))
{
var
avatar
=
cachedAvatars
[
username
];
if
(
avatar
!=
null
)
{
callback
(
cachedAvatars
[
username
]);
}
return
;
}
cachedAvatars
.
Add
(
username
,
null
);
var
request
=
UnityWebRequestTexture
.
GetTexture
(
$"https://sapi.moecube.com:444/a
ccounts/users/
{
username
}
.png"
);
UnityWebRequestTexture
.
GetTexture
(
$"https://sapi.moecube.com:444/a
vatar/avatar/
{
username
}
/100/ygopro2
.png"
);
var
operation
=
request
.
SendWebRequest
();
operation
.
completed
+=
_
=>
{
...
...
@@ -19,7 +33,9 @@ namespace DefaultNamespace
return
;
}
callback
(((
DownloadHandlerTexture
)
request
.
downloadHandler
).
texture
);
var
avatar
=
((
DownloadHandlerTexture
)
request
.
downloadHandler
).
texture
;
cachedAvatars
[
username
]
=
avatar
;
callback
(
avatar
);
};
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment