102 lines
2.0 KiB
C#
102 lines
2.0 KiB
C#
|
||
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");
|
||
}
|
||
|
||
|
||
|
||
}
|