Commit c6f403c4 authored by 杨泽宇's avatar 杨泽宇

更新

parent a46a2a06
......@@ -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()
{
SaveInputFields();
SaveData();
StartCoroutine(GetPositionData());
StartCoroutine(FaultInformation());
}
......@@ -155,49 +158,78 @@ public class LoginManager : MonoBehaviour
}
}
public void SaveInputFields()
public void SaveData()
{
// 使用 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;
}
}
}
......
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;
}
}
}
{
"productionlineID1": "1",
"productionlineID2": "",
"faultInterface": "",
"lineID1": "2",
"lineID2": "",
"post_url": ""
}
\ No newline at end of file
fileFormatVersion: 2
guid: d11e43e5ee75fe84a9d35ec5c179cdb1
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
{
"productionlineID1": "",
"productionlineID2": "4",
"faultInterface": "",
"lineID1": "",
"lineID2": "0",
"post_url": ""
}
\ No newline at end of file
fileFormatVersion: 2
guid: 9b6dd56c6efb85946b59cbf2b80ff772
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
......@@ -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
......@@ -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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment