82 lines
2.1 KiB
C#
82 lines
2.1 KiB
C#
|
||
using Newtonsoft.Json;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
/// <summary>
|
||
/// 端口线条信息
|
||
/// </summary>
|
||
[Serializable]
|
||
public class LineInfor : MonoBehaviour
|
||
{
|
||
InputField t;
|
||
[HideInInspector] public Root root;
|
||
|
||
public List<Transform> lines = new List<Transform>();
|
||
public string cableGroupName = "";
|
||
public string cableName = "";
|
||
|
||
private void Awake()
|
||
{
|
||
|
||
//if (PlayerPrefs.HasKey(this.root.myID))
|
||
//{
|
||
// string json = PlayerPrefs.GetString(root.myID);
|
||
// Root myObject = JsonUtility.FromJson<Root>(json);
|
||
// // 使用加载的字段值
|
||
// this.root.otherID = myObject.otherID;
|
||
//}
|
||
}
|
||
private void Update()
|
||
{
|
||
//if (!string.IsNullOrEmpty(root.otherID)) return;
|
||
//root.otherID = t.text;
|
||
//if (string.IsNullOrEmpty(root.otherID)) return;
|
||
//root.otherID = t.text;
|
||
//string json = JsonConvert.SerializeObject(root);
|
||
//PlayerPrefs.SetString(root.myID, json);
|
||
//PlayerPrefs.Save();
|
||
}
|
||
|
||
[ContextMenu("查看PlayerPrefs")]
|
||
void PrintAllPlayerPrefs()
|
||
{
|
||
// 获取PlayerPrefs中所有的键
|
||
string[] keys = GetAllPlayerPrefsKeys();
|
||
|
||
// 遍历所有的键,并打印对应的值
|
||
foreach (string key in keys)
|
||
{
|
||
string value = PlayerPrefs.GetString(key); // 或者使用对应的类型的Get方法,如GetInt(key), GetFloat(key)等
|
||
Debug.Log("Key: " + key + ", Value: " + value);
|
||
}
|
||
}
|
||
// 获取PlayerPrefs中所有的键
|
||
private string[] GetAllPlayerPrefsKeys()
|
||
{
|
||
int count = PlayerPrefs.GetInt("PlayerPrefsCount");
|
||
string[] keys = new string[count];
|
||
|
||
for (int i = 0; i < count; i++)
|
||
{
|
||
keys[i] = PlayerPrefs.GetString("PlayerPrefsKey" + i.ToString());
|
||
}
|
||
|
||
return keys;
|
||
}
|
||
|
||
|
||
#region JSON
|
||
[System.Serializable]
|
||
public class Root
|
||
{
|
||
[Header("自己ID")] public string myID;
|
||
|
||
[Header("对方ID")] public string otherID;
|
||
|
||
[Header("线条UID")] public string lineUID;
|
||
}
|
||
#endregion
|
||
}
|