A game about forced loneliness, made by TACStudios
1using UnityEngine;
2using UnityEditor;
3using UnityEditor.Callbacks;
4using UnityEditor.UIElements;
5using UnityEngine.UIElements;
6
7namespace Unity.Multiplayer.Center.Questionnaire
8{
9 /// <summary>
10 /// Because of the "questionnaire" extension, the default inspector is not shown.
11 /// Double clicking on the asset will open this custom inspector (in debug mode), which has a way to force saving
12 /// the asset.
13 /// </summary>
14 [CustomEditor(typeof(QuestionnaireObject))]
15 internal class QuestionnaireEditor : Editor
16 {
17 public override VisualElement CreateInspectorGUI()
18 {
19 var so = new SerializedObject(target);
20 var root = new VisualElement();
21 var questionnaire = (QuestionnaireObject) target;
22 root.Add(new Button(() => questionnaire.ForceReload() ){text = "Load Changes From Disk", tooltip = "Use when editing with external editor."});
23 root.Add(new Button(() => questionnaire.ForceSave() ){text = "Save local changes", tooltip = "Use when editing in inspector."});
24 var inspector = new PropertyField(so.FindProperty("Questionnaire"));
25 root.Add(inspector);
26 return root;
27 }
28
29 [OnOpenAsset(1)]
30 public static bool OpenMyCustomAsset(int instanceID, int line)
31 {
32 if (!EditorPrefs.GetBool("DeveloperMode")) return false;
33 var asset = EditorUtility.InstanceIDToObject(instanceID);
34 var path = AssetDatabase.GetAssetPath(asset);
35 if(string.IsNullOrEmpty(path) || !path.EndsWith("questionnaire"))
36 return false;
37
38 Selection.activeObject = QuestionnaireObject.instance;
39 return true;
40 }
41 }
42}