Browse Source

实施了一个简单读取一层Json的例子

master
DESKTOP-B25GA9E\W35 2 years ago
parent
commit
9b996a6828
  1. 29
      Assets/DataGenerateTools/src/JsonGenerate/GenerateToolsEditor.cs
  2. 11
      Assets/DataGenerateTools/src/JsonGenerate/GenerateToolsEditor.cs.meta
  3. 18
      Assets/DataGenerateTools/src/JsonGenerate/JsonFileLoaderEditor.cs

29
Assets/DataGenerateTools/src/JsonGenerate/GenerateToolsEditor.cs

@ -0,0 +1,29 @@ @@ -0,0 +1,29 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
namespace JXSoft {
public class GenerateToolsEditor : EditorWindow
{
public TextAsset JsonFile;
[MenuItem("JXSoft/Generate/JsonStruct")]
static void Init()
{
var window = GetWindow<JsonFileLoaderEditor>();
window.Show();
}
void OnGUI()
{
JsonFile = (TextAsset)EditorGUILayout.ObjectField("JsonFile", JsonFile, typeof(TextAsset), true);
if (GUILayout.Button("AnalyzeJsonFile"))
{
}
}
}
}

11
Assets/DataGenerateTools/src/JsonGenerate/GenerateToolsEditor.cs.meta

@ -0,0 +1,11 @@ @@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 333d97406b2769141b1fb4d484e2d422
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

18
Assets/DataGenerateTools/src/JsonGenerate/JsonFileLoaderEditor.cs

@ -11,11 +11,9 @@ namespace JXSoft { @@ -11,11 +11,9 @@ namespace JXSoft {
{
public TextAsset JsonFile;
AnimBool m_ShowExtraFields;
string m_String;
Color m_Color = Color.white;
int m_Number = 0;
public Dictionary<string, string> keyValuePairs;
[MenuItem("JXSoft/Generate/JsonFileLoader")]
[MenuItem("JXSoft/Loader/JsonFileLoader")]
static void Init()
{
var window = GetWindow<JsonFileLoaderEditor>();
@ -32,7 +30,17 @@ namespace JXSoft { @@ -32,7 +30,17 @@ namespace JXSoft {
JsonFile = (TextAsset)EditorGUILayout.ObjectField("JsonFile", JsonFile, typeof(TextAsset), true);
if (GUILayout.Button("AnalyzeJsonFile"))
{
if (JsonFile != null)
{
JsonData jsonData = JsonMapper.ToObject(JsonFile.text);
foreach (string key in jsonData.Keys)
{
Debug.Log(jsonData[key].GetJsonType());
for (int i = 0; i < jsonData[key].Count; i++) {
Debug.Log(jsonData[key][i].GetJsonType());
}
}
}
}
}
}

Loading…
Cancel
Save