Esempio n. 1
0
File: Menu.cs Progetto: shu1/dfu
 public void EndTouch(TouchInfo info)
 {
     if(titleSplash) {
     showStartButtons = true;
     titleSplash = false;
     }
 }
	private void Select(TouchInfo tInfo)
	{
		RaycastHit hit;
		Ray ray = Camera.main.ScreenPointToRay(tInfo.Position);

		bool towerHit = false;

		if(Physics.Raycast(ray, out hit, Mathf.Infinity, TowerMask));
		{
			if(hit.transform != null && !CurTarget.Equals(hit.transform))
			{
				CurTarget = hit.transform;
				G.i.StageM.CurTarget = hit.transform;
				SelectTower(CurTarget);

				towerHit = true;
			}
		}

		if(!towerHit)
		{
			if(Physics.Raycast(ray, out hit, Mathf.Infinity, TileMask));
			{
				if(hit.transform != null && !CurTarget.Equals(hit.transform))
				{
					CurTarget = hit.transform;
					G.i.StageM.CurTarget = hit.transform;
					SelectTile(CurTarget);
				}
			}
		}
	}
Esempio n. 3
0
		public TouchInfo(TouchInfo otherTouch) {
			fingerId = otherTouch.fingerId;
			beginFingerId = otherTouch.beginFingerId;
			deltaPosition = otherTouch.deltaPosition;
			position = otherTouch.position;
			beginPosition = otherTouch.beginPosition;
			beginTime = otherTouch.beginTime;
			phase = otherTouch.phase;
		}
Esempio n. 4
0
    void Update()
    {
        TouchInfo info = AppUtil.GetTouch();

        if (info == TouchInfo.Began)
        {
            // タッチ開始
            Debug.Log("画面がタッチされた");
            animator.SetTrigger("Tap");
        }
    }
Esempio n. 5
0
    private void onMove(TouchInfo e)
    {
        var delta = e.deltaScreenPoint;
        var pos   = transform.position;

        transform.position = new Vector3(
            Mathf.Clamp(pos.x + delta.x / 50, -moveLimit.x, moveLimit.x),
            Mathf.Clamp(pos.y + delta.y / 50, -moveLimit.y, moveLimit.y),
            0
            );
    }
Esempio n. 6
0
    public static void Update()
    {
        if (Input.touchCount != TouchCount && OnTouchCountChanged != null)
        {
            TouchCount = Input.touchCount;
            OnTouchCountChanged();
        }

        if (Input.touchCount > 0)
        {
            for (int i = 0; i < Input.touchCount; ++i)
            {
                Touch     currentTouch = Input.touches[i];
                TouchInfo touchInfo    = GetTouchInfo(currentTouch);

                if (touchInfo == null)
                {
                    touchInfos.Add(new TouchInfo(currentTouch));
                }
                else
                {
                    touchInfo.UpdateInfo(currentTouch);
                }

                switch (currentTouch.phase)
                {
                case TouchPhase.Began:
                    OnTouchStart?.Invoke(touchInfo);
                    break;

                case TouchPhase.Stationary:
                    OnTouchHold?.Invoke(touchInfo);
                    break;

                case TouchPhase.Moved:
                    OnTouchMove?.Invoke(touchInfo);
                    break;

                case TouchPhase.Ended:
                    touchInfos.Remove(touchInfo);
                    OnTouchEnd?.Invoke(touchInfo);
                    break;

                case TouchPhase.Canceled:
                    touchInfos.Remove(touchInfo);
                    OnTouchCancel?.Invoke(touchInfo);
                    break;

                default:
                    continue;
                }
            }
        }
    }
Esempio n. 7
0
 /// <summary>
 /// Checks to see if a touchevent is a valid touch event to grab this object.
 /// </summary>
 /// <param name="touchInfo"></param>
 /// <param name="eventType"></param>
 private void CheckForGrab(TouchInfo touchInfo, ETouchEventType eventType)
 {
     if (canGrab && eventType != ETouchEventType.EXIT && m_touchInfo == null && touchInfo.m_owners == 0)
     {
         touchInfo.m_owners++;
         m_touchInfo = touchInfo;
         m_touchInfo.ListenForMove(OnTouchMove);
         m_touchInfo.ListenForEnd(OnTouchEnd);
         Grab();
     }
 }
Esempio n. 8
0
        /// <summary>
        /// Begins a new touch input.
        /// </summary>
        private void BeginTouch(ref SDL_Event evt)
        {
            var touchID    = nextTouchID++;
            var touchIndex = touches.Count == 0 ? 0 : touches[touches.Count - 1].TouchIndex + 1;
            var touchInfo  = new TouchInfo(timestamp, touchID, touchIndex, evt.tfinger.fingerId,
                                           evt.tfinger.x, evt.tfinger.y, evt.tfinger.x, evt.tfinger.y, evt.tfinger.pressure, false);

            touches.Add(touchInfo);

            OnTouchDown(touchID, touchInfo.FingerID, touchInfo.CurrentX, touchInfo.CurrentY, touchInfo.Pressure);
        }
Esempio n. 9
0
 /// <summary>
 /// Consuming a touch is when a particular script takes ownership of the touch.
 /// Consume is recalled each frame until it is consumed and it is typically consumed in the begin phase.
 /// Each script should keep track of which touches it is taking ownership of.
 /// </summary>
 /// <param name="touch">An unconsumed touch</param>
 void Consume(ref TouchInfo touch)
 {
     if (touch.consumed = IsTouchConsumedByPan?.Invoke(touch) == true)
     {
         return;
     }
     if (touch.consumed = IsTouchConsumedByPicker?.Invoke(touch) == true)
     {
         return;
     }
 }
