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
ffb63a62
Commit
ffb63a62
authored
Aug 19, 2024
by
杨泽宇
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
更新
parent
94321db6
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
53 additions
and
40 deletions
+53
-40
LoginManager.cs
Assets/Scripts/Components/AGV/LoginManager.cs
+5
-0
SensorDataManger.cs
Assets/Scripts/Components/UI/SensorDataManger.cs
+45
-39
1_Main.unity
Assets/_Scenes/1_Main.unity
+3
-1
No files found.
Assets/Scripts/Components/AGV/LoginManager.cs
View file @
ffb63a62
...
...
@@ -12,6 +12,8 @@ public class LoginManager : MonoBehaviour
public
TMP_InputField
lineID
;
public
TMP_InputField
post_url
;
private
RobotPositionData
positionData
;
private
FaultEventData
faultData
;
...
...
@@ -167,6 +169,7 @@ public class LoginManager : MonoBehaviour
PlayerPrefs
.
SetString
(
"lineID2"
,
lineID
.
text
);
}
PlayerPrefs
.
SetString
(
"faultInterface"
,
faultInterface
.
text
);
PlayerPrefs
.
SetString
(
"post_url"
,
post_url
.
text
);
PlayerPrefs
.
Save
();
// 确保数据被保存
Debug
.
Log
(
"Input fields saved to PlayerPrefs."
);
...
...
@@ -188,6 +191,7 @@ public class LoginManager : MonoBehaviour
lineID
.
text
=
PlayerPrefs
.
GetString
(
"lineID2"
);
}
faultInterface
.
text
=
PlayerPrefs
.
GetString
(
"faultInterface"
);
post_url
.
text
=
PlayerPrefs
.
GetString
(
"post_url"
);
Debug
.
Log
(
"Input fields loaded from PlayerPrefs."
);
}
...
...
@@ -206,6 +210,7 @@ public class InputFieldData
public
string
faultInterface
;
public
string
lineID1
;
public
string
lineID2
;
public
string
post_url
;
}
// 定义机器人位置数据结构
...
...
Assets/Scripts/Components/UI/SensorDataManger.cs
View file @
ffb63a62
...
...
@@ -18,7 +18,7 @@ public class SensorDataManger : MonoBehaviour
public
GameObject
_parent2
;
public
Vector3
uiOffset
=
new
Vector3
(
0
,
2
,
3
);
// UI
相对于模型的位置偏移
public
Vector3
uiOffset
=
new
Vector3
(
0
,
2
,
3
);
// UI
相对于模型的位置偏移
private
GameObject
uiInstance
;
...
...
@@ -35,7 +35,7 @@ public class SensorDataManger : MonoBehaviour
void
Start
()
{
//
编辑模式下使用,创建
UI
//
编辑模式下使用,创建UI
//foreach (GameObject item in model1)
//{
// Create3dUI(item,_parent1);
...
...
@@ -46,6 +46,12 @@ public class SensorDataManger : MonoBehaviour
// Create3dUI(item, _parent2);
//}
lineId1
=
PlayerPrefs
.
GetString
(
"lineID1"
);
lineId2
=
PlayerPrefs
.
GetString
(
"lineID2"
);
post_url
=
PlayerPrefs
.
GetString
(
"post_url"
);
StartCoroutine
(
GetThreeModelSensorData1
());
StartCoroutine
(
GetThreeModelSensorData2
());
...
...
@@ -61,16 +67,16 @@ public class SensorDataManger : MonoBehaviour
{
if
(
tagert_obj
!=
null
&&
_prefab
!=
null
)
{
//
在模型上方生成U
I
//
在模型上方生成UI
uiInstance
=
Instantiate
(
_prefab
,
tagert_obj
.
transform
.
position
+
uiOffset
,
Quaternion
.
identity
);
//
设置UI为世界空间
//
设置UI为世界空间
Canvas
canvas
=
uiInstance
.
GetComponent
<
Canvas
>();
if
(
canvas
!=
null
)
{
canvas
.
renderMode
=
RenderMode
.
WorldSpace
;
}
//
设置UI跟随模型移动
//
设置UI跟随模型移动
uiInstance
.
transform
.
SetParent
(
_parent
.
transform
);
uiInstance
.
transform
.
name
=
tagert_obj
.
name
;
...
...
@@ -82,7 +88,7 @@ public class SensorDataManger : MonoBehaviour
}
else
{
Debug
.
LogError
(
"
目标模型或UI预制件未设置!
"
);
Debug
.
LogError
(
"
目标模型或UI预制件未设置!"
);
}
}
...
...
@@ -94,14 +100,14 @@ public class SensorDataManger : MonoBehaviour
{
using
(
UnityWebRequest
request
=
UnityWebRequest
.
Get
(
post_url
+
"?lineId="
+
lineId1
))
{
//
设置请求头
//
设置请求头
//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
))
...
...
@@ -110,7 +116,7 @@ public class SensorDataManger : MonoBehaviour
}
else
{
//
解析响应数据
//
解析响应数据
line_jd1
=
JsonMapper
.
ToObject
<
JsonData
>(
request
.
downloadHandler
.
text
);
if
(
line_jd1
!=
null
&&
line_jd1
.
ContainsKey
(
"data"
))
...
...
@@ -131,14 +137,14 @@ public class SensorDataManger : MonoBehaviour
{
using
(
UnityWebRequest
request
=
UnityWebRequest
.
Get
(
post_url
+
"?lineId="
+
lineId2
))
{
//
设置请求头
//
设置请求头
//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
))
...
...
@@ -147,7 +153,7 @@ public class SensorDataManger : MonoBehaviour
}
else
{
//
解析响应数据
//
解析响应数据
line_jd2
=
JsonMapper
.
ToObject
<
JsonData
>(
request
.
downloadHandler
.
text
);
if
(
line_jd2
!=
null
&&
line_jd2
.
ContainsKey
(
"data"
))
...
...
@@ -170,53 +176,53 @@ public class SensorDataManger : MonoBehaviour
GameObject
_obj
=
parent
.
transform
.
Find
(
item
[
"equipmentName"
].
ToString
()).
gameObject
;
if
(
_obj
)
{
_obj
.
transform
.
Find
(
"
设备名称"
).
Find
(
"Text-名称
"
).
GetComponent
<
TMP_Text
>().
text
=
item
[
"equipmentName"
].
ToString
();
_obj
.
transform
.
Find
(
"
设备名称"
).
Find
(
"Text-名称"
).
GetComponent
<
TMP_Text
>().
text
=
item
[
"equipmentName"
].
ToString
();
switch
(
item
[
"sensorType"
].
ToString
())
{
case
"TILT"
:
_obj
.
transform
.
Find
(
"
倾角
"
).
gameObject
.
SetActive
(
true
);
_obj
.
transform
.
Find
(
"
倾角"
).
Find
(
"Text-数据
"
).
GetComponent
<
TMP_Text
>().
text
=
item
[
"data"
].
ToString
();
_obj
.
transform
.
Find
(
"
倾角"
).
Find
(
"Text-数据
"
).
GetComponent
<
TMP_Text
>().
color
=
(
int
.
Parse
(
item
[
"flag"
].
ToString
()).
Equals
(
1
)
?
Color
.
red
:
Color
.
green
);
_obj
.
transform
.
Find
(
"
倾角"
).
gameObject
.
SetActive
(
true
);
_obj
.
transform
.
Find
(
"
倾角"
).
Find
(
"Text-数据"
)
.
GetComponent
<
TMP_Text
>().
text
=
item
[
"data"
].
ToString
();
_obj
.
transform
.
Find
(
"
倾角"
).
Find
(
"Text-数据"
)
.
GetComponent
<
TMP_Text
>().
color
=
(
int
.
Parse
(
item
[
"flag"
].
ToString
()).
Equals
(
1
)
?
Color
.
red
:
Color
.
green
);
break
;
case
"NOISE"
:
_obj
.
transform
.
Find
(
"
噪声
"
).
gameObject
.
SetActive
(
true
);
_obj
.
transform
.
Find
(
"
噪声"
).
Find
(
"Text-数据
"
).
GetComponent
<
TMP_Text
>().
text
=
item
[
"data"
].
ToString
();
_obj
.
transform
.
Find
(
"
噪声"
).
Find
(
"Text-数据
"
).
GetComponent
<
TMP_Text
>().
color
=
(
int
.
Parse
(
item
[
"flag"
].
ToString
()).
Equals
(
1
)
?
Color
.
red
:
Color
.
green
);
_obj
.
transform
.
Find
(
"
噪声"
).
gameObject
.
SetActive
(
true
);
_obj
.
transform
.
Find
(
"
噪声"
).
Find
(
"Text-数据"
)
.
GetComponent
<
TMP_Text
>().
text
=
item
[
"data"
].
ToString
();
_obj
.
transform
.
Find
(
"
噪声"
).
Find
(
"Text-数据"
)
.
GetComponent
<
TMP_Text
>().
color
=
(
int
.
Parse
(
item
[
"flag"
].
ToString
()).
Equals
(
1
)
?
Color
.
red
:
Color
.
green
);
break
;
case
"PRESSURE"
:
_obj
.
transform
.
Find
(
"
压力
"
).
gameObject
.
SetActive
(
true
);
_obj
.
transform
.
Find
(
"
压力"
).
Find
(
"Text-数据
"
).
GetComponent
<
TMP_Text
>().
text
=
item
[
"data"
].
ToString
();
_obj
.
transform
.
Find
(
"
压力"
).
Find
(
"Text-数据
"
).
GetComponent
<
TMP_Text
>().
color
=
(
int
.
Parse
(
item
[
"flag"
].
ToString
()).
Equals
(
1
)
?
Color
.
red
:
Color
.
green
);
_obj
.
transform
.
Find
(
"
压力"
).
gameObject
.
SetActive
(
true
);
_obj
.
transform
.
Find
(
"
压力"
).
Find
(
"Text-数据"
)
.
GetComponent
<
TMP_Text
>().
text
=
item
[
"data"
].
ToString
();
_obj
.
transform
.
Find
(
"
压力"
).
Find
(
"Text-数据"
)
.
GetComponent
<
TMP_Text
>().
color
=
(
int
.
Parse
(
item
[
"flag"
].
ToString
()).
Equals
(
1
)
?
Color
.
red
:
Color
.
green
);
break
;
case
"TEMPERATURE"
:
_obj
.
transform
.
Find
(
"
温度
"
).
gameObject
.
SetActive
(
true
);
_obj
.
transform
.
Find
(
"
温度"
).
Find
(
"Text-数据
"
).
GetComponent
<
TMP_Text
>().
text
=
item
[
"data"
].
ToString
();
_obj
.
transform
.
Find
(
"
温度"
).
Find
(
"Text-数据
"
).
GetComponent
<
TMP_Text
>().
color
=
(
int
.
Parse
(
item
[
"flag"
].
ToString
()).
Equals
(
1
)
?
Color
.
red
:
Color
.
green
);
_obj
.
transform
.
Find
(
"
温度"
).
gameObject
.
SetActive
(
true
);
_obj
.
transform
.
Find
(
"
温度"
).
Find
(
"Text-数据"
)
.
GetComponent
<
TMP_Text
>().
text
=
item
[
"data"
].
ToString
();
_obj
.
transform
.
Find
(
"
温度"
).
Find
(
"Text-数据"
)
.
GetComponent
<
TMP_Text
>().
color
=
(
int
.
Parse
(
item
[
"flag"
].
ToString
()).
Equals
(
1
)
?
Color
.
red
:
Color
.
green
);
break
;
case
"HUMIDITY"
:
_obj
.
transform
.
Find
(
"
湿度
"
).
gameObject
.
SetActive
(
true
);
_obj
.
transform
.
Find
(
"
湿度"
).
Find
(
"Text-数据
"
).
GetComponent
<
TMP_Text
>().
text
=
item
[
"data"
].
ToString
();
_obj
.
transform
.
Find
(
"
湿度"
).
Find
(
"Text-数据
"
).
GetComponent
<
TMP_Text
>().
color
=
(
int
.
Parse
(
item
[
"flag"
].
ToString
()).
Equals
(
1
)
?
Color
.
red
:
Color
.
green
);
_obj
.
transform
.
Find
(
"
湿度"
).
gameObject
.
SetActive
(
true
);
_obj
.
transform
.
Find
(
"
湿度"
).
Find
(
"Text-数据"
)
.
GetComponent
<
TMP_Text
>().
text
=
item
[
"data"
].
ToString
();
_obj
.
transform
.
Find
(
"
湿度"
).
Find
(
"Text-数据"
)
.
GetComponent
<
TMP_Text
>().
color
=
(
int
.
Parse
(
item
[
"flag"
].
ToString
()).
Equals
(
1
)
?
Color
.
red
:
Color
.
green
);
break
;
case
"SMOG"
:
_obj
.
transform
.
Find
(
"
烟雾
"
).
gameObject
.
SetActive
(
true
);
_obj
.
transform
.
Find
(
"
烟雾"
).
Find
(
"Text-数据
"
).
GetComponent
<
TMP_Text
>().
text
=
item
[
"data"
].
ToString
();
_obj
.
transform
.
Find
(
"
烟雾"
).
Find
(
"Text-数据
"
).
GetComponent
<
TMP_Text
>().
color
=
(
int
.
Parse
(
item
[
"flag"
].
ToString
()).
Equals
(
1
)
?
Color
.
red
:
Color
.
green
);
_obj
.
transform
.
Find
(
"
烟雾"
).
gameObject
.
SetActive
(
true
);
_obj
.
transform
.
Find
(
"
烟雾"
).
Find
(
"Text-数据"
)
.
GetComponent
<
TMP_Text
>().
text
=
item
[
"data"
].
ToString
();
_obj
.
transform
.
Find
(
"
烟雾"
).
Find
(
"Text-数据"
)
.
GetComponent
<
TMP_Text
>().
color
=
(
int
.
Parse
(
item
[
"flag"
].
ToString
()).
Equals
(
1
)
?
Color
.
red
:
Color
.
green
);
break
;
case
"PM2.5_E"
:
_obj
.
transform
.
Find
(
"PM2.5"
).
gameObject
.
SetActive
(
true
);
_obj
.
transform
.
Find
(
"PM2.5"
).
Find
(
"Text-
数据
"
).
GetComponent
<
TMP_Text
>().
text
=
item
[
"data"
].
ToString
();
_obj
.
transform
.
Find
(
"PM2.5"
).
Find
(
"Text-
数据
"
).
GetComponent
<
TMP_Text
>().
color
=
(
int
.
Parse
(
item
[
"flag"
].
ToString
()).
Equals
(
1
)
?
Color
.
red
:
Color
.
green
);
_obj
.
transform
.
Find
(
"PM2.5"
).
Find
(
"Text-
数据"
).
GetComponent
<
TMP_Text
>().
text
=
item
[
"data"
].
ToString
();
_obj
.
transform
.
Find
(
"PM2.5"
).
Find
(
"Text-
数据"
).
GetComponent
<
TMP_Text
>().
color
=
(
int
.
Parse
(
item
[
"flag"
].
ToString
()).
Equals
(
1
)
?
Color
.
red
:
Color
.
green
);
break
;
case
"PM10_E"
:
_obj
.
transform
.
Find
(
"PM10"
).
gameObject
.
SetActive
(
true
);
_obj
.
transform
.
Find
(
"PM10"
).
Find
(
"Text-
数据
"
).
GetComponent
<
TMP_Text
>().
text
=
item
[
"data"
].
ToString
();
_obj
.
transform
.
Find
(
"PM10"
).
Find
(
"Text-
数据
"
).
GetComponent
<
TMP_Text
>().
color
=
(
int
.
Parse
(
item
[
"flag"
].
ToString
()).
Equals
(
1
)
?
Color
.
red
:
Color
.
green
);
_obj
.
transform
.
Find
(
"PM10"
).
Find
(
"Text-
数据"
).
GetComponent
<
TMP_Text
>().
text
=
item
[
"data"
].
ToString
();
_obj
.
transform
.
Find
(
"PM10"
).
Find
(
"Text-
数据"
).
GetComponent
<
TMP_Text
>().
color
=
(
int
.
Parse
(
item
[
"flag"
].
ToString
()).
Equals
(
1
)
?
Color
.
red
:
Color
.
green
);
break
;
case
"PM1.0_E"
:
_obj
.
transform
.
Find
(
"PM1.0"
).
gameObject
.
SetActive
(
true
);
_obj
.
transform
.
Find
(
"PM1.0"
).
Find
(
"Text-
数据
"
).
GetComponent
<
TMP_Text
>().
text
=
item
[
"data"
].
ToString
();
_obj
.
transform
.
Find
(
"PM1.0"
).
Find
(
"Text-
数据
"
).
GetComponent
<
TMP_Text
>().
color
=
(
int
.
Parse
(
item
[
"flag"
].
ToString
()).
Equals
(
1
)
?
Color
.
red
:
Color
.
green
);
_obj
.
transform
.
Find
(
"PM1.0"
).
Find
(
"Text-
数据"
).
GetComponent
<
TMP_Text
>().
text
=
item
[
"data"
].
ToString
();
_obj
.
transform
.
Find
(
"PM1.0"
).
Find
(
"Text-
数据"
).
GetComponent
<
TMP_Text
>().
color
=
(
int
.
Parse
(
item
[
"flag"
].
ToString
()).
Equals
(
1
)
?
Color
.
red
:
Color
.
green
);
break
;
}
}
...
...
Assets/_Scenes/1_Main.unity
View file @
ffb63a62
...
...
@@ -23245,6 +23245,7 @@ MonoBehaviour:
productionlineID: {fileID: 899657090}
faultInterface: {fileID: 1049990126}
lineID: {fileID: 898557198}
post_url: {fileID: 0}
position: {x: 0, y: 0, z: 0}
IsFault: 0
Failure:
...
...
@@ -32400,6 +32401,7 @@ MonoBehaviour:
productionlineID: {fileID: 1822593256}
faultInterface: {fileID: 1049990126}
lineID: {fileID: 1559283959}
post_url: {fileID: 0}
position: {x: 0, y: 0, z: 0}
IsFault: 0
Failure:
...
...
@@ -43537,7 +43539,7 @@ MonoBehaviour:
uiOffset: {x: 0, y: 2, z: 0}
lineId1: EB6F0348492C181DE055000000000001
lineId2: AD6E344FAEEB2EA9E053A3001E0A371D
post_url:
http://192.168.50.113:8093/maintenance/bigScreen/sensor/getThreeModelSensorData
post_url:
--- !u!1 &820565486
GameObject:
m_ObjectHideFlags: 0
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