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
c6f403c4
Commit
c6f403c4
authored
Aug 22, 2024
by
杨泽宇
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
更新
parent
a46a2a06
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
153 additions
and
63 deletions
+153
-63
LoginManager.cs
Assets/Scripts/Components/AGV/LoginManager.cs
+56
-24
CollisionRotation.cs
Assets/Scripts/Components/CollisionRotation.cs
+38
-39
URL 1.json
Assets/Scripts/Core/URL 1.json
+8
-0
URL 1.json.meta
Assets/Scripts/Core/URL 1.json.meta
+7
-0
URL.json
Assets/Scripts/Core/URL.json
+8
-0
URL.json.meta
Assets/Scripts/Core/URL.json.meta
+7
-0
1_Main.unity
Assets/_Scenes/1_Main.unity
+27
-0
2_Main.unity
Assets/_Scenes/2_Main.unity
+2
-0
No files found.
Assets/Scripts/Components/AGV/LoginManager.cs
View file @
c6f403c4
...
...
@@ -29,10 +29,13 @@ public class LoginManager : MonoBehaviour
public
float
angle
;
public
bool
IsLine1
;
public
string
filePath
;
// JSON 文件路径
private
InputFieldData
inputFieldData
;
private
void
Awake
()
{
OnReceiveMsg
.
AddListener
(
_getData
);
// 从TextAsset读取数据并反序列化
inputFieldData
=
LoadData
(
filePath
);
LoadInputFields
();
// 在 Awake 中加载输入字段
}
...
...
@@ -44,7 +47,7 @@ public class LoginManager : MonoBehaviour
public
void
StartLogin
()
{
Save
InputFields
();
Save
Data
();
StartCoroutine
(
GetPositionData
());
StartCoroutine
(
FaultInformation
());
}
...
...
@@ -155,49 +158,78 @@ public class LoginManager : MonoBehaviour
}
}
public
void
Save
InputFields
()
public
void
Save
Data
()
{
// 使用 PlayerPrefs 保存输入字段数据
if
(
IsLine1
)
if
(
inputFieldData
!=
null
)
{
PlayerPrefs
.
SetString
(
"productionlineID1"
,
productionlineID
.
text
);
PlayerPrefs
.
SetString
(
"lineID1"
,
lineID
.
text
);
// 更新 InputFieldData 的内容
if
(
IsLine1
)
{
inputFieldData
.
productionlineID1
=
productionlineID
.
text
;
inputFieldData
.
lineID1
=
lineID
.
text
;
Debug
.
Log
(
inputFieldData
.
productionlineID1
);
Debug
.
Log
(
inputFieldData
.
lineID1
);
}
else
{
inputFieldData
.
productionlineID2
=
productionlineID
.
text
;
inputFieldData
.
lineID2
=
lineID
.
text
;
}
inputFieldData
.
faultInterface
=
faultInterface
.
text
;
inputFieldData
.
post_url
=
post_url
.
text
;
// 将数据序列化为 JSON 字符串
string
json
=
JsonUtility
.
ToJson
(
inputFieldData
,
true
);
// 将 JSON 写入文件
File
.
WriteAllText
(
filePath
,
json
);
Debug
.
Log
(
"数据已保存到:"
+
filePath
);
}
else
{
PlayerPrefs
.
SetString
(
"productionlineID2"
,
productionlineID
.
text
);
PlayerPrefs
.
SetString
(
"lineID2"
,
lineID
.
text
);
Debug
.
LogWarning
(
"InputFieldData为空,无法保存"
);
}
PlayerPrefs
.
SetString
(
"faultInterface"
,
faultInterface
.
text
);
PlayerPrefs
.
SetString
(
"post_url"
,
post_url
.
text
);
PlayerPrefs
.
Save
();
// 确保数据被保存
Debug
.
Log
(
"Input fields saved to PlayerPrefs."
);
}
public
void
LoadInputFields
()
{
// 使用 PlayerPrefs 加载输入字段数据
if
(
PlayerPrefs
.
HasKey
(
"productionlineID1"
))
// 打印读取到的信息
if
(
inputFieldData
!=
null
)
{
// 显示数据
if
(
IsLine1
)
{
productionlineID
.
text
=
PlayerPrefs
.
GetString
(
"productionlineID1"
)
;
lineID
.
text
=
PlayerPrefs
.
GetString
(
"lineID1"
)
;
productionlineID
.
text
=
inputFieldData
.
productionlineID1
;
lineID
.
text
=
inputFieldData
.
lineID1
;
}
else
{
productionlineID
.
text
=
PlayerPrefs
.
GetString
(
"productionlineID2"
)
;
lineID
.
text
=
PlayerPrefs
.
GetString
(
"lineID2"
)
;
productionlineID
.
text
=
inputFieldData
.
productionlineID2
;
lineID
.
text
=
inputFieldData
.
lineID2
;
}
faultInterface
.
text
=
PlayerPrefs
.
GetString
(
"faultInterface"
);
post_url
.
text
=
PlayerPrefs
.
GetString
(
"post_url"
);
faultInterface
.
text
=
inputFieldData
.
faultInterface
;
post_url
.
text
=
inputFieldData
.
post_url
;
}
}
public
InputFieldData
LoadData
(
string
path
)
{
// 检查文件是否存在
if
(
File
.
Exists
(
path
))
{
// 读取 JSON 字符串
string
json
=
File
.
ReadAllText
(
path
);
Debug
.
Log
(
"Input fields loaded from PlayerPrefs."
);
// 反序列化 JSON 字符串为对象
InputFieldData
data
=
JsonUtility
.
FromJson
<
InputFieldData
>(
json
);
return
data
;
}
else
{
Debug
.
Log
(
"No saved input fields data found in PlayerPrefs."
);
Debug
.
LogWarning
(
"数据文件不存在:"
+
path
);
return
null
;
}
}
}
...
...
Assets/Scripts/Components/CollisionRotation.cs
View file @
c6f403c4
using
System.Collections
;
using
System.Collections.Generic
;
using
UnityEngine
;
using
Cinemachine
;
public
class
CollisionRotation
:
MonoBehaviour
{
public
bool
IsRobotInspection1
;
public
string
CollisionObjectName
;
public
GameObject
GazeAtTheObject
;
private
CinemachineVirtualCamera
virtualCamera
;
private
void
OnTriggerEnter
(
Collider
other
)
{
// 查找带有TouristModeController脚本的对象
TouristModeController
touristModeController
=
FindObjectOfType
<
TouristModeController
>();
// 检查是否找到该对象
if
(
touristModeController
!=
null
)
{
if
(
IsRobotInspection1
)
{
using
System.Collections
;
using
System.Collections.Generic
;
using
UnityEngine
;
using
Cinemachine
;
public
class
CollisionRotation
:
MonoBehaviour
{
public
bool
IsRobotInspection1
;
public
string
CollisionObjectName
;
public
GameObject
GazeAtTheObject
;
private
CinemachineVirtualCamera
virtualCamera
;
private
void
OnTriggerEnter
(
Collider
other
)
{
// 查找带有TouristModeController脚本的对象
TouristModeController
touristModeController
=
FindObjectOfType
<
TouristModeController
>();
// 检查是否找到该对象
if
(
touristModeController
!=
null
)
{
if
(
IsRobotInspection1
)
{
if
(
touristModeController
.
CameraInspection1
!=
null
)
{
virtualCamera
=
touristModeController
.
CameraInspection1
.
GetComponent
<
CinemachineVirtualCamera
>();
Debug
.
Log
(
"1"
);
}
}
else
{
}
}
else
{
if
(
touristModeController
.
CameraInspection2
!=
null
)
{
virtualCamera
=
touristModeController
.
CameraInspection2
.
GetComponent
<
CinemachineVirtualCamera
>();
}
}
}
if
(
other
.
name
==
CollisionObjectName
)
{
virtualCamera
.
LookAt
=
GazeAtTheObject
.
transform
;
}
}
}
}
}
}
if
(
other
.
name
==
CollisionObjectName
)
{
virtualCamera
.
LookAt
=
GazeAtTheObject
.
transform
;
}
}
}
Assets/Scripts/Core/URL 1.json
0 → 100644
View file @
c6f403c4
{
"productionlineID1"
:
"1"
,
"productionlineID2"
:
""
,
"faultInterface"
:
""
,
"lineID1"
:
"2"
,
"lineID2"
:
""
,
"post_url"
:
""
}
\ No newline at end of file
Assets/Scripts/Core/URL 1.json.meta
0 → 100644
View file @
c6f403c4
fileFormatVersion: 2
guid: d11e43e5ee75fe84a9d35ec5c179cdb1
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
Assets/Scripts/Core/URL.json
0 → 100644
View file @
c6f403c4
{
"productionlineID1"
:
""
,
"productionlineID2"
:
"4"
,
"faultInterface"
:
""
,
"lineID1"
:
""
,
"lineID2"
:
"0"
,
"post_url"
:
""
}
\ No newline at end of file
Assets/Scripts/Core/URL.json.meta
0 → 100644
View file @
c6f403c4
fileFormatVersion: 2
guid: 9b6dd56c6efb85946b59cbf2b80ff772
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
Assets/_Scenes/1_Main.unity
View file @
c6f403c4
...
...
@@ -23279,6 +23279,7 @@ MonoBehaviour:
data: []
angle: 0
IsLine1: 0
filePath: Assets\Scripts\Core\URL 1.json
--- !u!114 &346303892
MonoBehaviour:
m_ObjectHideFlags: 0
...
...
@@ -32435,6 +32436,7 @@ MonoBehaviour:
data: []
angle: 0
IsLine1: 1
filePath: Assets\Scripts\Core\URL.json
--- !u!114 &560685329
MonoBehaviour:
m_ObjectHideFlags: 0
...
...
@@ -41507,6 +41509,21 @@ PrefabInstance:
propertyPath: m_Enabled
value: 1
objectReference: {fileID: 0}
- target: {fileID: 2685396656507067807, guid: ed32f55596f4ce64e96fe9f95c481cc0,
type: 3}
propertyPath: m_text
value: "\u200B"
objectReference: {fileID: 0}
- target: {fileID: 2685396656658087369, guid: ed32f55596f4ce64e96fe9f95c481cc0,
type: 3}
propertyPath: m_text
value: "\u200B"
objectReference: {fileID: 0}
- target: {fileID: 2685396656687818813, guid: ed32f55596f4ce64e96fe9f95c481cc0,
type: 3}
propertyPath: m_text
value: "\u200B"
objectReference: {fileID: 0}
- target: {fileID: 2685396657144146276, guid: ed32f55596f4ce64e96fe9f95c481cc0,
type: 3}
propertyPath: m_Enabled
...
...
@@ -41547,6 +41564,11 @@ PrefabInstance:
propertyPath: m_IsActive
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2685396657664684365, guid: ed32f55596f4ce64e96fe9f95c481cc0,
type: 3}
propertyPath: m_text
value: "\u200B"
objectReference: {fileID: 0}
- target: {fileID: 2685396657690188027, guid: ed32f55596f4ce64e96fe9f95c481cc0,
type: 3}
propertyPath: m_Enabled
...
...
@@ -41632,6 +41654,11 @@ PrefabInstance:
propertyPath: m_Text
value:
objectReference: {fileID: 0}
- target: {fileID: 2685396658297151241, guid: ed32f55596f4ce64e96fe9f95c481cc0,
type: 3}
propertyPath: m_text
value: "\u200B"
objectReference: {fileID: 0}
- target: {fileID: 2685396658312707601, guid: ed32f55596f4ce64e96fe9f95c481cc0,
type: 3}
propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.data[0].m_Target
Assets/_Scenes/2_Main.unity
View file @
c6f403c4
...
...
@@ -21580,6 +21580,7 @@ MonoBehaviour:
data: []
angle: 0
IsLine1: 0
filePath:
--- !u!114 &346303892
MonoBehaviour:
m_ObjectHideFlags: 0
...
...
@@ -34161,6 +34162,7 @@ MonoBehaviour:
data: []
angle: 0
IsLine1: 1
filePath: Assets\Scripts\Core\URL.json
--- !u!114 &560685329
MonoBehaviour:
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