Beispiel #1
0
    private IObjectBase HandleObject;       // 判断鼠标持有的对象

    private void UpdateEvent()
    {
        RuleMouseEventBase ruleEvent = GetUpdateEvent(Event.current);

        if (null == ruleEvent)
        {
            return;
        }

        if (ruleEvent is RuleMouseDownEvent)
        {
            RuleMouseDownEvent e = ruleEvent as RuleMouseDownEvent;

            HandleObject = e.HandleTarget;
        }
        else if (ruleEvent is RuleMouseDragEvent)
        {
            RuleMouseDragEvent e = ruleEvent as RuleMouseDragEvent;

            if (null != HandleObject)
            {
                HandleObject.SetPosition(e.CurrentPos);
            }
        }
        else if (ruleEvent is RuleMouseUpEvent)
        {
            RuleMouseUpEvent e = ruleEvent as RuleMouseUpEvent;

            HandleObject = e.HandleTarget;
        }
    }
Beispiel #2
0
    private bool ___isMouseDown;            // 判断鼠标是否是落下状态

    public RuleMouseEventBase GetUpdateEvent(Event e)
    {
        if (null == SelectedRuleObject)
        {
            return(null);
        }

        if (null == e)
        {
            return(null);
        }

        if (e.button == 1 && e.type == EventType.ContextClick)
        {
            var pTarget = SelectedRuleObject.TryGetExecuterAtPos(e.mousePosition);
            if (null == pTarget)
            {
                return(null);
            }

            RuleContextEvent ruleContextEvent = new RuleContextEvent(e.mousePosition, pTarget);
            return(ruleContextEvent);
        }

        if (e.button != 0)
        {
            return(null);
        }

        if (mouseOverWindow != this)
        {
            RuleMouseEventBase eventClear = CheckOutWindow();
            ___isMouseDown = false;
            ___target      = null;
            return(eventClear);
        }

        switch (e.type)
        {
        case EventType.mouseDown:
        {
            ___isMouseDown         = true;
            ___mStartClickPosition = e.mousePosition;
            ___mLastPosition       = e.mousePosition;

            ___target = SelectedRuleObject.TryGetExecuterAtPos(e.mousePosition);
            if (null == ___target)
            {
                return(null);
            }
            RuleMouseDownEvent downEvent = new RuleMouseDownEvent(e.mousePosition, ___target);
            return(downEvent);
        }

        case EventType.mouseUp:
        {
            ___target = SelectedRuleObject.TryGetExecuterAtPos(e.mousePosition);
            RuleMouseUpEvent upEvent = new RuleMouseUpEvent(___mStartClickPosition, e.mousePosition, ___target);
            ___isMouseDown = false;
            return(upEvent);
        }

        case EventType.mouseDrag:
        {
            if (___isMouseDown && ___target != null)
            {
                RuleMouseDragEvent dragEvent = new RuleMouseDragEvent(___mLastPosition, e.mousePosition, ___target);
                ___mLastPosition = e.mousePosition;
                return(dragEvent);
            }
            return(null);
        }
        }
        return(null);
    }