Esempio n. 10
0
        private TouchInfo GetTouchInfo(int touchId)
        {
            TouchInfo touchInfo = null;

            if (!m_Fingers.TryGetValue(touchId, out touchInfo))
            {
                touchInfo = new TouchInfo();
                m_Fingers.Add(touchId, touchInfo);
            }
            return(touchInfo);
        }
Esempio n. 11
0
        internal void ReadFromBuffer(byte[] buffer)
        {
            const int offset        = 35;
            const int touchDataSize = 4;

            Count = 0;

            Array.Copy(TouchInfos, PreviousTouchInfos, TouchInfos.Length);

            var now = DateTime.UtcNow;

            for (var i = 0; i < MaxTouches; i++)
            {
                var      localOffset = offset + (i * touchDataSize);
                var      isActive = (buffer[localOffset] & 0x80) == 0;
                var      touchId = (byte)(buffer[localOffset] & 0x7F);
                var      touchX = buffer[localOffset + 1] + ((buffer[localOffset + 2] & 0xF) * 255);
                var      touchY = ((buffer[localOffset + 2] & 0xF0) >> 4) + (buffer[localOffset + 3] * 16);
                int      startX, startY;
                DateTime startWhen;

                if (
                    (PreviousTouchInfos[i].Id == touchId) &&
                    PreviousTouchInfos[i].IsActive
                    )
                {
                    startX    = PreviousTouchInfos[i].StartX;
                    startY    = PreviousTouchInfos[i].StartY;
                    startWhen = PreviousTouchInfos[i].StartWhen;
                }
                else
                {
                    startX    = touchX;
                    startY    = touchY;
                    startWhen = now;
                }

                TouchInfos[i] = new TouchInfo {
                    IsActive  = isActive,
                    Id        = touchId,
                    X         = touchX,
                    Y         = touchY,
                    StartX    = startX,
                    StartY    = startY,
                    StartWhen = startWhen,
                    When      = now
                };

                if (isActive)
                {
                    Count = Math.Max(Count, i + 1);
                }
            }
        }
Esempio n. 12
0
    private void TouchEndedHandler(TouchInfo touchInfo)
    {
        if (catchSwitchState == null)
        {
            return;
        }

        var delta = touchInfo.TouchPosition.x - previewPosition;

        ProcessingSwitch(delta);
        catchSwitchState = null;
    }
Esempio n. 13
0
 static void ProcessTouches()
 {
     touch = new TouchInfo();
     if (Application.platform == RuntimePlatform.Android || Application.platform == RuntimePlatform.IPhonePlayer)
     {
         ProcessRealTouches();
     }
     else
     {
         ProcessMouseEvents();
     }
 }
Esempio n. 14
0
    // Update is called once per frame
    void Update()
    {
        state = AppUtil.GetTouch();
        if (state == TouchInfo.Began || state == TouchInfo.Moved || state == TouchInfo.Ended)
        {
            // タッチ開始
            position = AppUtil.GetTouchPosition();
            position = Camera.main.ScreenToWorldPoint(position);
        }
        transform.position = new Vector3(position.x, position.y, -1); // position;
//        transform.position = new Vector3( position.x / width -0.5f, position.y / height/2f - 0.5f, -1);
    }
Esempio n. 15
0
 void onMove(TouchInfo touch)
 {
     if ((transform.rotation.eulerAngles.x + touch.delta.y) > 320f && (transform.rotation.eulerAngles.x + touch.delta.y) < 360f)
     {
         xCoord = touch.delta.y;
     }
     else
     {
         xCoord = 0f;
     }
     transform.localRotation = Quaternion.Lerp(transform.localRotation, Quaternion.Euler(transform.rotation.eulerAngles + (new Vector3(xCoord, touch.delta.x, 0) * angularValue)), Time.deltaTime * 5f);
 }
Esempio n. 16
0
        /// <summary>
        /// タッチイベントを発行する
        /// </summary>
        /// <param name="type"></param>
        /// <param name="touchInfo"></param>
        private void DispatchEvent(Event.TYPE type, TouchInfo touchInfo)
        {
            List <Event> eventList;

            if (_events.TryGetValue((uint)type, out eventList))
            {
                for (int i = 0; i < eventList.Count; ++i)
                {
                    eventList[i].onTouch(touchInfo);
                }
            }
        }
	private void OneTouchClick(TouchInfo tInfo)
	{
		if(UICamera.hoveredObject == null)
		{
			if(SensitivityValue < tInfo.BeginDeltaPosition.x && SensitivityValue > tInfo.BeginDeltaPosition.x
			   && SensitivityValue < tInfo.BeginDeltaPosition.y && SensitivityValue > tInfo.BeginDeltaPosition.y
			   && tInfo.Type != TouchType.END)
				return;

			Select(tInfo);
		}
	}
Esempio n. 18
0
        /// <summary>
        /// Assigns the drag pointer and sets the UI into drag mode
        /// </summary>
        /// <param name="pointer"></param>
        protected virtual void OnStartDrag(PointerActionInfo pointer)
        {
            var touchInfo = pointer as TouchInfo;

            if (touchInfo != null)
            {
                if (m_IsGhostSelected)
                {
                    m_GameUI.ChangeToDragMode();
                    m_DragPointer = touchInfo;
                }
            }
        }
