using UnityEngine; using UnityEditor; using System.Linq; using SimpleJSON; using System.IO; namespace dlu { [CustomEditor(typeof(SceneController))] public class SceneControllerEditor : Editor { private bool showLabels; private bool exportContext; private JSONArray sceneJson; public override void OnInspectorGUI() { SceneController sc = (SceneController) target; base.DrawDefaultInspector(); EditorGUILayout.Space(); this.ExportContext(sc); EditorGUILayout.Space(); this.ShowSemanticLabels(sc); } private void ShowSemanticLabels(SceneController sc) { showLabels = EditorGUILayout.BeginFoldoutHeaderGroup(showLabels, "Semantic labels"); if (showLabels) { if (sc.semanticBehaviours == null || GUILayout.Button("Refresh list of semantic labels")) { sc.FindSemanticLabels(); } foreach (SemanticBehaviour sb in sc.semanticBehaviours) { string label = sb.GetComponent().name; 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) { exportContext = EditorGUILayout.BeginFoldoutHeaderGroup(exportContext, "Export context"); if (exportContext) { if (sceneJson == null || GUILayout.Button("Refresh scene JSON")) { sceneJson = sc.GenerateContextJSON(); } EditorGUILayout.TextArea(sceneJson.ToString()); string exportFile = EditorGUILayout.TextField("Export file", "Assets/DLU/Resources/context.json"); if (GUILayout.Button("Export to file")) { File.WriteAllText(exportFile, sceneJson.ToString()); } } EditorGUILayout.EndFoldoutHeaderGroup(); } } }