forked from TouchScript/TouchScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTouchManagerEditor.cs
More file actions
95 lines (81 loc) · 3.53 KB
/
TouchManagerEditor.cs
File metadata and controls
95 lines (81 loc) · 3.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
* @author Valentin Simonov / http://va.lent.in/
*/
using System;
using TouchScript.Editor.Utils;
using TouchScript.Layers;
using UnityEditor;
using UnityEngine;
using Object = UnityEngine.Object;
namespace TouchScript.Editor
{
[CustomEditor(typeof(TouchManager))]
public class TouchManagerEditor : UnityEditor.Editor
{
public const string TEXT_LIVEDPI = "DPI used in built app runing on target device.";
public const string TEXT_EDITORDPI = "DPI used in the editor.";
public const string TEXT_MOVEDOWN = "Move down.";
private SerializedProperty editorDPI;
private GUIStyle layerButtonStyle;
private SerializedProperty layers;
private SerializedProperty liveDPI;
private bool showLayers;
private void OnEnable()
{
liveDPI = serializedObject.FindProperty("liveDpi");
editorDPI = serializedObject.FindProperty("editorDpi");
layers = serializedObject.FindProperty("layers");
}
public override void OnInspectorGUI()
{
if (layerButtonStyle == null)
{
layerButtonStyle = new GUIStyle(EditorStyles.miniButton);
layerButtonStyle.fontSize = 9;
layerButtonStyle.contentOffset = new Vector2(0, 0);
}
serializedObject.Update();
GUI.changed = false;
EditorGUILayout.PropertyField(liveDPI, new GUIContent("Live DPI", TEXT_LIVEDPI));
EditorGUILayout.PropertyField(editorDPI, new GUIContent("Editor DPI", TEXT_EDITORDPI));
showLayers = GUIElements.Foldout(showLayers, new GUIContent(String.Format("Layers ({0})", layers.arraySize)),
() =>
{
EditorGUILayout.BeginVertical();
for (int i = 0; i < layers.arraySize; i++)
{
var layer = layers.GetArrayElementAtIndex(i).objectReferenceValue as TouchLayer;
string name;
if (layer == null) name = "Unknown";
else name = layer.Name;
var rect = EditorGUILayout.BeginHorizontal(GUIElements.BoxStyle, GUILayout.Height(23));
EditorGUILayout.LabelField(name, GUIElements.BoxLabelStyle, GUILayout.ExpandWidth(true));
if (GUILayout.Button(new GUIContent("v", TEXT_MOVEDOWN), layerButtonStyle, GUILayout.Width(20), GUILayout.Height(18)))
{
layers.MoveArrayElement(i, i + 1);
} else if (Event.current.type == EventType.MouseDown && rect.Contains(Event.current.mousePosition))
{
EditorGUIUtility.PingObject(layer);
}
EditorGUILayout.EndHorizontal();
}
EditorGUILayout.EndVertical();
GUILayout.Space(5f);
if (GUILayout.Button("Refresh", GUILayout.MaxWidth(100))) refresh();
});
serializedObject.ApplyModifiedProperties();
}
private void refresh()
{
layers.ClearArray();
Object[] allLayers = FindObjectsOfType(typeof(TouchLayer));
int i = 0;
layers.arraySize = allLayers.Length;
foreach (TouchLayer l in allLayers)
{
layers.GetArrayElementAtIndex(i).objectReferenceValue = l;
i++;
}
}
}
}