Esempio n. 19
0
    protected override void OnMoved(TouchInfo touchInfo)
    {
        GestureInfoPan gesture = new GestureInfoPan(touchInfo.GetDeltaPosition(), TouchPhase.Moved);

        if (this.broadcastWhilePanningI != null)
        {
            this.broadcastWhilePanningI(gesture);
        }
        if (this.broadcastWhilePanning != null)
        {
            this.broadcastWhilePanning();
        }
    }
Esempio n. 20
0
        public InputTouchWrapper()
        {
            EnhancedTouch.EnhancedTouchSupport.Enable();

            touchInfoCaches = new TouchInfo[cacheCount];

            for (int i = 0; i < cacheCount; i++)
            {
                touchInfoCaches[i] = new TouchInfo();
            }

            ResetTouchInfo();
        }
Esempio n. 21
0
    private void CheckInput()
    {
        if (t.infos.Count == 0)
        {
            return;
        }

        for (int i = 0; i < t.infos.Count; ++i)
        {
            TouchInfo info = t.infos[i];
            TouchLine(info);
        }
    }
    // Use this for initialization
    void Start()
    {
        this.leftInfo = new TouchInfo( this.count );
        this.rightInfo = new TouchInfo( this.count );

        // 触覚を動かす
        var touchCheck = Observable.Interval( System.TimeSpan.FromSeconds(1f) ).Subscribe(_=>{
            for( var i = 1; i < this.count ; i ++ ){
                this.TouchWithRan( this.longRangeTouch, i );
                this.TouchWithRan( this.shortRangeTouch, i );
            }
        });
        // 触覚の結果に応じて、移動可能方向を決定する
    }
    private SimpleGesture.GestureDelegate <GestureInfoSwipe> Get9AxisDelegateI(TouchInfo touchInfo)
    {
        Vector2 direction = (touchInfo.GetLastPosition() - touchInfo.GetFirstPosition()).normalized;
        float   angle     = Vector2.Angle(direction, Vector2.right);

        if (angle <= 20.0f)
        {
            return(this.broadcastOn9AxisSwipeRHTI);
        }
        else if (angle >= 160.0f)
        {
            return(this.broadcastOn9AxisSwipeLFTI);
        }
        else if (angle > 20.0f && angle <= 70.0f)
        {
            if (direction.y > 0.0f)
            {
                return(this.broadcastOn9AxisSwipeDURI);
            }
            else
            {
                return(this.broadcastOn9AxisSwipeDDRI);
            }
        }
        else if (angle > 70.0f && angle <= 110.0f)
        {
            if (direction.y > 0.0f)
            {
                return(this.broadcastOn9AxisSwipeUPRI);
            }
            else
            {
                return(this.broadcastOn9AxisSwipeDWNI);
            }
        }
        else if (angle > 110.0f && angle < 160.0f)
        {
            if (direction.y > 0.0f)
            {
                return(this.broadcastOn9AxisSwipeDULI);
            }
            else
            {
                return(this.broadcastOn9AxisSwipeDDLI);
            }
        }

        Debug.LogError(SimpleGesture.ERROR_ANGLE_VALUE_NOT_CAUGHT + " {" + angle + "}");
        return(null);
    }
Esempio n. 24
0
 void OnTouchBegan(TouchInfo touch)
 {
     if (isLanded)
     {
         if (touch.position.x > Screen.width / 2f)
         {
             MoveRight();
         }
         else
         {
             MoveLeft();
         }
     }
 }
    public TouchInfo GetStickInfo()
    {
        int i = 0;

        for (int num = touchInfos.Length; i < num; i++)
        {
            TouchInfo touchInfo = touchInfos[i];
            if (touchInfo.id != -1 && touchInfo.activeAxis && touchInfo.enable)
            {
                return(touchInfo);
            }
        }
        return(null);
    }
    public bool IsActiveStick()
    {
        int i = 0;

        for (int num = touchInfos.Length; i < num; i++)
        {
            TouchInfo touchInfo = touchInfos[i];
            if (touchInfo.id != -1 && touchInfo.activeAxis && touchInfo.enable)
            {
                return(true);
            }
        }
        return(false);
    }
    public TouchInfo GetActiveInfo(bool check_enable = false)
    {
        int i = 0;

        for (int num = touchInfos.Length; i < num; i++)
        {
            TouchInfo touchInfo = touchInfos[i];
            if (touchInfo.id != -1 && (!check_enable || touchInfo.enable))
            {
                return(touchInfo);
            }
        }
        return(null);
    }
    public bool IsTouchIgnoreHit()
    {
        int i = 0;

        for (int num = touchInfos.Length; i < num; i++)
        {
            TouchInfo touchInfo = touchInfos[i];
            if (touchInfo.id != -1)
            {
                return(true);
            }
        }
        return(false);
    }
    private TouchInfo GetInfo(int id)
    {
        int i = 0;

        for (int num = touchInfos.Length; i < num; i++)
        {
            TouchInfo touchInfo = touchInfos[i];
            if (touchInfo.id == id)
            {
                return(touchInfo);
            }
        }
        return(null);
    }
Esempio n. 30
0
    /// <summary>
    /// Cleans up touch info once the touch event controlign this object ends
    /// </summary>
    /// <param name="touchInfo"></param>
    private void OnTouchEnd(TouchInfo touchInfo)
    {
        if (m_springJoint.connectedBody)
        {
            m_springJoint.connectedBody.drag        = m_oldDrag;
            m_springJoint.connectedBody.angularDrag = m_oldAngularDrag;
            m_springJoint.connectedBody             = null;
        }
        m_touchInfo.StopListenForMove(OnTouchMove);
        m_touchInfo.StopListenForEnd(OnTouchEnd);
        m_touchInfo.m_owners--;

        m_touchInfo = null;
    }
