Question by
William_Goodspeed · Jan 11, 2016 at 06:14 PM ·
c#editorinspectoreditor-scriptingjson
Loading Json from Resources via Editor Script
Hey folks,
So I'm taking my first real look at Editor Scripts and I'm having a bit of difficulty loading and reading a Json file in the way I want to. I find it quite hard without the ability to Debug, which I'm presuming you can't do in an Editor Script?
So what I'm trying to do is Load a Json file and then compile a drop down menu in the inspector which will be populated by the entries from a particular field in the Json.
This is where I'm at:
using UnityEngine;
using UnityEditor;
using System;
using System.Collections;
using System.Text;
using System.Collections.Generic;
using JsonFx.Json;
public class TileEditor : EditorWindow
{
public string[] Name;
[MenuItem("Tools/Tile Editor")]
static void Init()
{
EditorWindow window = GetWindow(typeof(TileEditor));
window.Show();
}
public void OnGUI()
{
Name = EditorGUILayout.TextField("The Name is", Name);
if (GUILayout.Button("Load Tile"))
{
DisplayAvailableTiles();
}
}
void DisplayAvailableTiles()
{
string filePath = "Data/graph/Tiles.json";
TextAsset targetFile = Resources.Load<TextAsset>(filePath);
foreach (var item in targetFile)
{
Name.Add(item.Name);
}
}
}
Comment
Answer by nancyrai37 · Feb 20, 2018 at 04:06 PM
Hello,
I have SSIS JSON package which is really helpful and easy to use. All the things are discussed properly. Feel free to visit Hope it will help... :-)