Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
alsunj
/
blackjack
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
885fb53f
authored
May 02, 2023
by
alsunj
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
1e0abe38
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
94 additions
and
0 deletions
scripts/C#/ScoreTable.cs
scripts/C#/ScoreTable.cs
0 → 100644
View file @
885fb53f
using
System.Collections
;
using
System.Collections.Generic
;
using
UnityEngine.UI
;
using
UnityEngine.SceneManagement
;
using
UnityEngine
;
public
class
ScoreTable
:
MonoBehaviour
{
public
Text
usernamePrefab
;
public
Text
bankPrefab
;
public
Text
winsPrefab
;
public
Text
losesPrefab
;
public
Text
wlPrefab
;
public
RectTransform
content
;
private
void
Start
()
{
StartCoroutine
(
Callstats
());
}
IEnumerator
Callstats
()
{
WWWForm
form
=
new
WWWForm
();
WWW
www
=
new
WWW
(
"http://localhost/Table.php"
,
form
);
yield
return
www
;
if
(
www
.
text
[
0
]
==
'0'
)
{
// If no results were returned, do nothing
}
else
{
// Split the text returned by the PHP script into separate variables for username, bank, wins, and loses
string
[]
lines
=
www
.
text
.
Split
(
new
string
[]
{
"<br>"
},
System
.
StringSplitOptions
.
RemoveEmptyEntries
);
// Create new rows for each line of values
float
yOffset
=
100
;
foreach
(
string
line
in
lines
)
{
string
[]
values
=
line
.
Split
(
new
char
[]
{
' '
},
System
.
StringSplitOptions
.
RemoveEmptyEntries
);
if
(
values
.
Length
>=
4
)
{
string
usernameStr
=
values
[
0
];
string
bankStr
=
values
[
1
];
string
winsStr
=
values
[
2
];
string
losesStr
=
values
[
3
];
// Divide the integers in winsStr and losesStr
int
wins
=
int
.
Parse
(
winsStr
);
int
loses
=
int
.
Parse
(
losesStr
);
// Check if loses is greater than 0, if not set it to 1
if
(
loses
==
0
)
{
loses
=
1
;
}
float
wl
=
(
float
)
wins
/
(
float
)
loses
;
string
wlStr
=
wl
.
ToString
(
"F2"
);
// Create new UI elements for each value
Text
usernameText
=
Instantiate
(
usernamePrefab
,
content
.
transform
);
usernameText
.
text
=
usernameStr
;
Text
bankText
=
Instantiate
(
bankPrefab
,
content
.
transform
);
bankText
.
text
=
bankStr
;
Text
winsText
=
Instantiate
(
winsPrefab
,
content
.
transform
);
winsText
.
text
=
winsStr
;
Text
losesText
=
Instantiate
(
losesPrefab
,
content
.
transform
);
losesText
.
text
=
losesStr
;
Text
wlText
=
Instantiate
(
wlPrefab
,
content
.
transform
);
wlText
.
text
=
wlStr
;
// Position the new row of UI elements
Vector3
pos
=
new
Vector3
(-
243
,
yOffset
,
0
);
usernameText
.
rectTransform
.
localPosition
=
pos
;
bankText
.
rectTransform
.
localPosition
=
pos
+
new
Vector3
(
150
,
0
,
0
);
winsText
.
rectTransform
.
localPosition
=
pos
+
new
Vector3
(
310
,
0
,
0
);
losesText
.
rectTransform
.
localPosition
=
pos
+
new
Vector3
(
430
,
0
,
0
);
wlText
.
rectTransform
.
localPosition
=
pos
+
new
Vector3
(
550
,
0
,
0
);
// Increase the yOffset for the next row
yOffset
-=
30
;
}
}
}
}
}
\ No newline at end of file
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