Esempio n. 31
0
 // Update is called once per frame
 void Update()
 {
     //タッチ情報の取得
     for (int i = 0; i < Input.touchCount; i++)
     {
         touch = AppUtil.GetTouch();
     }
     this.TouchPinchEvent();
     //タッチしたときかどうか
     if (touch == TouchInfo.Began)
     {
         this.TouchRayEvent();
     }
 }
Esempio n. 32
0
    // Update is called once per frame
    void Update()
    {
        m_Pos.SetPosition(transform.position);

        float horizontal = CrossPlatformInputManager.GetAxisRaw("Horizontal");
        float vertical   = CrossPlatformInputManager.GetAxisRaw("Vertical");
        bool  boJump     = CrossPlatformInputManager.GetButton("Jump");

        if (Input.GetKey(KeyCode.RightArrow))
        {
            m_Pos.AddPositionX(0.1f);
        }
        else if (Input.GetKey(KeyCode.LeftArrow))
        {
            m_Pos.AddPositionX(-0.1f);
        }

        //シーン切り替え
        if (Input.GetKeyDown(KeyCode.X))
        {
            SceneManager.LoadSceneAsync("GameMain");
        }

        TouchInfo info = AppUtil.GetTouch();

        if (Input.GetKey(KeyCode.Z) || boJump)
        {
            for (int i = 0; i < 100; i++)
            {
                if (obj[i] == null)
                {
                    obj[i] = mRes.CreateInstantiate("Sphere") as GameObject;
                    break;
                }
            }
        }

        for (int i = 0; i < 100; i++)
        {
            if (obj[i])
            {
                if (obj[i].transform.position.y <= -10.0f)
                {
                    Destroy(obj[i]);
                    obj[i] = null;
                }
            }
        }
        transform.position = m_Pos.GetPosition();
    }
Esempio n. 33
0
    void MoveHandle(TouchInfo currentTouchInfo, Touch currentTouch)
    {
        Vector3 currentTouchPosition = new Vector3(currentTouch.position.x, currentTouch.position.y);
        Vector3 deltaSinceTouchStart = currentTouchPosition - currentTouchInfo.touchStart;

        if (deltaSinceTouchStart.magnitude < handleMovementRange)
        {
            joystickHandle.position += new Vector3(currentTouch.deltaPosition.x, currentTouch.deltaPosition.y);
        }
        else
        {
            joystickHandle.localPosition = (currentTouchPosition - joystick.position).normalized * handleMovementRange;
        }
    }
    private void OneTouchClick(TouchInfo tInfo)
    {
        if (UICamera.hoveredObject == null)
        {
            if (SensitivityValue < tInfo.BeginDeltaPosition.x && SensitivityValue > tInfo.BeginDeltaPosition.x &&
                SensitivityValue < tInfo.BeginDeltaPosition.y && SensitivityValue > tInfo.BeginDeltaPosition.y &&
                tInfo.Type != TouchType.END)
            {
                return;
            }

            Select(tInfo);
        }
    }
Esempio n. 35
0
        /// <summary>
        /// Updates the position and pressure of a touch.
        /// </summary>
        /// <param name="touch">The touch to update.</param>
        /// <param name="x">The x-coordinate of the touch.</param>
        /// <param name="y">The y-coordinate of the touch.</param>
        /// <param name="dx">The change in the touch's x-coordinate.</param>
        /// <param name="dy">The change in the touch's y-coordinate.</param>
        /// <param name="pressure">The pressure of the touch.</param>
        protected void SetTouchPosition(ref TouchInfo touch, Single x, Single y, out Single dx, out Single dy, Single pressure)
        {
            dx = x - touch.CurrentX;
            dy = y - touch.CurrentY;

            touch.CurrentX = x;
            touch.CurrentY = y;
            touch.Pressure = pressure;

            var dpixels  = DenormalizeCoordinates(dx, dy);
            var distance = (Single)Math.Sqrt((dpixels.X * dpixels.X) + (dpixels.Y * dpixels.Y));

            touch.Distance += distance;
        }
	public override void Init()
	{
		base.Init();

		m_aoTouchInfos = new TouchInfo[mk_iMaxTouchNumber];

		InitTouch();

		m_aoCommandsGesture = new InputCompositeGesture[(int)GestureCommandType.COUNT];
		InputCompositeGesture[] aoCommand = GameObject.FindObjectsOfType<InputCompositeGesture>();
		for(int i = 0; i < aoCommand.Length; ++i)
		{
			m_aoCommandsGesture[(int)aoCommand[i].CommandType] = aoCommand[i];
		}
	}
Esempio n. 37
0
File: Player.cs Progetto: shu1/dfu
    // Reset sphere to intial conditions to be called whenever a goal is scored
    public void ResetSphere()
    {
        bTouchDown = false;
        bPenalty = false;
        bCooldown = false;
        bOverload = false;
        chargeTime = 0;

        downTouch = null;
        renderer.enabled = false;
        collider.enabled = false;
        balls = GameObject.FindGameObjectsWithTag("ball");	// TODO: don't do this in Update()!
        if (overloadParticleSystem) {
            overloadParticleSystem.GetComponent<ParticleSystem>().Stop();
        }

        UpdateSphere(null);
    }
Esempio n. 38
0
    public void addTargetedDelegate(TouchTargetedDelegate intarget, int inTouchPriority, bool inswallowsTouches)
    {
        int i = 0;
        //searching for place to insert delegate
        for (i = 0; i < targetedHandlers.Count; i++)
        {
            if ((targetedHandlersTouchInfo[i] as TouchInfo).touchPriority > inTouchPriority)
                break;
        }

        targetedHandlers.Insert(i, intarget);

        TouchInfo newTouchInfo = new TouchInfo();
        newTouchInfo.swallowsTouches = inswallowsTouches;
        newTouchInfo.touchPriority = inTouchPriority;

        targetedHandlersTouchInfo.Insert(i, newTouchInfo);
    }
