Use() public method

Use this event.

public Use ( ) : void
return void
Ejemplo n.º 1
0
 void DrawList(Rect rect){
     UnityEngine.Event evt = UnityEngine.Event.current;
     int i = -1;
     foreach (var element in m_Data.m_ListElements) {
         i++;
         Rect label_rect = new Rect(rect.x, rect.y + k_Margin + i * k_LineHeight, rect.width, k_LineHeight);
         switch (evt.type){
             case EventType.Repaint:{
                 bool isHover = i == m_SelectedCompletionIndex;
                 menuItem.Draw(label_rect, element.m_Content, isHover, element.selected, element.selected, false);                            
             }
             break;
             case EventType.MouseDown:{
                 if (evt.button == 0) {
                     if (label_rect.Contains(evt.mousePosition)) {
                         if (m_Data.m_OnSelectCallback != null) m_Data.m_OnSelectCallback(element);
                         evt.Use();
                         editorWindow.Close();
                     }
                 }
             }
             break;
             case EventType.MouseMove:{
                 if (label_rect.Contains(evt.mousePosition)){
                     m_SelectedCompletionIndex = i;
                     evt.Use();
                 }
             }
             break;
         }
     }
 }
Ejemplo n.º 2
0
 private static void TextSharedEnd(bool changed, TextEditor te, UnityEngine.Event @event)
 {
     if (GetKeyboardControl())
     {
         LateLoaded.textFieldInput = true;
     }
     if (changed || (@event.type == EventType.Used))
     {
         if (lastInput != null)
         {
             textInputContent.text = te.content.text;
         }
         if (changed)
         {
             GUI.changed = true;
             lastInput.CheckChanges(textInputContent.text);
             lastInput.CheckPositioning(te.pos, te.selectPos);
             @event.Use();
         }
         else
         {
             lastInput.CheckPositioning(te.pos, te.selectPos);
         }
     }
     if (submit)
     {
         submit = false;
         if (lastInput.SendSubmitMessage())
         {
             @event.Use();
         }
     }
 }
Ejemplo n.º 3
0
 // Token: 0x06004EA7 RID: 20135 RVA: 0x001458C0 File Offset: 0x00143AC0
 private static void TextSharedEnd(bool changed, TextEditor te, UnityEngine.Event @event)
 {
     if (global::UIUnityEvents.GetKeyboardControl())
     {
         global::UIUnityEvents.LateLoaded.textFieldInput = true;
     }
     if (changed || @event.type == 12)
     {
         if (global::UIUnityEvents.lastInput)
         {
             global::UIUnityEvents.textInputContent.text = te.content.text;
         }
         if (changed)
         {
             GUI.changed = true;
             global::UIUnityEvents.lastInput.CheckChanges(global::UIUnityEvents.textInputContent.text);
             global::UIUnityEvents.lastInput.CheckPositioning(te.pos, te.selectPos);
             @event.Use();
         }
         else
         {
             global::UIUnityEvents.lastInput.CheckPositioning(te.pos, te.selectPos);
         }
     }
     if (global::UIUnityEvents.submit)
     {
         global::UIUnityEvents.submit = false;
         if (global::UIUnityEvents.lastInput.SendSubmitMessage())
         {
             @event.Use();
         }
     }
 }
Ejemplo n.º 4
0
        private void DragCanvas()
        {
            // This code is borrowed from ICode(https://www.assetstore.unity3d.com/en/#!/content/13761)
            if (_currentEvent.button != 2)
            {
                return;
            }

            int controlID = GUIUtility.GetControlID(FocusType.Passive);

            switch (_currentEvent.rawType)
            {
            case EventType.MouseDown:
                GUIUtility.hotControl = controlID;
                _currentEvent.Use();
                break;

            case EventType.MouseUp:
                if (GUIUtility.hotControl == controlID)
                {
                    GUIUtility.hotControl = 0;
                    _currentEvent.Use();
                }
                break;

            case EventType.MouseDrag:
                if (GUIUtility.hotControl == controlID)
                {
                    UpdateScrollPosition(_scrollPosition - _currentEvent.delta);
                    _currentEvent.Use();
                }
                break;
            }
        }
        private void ProcessEvent(UnityEngine.Event currentEvent)
        {
            if (currentEvent.type == EventType.KeyDown)
            {
                switch (currentEvent.keyCode)
                {
                case KeyCode.DownArrow:
                    this.scrollToIndex = this.hoverIndex = Mathf.Min(this.list.maxIndex, this.hoverIndex + 1);
                    this.scrollOffset  = rowHeight;
                    currentEvent.Use();
                    break;

                case KeyCode.UpArrow:
                    this.scrollToIndex = this.hoverIndex = Mathf.Max(0, this.hoverIndex - 1);
                    this.scrollOffset  = -rowHeight;
                    currentEvent.Use();
                    break;

                case KeyCode.Return:
                    if (this.hoverIndex >= 0 && this.hoverIndex < this.list.currentEntries.Count)
                    {
                        this.onSelection(this.list.currentEntries[hoverIndex].index);
                        EditorWindow.focusedWindow.Close();
                    }
                    break;

                case KeyCode.Escape:
                    EditorWindow.focusedWindow.Close();
                    break;
                }
            }
        }
Ejemplo n.º 6
0
 private static void TextDrag(UICamera camera, UIInput input, UnityEngine.Event @event, UILabel label)
 {
     if ((input == lastInput) && (camera == lastInputCamera))
     {
         lastLabel = label;
         TextEditor te = null;
         if (GetTextEditor(out te))
         {
             if (controlID == GUIUtility.hotControl)
             {
                 UITextPosition res = camera.RaycastText(Input.mousePosition, label);
                 if ([email protected])
                 {
                     SelectTextPosition(@event, te, ref res);
                 }
                 else
                 {
                     MoveTextPosition(@event, te, ref res);
                 }
                 @event.Use();
             }
             TextSharedEnd(false, te, @event);
         }
     }
 }
Ejemplo n.º 7
0
    private static void TextClickDown(UICamera camera, UIInput input, UnityEngine.Event @event, UILabel label)
    {
        UITextPosition uITextPosition = ([email protected] ? camera.RaycastText(Input.mousePosition, label) : new UITextPosition());
        TextEditor     textEditor     = null;

        UIUnityEvents.ChangeFocus(camera, input, label);
        if (UIUnityEvents.GetTextEditor(out textEditor))
        {
            GUIUtility.hotControl = UIUnityEvents.controlID;
            UIUnityEvents.SetKeyboardControl();
            UIUnityEvents.MoveTextPosition(@event, textEditor, ref uITextPosition);
            int num = @event.clickCount;
            if (num == 2)
            {
                textEditor.SelectCurrentWord();
                textEditor.DblClickSnap(TextEditor.DblClickSnapping.WORDS);
                textEditor.MouseDragSelectsWholeWords(true);
            }
            else if (num == 3)
            {
                if (input.trippleClickSelect)
                {
                    textEditor.SelectCurrentParagraph();
                    textEditor.MouseDragSelectsWholeWords(true);
                    textEditor.DblClickSnap(TextEditor.DblClickSnapping.PARAGRAPHS);
                }
            }
            @event.Use();
        }
        else
        {
            Debug.LogError("Null Text Editor");
        }
        UIUnityEvents.TextSharedEnd(false, textEditor, @event);
    }
Ejemplo n.º 8
0
 public override void Use()
 {
     if (m_internalEvent != null)
     {
         m_internalEvent.Use();
     }
 }
Ejemplo n.º 9
0
        private static bool EditorToggle(Rect position, bool value, GUIContent content, GUIStyle style)
        {
            int hashCode = "AlignToggle".GetHashCode();
            int id       = EditorGUIUtility.GetControlID(hashCode, EditorGUIUtility.native, position);

            UnityEngine.Event evt = UnityEngine.Event.current;

            // Toggle selected toggle on space or return key
            if (EditorGUIUtility.keyboardControl == id && evt.type == EventType.KeyDown &&
                (evt.keyCode == KeyCode.Space || evt.keyCode == KeyCode.Return || evt.keyCode == KeyCode.KeypadEnter))
            {
                value = !value;
                evt.Use();
                GUI.changed = true;
            }

            if (evt.type == EventType.KeyDown && UnityEngine.Event.current.button == 0 &&
                position.Contains(UnityEngine.Event.current.mousePosition))
            {
                GUIUtility.keyboardControl        = id;
                EditorGUIUtility.editingTextField = false;
                HandleUtility.Repaint();
            }

            bool returnValue = GUI.Toggle(position, id, value, content, style);

            return(returnValue);
        }
Ejemplo n.º 10
0
        public bool this [KeyCode c] {
            get {
                bool r;
                if (!listenCodes.TryGetValue(c, out r))
                {
                    UnityEngine.Event e = UnityEngine.Event.current;
                    if (e.type != EventType.KeyDown)
                    {
                        return(false);
                    }
                    if (GUIUtils.KeyboardOverriden())
                    {
                        //Debug.Log("override key" );
                        return(false);
                    }

                    r = e.keyCode == c;
                    if (r)
                    {
                        e.Use();
                    }
                    listenCodes[c] = r;
                }
                return(r);
            }
        }
Ejemplo n.º 11
0
 // Token: 0x06004EB3 RID: 20147 RVA: 0x00145CD8 File Offset: 0x00143ED8
 private static void TextDrag(global::UICamera camera, global::UIInput input, UnityEngine.Event @event, global::UILabel label)
 {
     if (input == global::UIUnityEvents.lastInput && camera == global::UIUnityEvents.lastInputCamera)
     {
         global::UIUnityEvents.lastLabel = label;
         TextEditor te = null;
         if (!global::UIUnityEvents.GetTextEditor(out te))
         {
             return;
         }
         if (global::UIUnityEvents.controlID == GUIUtility.hotControl)
         {
             global::UITextPosition uitextPosition = camera.RaycastText(Input.mousePosition, label);
             if ([email protected])
             {
                 global::UIUnityEvents.SelectTextPosition(@event, te, ref uitextPosition);
             }
             else
             {
                 global::UIUnityEvents.MoveTextPosition(@event, te, ref uitextPosition);
             }
             @event.Use();
         }
         global::UIUnityEvents.TextSharedEnd(false, te, @event);
     }
 }
Ejemplo n.º 12
0
 // Token: 0x06004EB1 RID: 20145 RVA: 0x00145C14 File Offset: 0x00143E14
 private static void TextClickUp(global::UICamera camera, global::UIInput input, UnityEngine.Event @event, global::UILabel label)
 {
     if (input == global::UIUnityEvents.lastInput && camera == global::UIUnityEvents.lastInputCamera)
     {
         global::UIUnityEvents.lastLabel = label;
         TextEditor textEditor = null;
         if (!global::UIUnityEvents.GetTextEditor(out textEditor))
         {
             return;
         }
         if (global::UIUnityEvents.controlID == GUIUtility.hotControl)
         {
             textEditor.MouseDragSelectsWholeWords(false);
             GUIUtility.hotControl = 0;
             @event.Use();
             global::UIUnityEvents.SetKeyboardControl();
         }
         else
         {
             Debug.Log(string.Concat(new object[]
             {
                 "Did not match ",
                 global::UIUnityEvents.controlID,
                 " ",
                 GUIUtility.hotControl
             }));
         }
         global::UIUnityEvents.TextSharedEnd(false, textEditor, @event);
     }
 }
Ejemplo n.º 13
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="e"></param>
 protected override void OnContextClick( Event e )
 {
     if ( Positionless || PointInControl( e.mousePosition ) )
     {
         Menu.ShowAsContext();
         e.Use();
     }
 }
Ejemplo n.º 14
0
        public override void Process(Event e)
        {
            //Debug.Log("KeyboardProcessor.Process: " + e.keyCode);

#if DEBUG
            if (DebugMode)
            {
                Debug.Log("KeyboardProcessor.Process");
            }
#endif

            /**
             * 1) Overal key events
             * */
            if (e.type == EventType.KeyDown)
            {
                if (e.keyCode == KeyCode.None) // Unity 4.3.0f2 bug ("ghost keystroke")
                {
                    return;
                }
                //Debug.Log("KeyboardProcessor.KeyDown");
                ProcessSpecialKeys(e);
#if DEBUG
                if (DebugMode)
                {
                    Debug.Log("KeyboardProcessor.KeyDown");
                }
#endif
                if (SystemManager.KeyDownSignal.Connected)
                {
                    SystemManager.KeyDownSignal.Emit(e);
                }
            }

            else if (e.type == EventType.KeyUp)
            {
                ProcessSpecialKeys(e);
#if DEBUG
                if (DebugMode)
                {
                    Debug.Log("KeyboardProcessor.KeyUp");
                }
#endif

                if (SystemManager.KeyUpSignal.Connected)
                {
                    SystemManager.KeyUpSignal.Emit(e);
                }
            }

            if (e.keyCode == KeyCode.Tab || e.character == '\t')
            {
                e.Use();
            }
        }
        public override void eventHandler(GameObject gameObject, QObjectList objectList, Event currentEvent, Rect curRect)
        {
            if (currentEvent.isMouse && currentEvent.type == EventType.MouseDown && currentEvent.button == 0 && curRect.Contains(currentEvent.mousePosition))
            {
                currentEvent.Use();

                Type iconSelectorType = Assembly.Load("UnityEditor").GetType("UnityEditor.IconSelector");
                MethodInfo showIconSelectorMethodInfo = iconSelectorType.GetMethod("ShowAtPosition", BindingFlags.Static | BindingFlags.NonPublic);
                showIconSelectorMethodInfo.Invoke(null, new object[] { gameObject, curRect, true });
            }
        }
