SceneControllerEditor.cs 1.82 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
        if (GUILayout.Button("Refresh list of semantic labels"))
19
        {
20
            JSONHandler.instance.RefreshSemanticLabels();
21
        }
22

23
24
        EditorGUILayout.Space();
        base.DrawDefaultInspector();
25

Sebastian Höffner's avatar
Sebastian Höffner committed
26
        EditorGUILayout.Space();
27
        ExportContext(sc);
28
29

        EditorGUILayout.Space();
30
        ShowSemanticLabels(sc);
31

32
33
    }

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

        EditorGUILayout.EndFoldoutHeaderGroup();
    }

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

}