• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Touch类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中Touch的典型用法代码示例。如果您正苦于以下问题:C# Touch类的具体用法?C# Touch怎么用?C# Touch使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Touch类属于命名空间,在下文中一共展示了Touch类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: TestForTouchOrSwipeGesture

    private void TestForTouchOrSwipeGesture(Touch touch)
    {
        Vector2 lastPosition = touch.position;
        float distance = Vector2.Distance(lastPosition, touchStartPosition);

        if (distance > minimumSwipeDistanceInPixels)
        {
            float dy = lastPosition.y - touchStartPosition.y;
            float dx = lastPosition.x - touchStartPosition.x;

            float angle = Mathf.Rad2Deg * Mathf.Atan2(dx, dy);

            angle = (360 + angle - 45) % 360;

            if (angle < 90)
                OnSwipeDetectedRaise(Swipe.Right);
            else if (angle < 180)
                OnSwipeDetectedRaise(Swipe.Down);
            else if (angle < 270)
                OnSwipeDetectedRaise(Swipe.Left);
            else
                OnSwipeDetectedRaise(Swipe.Up);
        }
        else
        {
            OnTouchDetectedRaise(touch);
        }
    }
开发者ID:myroslavHub,项目名称:FastLine,代码行数:28,代码来源:TouchAndSwipeBehavior.cs


示例2: Update

    private void Update() {
        
        if(Interactable) {
            foreach(Touch touch in Input.touches) {
                if(rectTransform.rect.Contains((Vector3) touch.position - rectTransform.position) && touch.phase == TouchPhase.Began) {
                    followTouch = touch;
                    OnPointerDown();
                    
                }
            }

            foreach (Touch touch in Input.touches) {
                if (followTouch.fingerId == touch.fingerId && rectTransform.rect.Contains((Vector3)touch.position - rectTransform.position)) {
                    if (OnHold != null)
                        OnHold.Invoke();
                }
            }

            foreach (Touch touch in Input.touches) {
                if(followTouch.fingerId == touch.fingerId && 
                    (touch.phase == TouchPhase.Ended 
                    || touch.phase == TouchPhase.Canceled 
                    || !rectTransform.rect.Contains((Vector3) touch.position - rectTransform.position))) {
                    OnPointerUp();
                }
            }
        }

    }
开发者ID:NaNLagger,项目名称:ZombieStarve,代码行数:29,代码来源:UIButton.cs


示例3: Update

	void Update ()
    {
      
        if (Input.touchCount > 0)
        {
            myTouch = Input.GetTouch(0);
            myFIngerID = myTouch.fingerId;
        }

        else
        {
            iWasTouched = false;
            hasMoved = false;
        }

        if (EventSystem.current.IsPointerOverGameObject(myFIngerID) && Input.touchCount > 0)
        {
          
            iWasTouched = true;
          
            return;
        }

        gameObject.transform.GetChild(0).GetComponent<Text>().text = iWasTouched.ToString();

        if (iWasTouched == true && myTouch.phase == TouchPhase.Moved)
        {
            hasMoved = true;
            gameObject.transform.position = myTouch.position;

        }

    }
开发者ID:cuchullainh,项目名称:SMartphoneTest,代码行数:33,代码来源:buttonMove.cs


示例4: Update

    void Update() {
        
        if (Input.touchCount <= 0) {
            ID = -1;
        }
        else if (ID == -1 && Input.touchCount > 0) {
            for (var i = 0; i < Input.touchCount; ++i) {
                Vector2 temp = new Vector2(Input.touches[i].position.x, Input.touches[i].position.y) - startPos;
                if (temp.magnitude < radius * canvas.scaleFactor) {
                    if (Input.touches[i].phase == TouchPhase.Began) {
                        ID = Input.touches[i].fingerId;
                        action = true;
                        TouchOnJoystick = Input.touches[i];
                        Debug.Log(TouchOnJoystick.fingerId);
                    }
                }
            }
        }

        for (var i = 0; i < Input.touchCount; ++i) {
            if (ID == Input.touches[i].fingerId && action) {
                FollowFinger(Input.touches[i].position);
            }
        }

        for (var i = 0; i < Input.touchCount; ++i) {
            if (ID == Input.touches[i].fingerId && action) {
                if(Input.touches[i].phase == TouchPhase.Canceled || Input.touches[i].phase == TouchPhase.Ended) {
                    action = false;
                    if (joystickImage) {
                        joystickImage.CrossFadeAlpha(0.2f, .1f, true);
                    }
                    transform.position = startPos;
                    ID = -1;
                }
            }
        }

        UpdateInput();

#if UNITY_EDITOR
        /*//Mouse
        if (Input.GetMouseButtonDown(0)) {
            if (Mathf.Abs(Input.mousePosition.x - startPos.x) < radius &&
                    Mathf.Abs(Input.mousePosition.y - startPos.y) < radius) {
                FollowFinger(Input.mousePosition);
                action = true;
            }
        }

        if(Input.GetMouseButton(0) && action) {
            FollowFinger(Input.mousePosition);
        }
        
        if(Input.GetMouseButtonUp(0)) {
            gameObject.transform.position = startPos;
            action = false;
        }*/
#endif
    }
