SceneControllerEditor.cs 1.97 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
13

namespace dlu
{

[CustomEditor(typeof(SceneController))]
public class SceneControllerEditor : Editor
{
    private bool showLabels;
Sebastian Höffner's avatar
Sebastian Höffner committed
14
    private bool exportContext;
15
16
17
18
19
20

    public override void OnInspectorGUI()
    {
        SceneController sc = (SceneController) target;
        base.DrawDefaultInspector();

Sebastian Höffner's avatar
Sebastian Höffner committed
21
22
        EditorGUILayout.Space();
        this.ExportContext(sc);
23
24

        EditorGUILayout.Space();
25
        this.ShowSemanticLabels(sc);
26
27
    }

28
    private void ShowSemanticLabels(SceneController sc)
29
30
31
32
33
    {
        showLabels = EditorGUILayout.BeginFoldoutHeaderGroup(showLabels, "Semantic labels");

        if (showLabels)
        {
34
            if (sc.semanticBehaviours == null || GUILayout.Button("Refresh list of semantic labels"))
35
            {
36
                sc.FindSemanticLabels();
37
38
            }

39
            foreach (SemanticBehaviour sb in sc.semanticBehaviours)
40
            {
41
42
                string label = sb.GetComponent<InstanceIdentifier>().name;
                if (sb.is_a.Count() > 0)
43
                {
44
                    label += $" a {sb.is_a.Split('#')[1]}";
45
                }
46
                EditorGUILayout.ObjectField(label, sb.gameObject, typeof(GameObject), true);
47
48
            }
        }
Sebastian Höffner's avatar
Sebastian Höffner committed
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69

        EditorGUILayout.EndFoldoutHeaderGroup();
    }

    private void ExportContext(SceneController sc)
    {
        exportContext = EditorGUILayout.BeginFoldoutHeaderGroup(exportContext, "Export context");

        if (exportContext)
        {
            JSONArray 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();
70
71
72
73
    }
}

}