Files
ZHGD_Web/Assets/Editor/CustomUtils.cs

92 lines
3.4 KiB
C#
Raw Permalink Normal View History

2025-07-13 23:16:20 +08:00
using LitJson;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using UnityEditor;
using UnityEngine;
using UnityEngine.SceneManagement;
public class CustomUtils : Editor
{
[MenuItem("Custom/<2F><><EFBFBD><EFBFBD><E6B3A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ѹ<EFBFBD>ֵ<EFBFBD>Ĺ<EFBFBD><C4B9><EFBFBD>ģ<EFBFBD><C4A3>")]
public static void SaveWorkShipInfo()
{
//<2F><><EFBFBD>ұ<EFBFBD><D2B1><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC>еĹ<D0B5><C4B9><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD>
List<WorkShip> workShips = new List<WorkShip>();
JsonData data = JsonMapper.ToObject(File.ReadAllText(Application.streamingAssetsPath + "/Processing/WorkShipInfo.json"));
foreach (JsonData item in data)
{
WorkShip workShip = new WorkShip();
workShip.SceneName = item["SceneName"].ToString();
workShip.MeshInfos = new List<Meshinfo>();
foreach (JsonData meshInfos in item["MeshInfos"])
{
Meshinfo meshinfo = new Meshinfo();
meshinfo.type = int.Parse(meshInfos["type"].ToString());
meshinfo.key = meshInfos["key"].ToString();
meshinfo.meshName = meshInfos["meshName"].ToString();
meshinfo.content = meshInfos["content"].ToString();
workShip.MeshInfos.Add(meshinfo);
}
workShips.Add(workShip);
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>еĹ<D0B5><C4B9><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD>
string sceneName = SceneManager.GetActiveScene().name;
WorkShip nowWorkShip = new WorkShip();
nowWorkShip.SceneName = sceneName;
nowWorkShip.MeshInfos = new List<Meshinfo>();
List<WorkShipBind> workShipBinds = FindObjectsOfType<WorkShipBind>().ToList();
foreach (WorkShipBind meshInfo in workShipBinds)
{
Meshinfo meshinfo = new Meshinfo();
meshinfo.type = meshInfo.type;
if(string.IsNullOrEmpty(meshInfo.key))
{
meshInfo.key = meshInfo.gameObject.GetInstanceID() + "";
}
meshinfo.key = meshInfo.key;
if (string.IsNullOrEmpty(meshInfo.meshName))
{
meshInfo.meshName = meshInfo.gameObject.name;
}
meshinfo.meshName = meshInfo.meshName;
meshinfo.content = meshInfo.content;
nowWorkShip.MeshInfos.Add(meshinfo);
}
//ƥ<><C6A5><EFBFBD>Գ<EFBFBD><D4B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD><C2B5><EFBFBD><E6BBBB><EFBFBD>ɵ<EFBFBD>
WorkShip nowSceneWorkShip = workShips.Find(x => x.SceneName == sceneName);
if(nowSceneWorkShip == null)
{
//û<>е<EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
workShips.Add(nowWorkShip);
}
else
{
//<2F>е<EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD>ľ͸<C4BE><CDB8><EFBFBD>
foreach (Meshinfo item in nowWorkShip.MeshInfos)
{
Meshinfo localMeshinfo = nowSceneWorkShip.MeshInfos.Find(x=>x.key == item.key);
if(localMeshinfo == null)
{
//Ϊ<>վ<EFBFBD>ֱ<EFBFBD>Ӽӽ<D3BC>ȥ
nowSceneWorkShip.MeshInfos.Add(item);
}
else
{
//<2F><>Ϊ<EFBFBD>վ͸<D5BE><CDB8><EFBFBD><EFBFBD><EFBFBD>Ϣ
localMeshinfo.type = item.type;
localMeshinfo.key = item.key;
localMeshinfo.meshName = item.meshName;
localMeshinfo.content = item.content;
}
}
}
string workShipInfos = Regex.Unescape(JsonMapper.ToJson(workShips));
File.WriteAllText(Application.streamingAssetsPath + "/Processing/WorkShipInfo.json", workShipInfos);
Debug.Log("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɣ<EFBFBD><C9A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
}
}