开发者ID:NaNLagger,项目名称:ZombieStarve,代码行数:60,代码来源:Joystick.cs


示例5: MoveInputAt

    void MoveInputAt(Touch touch, int n)
    {
        Ray ray = InputCamera.ScreenPointToRay(touch.position);
        RaycastHit hit;
        //Handle Swipe
        if (Mathf.Abs(touch.position.x - SwipeInfos[n].StartPos.x) > comfortZone) { //Cant be swipe is deviate too much from a straith line
            SwipeInfos[n].canBeSwipe_Vertical = false;
            //Debug.Log("Swipe Cancelled by mouv : " + n);
        }
        if (Mathf.Abs(touch.position.y - SwipeInfos[n].StartPos.y) > comfortZone) { //Cant be swipe is deviate too much from a straith line
            SwipeInfos[n].canBeSwipe_Horizontal = false;
            //Debug.Log("Swipe Cancelled by mouv : " + n);
        }
        SwipeInfos[n].idleTime = 0;

        //check Button presses
        if (Physics.Raycast(ray, out hit, TouchInputMask)) {

            GameObject newRecipient = hit.collider.transform.gameObject;
            if (touchesTargets[n] != null && touchesTargets[n] == newRecipient) {
                return;//We are on the same target even though we moved, handle swipes here
            } else {
                RemoveInputFromButton(touch, n);
                newRecipient.SendMessage("FingerOn", n, SendMessageOptions.DontRequireReceiver);
                touchesTargets[n] = newRecipient;
            }

        }
    }
开发者ID:sprawls,项目名称:LudumDare33,代码行数:29,代码来源:TouchInput.cs


示例6: OnTouchEnd

 void OnTouchEnd(Touch touch)
 {
     if (IsPlayer(touch)) {
         player.outsideMotion = Vector3.zero;
         player = null;
     }
 }
开发者ID:Turnary-Games,项目名称:Battery-Golem,代码行数:7,代码来源:Lilypad.cs


示例7: assignTouch

    private float startTime; //    Time when touch first occured

    #endregion Fields

    #region Methods

    //    Assign a new touch to track
    public void assignTouch(Touch touch)
    {
        myTouch = touch;
        free = false;

        processTouch ();
    }
开发者ID:jerryhsiung,项目名称:chubbybunny,代码行数:14,代码来源:TouchAssistant.cs


示例8: onTouchEnded

	public override void onTouchEnded( Touch touch, Vector2 touchPos, bool touchWasInsideTouchFrame )
	{
		base.onTouchEnded( touch, touchPos, touchWasInsideTouchFrame );
		
		if( onlyFireStartAndEndEvents && onActivationEnded != null )
			onActivationEnded( this );
	}
开发者ID:Foxzter,项目名称:net.kibotu.sandbox.unity.dragnslay,代码行数:7,代码来源:UIContinuousButton.cs


示例9: Update

    // Update is called once per frame
    public void Update(Touch touch)
    {
        // Is Touch over UI
        int pointerID = touch.fingerId;
        if (EventSystem.current.IsPointerOverGameObject(pointerID))
        {
            return;
        }

        var phase = touch.phase;
        switch (phase)
        {
            case TouchPhase.Began:
                Began = true;
                break;
            case TouchPhase.Moved:
                Moved = true;
                break;
            case TouchPhase.Stationary:
                Stationary = true;
                break;
            case TouchPhase.Ended:
                Ended = true;
                break;
        }
    }
开发者ID:Saphatonic,项目名称:M154,代码行数:27,代码来源:SingleTouch.cs