Esempio n. 39
0
    public void TouchInput(TouchInfo touchInfo)
    {
        SriTouchGestures gesture = touchInfo.touchGesture;
        m_touchReleased = false;

        switch(gesture)
        {
            case SriTouchGestures.SRI_NONE:

            break;

            case SriTouchGestures.SRI_SWIPEDDOWN:

                Debug.Log("Lift Swiped Down");

                if(m_liftReady)
                {
                    if(m_i > 0)
                    {
                        m_i--;
                    }
                }

            break;

            case SriTouchGestures.SRI_SWIPEDUP:

                Debug.Log("Lift Swiped Up");

                if(m_liftReady)
                {
                    if(m_i < 1)
                    {
                        m_i++;
                    }
                }

            break;

            case SriTouchGestures.SRI_RELEASED:

            break;
        }
    }
Esempio n. 40
0
File: Menu.cs Progetto: shu1/dfu
 public void StartTouch(TouchInfo info)
 {
 }
Esempio n. 41
0
 public void StartTouch( TouchInfo touch )
 {
     if ( OnStartTouch != null )
         OnStartTouch( touch );
 }
Esempio n. 42
0
 public void UpdateTouch( TouchInfo touch )
 {
     if ( OnUpdateTouch != null )
         OnUpdateTouch( touch );
 }
Esempio n. 43
0
File: Game.cs Progetto: shu1/dfu
 // Determines which player's region it started in, and calls the TouchStarted() of the corresponding player
 void TouchStarted(TouchInfo touch)
 {
     int playerIndex = GetPlayerIndex(touch.worldPos.x, touch.worldPos.y);
     if (playerIndex >= 0) {	// -1 indicates buffer zone touch
         players[playerIndex].TouchStarted(touch);
     }
     else {
     //			Instantiate(invalidPrefab, touch.worldPos, Quaternion.identity);	// TODO: prefab
     }
 }
Esempio n. 44
0
File: Results.cs Progetto: shu1/dfu
 public void EndTouch(TouchInfo info)
 {
     showBackButton = true;
 }
Esempio n. 45
0
/* Only used for debugging
#if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN || UNITY_WEBPLAYER
	public override void onTouchEnded( UIFakeTouch touch, Vector2 touchPos, bool touchWasInsideTouchFrame )
#else
	public override void onTouchEnded( Touch touch, Vector2 touchPos, bool touchWasInsideTouchFrame )
#endif
	{
		//Debug.Log( "TOUCH ENDED" );
		//Debug.Log( string.Format( "x: {0}, y: {1}", touch.position.x, touch.position.y ) );
	}
*/

	
#if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN || UNITY_WEBPLAYER
	private bool processTouchInfoWithTouch( TouchInfo touchInfo, UIFakeTouch touch )
Esempio n. 46
0
File: Player.cs Progetto: shu1/dfu
 // Performs regular touch end functions only if the ended touch is the currently valid touch.
 public void TouchEnded(TouchInfo touch)
 {
     if (touch == downTouch) {	// Check if this is the currently valid touch
         downTouch = null;
         bTouchDown = false;
         bCooldown = true;	// Enter cooldown mode upon touch release
     }
 }
Esempio n. 47
0
File: Player.cs Progetto: shu1/dfu
    // Checks whether any valid touch already exists. If not, it makes the incoming touch the currently valid touch.
    public void TouchStarted(TouchInfo touch)
    {
        bool bInvalid = true;

        // Determine whether a currently valid touch already exists
        if (!bTouchDown && !bCooldown && spamTimer <= 0) {
            float dx = Mathf.Abs(touch.worldPos.x);
            float dy = Mathf.Abs(touch.worldPos.y);
            float distance = Mathf.Sqrt(dx * dx + dy * dy);

            // Determine whether touch occurred within crease
            if ((distance < maxTouchRadius) && (distance > minTouchRadius)) {
                balls = GameObject.FindGameObjectsWithTag("ball");

                foreach (GameObject ball in balls) {
                    //Checks if the sphere is being spawned on top of a ball
                    Vector3 touchPos = new Vector3(touch.worldPos.x, touch.worldPos.y, 0);
                    if ((touchPos - ball.transform.position).sqrMagnitude > (sphereRadius + ballRadius) * (sphereRadius + ballRadius)) {
                        bInvalid = false;
                        bPenalty = false;
                        bTouchDown = true;
                        renderer.enabled = true;
                        collider.enabled = true;
                        spamTimer = spamTimerStart;
                        downTouch = touch;
                        transform.position = touchPos;
                        chargeTime = 1;
                    }
                }
            }
        }

        if (bInvalid) {
            audio.PlayOneShot(invalidSound);
            Instantiate(invalidPrefab, touch.worldPos, Quaternion.identity);
        }
    }
Esempio n. 48
0
File: Player.cs Progetto: shu1/dfu
    // Performs a regular update upon a touch being held down, only if the held touch is the currently valid touch.
    public void TouchUpdate(TouchInfo touch)
    {
        if (touch == downTouch && !bCooldown) {	// Check if this is the currently valid touch
            chargeTime = chargeTime + Time.deltaTime;

            Vector3 gestureVector = touch.worldPos - transform.position;
        //			accel = Vector3.Dot(gestureVector, playerForward);
            spin = Vector3.Dot(gestureVector, playerRight);

            UpdateSphere(touch);

            balls = GameObject.FindGameObjectsWithTag("ball");	// TODO: don't do this in Update()!
        }
    }