Ejemplo n.º 16
0
 static public int Use(IntPtr l)
 {
     try {
         UnityEngine.Event self = (UnityEngine.Event)checkSelf(l);
         self.Use();
         return(0);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Ejemplo n.º 17
0
 static public int Use(IntPtr l)
 {
     try{
         UnityEngine.Event self = (UnityEngine.Event)checkSelf(l);
         self.Use();
         return(0);
     }
     catch (Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return(0);
     }
 }
Ejemplo n.º 18
0
        protected override void OnMouseDown( Event e )
        {
            if ( m_label.PointInControl( e.mousePosition ) )
            {
                if ( BoundDecoratorlSelected != null && m_target != null )
                {
                    BoundDecoratorlSelected( m_target, e.button );
                }

                e.Use();
            }            
        }
        public static Vector2 Drag2D(Vector2 scrollPosition, Rect position)
        {
            int controlID = GUIUtility.GetControlID("Slider".GetHashCode(), FocusType.Passive);

            UnityEngine.Event current = UnityEngine.Event.current;
            switch (current.GetTypeForControl(controlID))
            {
            case EventType.MouseDown:
                if (position.Contains(current.mousePosition) && position.width > 50f)
                {
                    GUIUtility.hotControl = controlID;
                    current.Use();
                    // 让鼠标可以拖动到屏幕外后,从另一边出来
                    EditorGUIUtility.SetWantsMouseJumping(1);
                }
                break;

            case EventType.MouseUp:
                if (GUIUtility.hotControl == controlID)
                {
                    GUIUtility.hotControl = 0;
                }
                EditorGUIUtility.SetWantsMouseJumping(0);
                break;

            case EventType.MouseDrag:
                if (GUIUtility.hotControl == controlID)
                {
                    // 按住 Shift 键后,可以加快旋转
                    scrollPosition  -= current.delta * (float)((!current.shift) ? 1 : 3) / Mathf.Min(position.width, position.height) * 140f;
                    scrollPosition.y = Mathf.Clamp(scrollPosition.y, -90f, 90f);
                    current.Use();
                    GUI.changed = true;
                }
                break;
            }
            return(scrollPosition);
        }
 static int Use(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 1);
         UnityEngine.Event obj = (UnityEngine.Event)ToLua.CheckObject(L, 1, typeof(UnityEngine.Event));
         obj.Use();
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Ejemplo n.º 21
0
        public static void ShowContextMenu(Rect checkRect, GenericMenu menu)
        {
            UnityEngine.Event evt = UnityEngine.Event.current;

            if (evt.type == EventType.ContextClick)
            {
                Vector2 mousePos = evt.mousePosition;
                if (checkRect.Contains(mousePos))
                {
                    menu.ShowAsContext();
                    evt.Use();
                }
            }
        }
Ejemplo n.º 22
0
        public static void ShowContextMenu(Rect checkRect, System.Action showMenu)
        {
            UnityEngine.Event evt = UnityEngine.Event.current;

            if (evt.type == EventType.ContextClick)
            {
                Vector2 mousePos = evt.mousePosition;
                if (checkRect.Contains(mousePos))
                {
                    showMenu();
                    evt.Use();
                }
            }
        }
 internal static bool MainActionKeyForControl(Event evt, int controlId)
 {
     if (GUIUtility.keyboardControl != controlId)
     {
         return false;
     }
     bool flag2 = ((evt.alt || evt.shift) || evt.command) || evt.control;
     if (((evt.type == EventType.KeyDown) && (evt.character == ' ')) && !flag2)
     {
         evt.Use();
         return false;
     }
     return (((evt.type == EventType.KeyDown) && (((evt.keyCode == KeyCode.Space) || (evt.keyCode == KeyCode.Return)) || (evt.keyCode == KeyCode.KeypadEnter))) && !flag2);
 }
Ejemplo n.º 24
0
        public bool HandleEvent(Event currentEvent)
        {
            switch(currentEvent.type)
            {
            case EventType.MouseUp:
                if(!Rect.Contains(currentEvent.mousePosition)) {
                    break;
                }

                OnMouseUp(currentEvent.button, currentEvent.mousePosition);
                currentEvent.Use();
                return true;
            }
            return false;
        }
Ejemplo n.º 25
0
        private void HandleDragAndDrop(UnityEngine.Event currentEvent, Rect dropArea)
        {
            if (currentEvent.type == EventType.DragExited)
            {
                // clear dragged data
                DragAndDrop.PrepareStartDrag();
            }
            else if (currentEvent.type == EventType.DragUpdated || currentEvent.type == EventType.DragPerform)
            {
                if (dropArea.Contains(currentEvent.mousePosition))
                {
                    var DDData = GetAkDragDropData();

                    if (currentEvent.type == EventType.DragUpdated)
                    {
                        DragAndDrop.visualMode = DDData != null ? DragAndDropVisualMode.Link : DragAndDropVisualMode.Rejected;
                    }
                    else
                    {
                        DragAndDrop.AcceptDrag();

                        if (DDData != null)
                        {
                            AkUtilities.SetByteArrayProperty(m_guidProperty[0], DDData.guid.ToByteArray());
                            m_IDProperty[0].intValue = DDData.ID;

                            AkDragDropGroupData DDGroupData = DDData as AkDragDropGroupData;
                            if (DDGroupData != null)
                            {
                                if (m_guidProperty.Length > 1)
                                {
                                    AkUtilities.SetByteArrayProperty(m_guidProperty[1], DDGroupData.groupGuid.ToByteArray());
                                }
                                if (m_IDProperty.Length > 1)
                                {
                                    m_IDProperty[1].intValue = DDGroupData.groupID;
                                }
                            }

                            //needed for the undo operation to work
                            GUIUtility.hotControl = 0;
                        }
                    }
                    currentEvent.Use();
                }
            }
        }
Ejemplo n.º 26
0
        public static bool OnMouseUp(this UnityEngine.Event source, int index)
        {
            var id   = GUIUtility.GetControlID(FocusType.Passive);
            var type = source.GetTypeForControl(id);

            if (type == EventType.MouseUp && source.button == index)
            {
                GUIUtility.hotControl = 0;
                source.Use();

                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 27
0
        public static bool OnMouseDown(this UnityEngine.Event source, Rect rect, int index)
        {
            var id   = GUIUtility.GetControlID(FocusType.Passive);
            var type = source.GetTypeForControl(id);

            if (type == EventType.MouseDown && source.button == index && rect.Contains(source.mousePosition))
            {
                GUIUtility.hotControl = id;
                source.Use();

                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 28
0
        public static bool OnMouseMoveDrag(this UnityEngine.Event source)
        {
            var id   = GUIUtility.GetControlID(FocusType.Passive);
            var type = source.GetTypeForControl(id);

            if (type == EventType.MouseDrag)
            {
                GUIUtility.hotControl = id;
                source.Use();

                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 29
0
        public override void Process(Event e)
        {
#if DEBUG
            if (DebugMode)
            {
                Debug.Log("KeyboardProcessor.Process");
            }
#endif

            /**
             * 1) Overal key events
             * */
            if (e.type == EventType.KeyDown)
            {
#if DEBUG
                if (DebugMode)
                {
                    Debug.Log("KeyboardProcessor.KeyDown");
                }
#endif
                if (SystemManager.KeyDownSignal.Connected)
                {
                    SystemManager.KeyDownSignal.Emit(e);
                }
            }

            else if (e.type == EventType.KeyUp)
            {
#if DEBUG
                if (DebugMode)
                {
                    Debug.Log("KeyboardProcessor.KeyUp");
                }
#endif

                if (SystemManager.KeyUpSignal.Connected)
                {
                    SystemManager.KeyUpSignal.Emit(e);
                }
            }

            if (e.keyCode == KeyCode.Tab || e.character == '\t')
            {
                e.Use();
            }
        }
Ejemplo n.º 30
0
    void MouseScroll(Rect position)
    {
        UnityEngine.Event current = UnityEngine.Event.current;
        int controlID             = GUIUtility.GetControlID(sliderHash, FocusType.Passive);

        switch (current.GetTypeForControl(controlID))
        {
        case EventType.ScrollWheel:
            if (position.Contains(current.mousePosition))
            {
                m_orthoGoal          += current.delta.y * ((SkeletonDataAsset)target).scale * 10;
                GUIUtility.hotControl = controlID;
                current.Use();
            }
            break;
        }
    }
        void MouseScroll(Rect position)
        {
            UnityEngine.Event current = UnityEngine.Event.current;
            int controlID             = GUIUtility.GetControlID(SliderHash, FocusType.Passive);

            switch (current.GetTypeForControl(controlID))
            {
            case EventType.ScrollWheel:
                if (position.Contains(current.mousePosition))
                {
                    m_orthoGoal          += current.delta.y * 0.06f;
                    m_orthoGoal           = Mathf.Max(0.01f, m_orthoGoal);
                    GUIUtility.hotControl = controlID;
                    current.Use();
                }
                break;
            }
        }
                protected override void OnStopDragging(UnityEngine.Event inputEvent, bool cancelled)
                {
                    if (_dragMode == eDragType.Custom)
                    {
                        if (!cancelled)
                        {
                            Vector2 gridPos = GetEditorPosition(UnityEngine.Event.current.mousePosition);

                            StateEditorGUI draggedOnToState = null;

                            //Check mouse is over a state
                            foreach (StateEditorGUI editorGUI in _editableObjects)
                            {
                                if (editorGUI.GetBounds().Contains(gridPos))
                                {
                                    draggedOnToState = editorGUI;

                                    // Check its moved more than
                                    break;
                                }
                            }

                            if (draggedOnToState != null)
                            {
                                _draggingStateLink.SetStateRef(new StateRef(draggedOnToState.GetStateId()));
                            }
                            else
                            {
                                _draggingStateLink.SetStateRef(new StateRef());
                            }
                        }

                        inputEvent.Use();
                        _dragMode = eDragType.NotDragging;

                        _draggingState          = null;
                        _draggingStateLink      = new StateMachineEditorLink();
                        _draggingStateLinkIndex = 0;
                    }
                    else
                    {
                        base.OnStopDragging(inputEvent, cancelled);
                    }
                }
        public bool IsTap(Event e, Rect position, Rect hitPosition, ButtonType type, Texture2D textureNormal, Texture2D textureHover, Texture2D textureActive, string labelText, GUIStyle guiStyleLabel)
        {
            bool hitContain = (e.button == 0) && hitPosition.Contains(e.mousePosition);

            if (e.type == EventType.MouseDown && hitContain)
            {
                touching = true;
            }

            if (FASGesture.IsDragging || FASGesture.IsPinching)
            {
                touching = false;
            }

            if (e.type == EventType.MouseUp && hitContain && touching)
            {
                e.Use();

                if(!isActive)
                    StartCoroutine(ButtonIsActive());

                touching = false;

                return true;
            }

            Texture2D buttonTexture = (touching) ? textureHover : textureNormal;

            buttonTexture = (isActive) ? textureActive : buttonTexture;

            if (type == ButtonType.TextureOnly)
            {
                GUI.DrawTexture(position, buttonTexture, scaleMode);
            }
            else if (type == ButtonType.FrameAndLabel)
            {
                FresviiGUIUtility.DrawButtonFrame(position, buttonTexture, FresviiGUIManager.Instance.ScaleFactor);

                GUI.Label(position, labelText, guiStyleLabel);
            }

            return false;
        }
        public void Draw(Rect position, Event e)
        {
            if (labels.Count == 0) return;

            for (int i = 0; i < labels.Count; i++)
            {
                Rect buttonRect = new Rect(position.x + i * position.width / labels.Count, position.y, position.width / labels.Count, position.height);

                FresviiGUIUtility.DrawPosition pos = FresviiGUIUtility.DrawPosition.Center;

                if (i == 0) pos = FresviiGUIUtility.DrawPosition.Left;
                else if (i == labels.Count- 1) pos = FresviiGUIUtility.DrawPosition.Right;

                FresviiGUIUtility.DrawSplitTexture(buttonRect, (i == selectedIndex) ? buttonActive : buttonNegative, scaleFactor * 4.0f, scaleFactor * 4.0f, scaleFactor * 4.0f, scaleFactor * 4.0f, pos);

                guiStyleLabel.normal.textColor = ((i == selectedIndex) ? buttonLabelActive : buttonLabelNegative);

                GUI.Label(buttonRect, labels[i], guiStyleLabel);

                bool hitContain = (e.button == 0) && buttonRect.Contains(e.mousePosition);

                if (e.type == EventType.MouseDown && hitContain)
                {
                    touching = true;
                }

                if (FASGesture.IsDragging)
                {
                    touching = false;
                }

                if (e.type == EventType.MouseUp && hitContain && touching)
                {
                    e.Use();

                    OnTapped(i);

                    selectedIndex = i;
                }
            }
        }
Ejemplo n.º 35
0
        // EVENTS
        public override void eventHandler(GameObject gameObject, QObjectList objectList, Event currentEvent, Rect curRect)
        {
            if (currentEvent.isMouse && currentEvent.type == EventType.MouseDown && currentEvent.button == 0 && curRect.Contains(currentEvent.mousePosition))
            {
                if (currentEvent.type == EventType.MouseDown)
                {
                    Color color = QResources.getInstance().getColor(QColor.Background);
                    color.a = 0.1f;

                    if (objectList != null) objectList.gameObjectColor.TryGetValue(gameObject, out color);

                    try
                    {
                        PopupWindow.Show(curRect, new QColorPickerWindow(Selection.Contains(gameObject) ? Selection.gameObjects : new GameObject[] { gameObject }, colorSelectedHandler, colorRemovedHandler));
                    }
                    catch
                    {}
                }
                currentEvent.Use();
            }
        }
Ejemplo n.º 36
0
        // Use this method when checking if user hit Space or Return in order to activate the main action
        // for a control, such as opening a popup menu or color picker.
        internal static bool MainActionKeyForControl(this UnityEngine.Event evt, int controlId)
        {
            if (EditorGUIUtility.keyboardControl != controlId)
            {
                return(false);
            }

            bool anyModifiers = (evt.alt || evt.shift || evt.command || evt.control);

            // Block window maximize (on OSX ML, we need to show the menu as part of the KeyCode event, so we can't do the usual check)
            if (evt.type == EventType.KeyDown && evt.character == ' ' && !anyModifiers)
            {
                evt.Use();
                return(false);
            }

            // Space or return is action key
            return(evt.type == EventType.KeyDown &&
                   (evt.keyCode == KeyCode.Space || evt.keyCode == KeyCode.Return || evt.keyCode == KeyCode.KeypadEnter) &&
                   !anyModifiers);
        }
Ejemplo n.º 37
0
    // Token: 0x06004EAF RID: 20143 RVA: 0x00145B2C File Offset: 0x00143D2C
    private static void TextClickDown(global::UICamera camera, global::UIInput input, UnityEngine.Event @event, global::UILabel label)
    {
        global::UITextPosition uitextPosition = ([email protected]) ? camera.RaycastText(Input.mousePosition, label) : default(global::UITextPosition);
        TextEditor             textEditor     = null;

        global::UIUnityEvents.ChangeFocus(camera, input, label);
        if (!global::UIUnityEvents.GetTextEditor(out textEditor))
        {
            Debug.LogError("Null Text Editor");
        }
        else
        {
            GUIUtility.hotControl = global::UIUnityEvents.controlID;
            global::UIUnityEvents.SetKeyboardControl();
            global::UIUnityEvents.MoveTextPosition(@event, textEditor, ref uitextPosition);
            int clickCount = @event.clickCount;
            if (clickCount != 2)
            {
                if (clickCount == 3)
                {
                    if (input.trippleClickSelect)
                    {
                        textEditor.SelectCurrentParagraph();
                        textEditor.MouseDragSelectsWholeWords(true);
                        textEditor.DblClickSnap(1);
                    }
                }
            }
            else
            {
                textEditor.SelectCurrentWord();
                textEditor.DblClickSnap(0);
                textEditor.MouseDragSelectsWholeWords(true);
            }
            @event.Use();
        }
        global::UIUnityEvents.TextSharedEnd(false, textEditor, @event);
    }
Ejemplo n.º 38
0
        /// <summary>
        /// A special method, since ScrollWheel event is not a mouse event nor a key event
        /// </summary>
        /// <param name="e"></param>
        public void ProcessWheel(Event e)
        {
#if DEBUG
            if (DebugMode)
            {
                Debug.Log("MouseProcessor.ProcessWheel");
            }
#endif
            _mousePosition = new Point(e.mousePosition.x, e.mousePosition.y);

#if DEBUG
            if (DebugMode)
            {
                Debug.Log("MouseProcessor.ScrollWheel");
            }
#endif
            if (SystemManager.MouseWheelSignal.Connected)
            {
                SystemManager.MouseWheelSignal.Emit(e, _mousePosition, e.delta.y);
            }

            e.Use(); // cancel the Unity default
        }
Ejemplo n.º 39
0
        public override void eventHandler(GameObject gameObject, QObjectList objectList, Event currentEvent, Rect curRect)
        {
            if (currentEvent.isMouse && currentEvent.type == EventType.MouseDown && currentEvent.button == 0 && curRect.Contains(currentEvent.mousePosition))
            {
                currentEvent.Use();

                int intStaticFlags = (int)staticFlags;
                gameObjects = Selection.Contains(gameObject) ? Selection.gameObjects : new GameObject[] { gameObject };

                GenericMenu menu = new GenericMenu();
                menu.AddItem(new GUIContent("Nothing"                   ), intStaticFlags == 0, staticChangeHandler, 0);
                menu.AddItem(new GUIContent("Everything"                ), intStaticFlags == -1, staticChangeHandler, -1);
                menu.AddItem(new GUIContent("Lightmap Static"           ), (intStaticFlags & (int)StaticEditorFlags.LightmapStatic) > 0, staticChangeHandler, (int)StaticEditorFlags.LightmapStatic);
                menu.AddItem(new GUIContent("Occluder Static"           ), (intStaticFlags & (int)StaticEditorFlags.OccluderStatic) > 0, staticChangeHandler, (int)StaticEditorFlags.OccluderStatic);
                menu.AddItem(new GUIContent("Batching Static"           ), (intStaticFlags & (int)StaticEditorFlags.BatchingStatic) > 0, staticChangeHandler, (int)StaticEditorFlags.BatchingStatic);
                menu.AddItem(new GUIContent("Navigation Static"         ), (intStaticFlags & (int)StaticEditorFlags.NavigationStatic) > 0, staticChangeHandler, (int)StaticEditorFlags.NavigationStatic);
                menu.AddItem(new GUIContent("Occludee Static"           ), (intStaticFlags & (int)StaticEditorFlags.OccludeeStatic) > 0, staticChangeHandler, (int)StaticEditorFlags.OccludeeStatic);
                menu.AddItem(new GUIContent("Off Mesh Link Generation"  ), (intStaticFlags & (int)StaticEditorFlags.OffMeshLinkGeneration) > 0, staticChangeHandler, (int)StaticEditorFlags.OffMeshLinkGeneration);
                #if UNITY_5
                menu.AddItem(new GUIContent("Reflection Probe Static"   ), (intStaticFlags & (int)StaticEditorFlags.ReflectionProbeStatic) > 0, staticChangeHandler, (int)StaticEditorFlags.ReflectionProbeStatic);
                #endif
                menu.ShowAsContext();
            }
        }
Ejemplo n.º 40
0
	/// <summary>
	/// Handle the specified event.
	/// </summary>

	bool ProcessEvent (Event ev)
	{
		RuntimePlatform rp = Application.platform;
		bool isMac = (rp == RuntimePlatform.OSXEditor || rp == RuntimePlatform.OSXPlayer || rp == RuntimePlatform.OSXWebPlayer);
		bool ctrl = isMac ? (ev.modifiers == EventModifiers.Command) : (ev.modifiers == EventModifiers.Control);

		switch (ev.keyCode)
		{
			case KeyCode.Backspace:
			{
				ev.Use();
				mEditor.Backspace();
				UpdateLabel();
				ExecuteOnChange();
				return true;
			}

			case KeyCode.Delete:
			{
				ev.Use();
				mEditor.Delete();
				UpdateLabel();
				ExecuteOnChange();
				return true;
			}

			case KeyCode.LeftArrow:
			{
				ev.Use();
				mEditor.MoveLeft();
				UpdateLabel();
				return true;
			}

			case KeyCode.RightArrow:
			{
				ev.Use();
				mEditor.MoveRight();
				UpdateLabel();
				return true;
			}
			
			case KeyCode.Home:
			case KeyCode.UpArrow:
			{
				ev.Use();
				mEditor.MoveTextStart();
				UpdateLabel();
				return true;
			}

			case KeyCode.End:
			case KeyCode.DownArrow:
			{
				ev.Use();
				mEditor.MoveTextEnd();
				UpdateLabel();
				return true;
			}

			// Copy
			case KeyCode.C:
			{
				if (ctrl)
				{
					ev.Use();
					NGUITools.clipboard = value;
				}
				return true;
			}

			// Paste
			case KeyCode.V:
			{
				if (ctrl)
				{
					ev.Use();
					Append(NGUITools.clipboard);
				}
				return true;
			}

			// Cut
			case KeyCode.X:
			{
				if (ctrl)
				{
					ev.Use();
					NGUITools.clipboard = value;
					value = "";
				}
				return true;
			}

			// Submit
			case KeyCode.Return:
			case KeyCode.KeypadEnter:
			{
				ev.Use();
				
				if (ctrl && label != null && label.overflowMethod != UILabel.Overflow.ClampContent)
				{
					char c = '\n';
					if (onValidate != null) c = onValidate(mEditor.content.text, mEditor.selectPos, c);
					else if (validation != Validation.None) c = Validate(mEditor.content.text, mEditor.selectPos, c);

					// Append the character
					if (c != 0)
					{
						mEditor.Insert(c);
						UpdateLabel();
						ExecuteOnChange();
					}
				}
				else
				{
					UICamera.currentKey = ev.keyCode;
					Submit();
					UICamera.currentKey = KeyCode.None;
					isSelected = false;
					UpdateLabel();
					ExecuteOnChange();
				}
				return true;
			}
		}
		return false;
	}
Ejemplo n.º 41
0
        public override void OnInspectorGUI()
        {
            serializedObject.Update();
            spEditorConfirmations = serializedObject.FindProperty ("editorConfirmations");

            currentEvent = Event.current;

            if (currentEvent.isMouse )
            {
                mousePosition = currentEvent.mousePosition;
            }

            usableWidth = Screen.width - 50;
            Rect buttonsSize = GUILayoutUtility.GetRect(usableWidth, 20);
            GUI.Box (buttonsSize, string.Empty);
            buttonsSize.width = 30;
            SerializedProperty p = serializedObject.FindProperty ("animations");
            if (GUI.Button(buttonsSize, "+"))
            {
                if (!spEditorConfirmations.boolValue || (spEditorConfirmations.boolValue && EditorUtility.DisplayDialog
                                                         ("New Animation",
                 "Are you sure you want to create a new animation ?", "Yes", "No")))
                {

                    int idx = p.arraySize;
                    p.InsertArrayElementAtIndex(idx);
                    SerializedProperty newItem = p.GetArrayElementAtIndex(idx);
                    newItem.FindPropertyRelative("newFramesTime").floatValue = 0.1f;
                    newItem.FindPropertyRelative("speedRatio").floatValue = 1;
                    newItem.FindPropertyRelative("name").stringValue = "new animation";
                    newItem.FindPropertyRelative("loop").enumValueIndex = 0;
                    newItem.FindPropertyRelative("frameToLoop").intValue = 0;
                    newItem.FindPropertyRelative("frameDatas").arraySize = 0;
                    newItem.FindPropertyRelative("selectedIndex").intValue = -1;
                    serializedObject.ApplyModifiedProperties();
                    return;
                }
            }
            buttonsSize.xMin = usableWidth - 80;
            buttonsSize.width = 95;
            spEditorConfirmations.boolValue = EditorGUI.ToggleLeft (buttonsSize, new GUIContent ("Confirmations"), spEditorConfirmations.boolValue);

            float currentHeight = 20;
            float lastMinY = 75;
            for (int i = 0 ; i < p.arraySize; i++)
            {
                SerializedProperty item = p.GetArrayElementAtIndex(i);
                SerializedProperty spframeDatas = item.FindPropertyRelative("frameDatas");
                float aditional = 0;
                if (spframeDatas != null && spframeDatas.arraySize > 0)
                {
                    aditional = ((spframeDatas.arraySize) * (FRAMEQUAD_WIDTH + FRAMEQUAD_WIDTH_SEPARATION));
                    aditional = (Mathf.Ceil(aditional / usableWidth)) * (FRAMEQUAD_HEIGHT+FRAMEQUAD_HEIGHT_SEPARATION);
                    aditional+=160;
                }
                currentHeight = 175 + aditional;

                Rect totalSize = GUILayoutUtility.GetRect(usableWidth, currentHeight);
                totalSize.yMin = lastMinY;
                totalSize.height = currentHeight;
                DrawListItem(i, totalSize, item, (target as SpriteAnimationAsset).animations[i], new GUIContent( string.Empty ));
                lastMinY = totalSize.yMax;
                Rect supressButton = new Rect(totalSize.xMax - 40, totalSize.yMin+5, 40, 18);
                if (GUI.Button(supressButton, "X"))
                {
                    if (!spEditorConfirmations.boolValue || (spEditorConfirmations.boolValue && EditorUtility.DisplayDialog
                    ("Delete Item ?",
                    "Are you sure you want to delete animation '" + (target as SpriteAnimationAsset).animations[i].name + "' ?", "Yes", "No")))
                    {
                        p.DeleteArrayElementAtIndex(i);
                        serializedObject.ApplyModifiedProperties();
                        return;
                    }
                }
            }

            switch (currentEvent.type)
            {
                case EventType.MouseDrag:
                    CustomDragData existingDragData = DragAndDrop.GetGenericData("dragKeyframe") as CustomDragData;
                    if (existingDragData != null){
                        DragAndDrop.visualMode = DragAndDropVisualMode.Link;
                        isDragginKeyframe = true;
                        DragAndDrop.StartDrag("Dragging List ELement");
                        currentEvent.Use();
                    }
                    break;
                case EventType.mouseUp:
                    if (isDragginKeyframe)
                    {
                        DragAndDrop.paths = null;
                        DragAndDrop.objectReferences = new UnityEngine.Object[ 0 ];
                        DragAndDrop.PrepareStartDrag();// reset data
                        isDragginKeyframe = false;
                    }
                    break;
                case EventType.DragExited:
                    if ( isDragginKeyframe)
                    {
                        DragAndDrop.paths = null;
                        DragAndDrop.objectReferences = new UnityEngine.Object[ 0 ];
                        isDragginKeyframe = false;
                        DragAndDrop.PrepareStartDrag();
                        currentEvent.Use();
                    }
                    break;
            }

            if (GUI.changed)
                serializedObject.ApplyModifiedProperties();
        }
Ejemplo n.º 42
0
	void OnSceneGUI(SceneView scnview)
	{
		if(!enabled)// || (EditorWindow.focusedWindow != scnview && !lockhandleToCenter))
			return;

		if(editor && editor.editLevel != EditLevel.Plugin)
			editor.SetEditLevel(EditLevel.Plugin);
 
// #if UNITY_5
// 		if( Lightmapping.giWorkflowMode == Lightmapping.GIWorkflowMode.Iterative )
// 		{
// 			pb_Lightmapping.PushGIWorkflowMode();
// 			Lightmapping.Cancel();
// 			Debug.LogWarning("Vertex Painter requires Continuous Baking to be Off.  When you close the Vertex Painter tool, Continuous Baking will returned to it's previous state automatically.\nIf you toggle Continuous Baking On while the Vertex Painter is open, you may lose all mesh vertex colors.");
// 		}
// #endif

		currentEvent = Event.current;
		sceneCamera = scnview.camera;

		screenCenter.x = Screen.width/2f;
		screenCenter.y = Screen.height/2f;

		mouseMoveEvent = currentEvent.type == EventType.MouseMove;
		
		/**
		 * Check if a new object is under the mouse.
		 */
		if( mouseMoveEvent )
		{
			GameObject go = HandleUtility.PickGameObject(Event.current.mousePosition, false);

			if( go != null && (pb == null || go != pb.gameObject) )
			{
				pb = go.GetComponent<pb_Object>();

				if(pb != null)
				{
					textures = GetTextures( pb.transform.GetComponent<MeshRenderer>().sharedMaterial ).ToArray();
					Repaint();

					modified.Add(pb);
					
					pb.ToMesh();
					pb.Refresh();
				}
			}
		}

		/**
		 * Hit test scene
		 */
		if(!lockhandleToCenter && !pb_Handle_Utility.SceneViewInUse(currentEvent))
		{
			if(pb != null)
			{
				if(!hovering.ContainsKey(pb))
				{
					hovering.Add(pb, pb.colors ?? new Color[pb.vertexCount]);
				}
				else
				{
					if(pb.msh.vertexCount != pb.vertexCount)
					{
						// script reload can make this happen
						pb.ToMesh();
						pb.Refresh();
					}

					pb.msh.colors = hovering[pb];
				}
 
				Ray ray = HandleUtility.GUIPointToWorldRay(currentEvent.mousePosition);
				pb_RaycastHit hit;

				if ( pb_Handle_Utility.MeshRaycast(ray, pb, out hit) )
				{
					handlePosition = pb.transform.TransformPoint(hit.Point);
					handleDistance = Vector3.Distance(handlePosition, sceneCamera.transform.position);					
					handleRotation = Quaternion.LookRotation(nonzero(pb.transform.TransformDirection(hit.Normal)), Vector3.up);
 
					Color[] colors = pb.msh.colors;

					int[][] sharedIndices = pb.sharedIndices.ToArray();

					// wrapped in try/catch because a script reload can cause the mesh
					// to re-unwrap itself in some crazy configuration, throwing off the 
					// vertex count sync.
					try
					{
						for(int i = 0; i < sharedIndices.Length; i++)
						{
							float dist = Vector3.Distance(hit.Point, pb.vertices[sharedIndices[i][0]]);

							if(dist < brushSize)
							{
								for(int n = 0; n < sharedIndices[i].Length; n++)
								{
									colors[sharedIndices[i][n]] = Lerp(hovering[pb][sharedIndices[i][n]], color, (1f-(dist/brushSize)) * brushOpacity );
								}
							}
						}
	 				} catch { /* shhhhh */ }

					// show a preview
					pb.msh.colors = colors;
				}
				else
				{
					// Clear
					foreach(KeyValuePair<pb_Object, Color[]> kvp in hovering)
						kvp.Key.msh.colors = kvp.Value;
 
					hovering.Clear();

					ray = HandleUtility.GUIPointToWorldRay(currentEvent.mousePosition);
					handleRotation = Quaternion.LookRotation(sceneCamera.transform.forward, Vector3.up);
					handlePosition = ray.origin + ray.direction * handleDistance;
				}
			}
		}
		else
		{
			// No longer focusing object
			foreach(KeyValuePair<pb_Object, Color[]> kvp in hovering)
			{
				kvp.Key.msh.colors = kvp.Value;
			}
 
			hovering.Clear();
 	
			Ray ray = HandleUtility.GUIPointToWorldRay(lockhandleToCenter ? screenCenter : currentEvent.mousePosition);
			handleRotation = Quaternion.LookRotation(sceneCamera.transform.forward, Vector3.up);
			handlePosition = ray.origin + ray.direction * handleDistance;
 		}

		/**
		*    Draw the handles
		*/
 		Handles.color = InnerRingColor;
			Handles.CircleCap(0, handlePosition, handleRotation, brushSize * .2f);
 		Handles.color = MiddleRingColor;
			Handles.CircleCap(0, handlePosition, handleRotation, brushSize * .5f);
 		Handles.color = OuterRingColor;		
			Handles.CircleCap(0, handlePosition, handleRotation, brushSize);
 		Handles.color = Color.white;
 
		// This prevents us from selecting other objects in the scene,
		// and allows for the selection of faces / vertices.
		int controlID = GUIUtility.GetControlID(FocusType.Passive);
		HandleUtility.AddDefaultControl(controlID);
 
		/**
		 * Apply colors to mesh
		 */
		if( (currentEvent.type == EventType.MouseDown || currentEvent.type == EventType.MouseDrag) &&
		   	(currentEvent.button == MOUSE_BUTTON_LEFT) &&
		   	currentEvent.modifiers == (EventModifiers)0 &&
		   	((CurTime - lastBrushApplication) > 1f/(brushStrength * BRUSH_STRENGTH_MAX)) )
		{
			lastBrushApplication = CurTime;

			Dictionary<pb_Object, Color[]> sticky = new Dictionary<pb_Object, Color[]>();
 	
			if(!isPainting)
			{
				Undo.RegisterCompleteObjectUndo(hovering.Keys.ToArray(), "Apply Vertex Colors");
				isPainting = true;
			}


 			// Apply colors
			foreach(KeyValuePair<pb_Object, Color[]> kvp in hovering)
			{
				Color[] colors = kvp.Key.msh.colors;

				sticky.Add(kvp.Key, colors);

				kvp.Key.SetColors(colors);
			}
 
			hovering = sticky;
		}

		if(currentEvent.control && currentEvent.type == EventType.ScrollWheel)
		{
			currentEvent.Use();
			brushSize += (currentEvent.delta.y > 0f ? -1f : 1f) * (brushSize * .1f);
			brushSize = Mathf.Clamp(brushSize, .01f, BRUSH_SIZE_MAX);

			Repaint();
		}

		if(currentEvent.type == EventType.MouseUp)
			isPainting = false;
 
		if(mpos != currentEvent.mousePosition && currentEvent.type == EventType.Repaint)
		{
			mpos = currentEvent.mousePosition;
			SceneView.RepaintAll();
		}
	}
Ejemplo n.º 43
0
        void HandleEvents(Event e, Vector2 canvasMousePos)
        {
            //variable is set as well, so that  nodes know if they can be clicked
            var inspectorWithScrollbar = new Rect(inspectorRect.x, inspectorRect.y, inspectorRect.width + 14, inspectorRect.height);
            allowClick = !inspectorWithScrollbar.Contains(e.mousePosition) && !blackboardRect.Contains(e.mousePosition);
            if (!allowClick){
                return;
            }

            //Tilt '`' and 'space' opens up the compelte context menu browser
            if (e.type == EventType.KeyDown && !e.shift && (e.keyCode == KeyCode.BackQuote || e.keyCode == KeyCode.Space) ){
                CompleteContextMenu.Show( GetAddNodeMenu(canvasMousePos), e.mousePosition, string.Format("Add {0} Node", this.GetType().Name) );
            }

            //right click canvas context menu. Basicaly for adding new nodes
            if (e.type == EventType.ContextClick){

                var menu = GetAddNodeMenu(canvasMousePos);

                if (Node.copiedNodes != null && Node.copiedNodes[0].GetType().IsSubclassOf(baseNodeType)){

                    if (Node.copiedNodes.Length == 1){
                        menu.AddItem(new GUIContent(string.Format("Paste Node ({0})", Node.copiedNodes[0].GetType().Name )), false, ()=> { var newNode = Node.copiedNodes[0].Duplicate(this); newNode.nodePosition = canvasMousePos; });
                    } else if (Node.copiedNodes.Length > 1){
                        menu.AddItem(new GUIContent(string.Format("Paste Nodes ({0})", Node.copiedNodes.Length.ToString() )), false, ()=>
                        {
                            var newNodes = Graph.CopyNodesToGraph(Node.copiedNodes.ToList(), this);
                            var diff = newNodes[0].nodeRect.center - canvasMousePos;
                            newNodes[0].nodePosition = canvasMousePos;
                            for (var i = 1; i < newNodes.Count; i++){
                                newNodes[i].nodePosition -= diff;
                            }
                        });
                    }
                }

                menu.ShowAsContext();
                e.Use();
            }
        }
Ejemplo n.º 44
0
        /// <summary>
        /// Subscribes to both KeyDown and KeyUp events from the SceneView delegate. This allows us to easily store key
        /// events in one place and mark them as used as necessary (for example to prevent error sounds on key down)
        /// </summary>
        void OnKeyAction(SceneView sceneView, Event e)
        {
            if (e.keyCode == KeyMappings.ToggleMode
                && !EnumHelper.IsFlagSet(e.modifiers, EventModifiers.Control)
               && !EnumHelper.IsFlagSet(e.modifiers, EventModifiers.Alt)
               && !EnumHelper.IsFlagSet(e.modifiers, EventModifiers.Command)
               && !EnumHelper.IsFlagSet(e.modifiers, EventModifiers.FunctionKey)
            //			    && GUIUtility.keyboardControl == 0
               )
            {
                // Toggle mode - immediately (key down)
                if (e.type == EventType.KeyDown)
                {
                    int currentModeInt = (int)CurrentSettings.CurrentMode;
                    int count = Enum.GetNames(typeof(MainMode)).Length;

                    if (EnumHelper.IsFlagSet(e.modifiers, EventModifiers.Shift))
                    {
                        currentModeInt--;
                    }
                    else
                    {
                        currentModeInt++;
                    }

                    if (currentModeInt >= count)
                    {
                        currentModeInt = 0;
                    }
                    else if (currentModeInt < 0)
                    {
                        currentModeInt = count - 1;
                    }
                    SetCurrentMode((MainMode)currentModeInt);

                    SceneView.RepaintAll();
                }
                e.Use();
            }
            //            else if (e.keyCode == KeyCode.R && EnumHelper.IsFlagSet(e.modifiers, EventModifiers.Shift)) // Rebuild
            //            {
            //                if (e.type == EventType.KeyUp)
            //                {
            //                    Build();
            //                }
            //                e.Use();
            //            }
            else if (e.keyCode == KeyMappings.IncreasePosSnapping)
            {
                if (e.type == EventType.KeyUp)
                {
                    CurrentSettings.ChangePosSnapDistance(2f);
                }
                e.Use();
            }
            else if (e.keyCode == KeyMappings.DecreasePosSnapping)
            {
                if (e.type == EventType.KeyUp)
                {
                    CurrentSettings.ChangePosSnapDistance(.5f);
                }
                e.Use();
            }
            else if (e.keyCode == KeyMappings.TogglePosSnapping)
            {
                if (e.type == EventType.KeyUp)
                {
                    CurrentSettings.PositionSnappingEnabled = !CurrentSettings.PositionSnappingEnabled;
                }
                e.Use();
            }
            else if(!mouseIsHeld && e.modifiers == EventModifiers.None && (e.keyCode == KeyMappings.ChangeBrushToAdditive || e.keyCode == KeyMappings.ChangeBrushToAdditive2))
            {
                if (e.type == EventType.KeyDown)
                {
                    bool anyChanged = false;

                    for (int i = 0; i < Selection.gameObjects.Length; i++)
                    {
                        Brush brush = Selection.gameObjects[i].GetComponent<Brush>();
                        if (brush != null)
                        {
                            Undo.RecordObject(brush, "Change Brush To Add");
                            brush.Mode = CSGMode.Add;
                            anyChanged = true;
                        }
                    }
                    if(anyChanged)
                    {
                        // Need to update the icon for the csg mode in the hierarchy
                        EditorApplication.RepaintHierarchyWindow();
                    }
                }
                e.Use();
            }
            else if(!mouseIsHeld && e.modifiers == EventModifiers.None && (e.keyCode == KeyMappings.ChangeBrushToSubtractive || e.keyCode == KeyMappings.ChangeBrushToSubtractive2))
            {
                if (e.type == EventType.KeyDown)
                {
                    bool anyChanged = false;

                    for (int i = 0; i < Selection.gameObjects.Length; i++)
                    {
                        Brush brush = Selection.gameObjects[i].GetComponent<Brush>();
                        if (brush != null)
                        {
                            Undo.RecordObject(brush, "Change Brush To Subtract");
                            brush.Mode = CSGMode.Subtract;
                            anyChanged = true;
                        }
                    }
                    if(anyChanged)
                    {
                        // Need to update the icon for the csg mode in the hierarchy
                        EditorApplication.RepaintHierarchyWindow();
                    }
                }
                e.Use();
            }
        }
Ejemplo n.º 45
0
 internal void HandleRenderer(Renderer r, int materialIndex, Event evt)
 {
   bool flag = false;
   switch (evt.type)
   {
     case EventType.DragUpdated:
       DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
       flag = true;
       break;
     case EventType.DragPerform:
       DragAndDrop.AcceptDrag();
       flag = true;
       break;
   }
   if (!flag)
     return;
   Undo.RecordObject((UnityEngine.Object) r, "Assign Material");
   Material[] sharedMaterials = r.sharedMaterials;
   if (!evt.alt && (materialIndex >= 0 && materialIndex < r.sharedMaterials.Length))
   {
     sharedMaterials[materialIndex] = this.target as Material;
   }
   else
   {
     for (int index = 0; index < sharedMaterials.Length; ++index)
       sharedMaterials[index] = this.target as Material;
   }
   r.sharedMaterials = sharedMaterials;
   evt.Use();
 }
Ejemplo n.º 46
0
 internal void HandleSkybox(GameObject go, Event evt)
 {
   bool flag1 = !(bool) ((UnityEngine.Object) go);
   bool flag2 = false;
   if (!flag1 || evt.type == EventType.DragExited)
   {
     evt.Use();
   }
   else
   {
     switch (evt.type)
     {
       case EventType.DragUpdated:
         DragAndDrop.visualMode = DragAndDropVisualMode.Link;
         flag2 = true;
         break;
       case EventType.DragPerform:
         DragAndDrop.AcceptDrag();
         flag2 = true;
         break;
     }
   }
   if (!flag2)
     return;
   Undo.RecordObject((UnityEngine.Object) UnityEngine.Object.FindObjectOfType<RenderSettings>(), "Assign Skybox Material");
   RenderSettings.skybox = this.target as Material;
   evt.Use();
 }
Ejemplo n.º 47
0
        /// <summary>
        /// A special method, since ScrollWheel event is not a mouse event nor a key event
        /// </summary>
        /// <param name="e"></param>
        public void ProcessWheel(Event e)
        {
            #if DEBUG
            if (DebugMode)
                Debug.Log("MouseProcessor.ProcessWheel");
            #endif
            _mousePosition = new Point(e.mousePosition.x, e.mousePosition.y);

            #if DEBUG
            if (DebugMode)
                Debug.Log("MouseProcessor.ScrollWheel");
            #endif
            if (SystemManager.MouseWheelSignal.Connected)
                SystemManager.MouseWheelSignal.Emit(e, _mousePosition, e.delta.y);

            e.Use(); // cancel the Unity default
        }
    private void UpdatePoseEditGUI( Event a_rEvent )
    {
        //Transform rRootTransform = Selection.activeTransform;
        Vector2 f2MouseGUIPos = a_rEvent.mousePosition;

        if( a_rEvent.isMouse )
        {
            int iMouseButton = a_rEvent.button;

            switch( a_rEvent.type )
            {
                case EventType.MouseMove:
                {
                    // Reset state
                    m_bIsDragging = false;

                    // Something selected, edit tool used => move bone
                    if( Uni2DEditorSmoothBindingGUI.activeBone != null && ms_eEditorTool != BoneEditorTool.Select )
                    {
                        Uni2DEditorSmoothBindingGUI.activeBone.MoveBoneAlongSpritePlane( f2MouseGUIPos - m_f2MouseGUIOffset, a_rEvent.alt );
                    }

                    // Consume event
                    a_rEvent.Use( );
                }
                break;	// End MouseMove

                case EventType.MouseDown:
                {
                    // Left click
                    if( iMouseButton == 0 )
                    {
                        // Reset drag state
                        m_bIsDragging = false;

                        // Selection
                        if( ms_eEditorTool == BoneEditorTool.Select )
                        {
                            // Pick bones in scene
                            BoneHandle ePickedHandle;
                            Uni2DSmoothBindingBone rNearestBone = Uni2DEditorSmoothBindingUtils.PickNearestBoneInPosingMode( ms_rSprite, f2MouseGUIPos, out ePickedHandle, null );

                            // Outer disc => move
                            if( ePickedHandle == BoneHandle.OuterDisc || ePickedHandle == BoneHandle.Link )
                            {
                                if( rNearestBone != null )
                                {
                                    // Change selection and editor tool
                                    Uni2DEditorSmoothBindingGUI.activeBone = rNearestBone;
                                    ms_eEditorTool = BoneEditorTool.Move;

                                    m_f2MouseGUIOffset = f2MouseGUIPos - HandleUtility.WorldToGUIPoint( rNearestBone.transform.position );
                                }
                            }
                            else // Bone picked via inner disc or no bone picked
                            {
                                // A bone has been picked (via inner disc)
                                // Set selection to this bone
                                if( rNearestBone != null )
                                {
                                    Uni2DEditorSmoothBindingGUI.activeBone = rNearestBone;
                                }
                                else // No bone picked
                                {
                                    // Get rid of selection if any
                                    if( Uni2DEditorSmoothBindingGUI.activeBone != null )
                                    {
                                        Uni2DEditorSmoothBindingGUI.activeBone = null;
                                    }
                                    else // no selection, no bone picked => create a new bone chain
                                    {
                                        m_rLastAddedBone = null;

                                        // Create a new root and set it as current active bone
                                        Uni2DEditorSmoothBindingGUI.activeBone = Uni2DEditorSmoothBindingUtils.AddBoneToSprite( ms_rSprite, f2MouseGUIPos, null );
                                        m_rBoneChainOrigin = Uni2DEditorSmoothBindingGUI.activeBone;

                                        // The bone is not a child of a newly created root
                                        //m_bStartFromExistingBone = false;

                                        // Change editor tool
                                        ms_eEditorTool = BoneEditorTool.Create;
                                    }
                                }
                            }
                        }	// end if( editor tool == select )
                    }

                    // Consume mouse event
                    a_rEvent.Use( );
                }
                break;	// end MouseDown

                case EventType.MouseDrag:
                {
                    if( iMouseButton == 0 )
                    {
                        switch( ms_eEditorTool )
                        {
                            case BoneEditorTool.Move:
                            {
                                // Something dragged? MOVE IT
                                if( Uni2DEditorSmoothBindingGUI.activeBone != null )
                                {
                                    // We're moving an existing bone => register undo at first drag event
                                    if( m_bIsDragging == false )
                                    {
                                        Undo.SetSnapshotTarget( Uni2DEditorSmoothBindingGUI.activeBone, "Move Uni2D Bone" );
                                        Undo.CreateSnapshot( );
                                        Undo.RegisterSnapshot( );
                                    }

                                    // Move/drag along sprite plane;
                                    Uni2DEditorSmoothBindingGUI.activeBone.MoveBoneAlongSpritePlane( f2MouseGUIPos - m_f2MouseGUIOffset, a_rEvent.alt );
                                }
                                m_bIsDragging = true;
                            }
                            break;

                            case BoneEditorTool.Select:
                            {
                                // Dragging a bone in select mode == dragging on inner disc => add a child to active bone
                                if( Uni2DEditorSmoothBindingGUI.activeBone != null && m_bIsDragging == false )
                                {
                                    m_rBoneChainOrigin       = Uni2DEditorSmoothBindingGUI.activeBone;
                                    m_rLastAddedBone         = null;
                                    Uni2DEditorSmoothBindingGUI.activeBone = Uni2DEditorSmoothBindingUtils.AddBoneToSprite( ms_rSprite, f2MouseGUIPos, Uni2DEditorSmoothBindingGUI.activeBone );
                                    //m_bStartFromExistingBone = true;
                                    ms_eEditorTool            = BoneEditorTool.Create;
                                }
                                m_bIsDragging = true;
                            }
                            break;

                            case BoneEditorTool.Create:
                            {
                                if( Uni2DEditorSmoothBindingGUI.activeBone != null )
                                {
                                    Uni2DEditorSmoothBindingGUI.activeBone.MoveBoneAlongSpritePlane( f2MouseGUIPos );
                                }
                                m_bIsDragging = true;
                            }
                            break;
                        }
                    }

                    // Consume event
                    a_rEvent.Use( );
                }
                break;	// End MouseDrag

                case EventType.MouseUp:
                {
                    if( iMouseButton == 0 )
                    {
                        switch( ms_eEditorTool )
                        {
                            // Creation
                            case BoneEditorTool.Create:
                            {
                                BoneHandle ePickedHandle;
                                Uni2DSmoothBindingBone rNearestBone = Uni2DEditorSmoothBindingUtils.PickNearestBoneInPosingMode( ms_rSprite, f2MouseGUIPos, out ePickedHandle, Uni2DEditorSmoothBindingGUI.activeBone );

                                // Mouse up near the last added bone => close bone chain
                                if( ePickedHandle == BoneHandle.InnerDisc && rNearestBone == m_rLastAddedBone )
                                {
                                    Uni2DEditorSmoothBindingUtils.DeleteBone( ms_rSprite, Uni2DEditorSmoothBindingGUI.activeBone );

                                    m_rLastAddedBone = null;
                                    Uni2DEditorSmoothBindingGUI.activeBone = null;
                                    ms_eEditorTool = BoneEditorTool.Select;
                                }
                                else
                                {
                                    m_rLastAddedBone = Uni2DEditorSmoothBindingGUI.activeBone;
                                    Undo.RegisterCreatedObjectUndo( m_rLastAddedBone.gameObject, "Add Uni2D Bone" );

                                    // Creating => validate bone and create another one
                                    Uni2DEditorSmoothBindingGUI.activeBone = Uni2DEditorSmoothBindingUtils.AddBoneToSprite( ms_rSprite, f2MouseGUIPos, m_rLastAddedBone );

                                }
                            }
                            break;

                            // Move
                            case BoneEditorTool.Move:
                            {
                                Undo.ClearSnapshotTarget( );
                                Undo.RegisterSnapshot( );
                                ms_eEditorTool = BoneEditorTool.Select;
                            }
                            break;
                        }

                        // Reset dragging state
                        m_bIsDragging = false;
                        m_f2MouseGUIOffset = Vector2.zero;
                    }	// end if( left button )
                    else if( iMouseButton == 1 )	// Delete / stop bone creation
                    {
                        switch( ms_eEditorTool )
                        {
                            case BoneEditorTool.Select:
                            {
                                BoneHandle eBoneHandle;
                                Uni2DSmoothBindingBone rNearestBone = Uni2DEditorSmoothBindingUtils.PickNearestBoneInPosingMode( ms_rSprite, f2MouseGUIPos, out eBoneHandle, null );

                                if( rNearestBone != null )
                                {
                                    if( eBoneHandle == BoneHandle.Link )
                                    {
                                        //Undo.RegisterSetTransformParentUndo( rNearestBone.transform, rRootTransform, "Break Uni2D Bone" );
                                        rNearestBone.Break( );
                                    }
                                    else
                                    {
                                        Undo.RegisterSceneUndo( "Delete Uni2D Bone" );
                                        Uni2DEditorSmoothBindingUtils.DeleteBone( ms_rSprite, rNearestBone );
                                    }
                                }
                            }
                            break;

                            case BoneEditorTool.Create:
                            {
                                // Close bone chain
                                Uni2DEditorSmoothBindingUtils.DeleteBone( ms_rSprite, Uni2DEditorSmoothBindingGUI.activeBone );
                                ms_eEditorTool = BoneEditorTool.Select;
                            }
                            break;

                            case BoneEditorTool.Move:
                            {
                                ms_eEditorTool = BoneEditorTool.Select;
                            }
                            break;
                        }
                    }	// End if( right button )

                    // Consume event
                    a_rEvent.Use( );
                }
                break;	// End MouseUp
            }	// End switch( event.type )
        }	// end if( mouse events )
        else if( a_rEvent.isKey && a_rEvent.type == EventType.keyDown )
        {
            switch( a_rEvent.keyCode )
            {
                case KeyCode.Escape:
                {
                    switch( ms_eEditorTool )
                    {
                        case BoneEditorTool.Select:
                        {
                            if( Uni2DEditorSmoothBindingGUI.activeBone != null )
                            {
                                Uni2DEditorSmoothBindingGUI.activeBone = null;
                            }
                            else
                            {
                                Uni2DEditorSmoothBindingGUI.CurrentBoneEditMode = BoneEditMode.None;
                            }
                        }
                        break;

                        case BoneEditorTool.Move:
                        {
                            Undo.RestoreSnapshot( );
                            ms_eEditorTool = BoneEditorTool.Select;
                        }
                        break;

                        case BoneEditorTool.Create:
                        {
                            Uni2DEditorSmoothBindingUtils.DeleteBone( ms_rSprite, Uni2DEditorSmoothBindingGUI.activeBone );
                            ms_eEditorTool = BoneEditorTool.Select;
                        }
                        break;
                    }
                    a_rEvent.Use( );
                }
                break;	// End Escape

                // Delete last created bone (if any)
                case KeyCode.Backspace:
                {
                    if( ms_eEditorTool == BoneEditorTool.Create )
                    {
                        if( m_rLastAddedBone != null && m_rLastAddedBone != m_rBoneChainOrigin )
                        {
                            Undo.RegisterSceneUndo( "Delete Uni2D Bone" );
                            Uni2DEditorSmoothBindingUtils.DeleteBone( ms_rSprite, Uni2DEditorSmoothBindingGUI.activeBone );

                            Uni2DEditorSmoothBindingGUI.activeBone = Uni2DEditorSmoothBindingUtils.AddBoneToSprite( ms_rSprite, f2MouseGUIPos, m_rLastAddedBone.Parent );
                            Uni2DEditorSmoothBindingUtils.DeleteBone( ms_rSprite, m_rLastAddedBone );

                            Uni2DSmoothBindingBone rParentActiveBone = Uni2DEditorSmoothBindingGUI.activeBone.Parent;
                            if( rParentActiveBone != null && rParentActiveBone.IsFakeRootBone )
                            {
                                m_rLastAddedBone = rParentActiveBone.Parent;	// Grand-pa'
                            }
                            else
                            {
                                m_rLastAddedBone = rParentActiveBone;
                            }
                        }
                    }
                    a_rEvent.Use( );
                }
                break;	// End Escape

                case KeyCode.Return:
                case KeyCode.KeypadEnter:
                {
                    ms_eEditorTool = BoneEditorTool.Select;
                    a_rEvent.Use( );
                }
                break;	// End Return / KeypadEnter
            }	// end switch( event.type )
        }	// end if( key down events )
        else
        {
            switch( a_rEvent.type )
            {
                case EventType.ValidateCommand:
                {
                    if( a_rEvent.commandName == "Delete" || a_rEvent.commandName == "UndoRedoPerformed" )
                    {
                        a_rEvent.Use( );
                    }
                }
                break;	// end ValidateCommand

                case EventType.ExecuteCommand:
                {
                    if( a_rEvent.commandName == "Delete" )
                    {
                        if( Uni2DEditorSmoothBindingGUI.activeBone != null && ms_eEditorTool != BoneEditorTool.Create )
                        {
                            Undo.RegisterSceneUndo( "Delete Uni2D Bone" );
                            Uni2DEditorSmoothBindingUtils.DeleteBone( ms_rSprite, Uni2DEditorSmoothBindingGUI.activeBone );
                            ms_eEditorTool = BoneEditorTool.Select;
                        }
                        a_rEvent.Use( );
                    }
                    else if( a_rEvent.commandName == "UndoRedoPerformed" )
                    {
                        if( ms_eEditorTool == BoneEditorTool.Create && Uni2DEditorSmoothBindingGUI.activeBone != null )
                        {
                            Uni2DEditorSmoothBindingUtils.DeleteBone( ms_rSprite, Uni2DEditorSmoothBindingGUI.activeBone );
                        }
                        m_rLastAddedBone = null;
                        Uni2DEditorSmoothBindingGUI.activeBone = null;
                        ms_eEditorTool = BoneEditorTool.Select;
                        //Uni2DEditorSmoothBindingGUI.CurrentBoneEditMode = BoneEditMode.None;

                        a_rEvent.Use( );
                    }
                }
                break;	// end ExecuteCommand
            }	// end switch( event.type )
        }	// end else
    }
    private void UpdateAnimEditGUI( Event a_rEvent )
    {
        Vector2 f2MouseGUIPos = a_rEvent.mousePosition;

        if( a_rEvent.isMouse )
        {
            int iMouseButton = a_rEvent.button;

            switch( a_rEvent.type )
            {
                case EventType.MouseMove:
                {
                    // Reset state
                    m_bIsDragging = false;

                    // Consume event
                    a_rEvent.Use( );
                }
                break;	// End MouseMove

                case EventType.MouseDown:
                {
                    // Left click
                    if( iMouseButton == 0 )
                    {
                        // Reset drag state
                        m_bIsDragging = false;

                        // Pick bones in scene
                        BoneHandle ePickedHandle;
                        Uni2DSmoothBindingBone rNearestBone = Uni2DEditorSmoothBindingUtils.PickNearestBoneInAnimMode( ms_rSprite, f2MouseGUIPos, out ePickedHandle, null );

                        // Selection
                        if( ms_eEditorTool == BoneEditorTool.Select && rNearestBone != null )
                        {
                            // Change selection and editor tool
                            Uni2DEditorSmoothBindingGUI.activeBone = rNearestBone;

                            m_f2MouseGUIOffset = f2MouseGUIPos - HandleUtility.WorldToGUIPoint( rNearestBone.transform.position );
                        }	// end if( editor tool == select )
                    }

                    // Consume mouse event
                    a_rEvent.Use( );
                }
                break;	// end MouseDown

                case EventType.MouseDrag:
                {
                    if( iMouseButton == 0 )
                    {
                        switch( ms_eEditorTool )
                        {
                            case BoneEditorTool.Move:
                            {
                                // Something dragged? MOVE IT
                                if( Uni2DEditorSmoothBindingGUI.activeBone != null )
                                {
                                    // We're moving an existing bone => register undo at first drag event
                                    if( m_bIsDragging == false )
                                    {
                                        Undo.SetSnapshotTarget( Uni2DEditorSmoothBindingGUI.activeBone, "Move Uni2D Bone" );
                                        Undo.CreateSnapshot( );
                                        Undo.RegisterSnapshot( );
                                    }

                                    // Move/drag along sprite plane
                                    Uni2DEditorSmoothBindingGUI.activeBone.RotateBoneAlongSpritePlane( f2MouseGUIPos - m_f2MouseGUIOffset );
                                }
                                m_bIsDragging = true;
                            }
                            break;

                            case BoneEditorTool.Select:
                            {
                                // Dragging a bone in select mode == dragging on inner disc => add a child to active bone
                                if( Uni2DEditorSmoothBindingGUI.activeBone != null && m_bIsDragging == false )
                                {
                                    ms_eEditorTool = BoneEditorTool.Move;
                                    m_f2MouseGUIOffset = f2MouseGUIPos - HandleUtility.WorldToGUIPoint( Uni2DEditorSmoothBindingGUI.activeBone.transform.position );

                                    Uni2DEditorSmoothBindingGUI.activeBone.RotateBoneAlongSpritePlane( f2MouseGUIPos - m_f2MouseGUIOffset );
                                }
                                m_bIsDragging = true;
                            }
                            break;
                        }
                    }

                    // Consume event
                    a_rEvent.Use( );
                }
                break;	// End MouseDrag

                case EventType.MouseUp:
                {
                    if( iMouseButton == 0 )
                    {
                        if( ms_eEditorTool == BoneEditorTool.Move )
                        {
                            Undo.ClearSnapshotTarget( );
                            Undo.RegisterSnapshot( );
                            ms_eEditorTool = BoneEditorTool.Select;
                        }

                        // Reset dragging state
                        m_bIsDragging = false;
                        m_f2MouseGUIOffset = Vector2.zero;
                    }	// end if( left button )
                    else if( iMouseButton == 1 && ms_eEditorTool == BoneEditorTool.Move )	// Delete / stop bone creation
                    {
                        ms_eEditorTool = BoneEditorTool.Select;
                    }	// End if( right button )

                    // Consume event
                    a_rEvent.Use( );
                }
                break;	// End MouseUp
            }	// End switch( event.type )
        }	// end if( mouse events )
        else if( a_rEvent.isKey && a_rEvent.type == EventType.keyDown )
        {
            switch( a_rEvent.keyCode )
            {
                case KeyCode.Escape:
                {
                    switch( ms_eEditorTool )
                    {
                        case BoneEditorTool.Select:
                        {
                            if( Uni2DEditorSmoothBindingGUI.activeBone != null )
                            {
                                Uni2DEditorSmoothBindingGUI.activeBone = null;
                            }
                            else
                            {
                                Uni2DEditorSmoothBindingGUI.CurrentBoneEditMode = BoneEditMode.None;
                            }
                        }
                        break;

                        case BoneEditorTool.Move:
                        {
                            Undo.RestoreSnapshot( );
                            ms_eEditorTool = BoneEditorTool.Select;
                        }
                        break;
                    }
                    a_rEvent.Use( );
                }
                break;	// End Escape

                case KeyCode.Return:
                case KeyCode.KeypadEnter:
                {
                    ms_eEditorTool = BoneEditorTool.Select;
                    a_rEvent.Use( );
                }
                break;	// End Return / KeypadEnter
            }	// end switch( event.type )
        }	// end if( key down events )
        else
        {
            switch( a_rEvent.type )
            {
                case EventType.ValidateCommand:
                {
                    if( a_rEvent.commandName == "Delete" || a_rEvent.commandName == "UndoRedoPerformed" )
                    {
                        a_rEvent.Use( );
                    }
                }
                break;	// end ValidateCommand

                case EventType.ExecuteCommand:
                {
                    if( a_rEvent.commandName == "Delete" )
                    {
                        a_rEvent.Use( );
                    }
                    else if( a_rEvent.commandName == "UndoRedoPerformed" )
                    {
                        Uni2DEditorSmoothBindingGUI.activeBone = null;
                        ms_eEditorTool = BoneEditorTool.Select;
                        //Uni2DEditorSmoothBindingGUI.CurrentBoneEditMode = BoneEditMode.None;
                        a_rEvent.Use( );
                    }
                }
                break;	// end ExecuteCommand
            }	// end switch( event.type )
        }	// end else
    }
Ejemplo n.º 50
0
 void handleSwipe(Event e, ref Vector2 scrollPosition)
 {
     if (e.type == EventType.MouseDrag){
         if (!mouseDrag){
             if ( Mathf.Abs( e.delta.x) > ignoreMovementAreaPixels
                 || Mathf.Abs( e.delta.y) > ignoreMovementAreaPixels){
                 GUIUtility.hotControl = GUIUtility.GetControlID(FocusType.Passive);
                 mouseDrag = true;
             } else {
                 return;
             }
         }
     #if UNITY_IOS
         scrollPosition += e.delta;
     #else
         scrollPosition -= e.delta;
     #endif
         e.Use();
     } else if (mouseDrag && e.type == EventType.MouseUp){
         mouseDrag = false;
         GUIUtility.hotControl = 0;
         verticalAlignItems(ref scrollPosition);
     }
 }
Ejemplo n.º 51
0
        //This is called outside Begin/End Windows from GraphEditor.
        void ShowToolbar(Event e)
        {
            var owner = this.agent != null && agent is GraphOwner && (agent as GraphOwner).graph == this? (GraphOwner)agent : null;

            GUILayout.BeginHorizontal(EditorStyles.toolbar);
            GUI.backgroundColor = new Color(1f,1f,1f,0.5f);

            ///FILE
            if (GUILayout.Button("File", EditorStyles.toolbarDropDown, GUILayout.Width(50))){
                var menu = new GenericMenu();

            #if !UNITY_WEBPLAYER

                //Import JSON
                menu.AddItem (new GUIContent ("Import JSON"), false, ()=>
                {
                    if (allNodes.Count > 0 && !EditorUtility.DisplayDialog("Import Graph", "All current graph information will be lost. Are you sure?", "YES", "NO"))
                        return;

                    var path = EditorUtility.OpenFilePanel( string.Format("Import '{0}' Graph", this.GetType().Name), "Assets", exportFileExtension);
                    if (!string.IsNullOrEmpty(path)){
                        if ( this.Deserialize( System.IO.File.ReadAllText(path), true, null ) == null){ //true: validate, null: this._objectReferences
                            EditorUtility.DisplayDialog("Import Failure", "Please read the logs for more information", "OK", "");
                        }
                    }
                });

                //Expot JSON
                menu.AddItem (new GUIContent ("Export JSON"), false, ()=>
                {
                    var path = EditorUtility.SaveFilePanelInProject (string.Format("Export '{0}' Graph", this.GetType().Name), "", exportFileExtension, "");
                    if (!string.IsNullOrEmpty(path)){
                        System.IO.File.WriteAllText( path, this.Serialize(true, null) ); //true: pretyJson, null: this._objectReferences
                        AssetDatabase.Refresh();
                    }
                });
            #else

                menu.AddDisabledItem(new GUIContent("Import JSON (not possible with webplayer active platform)"));
                menu.AddDisabledItem(new GUIContent("Export JSON (not possible with webplayer active platform)"));

            #endif
                menu.ShowAsContext();
            }

            ///EDIT
            if (GUILayout.Button("Edit", EditorStyles.toolbarDropDown, GUILayout.Width(50))){
                var menu = new GenericMenu();

                //Bind
                if (!Application.isPlaying && owner != null && !owner.graphIsLocal){
                    menu.AddItem(new GUIContent("Bind To Owner"), false, ()=>
                    {
                        if (EditorUtility.DisplayDialog("Bind To Owner", "This will create a local copy of the graph binded to the owner.\nIt will allow you to assign direct scene references in the graph.\nContinue?", "YES", "NO")){
                            var newGraph = (Graph)EditorUtils.AddScriptableComponent(owner.gameObject, owner.graphType);
                            newGraph.hideFlags = HideFlags.HideInInspector;

                            EditorUtility.CopySerialized(owner.graph, newGraph);
                            newGraph.Validate();

                            Undo.RegisterCreatedObjectUndo(newGraph, "New Local Graph");
                            Undo.RecordObject(owner, "New Local Graph");
                            owner.graph = newGraph;
                            EditorUtility.SetDirty(owner);
                            EditorUtility.SetDirty(newGraph);
                        }
                    });
                }
                else menu.AddDisabledItem(new GUIContent("Bind To Owner"));

                //Save to asset
                if (owner != null && owner.graphIsLocal){
                    menu.AddItem(new GUIContent("Save To Asset"), false, ()=>
                    {
                        var newGraph = (Graph)EditorUtils.CreateAsset(this.GetType(), true);
                        if (newGraph != null){
                            EditorUtility.CopySerialized(this, newGraph);
                            newGraph.Validate();
                            AssetDatabase.SaveAssets();
                        }
                    });
                }
                else menu.AddDisabledItem(new GUIContent("Save To Asset"));

                //Create defined vars
                if (blackboard != null){
                    menu.AddItem(new GUIContent("Create Defined Blackboard Variables"), false, ()=>
                    {
                        if (EditorUtility.DisplayDialog("Create Defined Variables", "This will fill the current Blackboard for each defined variable parameter in the graph.\nContinue?", "YES", "NO"))
                            CreateDefinedParameterVariables(blackboard);
                    });
                }
                else menu.AddDisabledItem(new GUIContent("Create Defined Blackboard Variables"));

                menu.ShowAsContext();
            }
            //////

            ///PREFS
            if (GUILayout.Button("Prefs", EditorStyles.toolbarDropDown, GUILayout.Width(50))){
                var menu = new GenericMenu();
                menu.AddItem (new GUIContent ("Icon Mode"), NCPrefs.iconMode, ()=> {NCPrefs.iconMode = !NCPrefs.iconMode;});
                menu.AddItem (new GUIContent ("Show Node Help"), NCPrefs.showNodeInfo, ()=> {NCPrefs.showNodeInfo = !NCPrefs.showNodeInfo;});
                menu.AddItem (new GUIContent ("Show Comments"), NCPrefs.showComments, ()=> {NCPrefs.showComments = !NCPrefs.showComments;});
                menu.AddItem (new GUIContent ("Show Summary Info"), NCPrefs.showTaskSummary, ()=> {NCPrefs.showTaskSummary = !NCPrefs.showTaskSummary;});
                menu.AddItem (new GUIContent ("Log Events"), NCPrefs.logEvents, ()=>{ NCPrefs.logEvents = !NCPrefs.logEvents; });
                menu.AddItem (new GUIContent ("Grid Snap"), NCPrefs.doSnap, ()=> {NCPrefs.doSnap = !NCPrefs.doSnap;});
                if (autoSort){
                    menu.AddItem (new GUIContent ("Automatic Hierarchical Move"), NCPrefs.hierarchicalMove, ()=> {NCPrefs.hierarchicalMove = !NCPrefs.hierarchicalMove;});
                }
                menu.AddItem (new GUIContent ("Connection Mode/Curved"), NCPrefs.curveMode == 0, ()=> {NCPrefs.curveMode = 0;});
                menu.AddItem (new GUIContent ("Connection Mode/Stepped"), NCPrefs.curveMode == 1, ()=> {NCPrefs.curveMode = 1;});
                menu.AddItem (new GUIContent ("Connection Mode/Straight"), NCPrefs.curveMode == 2, ()=> {NCPrefs.curveMode = 2;});
                //menu.AddItem (new GUIContent ("Use External Inspector"), NCPrefs.useExternalInspector, ()=> {NCPrefs.useExternalInspector = !NCPrefs.useExternalInspector;});
                menu.AddItem( new GUIContent("Preferred Types Editor..."), false, ()=>{PreferedTypesEditorWindow.ShowWindow();} );
                menu.ShowAsContext();
            }
            /////////

            GUILayout.Space(10);

            ////CLICK SELECT
            if (agent != null && GUILayout.Button("Select Owner", EditorStyles.toolbarButton, GUILayout.Width(80))){
                Selection.activeObject = agent;
                EditorGUIUtility.PingObject(agent);
            }

            if (EditorUtility.IsPersistent(this) && GUILayout.Button("Select Graph", EditorStyles.toolbarButton, GUILayout.Width(80))){
                Selection.activeObject = this;
                EditorGUIUtility.PingObject(this);
            }
            ////////////////

            GUILayout.Space(10);
            GUILayout.FlexibleSpace();

            //DROPDOWN GRAPHOWNER JUMP SELECTION
            if (owner != null && !NCPrefs.isLocked){
                if (GUILayout.Button(string.Format("[{0}]", owner.gameObject.name), EditorStyles.toolbarDropDown, GUILayout.Width(120))){
                    var menu = new GenericMenu();
                    foreach(var _o in FindObjectsOfType<GraphOwner>()){
                        var o = _o;
                        menu.AddItem (new GUIContent(o.GetType().Name + "s/" + o.gameObject.name), false, ()=> { Selection.activeObject = o; Selection.selectionChanged(); });
                    }
                    menu.ShowAsContext();
                }
            }
            ////////////////////////////////////

            NCPrefs.isLocked = GUILayout.Toggle(NCPrefs.isLocked, "Lock", EditorStyles.toolbarButton);
            GUILayout.Space(2);

            GUI.backgroundColor = new Color(1, 0.8f, 0.8f, 1);
            if (GUILayout.Button("Clear", EditorStyles.toolbarButton, GUILayout.Width(50))){
                if (EditorUtility.DisplayDialog("Clear Canvas", "This will delete all nodes of the currently viewing graph!\nAre you sure?", "YES", "NO!")){
                    ClearGraph();
                    e.Use();
                    return;
                }
            }

            GUILayout.EndHorizontal();
            GUI.backgroundColor = Color.white;
        }
Ejemplo n.º 52
0
	/// <summary>
	/// Handle the specified event.
	/// </summary>

	public virtual bool ProcessEvent (Event ev)
	{
		if (label == null) return false;

		RuntimePlatform rp = Application.platform;

		bool isMac = (
			rp == RuntimePlatform.OSXEditor ||
			rp == RuntimePlatform.OSXPlayer ||
			rp == RuntimePlatform.OSXWebPlayer);

		bool ctrl = isMac ?
			((ev.modifiers & EventModifiers.Command) != 0) :
			((ev.modifiers & EventModifiers.Control) != 0);

		// http://www.tasharen.com/forum/index.php?topic=10780.0
		if ((ev.modifiers & EventModifiers.Alt) != 0) ctrl = false;

		bool shift = ((ev.modifiers & EventModifiers.Shift) != 0);

		switch (ev.keyCode)
		{
			case KeyCode.Backspace:
			{
				ev.Use();
				DoBackspace();
				return true;
			}

			case KeyCode.Delete:
			{
				ev.Use();

				if (!string.IsNullOrEmpty(mValue))
				{
					if (mSelectionStart == mSelectionEnd)
					{
						if (mSelectionStart >= mValue.Length) return true;
						++mSelectionEnd;
					}
					Insert("");
				}
				return true;
			}

			case KeyCode.LeftArrow:
			{
				ev.Use();

				if (!string.IsNullOrEmpty(mValue))
				{
					mSelectionEnd = Mathf.Max(mSelectionEnd - 1, 0);
					if (!shift) mSelectionStart = mSelectionEnd;
					UpdateLabel();
				}
				return true;
			}

			case KeyCode.RightArrow:
			{
				ev.Use();

				if (!string.IsNullOrEmpty(mValue))
				{
					mSelectionEnd = Mathf.Min(mSelectionEnd + 1, mValue.Length);
					if (!shift) mSelectionStart = mSelectionEnd;
					UpdateLabel();
				}
				return true;
			}

			case KeyCode.PageUp:
			{
				ev.Use();

				if (!string.IsNullOrEmpty(mValue))
				{
					mSelectionEnd = 0;
					if (!shift) mSelectionStart = mSelectionEnd;
					UpdateLabel();
				}
				return true;
			}

			case KeyCode.PageDown:
			{
				ev.Use();

				if (!string.IsNullOrEmpty(mValue))
				{
					mSelectionEnd = mValue.Length;
					if (!shift) mSelectionStart = mSelectionEnd;
					UpdateLabel();
				}
				return true;
			}

			case KeyCode.Home:
			{
				ev.Use();

				if (!string.IsNullOrEmpty(mValue))
				{
					if (label.multiLine)
					{
						mSelectionEnd = label.GetCharacterIndex(mSelectionEnd, KeyCode.Home);
					}
					else mSelectionEnd = 0;

					if (!shift) mSelectionStart = mSelectionEnd;
					UpdateLabel();
				}
				return true;
			}

			case KeyCode.End:
			{
				ev.Use();

				if (!string.IsNullOrEmpty(mValue))
				{
					if (label.multiLine)
					{
						mSelectionEnd = label.GetCharacterIndex(mSelectionEnd, KeyCode.End);
					}
					else mSelectionEnd = mValue.Length;

					if (!shift) mSelectionStart = mSelectionEnd;
					UpdateLabel();
				}
				return true;
			}

			case KeyCode.UpArrow:
			{
				ev.Use();

				if (!string.IsNullOrEmpty(mValue))
				{
					mSelectionEnd = label.GetCharacterIndex(mSelectionEnd, KeyCode.UpArrow);
					if (mSelectionEnd != 0) mSelectionEnd += mDrawStart;
					if (!shift) mSelectionStart = mSelectionEnd;
					UpdateLabel();
				}
				return true;
			}

			case KeyCode.DownArrow:
			{
				ev.Use();

				if (!string.IsNullOrEmpty(mValue))
				{
					mSelectionEnd = label.GetCharacterIndex(mSelectionEnd, KeyCode.DownArrow);
					if (mSelectionEnd != label.processedText.Length) mSelectionEnd += mDrawStart;
					else mSelectionEnd = mValue.Length;
					if (!shift) mSelectionStart = mSelectionEnd;
					UpdateLabel();
				}
				return true;
			}

			// Select all
			case KeyCode.A:
			{
				if (ctrl)
				{
					ev.Use();
					mSelectionStart = 0;
					mSelectionEnd = mValue.Length;
					UpdateLabel();
				}
				return true;
			}

			// Copy
			case KeyCode.C:
			{
				if (ctrl)
				{
					ev.Use();
					NGUITools.clipboard = GetSelection();
				}
				return true;
			}

			// Paste
			case KeyCode.V:
			{
				if (ctrl)
				{
					ev.Use();
					Insert(NGUITools.clipboard);
				}
				return true;
			}

			// Cut
			case KeyCode.X:
			{
				if (ctrl)
				{
					ev.Use();
					NGUITools.clipboard = GetSelection();
					Insert("");
				}
				return true;
			}
		}
		return false;
	}
Ejemplo n.º 53
0
 public virtual bool ProcessEvent(Event ev)
 {
     if (this.label == null)
     {
         return false;
     }
     RuntimePlatform platform = Application.platform;
     bool flag = platform == RuntimePlatform.OSXEditor || platform == RuntimePlatform.OSXPlayer || platform == RuntimePlatform.OSXWebPlayer;
     bool flag2 = (!flag) ? ((ev.modifiers & EventModifiers.Control) != EventModifiers.None) : ((ev.modifiers & EventModifiers.Command) != EventModifiers.None);
     if ((ev.modifiers & EventModifiers.Alt) != EventModifiers.None)
     {
         flag2 = false;
     }
     bool flag3 = (ev.modifiers & EventModifiers.Shift) != EventModifiers.None;
     KeyCode keyCode = ev.keyCode;
     switch (keyCode)
     {
     case KeyCode.UpArrow:
         ev.Use();
         if (!string.IsNullOrEmpty(this.mValue))
         {
             this.mSelectionEnd = this.label.GetCharacterIndex(this.mSelectionEnd, KeyCode.UpArrow);
             if (this.mSelectionEnd != 0)
             {
                 this.mSelectionEnd += UIInput.mDrawStart;
             }
             if (!flag3)
             {
                 this.mSelectionStart = this.mSelectionEnd;
             }
             this.UpdateLabel();
         }
         return true;
     case KeyCode.DownArrow:
         ev.Use();
         if (!string.IsNullOrEmpty(this.mValue))
         {
             this.mSelectionEnd = this.label.GetCharacterIndex(this.mSelectionEnd, KeyCode.DownArrow);
             if (this.mSelectionEnd != this.label.processedText.Length)
             {
                 this.mSelectionEnd += UIInput.mDrawStart;
             }
             else
             {
                 this.mSelectionEnd = this.mValue.Length;
             }
             if (!flag3)
             {
                 this.mSelectionStart = this.mSelectionEnd;
             }
             this.UpdateLabel();
         }
         return true;
     case KeyCode.RightArrow:
         ev.Use();
         if (!string.IsNullOrEmpty(this.mValue))
         {
             this.mSelectionEnd = Mathf.Min(this.mSelectionEnd + 1, this.mValue.Length);
             if (!flag3)
             {
                 this.mSelectionStart = this.mSelectionEnd;
             }
             this.UpdateLabel();
         }
         return true;
     case KeyCode.LeftArrow:
         ev.Use();
         if (!string.IsNullOrEmpty(this.mValue))
         {
             this.mSelectionEnd = Mathf.Max(this.mSelectionEnd - 1, 0);
             if (!flag3)
             {
                 this.mSelectionStart = this.mSelectionEnd;
             }
             this.UpdateLabel();
         }
         return true;
     case KeyCode.Insert:
         IL_AD:
         switch (keyCode)
         {
         case KeyCode.A:
             if (flag2)
             {
                 ev.Use();
                 this.mSelectionStart = 0;
                 this.mSelectionEnd = this.mValue.Length;
                 this.UpdateLabel();
             }
             return true;
         case KeyCode.B:
             IL_C3:
             switch (keyCode)
             {
             case KeyCode.V:
                 if (flag2)
                 {
                     ev.Use();
                     this.Insert(NGUITools.clipboard);
                 }
                 return true;
             case KeyCode.W:
                 IL_D9:
                 if (keyCode == KeyCode.Backspace)
                 {
                     ev.Use();
                     this.DoBackspace();
                     return true;
                 }
                 if (keyCode != KeyCode.Delete)
                 {
                     return false;
                 }
                 ev.Use();
                 if (!string.IsNullOrEmpty(this.mValue))
                 {
                     if (this.mSelectionStart == this.mSelectionEnd)
                     {
                         if (this.mSelectionStart >= this.mValue.Length)
                         {
                             return true;
                         }
                         this.mSelectionEnd++;
                     }
                     this.Insert(string.Empty);
                 }
                 return true;
             case KeyCode.X:
                 if (flag2)
                 {
                     ev.Use();
                     NGUITools.clipboard = this.GetSelection();
                     this.Insert(string.Empty);
                 }
                 return true;
             }
             goto IL_D9;
         case KeyCode.C:
             if (flag2)
             {
                 ev.Use();
                 NGUITools.clipboard = this.GetSelection();
             }
             return true;
         }
         goto IL_C3;
     case KeyCode.Home:
         ev.Use();
         if (!string.IsNullOrEmpty(this.mValue))
         {
             if (this.label.multiLine)
             {
                 this.mSelectionEnd = this.label.GetCharacterIndex(this.mSelectionEnd, KeyCode.Home);
             }
             else
             {
                 this.mSelectionEnd = 0;
             }
             if (!flag3)
             {
                 this.mSelectionStart = this.mSelectionEnd;
             }
             this.UpdateLabel();
         }
         return true;
     case KeyCode.End:
         ev.Use();
         if (!string.IsNullOrEmpty(this.mValue))
         {
             if (this.label.multiLine)
             {
                 this.mSelectionEnd = this.label.GetCharacterIndex(this.mSelectionEnd, KeyCode.End);
             }
             else
             {
                 this.mSelectionEnd = this.mValue.Length;
             }
             if (!flag3)
             {
                 this.mSelectionStart = this.mSelectionEnd;
             }
             this.UpdateLabel();
         }
         return true;
     case KeyCode.PageUp:
         ev.Use();
         if (!string.IsNullOrEmpty(this.mValue))
         {
             this.mSelectionEnd = 0;
             if (!flag3)
             {
                 this.mSelectionStart = this.mSelectionEnd;
             }
             this.UpdateLabel();
         }
         return true;
     case KeyCode.PageDown:
         ev.Use();
         if (!string.IsNullOrEmpty(this.mValue))
         {
             this.mSelectionEnd = this.mValue.Length;
             if (!flag3)
             {
                 this.mSelectionStart = this.mSelectionEnd;
             }
             this.UpdateLabel();
         }
         return true;
     }
     goto IL_AD;
 }
Ejemplo n.º 54
0
    void OnEditingKeyDown( Event e )
    {
        if( e.keyCode == KeyCode.Escape || e.keyCode == KeyCode.Return )
        {
            ChangeState( NodeEditorState.Idle );
            e.Use();
        }

        Repaint();
    }
        protected override void OnMouseDown( Event e )
        {
            switch( e.button )
            {
                case 0:
                    if ( m_linkFrom != null )
                    {
                        BehaviorNodeControl node = IsPointOnNode( e.mousePosition );
                        
                        if ( node != null )
                        {
                            m_linkFrom.SetOutput( node, m_linkFromIndex );
                        }

                        m_linkFrom = null;
                        m_linkLine.From = Vector2.zero;
                        m_linkLine.To = Vector2.zero;

                        e.Use();
                    }
                break;

                case 1:
                    if ( m_linkFrom != null )
                    {
                        m_linkFrom = null;
                        m_linkLine.From = Vector2.zero;
                        m_linkLine.To = Vector2.zero;

                        e.Use();
                    }
                break;
            }
        }
Ejemplo n.º 56
0
 void OnIdleContextClick( Event e )
 {
     if( currentNode == null )
     {
         GenericMenu menu = new GenericMenu();
         menu.AddItem( new GUIContent("New Menu"), false, Callback, "newScreen" );
         menu.ShowAsContext();
         e.Use();
     }
 }
Ejemplo n.º 57
0
        void OnMouseUp(SceneView sceneView, Event e)
        {
            if (mouseIsDragging || CurrentSettings.CurrentMode == MainMode.Free || EditorHelper.IsMousePositionNearSceneGizmo(e.mousePosition))
            {
                return;
            }

            // Left click - select
            if (e.button == 0)
            {
                Ray ray = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);

            //                RaycastHit hit = new RaycastHit();
            //
            //                int layerMask = 1 << LayerMask.NameToLayer("CSGMesh");
            //                // Invert the layer mask
            //                layerMask = ~layerMask;
            //
            //                if (EnumHelper.IsFlagSet(e.modifiers, EventModifiers.Shift)
            //                   || EnumHelper.IsFlagSet(e.modifiers, EventModifiers.Control)
            //                   || EnumHelper.IsFlagSet(e.modifiers, EventModifiers.Command))
            //                {
            //                    // Shift mode means only add what they click (clicking nothing does nothing)
            //                    if (Physics.Raycast(ray, out hit, float.PositiveInfinity, layerMask))
            //                    {
            //                        if (Selection.objects == null || Selection.objects.Length == 0)
            //                        {
            //                            // Didn't already have a selection, so short cut via activeTransform
            //                            Selection.activeObject = hit.transform.gameObject;
            //                        }
            //                        else
            //                        {
            //                            List<UnityEngine.Object> objects = new List<UnityEngine.Object>(Selection.objects);
            //
            //                            if (objects.Contains(hit.transform.gameObject))
            //                            {
            //                                objects.Remove(hit.transform.gameObject);
            //                            }
            //                            else
            //                            {
            //                                objects.Add(hit.transform.gameObject);
            //                            }
            //                            Selection.objects = objects.ToArray();
            //                        }
            //                    }
            //                }
            //                else
                {
                    List<RaycastHit> hits = RaycastBrushesAll(ray);

                    GameObject selectedObject = null;

                    if(hits.Count == 0) // Didn't hit anything, blank the selection
                    {
                        previousHits.Clear();
                    }
                    else if(hits.Count == 1) // Only hit one thing, no ambiguity, this is what is selected
                    {
                        selectedObject = hits[0].collider.gameObject;
                        previousHits.Clear();
                    }
                    else
                    {
                        // First try and select anything other than what has been previously hit
                        for (int i = 0; i < hits.Count; i++)
                        {
                            if(!previousHits.Contains(hits[i].collider.gameObject))
                            {
                                selectedObject = hits[i].collider.gameObject;
                                break;
                            }
                        }

                        // Only found previously hit objects
                        if(selectedObject == null)
                        {
                            // Walk backwards to find the oldest previous hit that has been hit by this ray
                            for (int i = previousHits.Count-1; i >= 0 && selectedObject == null; i--)
                            {
                                for (int j = 0; j < hits.Count; j++)
                                {
                                    if(hits[j].collider.gameObject == previousHits[i])
                                    {
                                        selectedObject = previousHits[i];
                                        break;
                                    }
                                }
                            }
                        }
                    }

                    if (EnumHelper.IsFlagSet(e.modifiers, EventModifiers.Shift)
                        || EnumHelper.IsFlagSet(e.modifiers, EventModifiers.Control)
                        || EnumHelper.IsFlagSet(e.modifiers, EventModifiers.Command))
                    {
                        List<UnityEngine.Object> objects = new List<UnityEngine.Object>(Selection.objects);

                        if (objects.Contains(selectedObject))
                        {
                            objects.Remove(selectedObject);
                        }
                        else
                        {
                            objects.Add(selectedObject);
                        }
                        Selection.objects = objects.ToArray();
                    }
                    else
                    {
                        Selection.activeGameObject = selectedObject;
                    }

                    if(selectedObject != null)
                    {
                        previousHits.Remove(selectedObject);
                        // Most recent hit
                        previousHits.Insert(0, selectedObject);
                    }
                }
                e.Use();
            }
        }
Ejemplo n.º 58
0
    public void ProcessKeyboard(Event e)
    {
        if (e == null)
            return;

        if (GUIUtility.keyboardControl == 0)
        if (e.isKey) {
            ProcessKey (e);
        }

        if (e.isKey)
        if (e.keyCode == KeyCode.Tab || e.character == '\t')
            e.Use ();
    }
Ejemplo n.º 59
0
	/// <summary>
	/// Handle the specified event.
	/// </summary>

	protected virtual bool ProcessEvent (Event ev)
	{
		if (label == null) return false;

		RuntimePlatform rp = Application.platform;

		bool isMac = (
			rp == RuntimePlatform.OSXEditor ||
			rp == RuntimePlatform.OSXPlayer ||
			rp == RuntimePlatform.OSXWebPlayer);

		bool ctrl = isMac ?
			((ev.modifiers & EventModifiers.Command) != 0) :
			((ev.modifiers & EventModifiers.Control) != 0);

		bool shift = ((ev.modifiers & EventModifiers.Shift) != 0);

		switch (ev.keyCode)
		{
			case KeyCode.Backspace:
			{
				ev.Use();
				DoBackspace();
				return true;
			}

			case KeyCode.Delete:
			{
				ev.Use();

				if (!string.IsNullOrEmpty(mValue))
				{
					if (mSelectionStart == mSelectionEnd)
					{
						if (mSelectionStart >= mValue.Length) return true;
						++mSelectionEnd;
					}
					Insert("");
				}
				return true;
			}

			case KeyCode.LeftArrow:
			{
				ev.Use();

				if (!string.IsNullOrEmpty(mValue))
				{
					mSelectionEnd = Mathf.Max(mSelectionEnd - 1, 0);
					if (!shift) mSelectionStart = mSelectionEnd;
					UpdateLabel();
				}
				return true;
			}

			case KeyCode.RightArrow:
			{
				ev.Use();

				if (!string.IsNullOrEmpty(mValue))
				{
					mSelectionEnd = Mathf.Min(mSelectionEnd + 1, mValue.Length);
					if (!shift) mSelectionStart = mSelectionEnd;
					UpdateLabel();
				}
				return true;
			}

			case KeyCode.PageUp:
			{
				ev.Use();

				if (!string.IsNullOrEmpty(mValue))
				{
					mSelectionEnd = 0;
					if (!shift) mSelectionStart = mSelectionEnd;
					UpdateLabel();
				}
				return true;
			}

			case KeyCode.PageDown:
			{
				ev.Use();

				if (!string.IsNullOrEmpty(mValue))
				{
					mSelectionEnd = mValue.Length;
					if (!shift) mSelectionStart = mSelectionEnd;
					UpdateLabel();
				}
				return true;
			}

			case KeyCode.Home:
			{
				ev.Use();

				if (!string.IsNullOrEmpty(mValue))
				{
					if (label.multiLine)
					{
						mSelectionEnd = label.GetCharacterIndex(mSelectionEnd, KeyCode.Home);
					}
					else mSelectionEnd = 0;

					if (!shift) mSelectionStart = mSelectionEnd;
					UpdateLabel();
				}
				return true;
			}

			case KeyCode.End:
			{
				ev.Use();

				if (!string.IsNullOrEmpty(mValue))
				{
					if (label.multiLine)
					{
						mSelectionEnd = label.GetCharacterIndex(mSelectionEnd, KeyCode.End);
					}
					else mSelectionEnd = mValue.Length;

					if (!shift) mSelectionStart = mSelectionEnd;
					UpdateLabel();
				}
				return true;
			}

			case KeyCode.UpArrow:
			{
				ev.Use();

				if (!string.IsNullOrEmpty(mValue))
				{
					mSelectionEnd = label.GetCharacterIndex(mSelectionEnd, KeyCode.UpArrow);
					if (mSelectionEnd != 0) mSelectionEnd += mDrawStart;
					if (!shift) mSelectionStart = mSelectionEnd;
					UpdateLabel();
				}
				return true;
			}

			case KeyCode.DownArrow:
			{
				ev.Use();

				if (!string.IsNullOrEmpty(mValue))
				{
					mSelectionEnd = label.GetCharacterIndex(mSelectionEnd, KeyCode.DownArrow);
					if (mSelectionEnd != label.processedText.Length) mSelectionEnd += mDrawStart;
					else mSelectionEnd = mValue.Length;
					if (!shift) mSelectionStart = mSelectionEnd;
					UpdateLabel();
				}
				return true;
			}

			// Select all
			case KeyCode.A:
			{
				if (ctrl)
				{
					ev.Use();
					mSelectionStart = 0;
					mSelectionEnd = string.IsNullOrEmpty(mValue) ? 0 : mValue.Length;
					UpdateLabel();
				}
				return true;
			}

			// Copy
			case KeyCode.C:
			{
				if (ctrl)
				{
					ev.Use();
					NGUITools.clipboard = GetSelection();
				}
				return true;
			}

			// Paste
			case KeyCode.V:
			{
				if (ctrl)
				{
					ev.Use();
					Insert(NGUITools.clipboard);
				}
				return true;
			}

			// Cut
			case KeyCode.X:
			{
				if (ctrl)
				{
					ev.Use();
					NGUITools.clipboard = GetSelection();
					Insert("");
				}
				return true;
			}

			// Submit
			case KeyCode.Return:
			case KeyCode.KeypadEnter:
			{
				ev.Use();

				bool newLine = (onReturnKey == OnReturnKey.NewLine) ||
					(onReturnKey == OnReturnKey.Default &&
					label.multiLine && !ctrl &&
					label.overflowMethod != UILabel.Overflow.ClampContent &&
					validation == Validation.None);

				if (newLine)
				{
					Insert("\n");
				}
				else
				{
					UICamera.currentScheme = UICamera.ControlScheme.Controller;
					UICamera.currentKey = ev.keyCode;
					Submit();
					UICamera.currentKey = KeyCode.None;
				}
				return true;
			}
		}
		return false;
	}
Ejemplo n.º 60
0
        private void HandleKeys( Event e )
        {
            switch ( e.type ) {
                case EventType.KeyDown:
                    SetValue( e.keyCode, true );
                    ShiftHack( e.shift );
                    ControlHack( e.control );
                    AltHack( e.alt );
                    break;
                case EventType.KeyUp:
                    SetValue( e.keyCode, false );
                    ShiftHack( e.shift );
                    ControlHack( e.control );
                    AltHack( e.alt );
                    break;
                case EventType.Repaint:
                case EventType.Layout:
                    ShiftHack( e.shift );
                    break;
                default:
                    break;
            }

            #if UNITY_EDITOR_OSX
            if ( e.isKey ) {
            if ( e.keyCode == KeyCode.DownArrow || e.keyCode == KeyCode.LeftArrow || e.keyCode == KeyCode.RightArrow || e.keyCode == KeyCode.UpArrow ) {
                e.Use();
            }
            }
            #endif
        }