Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
山
山西检定流水线数字孪生项目
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
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
杨泽宇
山西检定流水线数字孪生项目
Commits
871fad6b
Commit
871fad6b
authored
Mar 06, 2025
by
潘梓豪
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
更新
parent
449ed984
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
77 additions
and
68 deletions
+77
-68
LoginManager.cs
Assets/Scripts/Components/AGV/LoginManager.cs
+74
-65
EditorBuildSettings.asset
ProjectSettings/EditorBuildSettings.asset
+2
-2
ProjectSettings.asset
ProjectSettings/ProjectSettings.asset
+1
-1
No files found.
Assets/Scripts/Components/AGV/LoginManager.cs
View file @
871fad6b
...
...
@@ -2,7 +2,6 @@ using System.Collections;
using
UnityEngine.Networking
;
using
UnityEngine
;
using
TMPro
;
using
System.IO
;
using
LitJson
;
using
System
;
...
...
@@ -40,7 +39,7 @@ public class LoginManager : MonoBehaviour
private
void
Awake
()
{
OnReceiveMsg
.
AddListener
(
_getData
);
StartCoroutine
(
GetJson
());
StartCoroutine
(
GetJson
());
}
private
void
Start
()
...
...
@@ -87,32 +86,34 @@ public class LoginManager : MonoBehaviour
{
while
(
true
)
{
using
(
UnityWebRequest
request
=
UnityWebRequest
.
Get
(
productionlineID
.
text
))
if
(!
String
.
IsNullOrEmpty
(
productionlineID
.
text
))
{
// 设置请求头
request
.
SetRequestHeader
(
"Content-Type"
,
"application/json"
);
using
(
UnityWebRequest
request
=
UnityWebRequest
.
Get
(
productionlineID
.
text
))
{
Debug
.
Log
(
productionlineID
.
text
);
// 设置请求头
request
.
SetRequestHeader
(
"Content-Type"
,
"application/json"
);
// 发送请求并等待响应
yield
return
request
.
SendWebRequest
();
// 发送请求并等待响应
yield
return
request
.
SendWebRequest
();
if
(!
string
.
IsNullOrEmpty
(
request
.
error
))
{
Debug
.
LogError
(
request
.
error
);
}
else
{
// 解析响应数据
string
responseJson
=
request
.
downloadHandler
.
text
;
Debug
.
Log
(
"Response: "
+
responseJson
);
// 使用 JsonUtility 解析 JSON 数据
positionData
=
JsonUtility
.
FromJson
<
RobotPositionData
>(
responseJson
);
OnReceiveMsg
.
Invoke
(
positionData
,
"RobotPositionData"
);
IsDataLoaded
=
true
;
if
(!
string
.
IsNullOrEmpty
(
request
.
error
))
{
Debug
.
LogError
(
request
.
error
);
}
else
{
// 解析响应数据
string
responseJson
=
request
.
downloadHandler
.
text
;
Debug
.
Log
(
"Response: "
+
responseJson
);
// 使用 JsonUtility 解析 JSON 数据
positionData
=
JsonMapper
.
ToObject
<
RobotPositionData
>(
responseJson
);
OnReceiveMsg
.
Invoke
(
positionData
,
"RobotPositionData"
);
IsDataLoaded
=
true
;
}
}
}
yield
return
new
WaitForSeconds
(
1
);
}
}
...
...
@@ -123,40 +124,43 @@ public class LoginManager : MonoBehaviour
while
(
true
)
{
using
(
UnityWebRequest
request
=
UnityWebRequest
.
PostWwwForm
(
faultInterface
.
text
,
jsonData
))
if
(!
String
.
IsNullOrEmpty
(
faultInterface
.
text
))
{
// 设置请求头
request
.
SetRequestHeader
(
"Content-Type"
,
"application/json"
);
// 设置请求体
byte
[]
bodyRaw
=
System
.
Text
.
Encoding
.
UTF8
.
GetBytes
(
jsonData
);
request
.
uploadHandler
=
new
UploadHandlerRaw
(
bodyRaw
);
// 发送请求并等待响应
yield
return
request
.
SendWebRequest
();
if
(!
string
.
IsNullOrEmpty
(
request
.
error
))
{
Debug
.
LogError
(
request
.
error
);
}
else
using
(
UnityWebRequest
request
=
UnityWebRequest
.
PostWwwForm
(
faultInterface
.
text
,
jsonData
))
{
//
解析响应数据
string
responseJson
=
request
.
downloadHandler
.
text
;
//
设置请求头
request
.
SetRequestHeader
(
"Content-Type"
,
"application/json"
)
;
// 使用 JsonUtility 解析 JSON 数据
faultData
=
JsonUtility
.
FromJson
<
FaultEventData
>(
responseJson
);
// 设置请求体
byte
[]
bodyRaw
=
System
.
Text
.
Encoding
.
UTF8
.
GetBytes
(
jsonData
);
request
.
uploadHandler
=
new
UploadHandlerRaw
(
bodyRaw
);
// 发送请求并等待响应
yield
return
request
.
SendWebRequest
();
// 检查是否成功拿到数据
if
(
faultData
!=
null
&&
faultData
.
code
==
200
)
if
(!
string
.
IsNullOrEmpty
(
request
.
error
))
{
OnReceiveMsg
.
Invoke
(
faultData
,
"FaultEventData"
);
Debug
.
Log
(
faultData
);
Debug
.
LogError
(
request
.
error
);
}
else
{
Debug
.
Log
(
"获取故障数据失败"
);
// 解析响应数据
string
responseJson
=
request
.
downloadHandler
.
text
;
// 使用 JsonUtility 解析 JSON 数据
faultData
=
JsonMapper
.
ToObject
<
FaultEventData
>(
responseJson
);
// 检查是否成功拿到数据
if
(
faultData
!=
null
&&
faultData
.
code
==
200
)
{
OnReceiveMsg
.
Invoke
(
faultData
,
"FaultEventData"
);
Debug
.
Log
(
faultData
);
}
else
{
Debug
.
Log
(
"获取故障数据失败"
);
}
}
}
}
...
...
@@ -168,26 +172,29 @@ public class LoginManager : MonoBehaviour
{
while
(
true
)
{
using
(
UnityWebRequest
request
=
UnityWebRequest
.
Get
(
post_url
.
text
+
"?lineId="
+
lineID
.
text
))
if
(!
String
.
IsNullOrEmpty
(
post_url
.
text
))
{
// 设置请求头
//request.SetRequestHeader("Content-Type", "application/json");
// 发送请求并等待响应
yield
return
request
.
SendWebRequest
();
if
(!
string
.
IsNullOrEmpty
(
request
.
error
))
{
Debug
.
LogError
(
request
.
error
);
}
else
using
(
UnityWebRequest
request
=
UnityWebRequest
.
Get
(
post_url
.
text
+
"?lineId="
+
lineID
.
text
))
{
// 解析响应数据
line_jd
=
JsonMapper
.
ToObject
<
JsonData
>(
request
.
downloadHandler
.
text
);
// 设置请求头
//request.SetRequestHeader("Content-Type", "application/json");
// 发送请求并等待响应
yield
return
request
.
SendWebRequest
();
if
(
line_jd
!=
null
&&
line_jd
.
ContainsKey
(
"data"
))
if
(!
string
.
IsNullOrEmpty
(
request
.
error
))
{
Debug
.
LogError
(
request
.
error
);
}
else
{
setData
(
_parent
,
line_jd
);
// 解析响应数据
line_jd
=
JsonMapper
.
ToObject
<
JsonData
>(
request
.
downloadHandler
.
text
);
if
(
line_jd
!=
null
&&
line_jd
.
ContainsKey
(
"data"
))
{
setData
(
_parent
,
line_jd
);
}
}
}
}
...
...
@@ -268,11 +275,13 @@ public class LoginManager : MonoBehaviour
rq
.
SetRequestHeader
(
"Access-Control-Allow-Origin"
,
"*"
);
rq
.
SetRequestHeader
(
"Accept"
,
"*"
);
yield
return
rq
.
SendWebRequest
();
if
(
string
.
IsNullOrEmpty
(
rq
.
error
))
{
try
{
inputFieldData
=
JsonUtility
.
FromJson
<
InputFieldData
>(
rq
.
downloadHandler
.
text
);
inputFieldData
=
JsonMapper
.
ToObject
<
InputFieldData
>(
rq
.
downloadHandler
.
text
);
Debug
.
Log
(
rq
.
downloadHandler
.
text
);
if
(
IsLine1
)
{
productionlineID
.
text
=
inputFieldData
.
productionlineID1
;
...
...
ProjectSettings/EditorBuildSettings.asset
View file @
871fad6b
...
...
@@ -5,7 +5,7 @@ EditorBuildSettings:
m_ObjectHideFlags
:
0
serializedVersion
:
2
m_Scenes
:
-
enabled
:
1
-
enabled
:
0
path
:
Assets/_Scenes/1_Main.unity
guid
:
a1193329f89803b4f8a14f6c0b15d2c1
-
enabled
:
0
...
...
@@ -14,7 +14,7 @@ EditorBuildSettings:
-
enabled
:
0
path
:
Assets/_Scenes/3_Main.unity
guid
:
20c0c67e1155d7340be70873c2eb30f1
-
enabled
:
0
-
enabled
:
1
path
:
Assets/_Scenes/4_Main.unity
guid
:
da74b35adf3770040b51552fc0cb9a98
-
enabled
:
0
...
...
ProjectSettings/ProjectSettings.asset
View file @
871fad6b
...
...
@@ -653,7 +653,7 @@ PlayerSettings:
webGLDebugSymbols
:
0
webGLEmscriptenArgs
:
webGLModulesDirectory
:
webGLTemplate
:
APPLICATION:Default
webGLTemplate
:
PROJECT:ZeusWebGL
webGLAnalyzeBuildSize
:
0
webGLUseEmbeddedResources
:
0
webGLCompressionFormat
:
2
...
...
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