Esempio n. 49
0
File: Player.cs Progetto: shu1/dfu
    // Updates sphere position and scale based on current charge time. Also detects sphere overload condition.
    void UpdateSphere(TouchInfo touch)
    {
        // Update sphere size according to current charge time
        float scale = Mathf.Min( (chargeTime * maxScale/maxChargeTime), maxScale);
        transform.localScale = new Vector3(scale, scale, scale);
        transform.Rotate(Vector3.forward * -spin);
        sphereRadius = scale / 2;	// TODO: is this right? Neil- I dunno... It'd only work if the original sphere is 1 unit in diameter. Scale is the multiplier on the original size.

        // Overload warning
        if (!bOverload && chargeTime > overloadTime) {
            overloadParticleSystem = (GameObject)Instantiate(overloadPrefab, transform.position, Quaternion.identity);
            bOverload = true;
        }

        // Overload condition
        if (chargeTime > overloadTime) {
            TouchEnded(touch);
            bPenalty = true;
        }
    }
 public void QueueTouch( Touch pxTouch, bool bCollided )
 {
     TouchInfo pxInfo = new TouchInfo( pxTouch, bCollided );
     m_pxTouchQueue.Enqueue( pxInfo );
 }
	private void OneTouchDrag(TouchInfo tInfo)
	{

	}
Esempio n. 52
0
File: Menu.cs Progetto: shu1/dfu
 public void UpdateTouch(TouchInfo info)
 {
 }
Esempio n. 53
0
 public void EndTouch( TouchInfo touch )
 {
     if ( OnEndTouch != null )
         OnEndTouch( touch );
 }
       private void workGrid_TouchDown(object sender, TouchEventArgs e)
 {
     TouchInfo infoT = new TouchInfo();
     infoT.touchDevice = e.TouchDevice;
     infoT.start = e.GetTouchPoint(gravityCanvas).Position;
     infoT.now = infoT.start;
     if (chkOrbitAssistance.IsChecked == true) 
     {
         infoT.orbitAssistance = true;
         touchInfos.Add(infoT);          
         return; }
           infoT.aim = new Line();
           infoT.aimSpeed = new Label();
           infoT.aim.X1 = infoT.start.X;
           infoT.aim.Y1 = infoT.start.Y;
           infoT.aim.X2 = infoT.now.X;
           infoT.aim.Y2 = infoT.now.Y;
           infoT.aim.Stroke = Brushes.White;
           infoT.aim.StrokeThickness = 10;
           infoT.aim.StrokeStartLineCap = PenLineCap.Triangle;
           touchInfos.Add(infoT);
           gravityCanvas.Children.Add(infoT.aim);
           //CaptureTouch(infoT.touchDevice);
           infoT.touchDevice.Capture(gravityCanvas,CaptureMode.Element);
       }
Esempio n. 55
0
	private bool processTouchInfoWithTouch( TouchInfo touchInfo, Touch touch )
