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
123 lines (107 loc) · 5.03 KB
/
Copy pathTouchManagerEditor.cs
File metadata and controls
123 lines (107 loc) · 5.03 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*
* @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.";
public const string TEXT_USESENDMESSAGE = "If you use UnityScript or prefer using Unity Messages you can turn them on with this option.";
public const string TEXT_SENDMESSAGETARGET = "The GameObject target of Unity Messages. If null, host GameObject is used.";
public const string TEXT_SENDMESSAGEEVENTS = "Which events should be sent as Unity Messages.";
private GUIStyle layerButtonStyle;
private TouchManager instance;
private SerializedProperty layers;
private bool showLayers;
private void OnEnable()
{
instance = target as TouchManager;
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();
EditorGUI.BeginChangeCheck();
var newLiveDPI = EditorGUILayout.IntField(new GUIContent("Live DPI", TEXT_LIVEDPI), (int)instance.LiveDPI);
var newEditorDPI = EditorGUILayout.IntField(new GUIContent("Editor DPI", TEXT_EDITORDPI), (int)instance.EditorDPI);
if (EditorGUI.EndChangeCheck())
{
instance.LiveDPI = newLiveDPI;
instance.EditorDPI = newEditorDPI;
}
EditorGUIUtility.labelWidth = 160;
EditorGUI.BeginChangeCheck();
var useSendMessage = GUILayout.Toggle(instance.UseSendMessage, new GUIContent("Use SendMessage", TEXT_USESENDMESSAGE));
var sTarget = instance.SendMessageTarget;
var sMask = instance.SendMessageEvents;
if (useSendMessage)
{
sTarget = EditorGUILayout.ObjectField(new GUIContent("SendMessage Target", TEXT_SENDMESSAGETARGET), sTarget, typeof(GameObject), true) as GameObject;
sMask = (TouchManager.MessageTypes)EditorGUILayout.EnumMaskField(new GUIContent("SendMessage Events", TEXT_SENDMESSAGEEVENTS), instance.SendMessageEvents);
}
if (EditorGUI.EndChangeCheck())
{
instance.UseSendMessage = useSendMessage;
instance.SendMessageTarget = sTarget;
instance.SendMessageEvents = sMask;
EditorUtility.SetDirty(instance);
}
if (Application.isPlaying) GUI.enabled = false;
showLayers = GUIElements.BeginFoldout(showLayers, new GUIContent(String.Format("Layers ({0})", layers.arraySize)));
if (showLayers)
{
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();
}
GUIElements.EndFoldout();
GUI.enabled = true;
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++;
}
}
}
}