Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in / Register
Toggle navigation
M
MusicBigWatermelon
Project
Project
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
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
王雪伟
MusicBigWatermelon
Commits
c74f1c3c
Commit
c74f1c3c
authored
Aug 03, 2021
by
王雪伟
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改接口请求
parent
0fa10fd5
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
75 additions
and
4 deletions
+75
-4
HttpTool.cs
Assets/Base/UnityTool/HTTP/HttpTool.cs
+55
-0
MainPanel.cs
Assets/Scripts/Panel/MainPanel.cs
+20
-4
No files found.
Assets/Base/UnityTool/HTTP/HttpTool.cs
View file @
c74f1c3c
...
@@ -43,6 +43,61 @@ public class HttpTool : MonoBehaviour
...
@@ -43,6 +43,61 @@ public class HttpTool : MonoBehaviour
//unityhttp header 的内容
//unityhttp header 的内容
requestHeader
.
Add
(
"Content-Type"
,
"application/json"
);
requestHeader
.
Add
(
"Content-Type"
,
"application/json"
);
}
}
public
void
_Get2
(
string
methodName
,
Dictionary
<
string
,
object
>
getParas
,
Action
<
Response
<
List
<
string
>>>
success
,
Action
<
string
,
string
>
failed
)
{
StartCoroutine
(
GetRequest2
(
BaseGameUrl
,
methodName
,
getParas
,
success
,
failed
));
}
private
IEnumerator
GetRequest2
(
string
BaseURL
,
string
methodName
,
Dictionary
<
string
,
object
>
getParas
,
Action
<
Response
<
List
<
string
>>>
success
,
Action
<
string
,
string
>
failed
)
{
string
url
=
BaseURL
+
methodName
+
"?"
+
addParams
(
getParas
);
using
(
UnityWebRequest
webRequest
=
UnityWebRequest
.
Get
(
url
))
{
//设置header
foreach
(
var
v
in
requestHeader
)
{
webRequest
.
SetRequestHeader
(
v
.
Key
,
(
string
)
v
.
Value
);
}
webRequest
.
timeout
=
timeOut
;
yield
return
webRequest
.
SendWebRequest
();
if
(
webRequest
.
isHttpError
||
webRequest
.
isNetworkError
)
{
if
(
failed
!=
null
)
{
failed
(
webRequest
.
error
,
webRequest
.
downloadHandler
.
text
);
}
}
else
{
string
json
=
webRequest
.
downloadHandler
.
text
;
Debug
.
unityLogger
.
Log
(
HttpLogTag
,
"GET RequestUrl=> "
+
url
);
Debug
.
unityLogger
.
Log
(
HttpLogTag
,
"Json=> "
+
json
);
if
(
success
!=
null
)
{
Response
<
List
<
string
>>
response
=
JsonMapper
.
ToObject
<
Response
<
List
<
string
>>>(
json
);
if
(
response
.
status
==
200
)
{
success
(
response
);
}
else
{
if
(
response
.
status
==
105
)
{
//提示信息
ToastPlugin
.
ToastHelper
.
ShowToast
(
response
.
msg
);
}
if
(
failed
!=
null
)
{
failed
(
response
.
status
.
ToString
(),
response
.
msg
);
}
}
}
}
}
}
public
void
_Get
<
T
>(
string
methodName
,
Dictionary
<
string
,
object
>
getParas
,
Action
<
T
>
success
,
Action
<
string
,
string
>
failed
)
public
void
_Get
<
T
>(
string
methodName
,
Dictionary
<
string
,
object
>
getParas
,
Action
<
T
>
success
,
Action
<
string
,
string
>
failed
)
{
{
...
...
Assets/Scripts/Panel/MainPanel.cs
View file @
c74f1c3c
...
@@ -58,6 +58,7 @@ public class MainPanel : BasePanel
...
@@ -58,6 +58,7 @@ public class MainPanel : BasePanel
{
{
IsSuccess
=
true
;
IsSuccess
=
true
;
Debug
.
unityLogger
.
Log
(
"合成音符红包"
);
Debug
.
unityLogger
.
Log
(
"合成音符红包"
);
UIMgr
.
Getinstance
().
ShowPanel
<
MusicRedBagPanel
>(
E_Layer
.
mid
);
}
}
GetControl
<
Text
>(
"ProgressTv"
).
text
=
playNoteIndex
+
"/"
+
notesList
.
Count
;
GetControl
<
Text
>(
"ProgressTv"
).
text
=
playNoteIndex
+
"/"
+
notesList
.
Count
;
...
@@ -72,20 +73,35 @@ public class MainPanel : BasePanel
...
@@ -72,20 +73,35 @@ public class MainPanel : BasePanel
/// </summary>
/// </summary>
public
void
GetNextNoteList
(
int
song_id
)
public
void
GetNextNoteList
(
int
song_id
)
{
{
//Dictionary<string, object> paras = new Dictionary<string, object>();
//paras.Add("song_id", song_id);
//HttpTool.Instance._Get("app/v1/watermelon/notes", paras, new Action<List<string>>((result) =>
//{
// IsSuccess = false;
// playNoteIndex = 0;
// notesList = result;
// GetControl<Text>("ProgressTv").text = "0/" + result.Count;
// GetControl<Image>("ProgressBar").fillAmount = 0 / (float)result.Count;
// Debug.unityLogger.Log("");
//}), new Action<string, string>((code, msg) =>
//{
// Debug.unityLogger.Log("获取下一组生成的球 " + code + " msg " + msg);
//}));
Dictionary
<
string
,
object
>
paras
=
new
Dictionary
<
string
,
object
>();
Dictionary
<
string
,
object
>
paras
=
new
Dictionary
<
string
,
object
>();
paras
.
Add
(
"song_id"
,
song_id
);
paras
.
Add
(
"song_id"
,
song_id
);
HttpTool
.
Instance
.
_Get
(
"app/v1/watermelon/notes"
,
paras
,
new
Action
<
List
<
string
>>((
result
)
=>
HttpTool
.
Instance
.
_Get
2
(
"app/v1/watermelon/notes"
,
paras
,
new
Action
<
Response
<
List
<
string
>
>>((
result
)
=>
{
{
IsSuccess
=
false
;
IsSuccess
=
false
;
playNoteIndex
=
0
;
playNoteIndex
=
0
;
notesList
=
result
;
notesList
=
result
.
result
.
data
;
GetControl
<
Text
>(
"ProgressTv"
).
text
=
"0/"
+
result
.
Count
;
GetControl
<
Text
>(
"ProgressTv"
).
text
=
"0/"
+
result
.
result
.
data
.
Count
;
GetControl
<
Image
>(
"ProgressBar"
).
fillAmount
=
0
/
(
float
)
result
.
Count
;
GetControl
<
Image
>(
"ProgressBar"
).
fillAmount
=
0
/
(
float
)
result
.
result
.
data
.
Count
;
Debug
.
unityLogger
.
Log
(
""
);
Debug
.
unityLogger
.
Log
(
""
);
}),
new
Action
<
string
,
string
>((
code
,
msg
)
=>
}),
new
Action
<
string
,
string
>((
code
,
msg
)
=>
{
{
Debug
.
unityLogger
.
Log
(
"获取下一组生成的球 "
+
code
+
" msg "
+
msg
);
Debug
.
unityLogger
.
Log
(
"获取下一组生成的球 "
+
code
+
" msg "
+
msg
);
}));
}));
}
}
}
}
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