#endif
	{
		// If we already completed the swipe detection or if none are availalbe get out of here
		if( touchInfo.swipeDetectionStatus != SwipeDetectionStatus.Waiting )
			return false;

		// If we have a time stipulation and we exceeded it stop listening for swipes
		if( timeToSwipe > 0.0f && ( Time.time - touchInfo.startTime ) > timeToSwipe )
		{
			touchInfo.swipeDetectionStatus = SwipeDetectionStatus.Failed;
			return false;
		}
		

		// When dealing with standalones (non touch-based devices) we need to be careful what we examaine
		// We filter out all touches (mouse movements really) that didnt move
#if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN || UNITY_WEBPLAYER
		if( touch.deltaPosition.x != 0.0f || touch.deltaPosition.y != 0.0f )
		{
#endif

		// Check the delta move positions.  We can rule out at least 2 directions
		if( touch.deltaPosition.x > 0.0f )
			touchInfo.swipeDetectionState &= ~SwipeDirection.Left;
		else
			touchInfo.swipeDetectionState &= ~SwipeDirection.Right;
		
		if( touch.deltaPosition.y < 0.0f )
			touchInfo.swipeDetectionState &= ~SwipeDirection.Up;
		else
			touchInfo.swipeDetectionState &= ~SwipeDirection.Down;

#if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN || UNITY_WEBPLAYER
		}
#endif
		
		//Debug.Log( string.Format( "swipeStatus: {0}", touchInfo.swipeDetectionState ) );
		
		// Grab the total distance moved in both directions
		float xDeltaAbs = Math.Abs( touchInfo.startPoint.x - touch.position.x );
		float yDeltaAbs = Math.Abs( touchInfo.startPoint.y - touch.position.y );
		
		// Only check for swipes in directions that havent been ruled out yet
		if( ( touchInfo.swipeDetectionState & SwipeDirection.Left ) != 0 )
		{
			if( xDeltaAbs > minimumDistance )
			{
				if( yDeltaAbs < allowedVariance )
				{
					touchInfo.completedSwipeDirection = SwipeDirection.Left;
					swipeVelocity = xDeltaAbs/timeToSwipe;
					return true;
				}
				
				// We exceeded our variance so this swipe is no longer allowed
				touchInfo.swipeDetectionState &= ~SwipeDirection.Left;
			}
		}

		// Right check
		if( ( touchInfo.swipeDetectionState & SwipeDirection.Right ) != 0 )
		{
			if( xDeltaAbs > minimumDistance )
			{
				if( yDeltaAbs < allowedVariance )
				{
					touchInfo.completedSwipeDirection = SwipeDirection.Right;
					swipeVelocity = xDeltaAbs/timeToSwipe;
					return true;
				}
				
				// We exceeded our variance so this swipe is no longer allowed
				touchInfo.swipeDetectionState &= ~SwipeDirection.Right;
			}
		}
		
		// Up check
		if( ( touchInfo.swipeDetectionState & SwipeDirection.Up ) != 0 )
		{
			if( yDeltaAbs > minimumDistance )
			{
				if( xDeltaAbs < allowedVariance )
				{
					touchInfo.completedSwipeDirection = SwipeDirection.Up;
					swipeVelocity = yDeltaAbs/timeToSwipe;
					return true;
				}
				
				// We exceeded our variance so this swipe is no longer allowed
				touchInfo.swipeDetectionState &= ~SwipeDirection.Up;
			}
		}
		
		// Down check
		if( ( touchInfo.swipeDetectionState & SwipeDirection.Down ) != 0 )
		{
			if( yDeltaAbs > minimumDistance )
			{
				if( xDeltaAbs < allowedVariance )
				{
					touchInfo.completedSwipeDirection = SwipeDirection.Down;
					swipeVelocity = yDeltaAbs/timeToSwipe;
					return true;
				}
				
				// We exceeded our variance so this swipe is no longer allowed
				touchInfo.swipeDetectionState &= ~SwipeDirection.Down;
			}
		}
		
		return false;
	}
	private void CheckMouseClick()
	{
		if(Input.GetMouseButtonUp(0))
		{
			isMousePressed = false;
			
			TouchInfo tInfo = new TouchInfo();
			
			int id = 0;
			Vector2 pos = Input.mousePosition;
			if(!isMousePressed)Begindelta[id] = pos;
			
			tInfo.Type = TouchType.END;
			tInfo.FingerId = id;
			
			tInfo.Position.x = pos.x;
			tInfo.Position.y = pos.y;
			
			tInfo.BeginDeltaPosition.x = pos.x - Begindelta[id].x;
			tInfo.BeginDeltaPosition.y = pos.y - Begindelta[id].y;
			
			tInfo.PrevDeltaPosition.x = pos.x - Prevdelta[id].x;
			tInfo.PrevDeltaPosition.y = pos.y - Prevdelta[id].y;
			
			switch(id)
			{
				case 0:	if(onTouch0 != null)onTouch0(tInfo); break;
				case 1:	if(onTouch1 != null)onTouch1(tInfo); break;
				case 2:	if(onTouch2 != null)onTouch2(tInfo); break;
				case 3:	if(onTouch3 != null)onTouch3(tInfo); break;
				case 4:	if(onTouch4 != null)onTouch4(tInfo); break;
			}
			
//			Debug.Log("CheckMouseClick :: tInfo :: Type = " + tInfo.Type + ", FingerId = " + tInfo.FingerId + ", Position = " + tInfo.Position + 
//			          ", BeginDeltaPosition = " + tInfo.BeginDeltaPosition + ", PrevDeltaPosition = " + tInfo.PrevDeltaPosition + 
//			          ", Begindelta[" + id + "]" + Begindelta[id] + ", Prevdelta[" + id + "]" + Prevdelta[id]);
		}
		else if(Input.GetMouseButtonDown(0))
		{
			TouchInfo tInfo = new TouchInfo();
			
			int id = 0;
			Vector2 pos = Input.mousePosition;
			Begindelta[id] = pos;
			
			tInfo.Type = TouchType.BEGIN;
			tInfo.FingerId = id;
			
			tInfo.Position.x = pos.x;
			tInfo.Position.y = pos.y;
			
			tInfo.BeginDeltaPosition = Vector2.zero;
			tInfo.PrevDeltaPosition = Vector2.zero;
			
			switch(id)
			{
				case 0:	if(onTouch0 != null)onTouch0(tInfo); break;
				case 1:	if(onTouch1 != null)onTouch1(tInfo); break;
				case 2:	if(onTouch2 != null)onTouch2(tInfo); break;
				case 3:	if(onTouch3 != null)onTouch3(tInfo); break;
				case 4:	if(onTouch4 != null)onTouch4(tInfo); break;
			}
			
			Prevdelta[id] = pos;
			isMousePressed = true;
			
//			Debug.Log("CheckMouseClick :: tInfo :: Type = " + tInfo.Type + ", FingerId = " + tInfo.FingerId + ", Position = " + tInfo.Position + 
//			          ", BeginDeltaPosition = " + tInfo.BeginDeltaPosition + ", PrevDeltaPosition = " + tInfo.PrevDeltaPosition + 
//			          ", Begindelta[" + id + "]" + Begindelta[id] + ", Prevdelta[" + id + "]" + Prevdelta[id]);
		}
		else if(Input.GetMouseButton(0))
		{
			if(isMousePressed)
			{
				TouchInfo tInfo = new TouchInfo();
				
				int id = 0;
				Vector2 pos = Input.mousePosition;
//				Begindelta[id] = pos;
				
				tInfo.Type = TouchType.MOVE;
				tInfo.FingerId = id;
				
				tInfo.Position.x = pos.x;
				tInfo.Position.y = pos.y;
				
				tInfo.BeginDeltaPosition.x = pos.x - Begindelta[id].x;
				tInfo.BeginDeltaPosition.y = pos.y - Begindelta[id].y;

				Begindelta[id] = pos;
				
				tInfo.PrevDeltaPosition.x = pos.x - Prevdelta[id].x;
				tInfo.PrevDeltaPosition.y = pos.y - Prevdelta[id].y;
				
				switch(id)
				{
					case 0:	if(onTouch0 != null)onTouch0(tInfo); break;
					case 1:	if(onTouch1 != null)onTouch1(tInfo); break;
					case 2:	if(onTouch2 != null)onTouch2(tInfo); break;
					case 3:	if(onTouch3 != null)onTouch3(tInfo); break;
					case 4:	if(onTouch4 != null)onTouch4(tInfo); break;
				}
				
				Prevdelta[id] = pos;
				
//				Debug.Log("CheckMouseClick :: tInfo :: Type = " + tInfo.Type + ", FingerId = " + tInfo.FingerId + ", Position = " + tInfo.Position + 
//				          ", BeginDeltaPosition = " + tInfo.BeginDeltaPosition + ", PrevDeltaPosition = " + tInfo.PrevDeltaPosition + 
//				          ", Begindelta[" + id + "]" + Begindelta[id] + ", Prevdelta[" + id + "]" + Prevdelta[id]);
			}
		}

#if UNITY_EDITOR
		if(Input.GetAxis("Mouse ScrollWheel") > 0)
		{
			if(onWheel != null)onWheel(true);
		}

		if(Input.GetAxis("Mouse ScrollWheel") < 0)
		{
			if(onWheel != null)onWheel(false);
		}
#endif
	}
