Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
I
igem-quantifly
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PLN
igem-quantifly
Commits
91430032
Unverified
Commit
91430032
authored
Oct 27, 2016
by
PLN (Algolia)
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Server: Fix json deserialization
parent
b294cb64
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
33 deletions
+21
-33
Server.cs
Assets/Scripts/API/Server.cs
+21
-26
SimpleEnnemy.cs
Assets/Scripts/SimpleEnnemy.cs
+0
-7
No files found.
Assets/Scripts/API/Server.cs
View file @
91430032
using
System
;
using
System
;
using
UnityEngine
;
using
UnityEngine
;
using
UnityEngine.Networking
;
using
System.Collections
;
using
System.Collections
;
using
System.Collections.Generic
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Linq
;
using
UnityEngine.Networking
;
namespace
Assets.Scripts.API
namespace
Assets.Scripts.API
{
{
public
class
Server
public
class
Server
:
MonoBehaviour
{
{
public
static
string
HOST_PROD
=
"https://quantifly.plnech.fr"
;
public
static
string
HOST
=
"http://localhost:8990"
;
public
static
string
HOST
=
"http://localhost:8990"
;
public
Server
()
public
Server
()
{
{
}
}
public
static
List
<
Score
>
GetScores
()
public
void
GetScores
()
{
{
StartCoroutine
(
GetScoresAsync
());
Debug
.
Log
(
"Done."
);
}
IEnumerator
GetScoresAsync
()
{
UnityWebRequest
www
=
UnityWebRequest
.
Get
(
HOST
+
"/scores/"
);
UnityWebRequest
www
=
UnityWebRequest
.
Get
(
HOST
+
"/scores/"
);
www
.
Send
();
yield
return
www
.
Send
();
if
(
www
.
isError
)
{
if
(
www
.
isError
)
{
Debug
.
LogError
(
"Error:"
+
www
.
error
);
Debug
.
LogError
(
"Error:"
+
www
.
error
);
return
null
;
}
else
{
Debug
.
Log
(
"Got response: "
+
www
.
downloadHandler
.
text
);
ScoresRes
res
=
ScoresRes
.
CreateFromJson
(
www
.
downloadHandler
.
text
);
Debug
.
Log
(
"Got scores: "
+
res
);
}
}
Debug
.
Log
(
"Got response: "
+
www
.
downloadHandler
.
text
);
ScoresRes
res
=
JsonUtility
.
FromJson
<
ScoresRes
>(
www
.
downloadHandler
.
text
);
//Debug.Log("Got scores: " + res.scores);
string
status
=
"{\"status\":\"ok\"}"
;
string
mockText
=
"{\"scores\":[{\"playerName\":\"John Smith\",\"team\":null,\"score\":10,\"date\":\"2016-10-23T12:42:54.810Z\",\"_id\":\"d21b623e9b394993be3224de89099194\"},"
+
"{\"playerName\":\"Randy\",\"team\":\"iGEM Headquarters\",\"score\":42,\"date\":\"2016-10-23T12:45:45.774Z\",\"_id\":\"a3a66de22b30450492f8f6b1bf178123\"}"
+
"]}"
;
ScoresRes
mock
=
ScoresRes
.
CreateFromJson
(
status
,
mockText
);
//TODO: Why does JsonUtility fail to deserialize? /o\
Debug
.
Log
(
"Mock scores: "
+
mock
);
return
res
.
scores
;
}
}
[
S
ystem
.
S
erializable
]
[
Serializable
]
public
class
ScoresRes
{
public
class
ScoresRes
{
public
string
status
{
get
;
set
;}
public
string
status
;
public
List
<
Score
>
scores
{
get
;
set
;}
public
Score
[]
scores
;
public
ScoresRes
()
{}
public
ScoresRes
()
{}
public
static
ScoresRes
CreateFromJson
(
string
s
tatus
,
string
scores
)
public
static
ScoresRes
CreateFromJson
(
string
s
coresJSON
)
{
{
return
new
ScoresRes
return
JsonUtility
.
FromJson
<
ScoresRes
>(
scoresJSON
);
{
status
=
status
,
scores
=
JsonUtility
.
FromJson
<
List
<
Score
>>(
scores
)
};
}
}
public
override
string
ToString
()
public
override
string
ToString
()
...
...
Assets/Scripts/SimpleEnnemy.cs
View file @
91430032
...
@@ -33,12 +33,5 @@ public class SimpleEnnemy : MonoBehaviour
...
@@ -33,12 +33,5 @@ public class SimpleEnnemy : MonoBehaviour
_player
.
GetComponent
<
Player
>().
Battery
-=
8
;
_player
.
GetComponent
<
Player
>().
Battery
-=
8
;
_player
.
GetComponent
<
Player
>().
SetBlinking
();
_player
.
GetComponent
<
Player
>().
SetBlinking
();
GetScores
();
// TODO: Successfully get scores from API
}
}
void
GetScores
()
{
Debug
.
Log
(
"Getting scores..."
);
Server
.
GetScores
();
Debug
.
Log
(
"Got scores."
);
}
}
}
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