SceneControllerEditor.cs 1.73 KB
Newer Older
1
2
3
using UnityEngine;
using UnityEditor;
using System.Linq;
Sebastian Höffner's avatar
Sebastian Höffner committed
4
5
using SimpleJSON;
using System.IO;
6
7
8
9
10
11
12

namespace dlu
{

[CustomEditor(typeof(SceneController))]
public class SceneControllerEditor : Editor
{
13
14
    private bool showLabels = false;

15
16
17
    public override void OnInspectorGUI()
    {
        SceneController sc = (SceneController) target;
18
        JSONHandler.instance.RefreshSemanticLabels();
19

20
21
        EditorGUILayout.Space();
        base.DrawDefaultInspector();
22

Sebastian Höffner's avatar
Sebastian Höffner committed
23
        EditorGUILayout.Space();
24
        ExportContext(sc);
25
26

        EditorGUILayout.Space();
27
        ShowSemanticLabels(sc);
28

29
30
    }

31
    private void ShowSemanticLabels(SceneController sc)
32
33
34
35
    {
        showLabels = EditorGUILayout.BeginFoldoutHeaderGroup(showLabels, "Semantic labels");
        if (showLabels)
        {
36
            foreach (SemanticBehaviour sb in JSONHandler.instance.semanticBehaviours)
37
            {
38
                string label = sb.GetComponent<InstanceIdentifier>().name;
39
                // Fill dict
40
                if (sb.is_a.Count() > 0)
41
                {
42
                    label += $" a {sb.is_a.Split('#')[1]}";
43
                }
44
                EditorGUILayout.ObjectField(label, sb.gameObject, typeof(GameObject), true);
45
46
            }
        }
Sebastian Höffner's avatar
Sebastian Höffner committed
47
48
49
50
51
52

        EditorGUILayout.EndFoldoutHeaderGroup();
    }

    private void ExportContext(SceneController sc)
    {
53
        string exportFile = EditorGUILayout.TextField("Export Context File", "Assets/DLU/Resources/context.json");
54
        JSONNode sceneJson = JSONHandler.instance.GenerateContextJSON();
55
56
57
58
59
60
        if (GUILayout.Button("Export to file"))
        {
            File.WriteAllText(exportFile, sceneJson.ToString());
        }
        EditorGUILayout.TextArea(sceneJson == null ? "" : sceneJson.ToString());
    }
61
62
63
}

}