Esempio n. 57
0
        internal void ReadFromBuffer(byte[] buffer)
        {
            const int offset = 35;
            const int touchDataSize = 4;

            Count = 0;

            Array.Copy(TouchInfos, PreviousTouchInfos, TouchInfos.Length);

            var now = DateTime.UtcNow;

            for (var i = 0; i < MaxTouches; i++) {
                var localOffset = offset + (i * touchDataSize);
                var isActive = (buffer[localOffset] & 0x80) == 0;
                var touchId = (byte)(buffer[localOffset] & 0x7F);
                var touchX = buffer[localOffset + 1] + ((buffer[localOffset + 2] & 0xF) * 255);
                var touchY = ((buffer[localOffset + 2] & 0xF0) >> 4) + (buffer[localOffset + 3] * 16);
                int startX, startY;
                DateTime startWhen;

                if (
                    (PreviousTouchInfos[i].Id == touchId) &&
                    PreviousTouchInfos[i].IsActive
                ) {
                    startX = PreviousTouchInfos[i].StartX;
                    startY = PreviousTouchInfos[i].StartY;
                    startWhen = PreviousTouchInfos[i].StartWhen;
                } else {
                    startX = touchX;
                    startY = touchY;
                    startWhen = now;
                }

                TouchInfos[i] = new TouchInfo {
                    IsActive = isActive,
                    Id = touchId,
                    X = touchX,
                    Y = touchY,
                    StartX = startX,
                    StartY = startY,
                    StartWhen = startWhen,
                    When = now
                };

                if (isActive) {
                    Count = Math.Max(Count, i + 1);
                }
            }
        }
	private void CheckTouch()
	{
		int count = Input.touchCount;
		if(count == 0) return;
		
		for(int i = 0; i < count; i++)
		{
			Touch touch = Input.GetTouch(i);
			int id = touch.fingerId;
			Vector2 pos = touch.position;
			
			TouchInfo tInfo = new TouchInfo();
			
			if(touch.phase == TouchPhase.Began)Begindelta[id] = touch.position;
			
			tInfo.Type = GetTouchType(touch.phase);
			tInfo.FingerId = id;
			
			tInfo.Position.x = pos.x;
			tInfo.Position.y = pos.y;
			
			if(tInfo.Type == TouchType.BEGIN)
			{
				tInfo.BeginDeltaPosition = Vector2.zero;
				tInfo.PrevDeltaPosition = Vector2.zero;
			}
			else
			{
				tInfo.BeginDeltaPosition.x = pos.x - Begindelta[id].x;
				tInfo.BeginDeltaPosition.y = pos.y - Begindelta[id].y;
				
				tInfo.PrevDeltaPosition.x = pos.x - Prevdelta[id].x;
				tInfo.PrevDeltaPosition.y = pos.y - Prevdelta[id].y;
			}
			
			switch(id)
			{
				case 0:	if(onTouch0 != null)onTouch0(tInfo); break;
				case 1:	if(onTouch1 != null)onTouch1(tInfo); break;
				case 2:	if(onTouch2 != null)onTouch2(tInfo); break;
				case 3:	if(onTouch3 != null)onTouch3(tInfo); break;
				case 4:	if(onTouch4 != null)onTouch4(tInfo); break;
			}
			
			
			if(touch.phase == TouchPhase.Began || touch.phase == TouchPhase.Moved)Prevdelta[id] = touch.position;
		}
	}
Esempio n. 59
0
File: Game.cs Progetto: shu1/dfu
 // Calls the TouchEnded() of all players. Players determine whether the touch belongs to them or not. Because if a player's touch ends outside the player's boundary, the player can still keep track of it.
 void TouchEnded(TouchInfo touch)
 {
     for (int i = 0; i < numPlayers; ++i) {
         players[i].TouchEnded(touch);
     }
 }
Esempio n. 60
0
File: Game.cs Progetto: shu1/dfu
 // Calls the TouchUpdate() of all players. Players determine whether the touch belongs to them or not. Because if a player's touch slides out of the player's boundary, the player can still keep track of it.
 void TouchUpdate(TouchInfo touch)
 {
     for (int i = 0; i < numPlayers; ++i) {
         players[i].TouchUpdate(touch);
     }
 }