91 lines
2.3 KiB
C#
91 lines
2.3 KiB
C#
using LitJson;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Text.RegularExpressions;
|
|
using UnityEditor;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public struct TranData
|
|
{
|
|
public string Name;
|
|
public string Position;
|
|
public string EulerAngles;
|
|
public string ErrorContent;
|
|
}
|
|
|
|
public class ModelNameInfoRoot
|
|
{
|
|
public Dictionary<string, List<TranData>> ModelInfos = new Dictionary<string, List<TranData>>();
|
|
}
|
|
|
|
public class AddDataToJson : MonoBehaviour
|
|
{
|
|
public InputField first;
|
|
public InputField second;
|
|
public InputField third;
|
|
|
|
public InputField content;
|
|
|
|
public Button clickAdd;
|
|
public Button save;
|
|
|
|
public Transform human;
|
|
|
|
ModelNameInfoRoot info = new ModelNameInfoRoot();
|
|
List<TranData> tempList = new List<TranData>();
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
//clickAdd.onClick.AddListener(AddData);
|
|
//save.onClick.AddListener(SaveDataToJson);
|
|
gameObject.GetComponent<HighLight_VR>().SetHight(human);
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
|
|
}
|
|
|
|
private void AddData()
|
|
{
|
|
|
|
}
|
|
|
|
private void SaveDataToJson()
|
|
{
|
|
TranData data = new TranData();
|
|
//info.ModelName = item.transform.name;
|
|
//info.ABName = item.transform.name;
|
|
tempList.Add(data);
|
|
info.ModelInfos.Add(first.text,tempList);
|
|
|
|
|
|
var vbasePath = Path.Combine(Application.streamingAssetsPath, "ObjData");
|
|
DirectoryInfo dir = new DirectoryInfo(vbasePath);
|
|
if (!dir.Exists)
|
|
dir.Create();
|
|
var vconfigPath = Path.Combine(vbasePath, "ModelInfo.json");
|
|
FileInfo fileInfo = new FileInfo(vconfigPath);
|
|
if (fileInfo.Exists)
|
|
fileInfo.Delete();
|
|
StreamWriter writer = fileInfo.CreateText();
|
|
string jsonStr = ParseJsonData(JsonMapper.ToJson(info));
|
|
writer.Write(jsonStr);
|
|
writer.Flush();
|
|
writer.Dispose();
|
|
writer.Close();
|
|
//AssetDatabase.Refresh();
|
|
}
|
|
|
|
private string ParseJsonData(string json)
|
|
{
|
|
Regex reg = new Regex(@"(?i)\\[uU]([0-9a-f]{4})");
|
|
string targetJson = reg.Replace(json, delegate (Match m) { return ((char)Convert.ToInt32(m.Groups[1].Value, 16)).ToString(); });
|
|
return targetJson;
|
|
}
|
|
}
|