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
8a423d39
Commit
8a423d39
authored
Aug 13, 2024
by
潘梓豪
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
更新预制体
parent
83af15aa
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
128307 additions
and
27445 deletions
+128307
-27445
SensorDataManger.cs
Assets/Scripts/Components/UI/SensorDataManger.cs
+143
-0
SensorDataManger.cs.meta
Assets/Scripts/Components/UI/SensorDataManger.cs.meta
+11
-0
1_Main.unity
Assets/_Scenes/1_Main.unity
+128153
-27445
标签-传感器数据-0810.prefab
Assets/_预设/UI/标签-传感器数据-0810.prefab
+0
-0
No files found.
Assets/Scripts/Components/UI/SensorDataManger.cs
0 → 100644
View file @
8a423d39
using
System.Collections
;
using
System.Collections.Generic
;
using
UnityEngine
;
using
UnityEngine.Networking
;
public
class
SensorDataManger
:
MonoBehaviour
{
// Start is called before the first frame update
public
GameObject
[]
model1
;
public
GameObject
[]
model2
;
public
GameObject
_prefab
;
public
GameObject
_parent1
;
public
GameObject
_parent2
;
public
Vector3
uiOffset
=
new
Vector3
(
0
,
2
,
3
);
// UI相对于模型的位置偏移
private
GameObject
uiInstance
;
public
string
lineId1
;
public
string
lineId2
;
void
Start
()
{
//foreach (GameObject item in model1)
//{
// Create3dUI(item,_parent1);
//}
//foreach (GameObject item in model2)
//{
// Create3dUI(item, _parent2);
//}
}
// Update is called once per frame
void
Update
()
{
}
void
Create3dUI
(
GameObject
tagert_obj
,
GameObject
_parent
)
{
if
(
tagert_obj
!=
null
&&
_prefab
!=
null
)
{
// 在模型上方生成UI
uiInstance
=
Instantiate
(
_prefab
,
tagert_obj
.
transform
.
position
+
uiOffset
,
Quaternion
.
identity
);
// 设置UI为世界空间
Canvas
canvas
=
uiInstance
.
GetComponent
<
Canvas
>();
if
(
canvas
!=
null
)
{
canvas
.
renderMode
=
RenderMode
.
WorldSpace
;
}
// 设置UI跟随模型移动
uiInstance
.
transform
.
SetParent
(
_parent
.
transform
);
uiInstance
.
transform
.
name
=
tagert_obj
.
name
;
uiInstance
.
transform
.
localScale
=
new
Vector3
(
0.01f
,
0.01f
,
0.01f
);
//uiInstance.transform.position = tagert_obj.transform.position;
//uiInstance.GetComponent<RectTransform>().position=new Vector3()
}
else
{
Debug
.
LogError
(
"目标模型或UI预制件未设置!"
);
}
}
public
IEnumerator
GetThreeModelSensorData1
()
{
string
jsonData
=
"{\"lineId\":\""
+
lineId1
+
"\"}"
;
string
post
=
""
;
while
(
true
)
{
using
(
UnityWebRequest
request
=
UnityWebRequest
.
PostWwwForm
(
post
,
jsonData
))
{
// 设置请求头
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
{
// 解析响应数据
string
responseJson
=
request
.
downloadHandler
.
text
;
}
}
yield
return
new
WaitForSeconds
(
1f
);
}
}
public
IEnumerator
GetThreeModelSensorData2
()
{
string
jsonData
=
"{\"lineId\":\""
+
lineId2
+
"\"}"
;
string
post
=
""
;
while
(
true
)
{
using
(
UnityWebRequest
request
=
UnityWebRequest
.
PostWwwForm
(
post
,
jsonData
))
{
// 设置请求头
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
{
// 解析响应数据
string
responseJson
=
request
.
downloadHandler
.
text
;
}
}
yield
return
new
WaitForSeconds
(
1f
);
}
}
}
Assets/Scripts/Components/UI/SensorDataManger.cs.meta
0 → 100644
View file @
8a423d39
fileFormatVersion: 2
guid: 05d56e7ba014d4848bc7a5d4f0ae7d38
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
Assets/_Scenes/1_Main.unity
View file @
8a423d39
This diff is collapsed.
Click to expand it.
Assets/_预设/UI/标签-传感器数据-0810.prefab
View file @
8a423d39
This diff is collapsed.
Click to expand it.
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