Example #1
0
		void Update ()
		{

				Debug.DrawRay (fromCam.transform.position, fromCam.transform.forward, Color.white);
				for (int i = 0; i < Input.touchCount; i++) {
						currTouch = i;
						ray = fromCam.ScreenPointToRay (Input.GetTouch (i).position);//creates ray from screen point position
						//Debug.DrawLine(fromCam.transform.position, );
						
						//Debug.Log (ray);
						//if the ray hit something, only if it hit something
						if (Physics.Raycast (ray, out rayHitInfo)) {
								//rayHitInfo.collider.name = 
								//Debug.Log (rayHitInfo);
								//if the thing that was hit implements ITouchable3D
								if (useInterfaceITouchable3DBase) {
										touchedObject = rayHitInfo.transform.GetComponent (typeof(ITouchable3DBase)) as ITouchable3DBase;
										//Debug.Log (rayHitInfo.gameobject.name);
										//If the ray hit something and it implements ITouchable3D
										if (touchedObject != null) {	
												
												switch (Input.GetTouch (i).phase) {
												case TouchPhase.Began:
														touchedObject.OnTouchBegan ();
														touch2Watch = currTouch;
														break;
												case TouchPhase.Ended:
														touchedObject.OnTouchEnded ();
														break;
												case TouchPhase.Moved:
														touchedObject.OnTouchMoved ();
														break;
												case TouchPhase.Stationary:
														touchedObject.OnTouchStayed ();
														break;
												}
										}
								} else {
										TouchableOB touch_ob_start = rayHitInfo.collider.gameObject.GetComponent<TouchableOB> ();
										//touch_ob_start.onSelected (rayHitInfo.collider.gameObject);
										if (touch_ob_start != null) {
												onSelected (rayHitInfo.collider.gameObject, Input.GetTouch (i).phase);
												Debug.Log ("onSelected");
										}
								}
						}
			//On Anywhere
			else if (touchedObject != null && touch2Watch == currTouch) {
								switch (Input.GetTouch (i).phase) {
								case TouchPhase.Ended:
										touchedObject.OnTouchEndedAnywhere ();
										touchedObject = null;
										break;
								case TouchPhase.Moved:
										touchedObject.OnTouchMovedAnywhere ();
										break;
								case TouchPhase.Stationary:
										touchedObject.OnTouchStayedAnywhere ();
										break;
								}
						}
				}
		}
Example #2
0
    void Update()
    {
        Debug.DrawRay(fromCam.transform.position, fromCam.transform.forward, Color.white);
        for (int i = 0; i < Input.touchCount; i++)
        {
            currTouch = i;
            ray       = fromCam.ScreenPointToRay(Input.GetTouch(i).position);                                //creates ray from screen point position
            //Debug.DrawLine(fromCam.transform.position, );

            //Debug.Log (ray);
            //if the ray hit something, only if it hit something
            if (Physics.Raycast(ray, out rayHitInfo))
            {
                //rayHitInfo.collider.name =
                //Debug.Log (rayHitInfo);
                //if the thing that was hit implements ITouchable3D
                if (useInterfaceITouchable3DBase)
                {
                    touchedObject = rayHitInfo.transform.GetComponent(typeof(ITouchable3DBase)) as ITouchable3DBase;
                    //Debug.Log (rayHitInfo.gameobject.name);
                    //If the ray hit something and it implements ITouchable3D
                    if (touchedObject != null)
                    {
                        switch (Input.GetTouch(i).phase)
                        {
                        case TouchPhase.Began:
                            touchedObject.OnTouchBegan();
                            touch2Watch = currTouch;
                            break;

                        case TouchPhase.Ended:
                            touchedObject.OnTouchEnded();
                            break;

                        case TouchPhase.Moved:
                            touchedObject.OnTouchMoved();
                            break;

                        case TouchPhase.Stationary:
                            touchedObject.OnTouchStayed();
                            break;
                        }
                    }
                }
                else
                {
                    TouchableOB touch_ob_start = rayHitInfo.collider.gameObject.GetComponent <TouchableOB> ();
                    //touch_ob_start.onSelected (rayHitInfo.collider.gameObject);
                    if (touch_ob_start != null)
                    {
                        onSelected(rayHitInfo.collider.gameObject, Input.GetTouch(i).phase);
                        Debug.Log("onSelected");
                    }
                }
            }
            //On Anywhere
            else if (touchedObject != null && touch2Watch == currTouch)
            {
                switch (Input.GetTouch(i).phase)
                {
                case TouchPhase.Ended:
                    touchedObject.OnTouchEndedAnywhere();
                    touchedObject = null;
                    break;

                case TouchPhase.Moved:
                    touchedObject.OnTouchMovedAnywhere();
                    break;

                case TouchPhase.Stationary:
                    touchedObject.OnTouchStayedAnywhere();
                    break;
                }
            }
        }
    }