using UnityEngine; using UnityEditor; using System.Linq; using SimpleJSON; using System.IO; namespace dlu { [CustomEditor(typeof(SceneController))] public class SceneControllerEditor : Editor { private bool showLabels = false; public override void OnInspectorGUI() { SceneController sc = (SceneController) target; JSONHandler.instance.RefreshSemanticLabels(); EditorGUILayout.Space(); base.DrawDefaultInspector(); EditorGUILayout.Space(); ExportContext(sc); EditorGUILayout.Space(); ShowSemanticLabels(sc); } private void ShowSemanticLabels(SceneController sc) { showLabels = EditorGUILayout.BeginFoldoutHeaderGroup(showLabels, "Semantic labels"); if (showLabels) { foreach (SemanticBehaviour sb in JSONHandler.instance.semanticBehaviours) { string label = sb.GetComponent().name; // Fill dict if (sb.is_a.Count() > 0) { label += $" a {sb.is_a.Split('#')[1]}"; } EditorGUILayout.ObjectField(label, sb.gameObject, typeof(GameObject), true); } } EditorGUILayout.EndFoldoutHeaderGroup(); } private void ExportContext(SceneController sc) { string exportFile = EditorGUILayout.TextField("Export Context File", "Assets/DLU/Resources/context.json"); JSONNode sceneJson = JSONHandler.instance.GenerateContextJSON(); if (GUILayout.Button("Export to file")) { File.WriteAllText(exportFile, sceneJson.ToString()); } EditorGUILayout.TextArea(sceneJson == null ? "" : sceneJson.ToString()); } } }