Exemplo n.º 1
0
        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();
        }
Exemplo n.º 2
0
        public override void OnInspectorGUI()
        {
            shouldRecognizeShown =
                GUIElements.Foldout(shouldRecognizeShown, new GUIContent("Friendly gestures", TEXT_FRIENDLY_HEADER),
                                    () =>
            {
                int gestureIndexToRemove = -1;
                int gesturesDrawn        = 0;

                serializedObject.UpdateIfDirtyOrScript();

                GUILayout.BeginVertical();
                for (int i = 0; i < serializedGestures.arraySize; i++)
                {
                    var gesture = serializedGestures.GetArrayElementAtIndex(i).objectReferenceValue as Gesture;

                    if (gesture == null)
                    {
                        //Debug.Log(string.Format("Gesture at {0} on {1} is null!!", i, target));
                        gestureIndexToRemove = i;
                    }
                    else
                    {
                        Rect rect = EditorGUILayout.BeginHorizontal(GUIElements.BoxStyle, GUILayout.Height(23));
                        EditorGUILayout.LabelField(
                            string.Format("{0} @ {1}", gesture.GetType().Name, gesture.name),
                            GUIElements.BoxLabelStyle, GUILayout.ExpandWidth(true));
                        if (GUILayout.Button("remove", GUILayout.Width(60), GUILayout.Height(16)))
                        {
                            gestureIndexToRemove = i;
                        }
                        else if (Event.current.type == EventType.MouseDown &&
                                 rect.Contains(Event.current.mousePosition))
                        {
                            EditorGUIUtility.PingObject(gesture);
                        }
                        EditorGUILayout.EndHorizontal();
                        gesturesDrawn++;
                    }
                }
                GUILayout.EndVertical();
                if (gesturesDrawn > 0)
                {
                    GUILayout.Space(9);
                }

                Rect dropArea = GUILayoutUtility.GetRect(0.0f, 50.0f, GUIElements.BoxStyle,
                                                         GUILayout.ExpandWidth(true));
                GUI.Box(dropArea, "Drag a Gesture Here", GUIElements.BoxStyle);
                switch (Event.current.type)
                {
                case EventType.DragUpdated:
                    if (dropArea.Contains(Event.current.mousePosition))
                    {
                        DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                    }
                    break;

                case EventType.DragPerform:
                    if (dropArea.Contains(Event.current.mousePosition))
                    {
                        DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                        DragAndDrop.AcceptDrag();

                        foreach (Object obj in DragAndDrop.objectReferences)
                        {
                            if (obj is GameObject)
                            {
                                var go             = obj as GameObject;
                                Gesture[] gestures = go.GetComponents <Gesture>();
                                foreach (Gesture gesture in gestures)
                                {
                                    addGesture(gesture);
                                }
                            }
                            else if (obj is Gesture)
                            {
                                addGesture(obj as Gesture);
                            }
                        }

                        Event.current.Use();
                    }
                    break;
                }

                if (gestureIndexToRemove > -1)
                {
                    removeGestureAt(gestureIndexToRemove);
                }
            });

            serializedObject.ApplyModifiedProperties();
        }