示例10: ForEachTouch

    protected override void ForEachTouch(Touch touch, Vector2 guiTouchPos)
    {

        bool shouldLatchFinger = gui.HitTest(touch.position);

        if (shouldLatchFinger && (lastFingerId == -1 || lastFingerId != touch.fingerId)) {
            lastFingerId = touch.fingerId;

            // Tell other joysticks we've latched this finger
            for (int index = 0; index < joysticks.Length; index++) {
                if (joysticks[index] != this) {
                    joysticks[index].LatchedFinger (touch.fingerId);
                }
            }
        }
        if (lastFingerId == touch.fingerId) {
                // Change the location of the joystick graphic to match where the touch is
                gui.pixelInset = new Rect (
                    Mathf.Clamp (guiTouchPos.x, guiBoundary.xMin, guiBoundary.xMax),
                    Mathf.Clamp (guiTouchPos.y, guiBoundary.yMin, guiBoundary.yMax),
                    gui.pixelInset.width,
                    gui.pixelInset.height);

                // if the touch is over then reset the joystick to its default position
                if (touch.phase == TouchPhase.Ended || touch.phase == TouchPhase.Canceled) {
                    ResetJoystick ();
                }
            }
    }
开发者ID:CaminhoneiroHell,项目名称:unity-game-programming-patterns,代码行数:29,代码来源:Joystick.cs


示例11: onTouchBegan

	// Touch handlers
	public override void onTouchBegan( Touch touch, Vector2 touchPos )
	{
		base.onTouchBegan( touch, touchPos );

		if( onlyFireStartAndEndEvents && onActivationStarted != null )
			onActivationStarted( this );
	}
开发者ID:Foxzter,项目名称:net.kibotu.sandbox.unity.dragnslay,代码行数:8,代码来源:UIContinuousButton.cs


示例12: RegisterSpins

	void RegisterSpins()
	{
		if (Input.touchCount == 2)
		{
			touchOne = Input.GetTouch(0);
			touchTwo = Input.GetTouch(1);
			touchOnePrev = touchOne.position - touchOne.deltaPosition;
			touchTwoPrev = touchTwo.position - touchTwo.deltaPosition;
			currentAngle = Angle(touchOne.position, touchTwo.position);
			prevAngle = Angle(touchOnePrev, touchTwoPrev);
			deltaAngle = Mathf.DeltaAngle(currentAngle, prevAngle);
			if (Mathf.Abs(deltaAngle) > minAngle){
				spinInput = deltaAngle * (Mathf.PI / 2);
				spinning = true;
			}
			else {
				spinInput = 0;
				deltaAngle = 0;
				spinning = false;
			}
		}
		else {
			spinInput = 0;
		}
	}
开发者ID:coderDarren,项目名称:GGJ2016,代码行数:25,代码来源:MultitouchHandler.cs


示例13: Orbit

    /**
    * Method:    Orbit
    * FullName:  Orbit
    * Access:    public
    * Qualifier:
    * @param   Touch touch
    * @return   void
    */
    void Orbit(Touch touch)
    {
        // rotates around the building

        x += touch.deltaPosition.x * xSpeed * 0.02f /* * distance*/;

        // rotates up and down (roof top)

        y -= touch.deltaPosition.y * ySpeed * 0.02f /* * distance*/;

        y = ClampAngle(y, yMinLimit, yMaxLimit);

        Quaternion rotation = Quaternion.Euler(y, x, 0);

        RaycastHit hit;

        if (Physics.Linecast(target.position, transform.position, out hit))

        {

              // distance -= hit.distance;

        }

        Vector3 negDistance = new Vector3(0.0f, 0.0f, -distance);

        Vector3 position = rotation * negDistance + target.position;

        transform.rotation = rotation;

        transform.position = position;
    }
开发者ID:joseph93,项目名称:Genos,代码行数:40,代码来源:TouchCamera.cs


示例14: ForEachTouch

    protected override void ForEachTouch(Touch touch, Vector2 guiTouchPos)
    {
        base.ForEachTouch(touch, guiTouchPos);

        if (lastFingerId == touch.fingerId)
        {
            // absolute position of touch relative to touchpad defines the input amount:
            Vector2 newAbsTouchPos = new Vector2((touch.position.x - touchZoneRect.center.x) / sensitivityRelativeX, (touch.position.y - touchZoneRect.center.y) / sensitivityRelativeY) * 2;

            Vector2 newPosition = Vector2.Lerp(position, newAbsTouchPos * sensitivity, Time.deltaTime * interpolateTime);

            // scale & clamp the touch position inside the allowed touch zone, between -1 and 1
            if (useX)
            {
                position.x = Mathf.Clamp(newPosition.x, -1, 1);
            }
            if (useY)
            {
                position.y = Mathf.Clamp(newPosition.y, -1, 1);
            }


            // if the touch is over then reset the joystick to its default position
            if (touch.phase == TouchPhase.Ended || touch.phase == TouchPhase.Canceled)
            {
                ResetJoystick();
            }
        }
    }
