Tz2/Assets/New/Scripts/NewLogic.cs

102 lines
2.0 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Collections.Generic;
using System.IO;
using System.Text.RegularExpressions;
using TMPro;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class NewLogic : MonoBehaviour
{
public Button particalBtn;
public Button examBtn;
// 你要操作的info.ini文件路径
private string filePath;
// 初始的info.ini文件内容
private string fileContent;
public List<Toggle> partTogs = new List<Toggle>();
public TextMeshProUGUI pingfen;
// Start is called before the first frame update
void Start()
{
// 获取info.ini文件的路径
filePath = Path.Combine(Application.streamingAssetsPath, "info.ini");
// 读取文件内容
if (File.Exists(filePath))
{
fileContent = File.ReadAllText(filePath);
}
else
{
Debug.LogError("info.ini 文件不存在!");
return;
}
// 设置按钮的点击事件
particalBtn.onClick.AddListener(() => ChangeMode("0"));
examBtn.onClick.AddListener(() => ChangeMode("3"));
}
/// <summary>
/// 通过更改配置文件的方式更改启动模式
/// </summary>
/// <param name="newMode"></param>
// 修改模式并保存文件
void ChangeMode(string newMode)
{
// 分割原始文件内容字符串
string[] parts = fileContent.Split(',');
// 更新模式字段假设mode位于第五个位置
parts[4] = newMode;
// 重新构建更新后的内容
fileContent = string.Join(",", parts);
// 保存修改后的文件
File.WriteAllText(filePath, fileContent);
// 输出修改后的内容
Debug.Log("Updated file content: " + fileContent);
}
/// <summary>
/// 练习模式按钮
/// </summary>
public void OnParticalBtnClick()
{
}
/// <summary>
/// 考核模式按钮
/// </summary>
public void OnExamBtnClick()
{
}
/// <summary>
/// 结构认知
/// </summary>
public void ToPartScene()
{
SceneManager.LoadScene("ModelShow");
}
}