internal void DispatchEvent(PopupEventArgs eventArgs)
        {
            switch (eventArgs.Type)
            {
            case "close":
                OnClose?.Invoke(eventArgs);
                break;

            case "drag":
                OnDrag?.Invoke(eventArgs);
                break;

            case "dragend":
                OnDragEnd?.Invoke(eventArgs);
                break;

            case "dragstart":
                OnDragStart?.Invoke(eventArgs);
                break;

            case "open":
                OnOpen?.Invoke(eventArgs);
                break;
            }
        }
예제 #2
0
        private void FixedUpdate()
        {
            if (IsPressing)
            {
                Ray ray = mainCamera.ScreenPointToRay(Input.mousePosition);
                if (plane.Raycast(ray, out float distance))
                {
                    // Restrict movement along the specified LOCAL axes, then
                    // clamp the targeted position based on the specified WORLD
                    // bounds and maximum distance from starting position.

                    Vector3 targetLocalPosition = transform.InverseTransformPoint(TargetMousePosition = ray.GetPoint(distance)) - offsetPosition;
                    targetLocalPosition.x = localMovement.x ? targetLocalPosition.x : 0;
                    targetLocalPosition.y = localMovement.y ? targetLocalPosition.y : 0;
                    targetLocalPosition.z = localMovement.z ? targetLocalPosition.z : 0;

                    targetWorldPosition   = startWorldPosition + Vector3.ClampMagnitude(transform.TransformPoint(targetLocalPosition) - startWorldPosition, maxDistance);
                    targetWorldPosition.x = Mathf.Clamp(targetWorldPosition.x, worldBounds.center.x - worldBounds.extents.x / 2f, worldBounds.center.x + worldBounds.extents.x / 2f);
                    targetWorldPosition.y = Mathf.Clamp(targetWorldPosition.y, worldBounds.center.y - worldBounds.extents.y / 2f, worldBounds.center.y + worldBounds.extents.y / 2f);
                    targetWorldPosition.z = Mathf.Clamp(targetWorldPosition.z, worldBounds.center.z - worldBounds.extents.z / 2f, worldBounds.center.z + worldBounds.extents.z / 2f);

                    if (draggable)
                    {
                        transform.position = targetWorldPosition;
                    }

                    OnDrag.Invoke();
                }
            }
        }
예제 #3
0
 /// <summary>
 /// Fires when we mousemove
 /// </summary>
 private void Drag(Object sender, MouseEventArgs e)
 {
     // only fire if we are dragging
     if (PointIsOnPadding(e.Location))
     {
         Cursor = Cursors.SizeNS;
     }
     else
     {
         Cursor = Cursors.SizeAll;
     }
     if (Dragging)
     {
         if (DraggingOnPadding)
         {
             int x = MouseDownLocation.X - e.X;
             int y = MouseDownLocation.Y - e.Y;
             Height = MouseDownSize.Height - y;
             Width  = MouseDownSize.Width - x;
         }
         else
         {
             // set the new location and invoke event
             Left = e.X + Left - MouseDownLocation.X;
             Top  = e.Y + Top - MouseDownLocation.Y;
             OnDrag?.Invoke();
         }
     }
 }
예제 #4
0
        private void Update()
        {
            if (IsTripleTouch)
            {
                OnTripleTouch?.Invoke();
                return;
            }

            if (StaticUtilities.IsPointerOverUIObject())
            {
                return;
            }

            var inputPosition = Input.mousePosition;

            if (IsPressed)
            {
                OnPress?.Invoke(inputPosition);
            }

            if (IsDrag)
            {
                OnDrag?.Invoke(inputPosition);
            }

            if (IsReleased)
            {
                OnRelease?.Invoke();
            }
        }
예제 #5
0
    private void OnMouseDrag()
    {
        if (PauseManager.Instance != null && PauseManager.Instance.IsPause)
        {
            return;
        }

        if (StartButton.Instance != null)
        {
            StartButton.Instance.Drag();
        }

        HandleBeat();
        lastTouchTime += Time.deltaTime;
        OnDrag?.Invoke();

        if (!counted)
        {
            float scale = (scalePower / necessaryTouchTime + 1) * Time.deltaTime;
            transform.localScale -= new Vector3(scale, scale, scale);

            if (lastTouchTime > necessaryTouchTime)
            {
                Beat();
            }
        }

        blood.Fill(true, 0.0002f / necessaryTouchTime * BPM.Instance?.Bpm ?? 60);
    }
예제 #6
0
 internal protected virtual void TriggerOnDrag(Component sender, int x, int y, MouseButton button)
 {
     if (OnDrag != null)
     {
         OnDrag.Invoke(new MouseButtonEventArgs(sender, x, y, button));
     }
 }
예제 #7
0
 public static void InitViewportControl(DragReceiver drag_)
 {
     _drag = drag_;
     _drag.WhenDragBegin = d => {
         _focusOverride             = _dragFocusOverride;
         _dragInertiaValue          = 0;
         CameraSystem.WorldPosition = MainCamera.transform.position;
     };
     _drag.WhenDrag = (d, offset, pos) => {
         var targetX = CameraSystem.X + offset.x * UnitPerPixel;
         var targetY = CameraSystem.Y + offset.y * UnitPerPixel;
         if (PositionLimit != null)
         {
             (targetX, targetY) = PositionLimit.Limit(targetX, targetY);
         }
         MainCamera.transform.position = CameraSystem.SystemToWorld(
             targetX,
             targetY,
             CameraSystem.Z);
         OnDrag.Invoke(offset, new Vector3(targetX, targetY, CameraSystem.Z));
     };
     _drag.WhenDragEnd = (d, delta) => {
         _focusOverride             = false;
         _dragInertiaValue          = delta.magnitude;
         _dragInertiaDelta          = delta / _dragInertiaValue;
         CameraSystem.WorldPosition = MainCamera.transform.position;
     };
     _drag.WhenPinch = (d, start, distance) => {
         var diff = (distance - start) * zoomSetting.dragFactor * zoomSetting.range * _screenHeightInverse;
         TargetZoom(_zoomTarget - diff);
     };
     ViewportControl(true);
 }
예제 #8
0
    private void OnEnable()
    {
        i = this;

        onClick += () => SetVectorFromClick(ref clickedPosition);
        onDrag  += () => draggedPosition = GetRaycastLocation();
    }
예제 #9
0
 public static void Clear()
 {
     OnDrag.Clear();
     OnZoom.Clear();
     _popupMessage?.Clear();
     _fadeMessage?.Clear();
     MainCanvas.DestroyChildren();
 }
예제 #10
0
 /// <summary>
 /// Triggers drag event if needed
 /// </summary>
 private void Update()
 {
     if (_isDragging && transform.hasChanged)
     {
         transform.hasChanged = false;
         OnDrag?.Invoke();
     }
 }
예제 #11
0
 void Update()
 {
     if (isDragging)
     {
         Vector2 mouseTranslation = Camera.main.ScreenToWorldPoint(Mouse.current.position.ReadValue()) - transform.position;
         transform.Translate(mouseTranslation);
         OnDrag.Invoke(this, transform.position);
     }
 }
예제 #12
0
    void Update()
    {
        if (Input.touches.Length < 0)
        {
            return;
        }

        if (Input.touches.Length > 0 && Input.GetTouch(0).phase == TouchPhase.Began)
        {
            this._downPossition = Input.GetTouch(0).position;
        }

        if (this._downPossition == Vector2.zero)
        {
            return;
        }
        else if (this._dragTimer > 0)
        {
            this._dragTimer -= Time.deltaTime;
        }

        if (Input.GetTouch(0).phase == TouchPhase.Moved)
        {
            this._currentPossiton = Input.GetTouch(0).position;
            float distance = this.GetSwipeDistance(this._downPossition, this._currentPossiton);

            if (distance != 0 && this._dragTimer > 0)
            {
                this._swiping = true;
                OnMove?.Invoke(distance);
            }
            else if (this._dragTimer <= 0 && !this._swiping)
            {
                OnDrag?.Invoke(this._currentPossiton);
            }
        }

        if (Input.GetTouch(0).phase == TouchPhase.Ended)
        {
            this._upPossition = Input.GetTouch(0).position;

            int direction = this.GetSwipeDirection(this._downPossition, this._upPossition);

            if (direction != 0)
            {
                this._swiping = false;
                OnSwipe?.Invoke(direction);
            }
            else if (!this._swiping)
            {
                OnTouch?.Invoke(this._downPossition);
            }

            this._dragTimer     = this._dragTimerReset;
            this._downPossition = Vector2.zero;
        }
    }
예제 #13
0
        void _update_drag(ICogaManager coga)
        {
            var vel = (coga.MousePosition - mousepos_lastframe);

            if (vel != Vector2.Zero)
            {
                OnDrag?.Invoke(Parent, vel);
            }
        }
예제 #14
0
        public static void Drag(PointerEventData eventData)
        {
            if (currentDragModel == null)
            {
                throw new ArgumentException("Can not drag, BeginDrag() was never called.");
            }

            OnDrag?.Invoke(currentDragModel, eventData);
            handler.Drag(currentDragModel, eventData);
        }
예제 #15
0
        /// <summary>
        /// Необходмо вызывать при передвижении мыши
        /// </summary>
        public void MouseMove(MouseEventArgs e)
        {
            if (!_drag)
            {
                return;
            }

            _rectangle.X = e.X - Radius / 2f;
            _rectangle.Y = e.Y - Radius / 2f;
            OnDrag?.Invoke(e.Location);
        }
        private void Timeline_MouseMove(object sender, MouseEventArgs e)
        {
            if (_dragging)
            {
                var pos = (e.Location.X - SideRenderOffset) / (Width - SideRenderOffset * 2f);

                pos = Math.Max(Math.Min(pos, 1), 0);

                OnDrag?.Invoke(this, pos);
            }
        }
예제 #17
0
 public void Update(float time)
 {
     if (lastPointerDownTime != null)
     {
         if (time - lastPointerDownTime > dragThresold ||
             Vector3.Distance(mousePos, Input.mousePosition) > distanceThresold)
         {
             OnDrag?.Invoke();
             lastPointerDownTime = null;
         }
     }
 }
예제 #18
0
    private void OnDisable()
    {
        foreach (Delegate d in onClick.GetInvocationList())
        {
            onClick -= d as OnClick;
        }

        foreach (Delegate d in onDrag.GetInvocationList())
        {
            onDrag -= d as OnDrag;
        }
    }
예제 #19
0
    void IDragHandler.OnDrag(PointerEventData eventData)
    {
        var timeoffset = Time.time - lastTime;
        var offset     = eventData.position - lastPos;

        lastPos  = eventData.position;
        lastTime = Time.time;
        if (OnDrag != null)
        {
            OnDrag.Invoke(offset, timeoffset);
        }
    }
예제 #20
0
 private static void Drag(object sender, EventArgs e)
 {
     if (translateVector.Length() == 0)
     {
         return;
     }
     foreach (var item in TargetList)
     {
         item.Location = targetStartPosList[item].Add(translateVector);
     }
     OnDrag?.Invoke(TargetList.ToArray());
 }
예제 #21
0
 private void Hold(Vector2 position)
 {
     if (isDragging)
     {
         rectTransform.position = position;
     }
     else if ((position - startTouchPosition).sqrMagnitude >= MinDistanceToDrag * MinDistanceToDrag && slot.LootItem != null)
     {
         isDragging = true;
         OnDrag?.Invoke(slot);
         rectTransform.SetParent(parentTransform.root);
     }
 }
예제 #22
0
        protected virtual void Update()
        {
            // Store
            var oldPosition = transform.localPosition;

            // Get the fingers we want to use
            var fingers = Use.GetFingers();

            // Calculate the screenDelta value based on these fingers
            var screenDelta = LeanGesture.GetScreenDelta(fingers);

            if (screenDelta != Vector2.zero)
            {
                // Perform the translation
                if (transform is RectTransform)
                {
                    TranslateUI(screenDelta);
                }
                else
                {
                    Translate(screenDelta);
                }
            }

            // Increment
            remainingTranslation += transform.localPosition - oldPosition;

            // Get t value
            var factor = LeanTouch.GetDampenFactor(Dampening, Time.deltaTime);

            // Dampen remainingDelta
            var newRemainingTranslation = Vector3.Lerp(remainingTranslation, Vector3.zero, factor);

            // Shift this transform by the change in delta
            Vector3 newPosition = oldPosition + remainingTranslation - newRemainingTranslation;

            transform.localPosition = newPosition;

            if (Vector3.Distance(oldPosition, newPosition) > 0)
            {
                OnDrag?.Invoke(oldPosition - newPosition);
            }

            if (fingers.Count == 0 && Inertia > 0.0f && Dampening > 0.0f)
            {
                newRemainingTranslation = Vector3.Lerp(newRemainingTranslation, remainingTranslation, Inertia);
            }

            // Update remainingDelta with the dampened value
            remainingTranslation = newRemainingTranslation;
        }
예제 #23
0
        protected virtual void Update()
        {
            // Get the fingers we want to use
            var fingers = Use.GetFingers();

            if (fingers.Count > 0)
            {
                Vector2 swipeDelta = fingers[0].SwipeScreenDelta;
                if (swipeDelta != Vector2.zero)
                {
                    OnDrag?.Invoke(swipeDelta, (startPosition + swipeDelta));
                }
            }
        }
예제 #24
0
    private void FireDragEvent()
    {
        GameObject    hitObj = GetHitGameObject(gestureFinger1.position);
        DragEventArgs args   = new DragEventArgs(gestureFinger1, hitObj);

        OnDrag?.Invoke(this, args);

        if (hitObj != null)
        {
            if (hitObj.TryGetComponent(out IDraggable draggable))
            {
                draggable.OnDrag(args);
            }
        }
    }
예제 #25
0
파일: Knob.cs 프로젝트: icemile/CodeProject
        /// <summary>
        /// Response mouse left button drag.
        /// </summary>
        protected virtual void OnMouseDrag()
        {
            if (!isEnabled)
            {
                return;
            }

            Angle += Input.GetAxis(inputAxis) * rotateSpeed * Time.deltaTime;
            if (rotateLimit)
            {
                Angle = Mathf.Clamp(Angle, angleRange.min, angleRange.max);
            }
            Rotate(Angle);
            OnDrag.Invoke();
        }