开发者ID:BasmanovDaniil,项目名称:Whoosh,代码行数:29,代码来源:TouchPadPositional.cs


示例15: GetTouchPointerEventData

        protected PointerEventData GetTouchPointerEventData(Touch input, out bool pressed, out bool released)
        {
            PointerEventData pointerData;
            var created = GetPointerData(input.fingerId, out pointerData, true);

            pointerData.Reset();

            pressed = created || (input.phase == TouchPhase.Began);
            released = (input.phase == TouchPhase.Canceled) || (input.phase == TouchPhase.Ended);

            if (created)
                pointerData.position = input.position;

            if (pressed)
                pointerData.delta = Vector2.zero;
            else
                pointerData.delta = input.position - pointerData.position;

            pointerData.position = input.position;

            pointerData.button = PointerEventData.InputButton.Left;

            eventSystem.RaycastAll(pointerData, m_RaycastResultCache);

            var raycast = FindFirstRaycast(m_RaycastResultCache);
            pointerData.pointerCurrentRaycast = raycast;
            m_RaycastResultCache.Clear();
            return pointerData;
        }
开发者ID:gdzzzyyy,项目名称:UGUIlok,代码行数:29,代码来源:PointerInputModule.cs


示例16: IsValidTouch

	bool IsValidTouch(Touch touch) {
		if ( touch.phase != TouchPhase.Began && touch.phase != TouchPhase.Moved ) 
			return false;
		Ray ray = Camera.main.ScreenPointToRay(touch.position);
		RaycastHit hit;
		return touchCollider.Raycast(ray, out hit, 100.0f);
	}
开发者ID:lucaswall,项目名称:awake,代码行数:7,代码来源:SigilFragment.cs


示例17: OnTouch

 void OnTouch(Touch touch)
 {
     if (IsPlayer (touch)) {
         player.outsideMotion = body.velocity;
         //player.body.AddForce(body.velocity);
     }
 }
开发者ID:Turnary-Games,项目名称:Battery-Golem,代码行数:7,代码来源:Lilypad.cs


示例18: TouchShoot

    void TouchShoot()
    {
        touch = Input.GetTouch (0);
        //Raycast to find out where the cannonball should be fired towards
        RaycastHit shothit;
        //Finding mouse position when left mouse button is pressed
        shot = touch.position;
        //Translating screen position of mouse to world position on the field.
        Ray mouseClick = Camera.main.ScreenPointToRay(shot);
        //Final vector for firing cannonball
        Vector3 shotdirection;

        //If the click actually lands on the field it will fire the cannonball
        if (Physics.Raycast(mouseClick, out shothit, Mathf.Infinity, layerMask))
        {
            if (shothit.collider.CompareTag ("Surface") || shothit.collider.CompareTag ("Surface"))
            {
                //Creating cannonball in front of cannon barrel
                reload = Instantiate(cannonball, shotorigin.position, shotorigin.rotation) as Rigidbody;
                //Calculating final shot vector by taking position of mouse and subtracting position of cannon
                shotdirection = shothit.point - reload.transform.position;
                shotdirection.Normalize ();
                //Applying force to cannonball along the vector
                reload.AddForce(shotdirection * shotspeed);
                //Play cannon animation
                GetComponent<Animation>().Play("Cannon_Fire");
            }

        }
    }
开发者ID:SeanCahalan,项目名称:unityThings,代码行数:30,代码来源:CannonFire.cs


示例19: onTouchMoved

	public override void onTouchMoved( Touch touch, Vector2 touchPos )
#endif
	{
		// dont fire this continously if we were asked to only fire start and end
		if( !onlyFireStartAndEndEvents && onTouchIsDown != null )
			onTouchIsDown( this );
	}
开发者ID:EskemaGames,项目名称:UIToolkit,代码行数:7,代码来源:UIContinuousButton.cs


示例20: InputCommands

 public InputCommands(Keyboard keyboard, Mouse mouse, Touch touch, GamePad gamePad)
 {
     this.keyboard = keyboard;
     this.mouse = mouse;
     this.touch = touch;
     this.gamePad = gamePad;
 }
开发者ID:hillwhite,项目名称:DeltaEngine,代码行数:7,代码来源:InputCommands.cs



注:本文中的Touch类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# TouchCollection类代码示例发布时间:2022-05-24
下一篇:
C# TorrentManager类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap