コード例 #1
0
 protected void OnDrag(DragEventArgs ie)
 {
     if(!sending) return;
     //print ("Event: drag");
     if(PointerDrag != null) PointerDrag(this, ie);
 }
コード例 #2
0
        protected override void UpdateEventState()
        {
            //if(lastevent != null)Debug.Log(lastevent.eventtype.ToString());
            //else Debug.Log("NULL");
            InputEventArgs ie = null;

            if(Input.GetMouseButton(0)){
                Vector3 position = Input.mousePosition;
                if(!down){
                    elapsedtime = 0;
                    //ie = new InputEvent((int)InputEvent.EventTypes.ClickDown, Input.mousePosition, Input.mousePosition, 0);
                    ie = new PointerDownEventArgs(position);
                    OnPointerDown((PointerDownEventArgs)ie);
                    down = true;
                }
                else{
                    dragforce = (lastevent.Position - position).magnitude / pinchdivider;
                    if(dragforce > cutoff || dragging){
                        dragging = true;
                        //dragforce = 1;//no idea if this is a good idea. DEPRECATED: smoothDrag((Input.mousePosition + lastevent.endpoint).magnitude);

                        //ie = new InputEvent((int)InputEvent.EventTypes.Drag, lastevent.endpoint, Input.mousePosition, dragforce);
                        ie = new DragEventArgs(lastevent.Position, position, dragforce * 100);

                        OnDrag((DragEventArgs)ie);
                    }
                    else{
                        elapsedtime += Time.deltaTime;
                        //ie = new InputEvent((int)InputEvent.EventTypes.Holding, Input.mousePosition, Input.mousePosition, 0);
                        ie = new HoldingEventArgs(position, elapsedtime);
                        OnHolding((HoldingEventArgs)ie);
                    }

                }
            }
            else if(down){
                if(dragging){
                    // end drag:
                    dragforce = (lastevent.Position - Input.mousePosition).magnitude / pinchdivider;
                    ie = new DragEventArgs(lastevent.Position, Input.mousePosition, dragforce);
                    OnDrag((DragEventArgs)ie);
                    // mouseup:
                    ie =  new PointerUpEventArgs(Input.mousePosition);
                    OnPointerUp((PointerUpEventArgs)ie);
                }
                else{
                    //ie = new InputEvent((int)InputEvent.EventTypes.ClickUp, Input.mousePosition, Input.mousePosition, 0);
                    ie =  new PointerUpEventArgs(Input.mousePosition);
                    OnPointerUp((PointerUpEventArgs)ie);
                }
                down = false;
                dragging = false;
            }
            else if(Input.GetAxis("Mouse ScrollWheel") != 0){
                //ie = new InputEvent((int)InputEvent.EventTypes.Zoom, Input.mousePosition, Input.mousePosition, Input.GetAxis("Mouse ScrollWheel"));
                ie = new ZoomEventArgs(Input.mousePosition, Input.GetAxis("Mouse ScrollWheel"));
                OnZoom((ZoomEventArgs)ie);
            }

            lastevent = ie;
        }
コード例 #3
0
        protected override void UpdateEventState()
        {
            InputEventArgs ie = new InputEventArgs();
            if(Input.touches.Length == 1){// move or tap
                lpinch = 0;

                Touch touch = Input.touches[0];

                Vector3 position = new Vector3(touch.position.x, touch.position.y);

                switch(touch.phase){
                case TouchPhase.Began:
                    if(!touching){
                        elapsedtime = 0; // holding timer reset
                        touching = true;
                        ie = new PointerDownEventArgs(position);
                        OnPointerDown((PointerDownEventArgs)ie);
                        print ("pointer down");
                    }
                    break;

                case TouchPhase.Moved:
                    dragforce = (lastevent.Position - position).magnitude/pinchdivider;
                    if(dragforce > cutoff){
                        dragging = true;
                        //ie = new InputEvent((int)InputEvent.EventTypes.Drag, lastevent.endpoint, position, (lastevent.endpoint-position).magnitude/pinchdivider * 100);
                        ie = new DragEventArgs(lastevent.Position, position, dragforce * 140);
                        OnDrag((DragEventArgs)ie);
                        //print ("dragging " + (lastevent.endpoint-position).magnitude.ToString());
                    }
                    else{
                        elapsedtime += Time.deltaTime;
                        //ie = new InputEvent((int)InputEvent.EventTypes.Holding, position, position, 0);
                        ie = new HoldingEventArgs(position, elapsedtime);
                        OnHolding((HoldingEventArgs)ie);
                        print ("holding");
                    }
                    break;

                case TouchPhase.Stationary:
                    if(dragging){

                        //ie = new InputEvent((int)InputEvent.EventTypes.Drag, position, position, 0);
                        ie = new DragEventArgs(position, position, 0);
                        OnDrag((DragEventArgs)ie);
                        print ("stationary drag");
                    }
                    else{
                        elapsedtime += Time.deltaTime;
                        ie = new HoldingEventArgs(position, elapsedtime);
                        OnHolding((HoldingEventArgs)ie);
                        print ("holding");
                    }
                    break;

                default: // for now: catches both ENDED and CANCELED
                    touching = false;
                    if(dragging){
                        dragforce = (lastevent.Position - position).magnitude/pinchdivider;
                        // end drag:
                        //ie = new InputEvent((int)InputEvent.EventTypes.Drag, lastevent.endpoint, position, (lastevent.endpoint-position).magnitude/pinchdivider * 5);
                        ie = new DragEventArgs(lastevent.Position, position, dragforce * 140);
                        OnDrag((DragEventArgs)ie);

                        print ("drag ended, f**k");

                        // touch up:
                        ie = new PointerUpEventArgs(position);
                        OnPointerUp((PointerUpEventArgs)ie);
                    }
                    else{
                        //ie = new InputEvent((int)InputEvent.EventTypes.ClickUp, position, position, 0);
                        ie = new PointerUpEventArgs(position);
                        OnPointerUp((PointerUpEventArgs)ie);
                        print ("pointer up");
                    }
                    dragging = false;
                    break;
                }

            }
            else if(Input.touches.Length == 2){ // pinch zoom

                Touch touch1 = Input.touches[0];
                Touch touch2 = Input.touches[1];

                float pinch = Vector2.Distance(touch1.position, touch2.position);
                if(lpinch > 0){
                    Vector2 meanpos = (touch1.position + touch2.position)*0.5f;

                    float pdelta = (pinch - lpinch)/pinchdivider *5f; // f**k :D

                    //ie = new InputEvent((int)InputEvent.EventTypes.Zoom, meanpos, new Vector3(meanpos.x, meanpos.y), pdelta);
                    ie = new ZoomEventArgs(meanpos, pdelta);
                    OnZoom((ZoomEventArgs)ie);
                }
                lpinch = pinch;
            }
            else{
                lpinch = 0;
            }

            lastevent = ie;
        }
コード例 #4
0
 void HandlePointerDrag(object o, DragEventArgs e)
 {
     if(objectToShow == null) return;
     objectToShow.transform.Rotate(Vector3.forward, -e.Direction.x *3);
 }