예제 #26
0
 static int SetDragCallBack(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 2);
         ScrollRectExtend obj  = (ScrollRectExtend)ToLua.CheckObject <ScrollRectExtend>(L, 1);
         OnDrag           arg0 = (OnDrag)ToLua.CheckDelegate <OnDrag>(L, 2);
         obj.SetDragCallBack(arg0);
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
예제 #27
0
    void Update()
    {
        //Mouse
        bool  isMouse    = Input.GetMouseButton(0) || Input.GetMouseButtonDown(0) || Input.GetMouseButtonUp(0);
        Touch mouseTouch = new Touch();

        mouseTouch.position = Input.mousePosition;
        mouseTouch.phase    = Input.GetMouseButton(0) ? UnityEngine.TouchPhase.Moved : mouseTouch.phase;
        mouseTouch.phase    = Input.GetMouseButtonDown(0) ? UnityEngine.TouchPhase.Began : mouseTouch.phase;
        mouseTouch.phase    = Input.GetMouseButtonUp(0) ? UnityEngine.TouchPhase.Ended : mouseTouch.phase;

        if (Input.touchCount != 1 && !isMouse && !drag.isDragging)
        {
            drag.isDragging = false;
            return;
        }



        Touch touch = isMouse ? mouseTouch : Input.touches[0];

        if (touch.phase == TouchPhase.Began)
        {
            drag.isDragging = true;
            drag.localStart = drag.localEnd = touch.position;
            drag.timeStart  = Time.time;
            OnDragBegan?.Invoke(drag);
        }
        if (drag.isDragging && touch.phase == TouchPhase.Moved)
        {
            drag.isDragging = true;
            drag.localEnd   = touch.position;
            drag.timeEnd    = Time.time;

            drag.DrawDebug(Color.white);
            OnDrag?.Invoke(drag);
        }
        if (drag.isDragging && (touch.phase == TouchPhase.Ended || touch.phase == TouchPhase.Canceled))
        {
            drag.localEnd   = touch.position;
            drag.isDragging = false;
            drag.timeEnd    = Time.time;

            drag.DrawDebug(Color.red);

            OnDragEnded?.Invoke(drag);
        }
    }
예제 #28
0
    private void Drag()
    {
        DragArgs dragArgs = new DragArgs();

        if (Input.GetMouseButton(0))
        {
            _mousePosition   = Input.mousePosition;
            offSetByPixel    = _mousePosition - _startPos;
            offSet           = _mousePosition / _startPos;
            _normalizeValueX = _mousePosition.x / _maxDistanceWidth;
            _normalizeValueY = _mousePosition.y / _maxDistanceHeight;

            dragArgs.drag   = new Vector2(_normalizeValueX, _normalizeValueY);
            dragArgs.offset = offSet;
            OnDrag?.Invoke(this, dragArgs);
        }
    }
예제 #29
0
        void _update(ICogaManager coga, float deltaTime)
        {
            // Continuation from previous input
            if (isMouseDown)
            {
                if (mouseDownTime == 0f)
                {
                    OnStartClicking?.Invoke(Parent);
                    mousepos_lastframe = coga.MousePosition;
                }
                mouseDownTime += deltaTime;
                if (coga.IsClickReleased)                 // Exit out
                {
                    _handle_up(coga);
                    return;
                }

                if (isDragging)
                {
                    _update_drag(coga);
                    return;
                }

                if ((Vector2.Distance(coga.MousePosition, mouseInitial)) >= MouseDragMinimumDistance)
                {
                    OnDragStart?.Invoke(Parent);
                    Parent.Manager.LockHover();
                    OnDrag?.Invoke(Parent, (coga.MousePosition - mouseInitial));
                    isDragging = true;
                    return;
                }
            }
            else
            {
                if (coga.IsClickPressed)
                {
                    isDragging    = false;
                    isMouseDown   = true;
                    mouseDownTime = 0f;
                    mouseInitial  = coga.MousePosition;
                }
            }

            mousepos_lastframe = coga.MousePosition;
        }
예제 #30
0
        /// <summary>
        /// Drag rocker.
        /// </summary>
        protected virtual void OnMouseDrag()
        {
            if (!isEnabled)
            {
                return;
            }

            var x = Input.GetAxis("Mouse Y");
            var y = Input.GetAxis("Mouse X");

            angles += new Vector3(x, -y) * rotateSpeed * Time.deltaTime;
            if (angles.magnitude > radiusAngle)
            {
                angles = angles.normalized * radiusAngle;
            }
            Rotate(angles);
            OnDrag.Invoke();
        }