public void RemoveTouch(Touch t)
 {
     if (touchCount > 0)
     {
         touchCount--;
     }
 }
Beispiel #2
0
    Joint addJoint(Rigidbody attachTo, GameObject go, Vector3 hitPoint, Touch t)
    {
        Joint j = (Joint)go.GetComponent <Joint>();

        // Initial position of the joint is the centre of the body we pickup or the hook
        if (hook != null)
        {
            go.transform.position = hook.transform.position;
        }
        else
        {
            go.transform.position = hitPoint;
        }

        // Deal with centre of mass
        if (attachToCenterOfMass)
        {
            Vector3 anchor = go.transform.InverseTransformPoint(attachTo.worldCenterOfMass);
            j.anchor = anchor;
        }
        else
        {
            j.anchor = Vector3.zero;
        }

        initJoint(j, attachTo);
        joints.Add(t.fingerId, j);
        return(j);
    }
Beispiel #3
0
    void addTouch(Touch t)
    {
        RaycastHit h      = new RaycastHit();
        bool       hasHit = (Physics.Raycast(getRay(t), out h, 100f, GetLayerMask(hitOnlyLayers)));

        addTouchIcon(h.point, t, hasHit);
    }
    void startTrace(RaycastHit h, Touch t, bool hasHit)
    {
        Vector3?   start = hasHit ? (Vector3?)h.point : null;
        TouchTrace tr    = new TouchTrace(Time.time, start);

        liveTraces.Add(t.fingerId, tr);
    }
Beispiel #5
0
    void removeTouchIcon(Touch t)
    {
        GameObject go = touchIcons[t.fingerId];

        touchIcons.Remove(t.fingerId);
        Destroy(go);
    }
Beispiel #6
0
    void updateTouchIcon(Vector3 hitPoint, Touch t, bool visible)
    {
        GameObject go = touchIcons[t.fingerId];

        go.transform.position = hitPoint;
        go.renderer.enabled   = visible;
    }
Beispiel #7
0
    void removeDragger(Touch t)
    {
        GameObject go = draggers[t.fingerId];

        draggers.Remove(t.fingerId);
        Destroy(go);
    }
Beispiel #8
0
    Ray getRay(Touch t)
    {
        Vector3 touchPoint = new Vector3(t.position.x, t.position.y, 0f);
        Ray     targetRay  = targetCam.ScreenPointToRay(touchPoint);

        return(targetRay);
    }
Beispiel #9
0
    void Update()
    {
        if (frameTouches.Length > 0 && frameTouches[0].phase == TouchPhase.Ended)
        {
            frameTouches = new Touch[0];
        }

        Vector2 pos = new Vector2(Input.mousePosition.x, Input.mousePosition.y);

        if (Input.GetMouseButtonDown(0) && touchCount == 0)
        {
            // New touch
            Touch t = new Touch(0, pos, Vector2.zero, 0f, 0, TouchPhase.Began);
            frameTouches = new Touch[1] {
                t
            };
            touchCount = 1;
        }
        else if (Input.GetMouseButtonUp(0))
        {
            // Removed touch
            Vector2 deltaPos = frameTouches[0].position - pos;
            Touch   t        = new Touch(0, pos, deltaPos, 0f, 0, TouchPhase.Ended);
            frameTouches[0] = t;
            touchCount      = 0;
        }
        else if (Input.GetMouseButton(0))
        {
            Vector2    deltaPos = frameTouches[0].position - pos;
            TouchPhase phase    = deltaPos == Vector2.zero ? TouchPhase.Stationary : TouchPhase.Moved;
            Touch      t        = new Touch(0, pos, deltaPos, 0f, 0, phase);
            frameTouches[0] = t;
        }
    }
	public override void RemoveTouch(Touch t)
	{
		base.RemoveTouch(t);
		
		if (Tolerances.TriggerOnTouchDown) return;
		
		// Not most recent touch?
		if (curTouch.fingerId != t.fingerId) return;
		
		if (Tolerances.CheckHeldTime && Time.time - TimeAdded > Tolerances.MaxHeldTime) return;
		
		if (Tolerances.CheckMovementThreshold)
		{
			// Over the movement threshold?
			Vector2 curTouchPos = new Vector2(
					t.position.x / (float)screenWidth,
				    t.position.y / (float)screenHeight);
		
			if (Vector2.Distance(curTouchPos, originalPos) > Tolerances.MaximumPosChange) return;
		}		
		
		// Check if the touch still hits the same collider
		RaycastHit h = new RaycastHit();
		
		if(Tolerances.CheckHitsSameCollider && !HitsOrigCollider(t, out h)) return;
			
		DoClick(h);
		
		ClearCurTouch();
	}
    void removeTouch(Touch t)
    {
        RaycastHit h      = new RaycastHit();
        bool       hasHit = (Physics.Raycast(getRay(t), out h, Mathf.Infinity, LayerHelper.GetLayerMask(hitOnlyLayers)));

        endTrace(h, t, hasHit);
    }
Beispiel #12
0
	void Update()
	{
		if (frameTouches.Length > 0 && frameTouches[0].phase == TouchPhase.Ended) frameTouches = new Touch[0];
		
		Vector2 pos = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
		if (Input.GetMouseButtonDown(0) && touchCount == 0)
		{
			// New touch
			Touch t = new Touch(0, pos, Vector2.zero, 0f, 0, TouchPhase.Began);
			frameTouches = new Touch[1] { t };
			touchCount = 1;
		}
		else if (Input.GetMouseButtonUp(0))
		{
			// Removed touch
			Vector2 deltaPos = frameTouches[0].position - pos;
			Touch t = new Touch(0, pos, deltaPos, 0f, 0, TouchPhase.Ended);
			frameTouches[0] = t;
			touchCount = 0;
		}
		else if (Input.GetMouseButton(0))
		{
			Vector2 deltaPos = frameTouches[0].position - pos;
			TouchPhase phase = deltaPos == Vector2.zero ? TouchPhase.Stationary : TouchPhase.Moved;
			Touch t = new Touch(0, pos, deltaPos, 0f, 0, phase);
			frameTouches[0] = t;
		}
	}
Beispiel #13
0
 public void UpdateTouch(Touch t)
 {
     if (!touches.ContainsKey(t.fingerId))
     {
         return;
     }
     touches[t.fingerId] = t;
 }
Beispiel #14
0
	public void AddTouch(Touch t, RaycastHit hit, Camera hitOn)
	{
		// Create the object we want in the touch position
		GameObject go = createInstance(hit.point, hitOn);
		
		// If object has a collider, relink internally
		if (DoRecast && go.collider != null) linker.AddTouch(t, hitOn, go.collider);
	}
	public override void AddTouch (Touch t, RaycastHit hit, Camera hitOn)
	{
		base.AddTouch(t, hit, hitOn);
		
		TimeAdded = Time.time;
		
		if (Tolerances.TriggerOnTouchDown) DoClick(hit);
	}
	public override void RemoveTouch(Touch t)
	{
		base.RemoveTouch(t);
		
		if(curTouch.fingerId == t.fingerId)
		{
			CancelHeld();
		}
	}
Beispiel #17
0
    public override void RemoveTouch(Touch t)
    {
        base.RemoveTouch(t);

        if (curTouch.fingerId == t.fingerId)
        {
            CancelHeld();
        }
    }
Beispiel #18
0
 protected bool HitsOrigCollider(Touch inTouch, out RaycastHit outHit)
 {
     if (origCollider == null)
     {
         outHit = new RaycastHit();
         return(false);
     }
     return(origCollider.Raycast(getRay(inTouch), out outHit, Mathf.Infinity));
 }
Beispiel #19
0
    GameObject addTouchIcon(Vector3 hitPoint, Touch t, bool visible)
    {
        GameObject go = (GameObject)Instantiate(TouchIcon);

        go.transform.position = new Vector3(hitPoint.x, hitPoint.y, hitPoint.z);
        go.renderer.enabled   = visible;

        touchIcons.Add(t.fingerId, go);
        return(go);
    }
Beispiel #20
0
    void updateTouchIcon(Touch t)
    {
        if (!touchIcons.ContainsKey(t.fingerId))
        {
            return;
        }
        GUITexture go = touchIcons[t.fingerId];

        setTouchIconPos(go, t.position);
    }
Beispiel #21
0
    GUITexture addTouchIcon(Touch t)
    {
        GameObject touchIcon = (GameObject)Instantiate(GUITouchIcon);
        GUITexture texture   = touchIcon.GetComponent <GUITexture>();

        setTouchIconPos(texture, t.position);

        touchIcons.Add(t.fingerId, texture);
        return(texture);
    }
Beispiel #22
0
    public void RemoveTouch(Touch t)
    {
        if (!enabled)
        {
            return;
        }

        removeJoint(t.fingerId);
        removeDragger(t);
    }
Beispiel #23
0
    void updateDragger(Vector3 hitPoint, Touch t, bool visible)
    {
        GameObject go = draggers[t.fingerId];

        go.transform.position = hitPoint;

        if (go.renderer != null)
        {
            go.renderer.enabled = visible && showDraggers;
        }
    }
Beispiel #24
0
    public void AddTouch(Touch t, RaycastHit hit, Camera hitOn)
    {
        // Create the object we want in the touch position
        GameObject go = createInstance(hit.point, hitOn);

        // If object has a collider, relink internally
        if (DoRecast && go.collider != null)
        {
            linker.AddTouch(t, hitOn, go.collider);
        }
    }
    public override void AddTouch(Touch t, RaycastHit hit, Camera hitOn)
    {
        base.AddTouch(t, hit, hitOn);

        TimeAdded = Time.time;

        if (Tolerances.TriggerOnTouchDown)
        {
            DoClick(hit);
        }
    }
    void updateTouch(Touch t)
    {
        RaycastHit h      = new RaycastHit();
        bool       hasHit = (Physics.Raycast(getRay(t), out h, Mathf.Infinity, LayerHelper.GetLayerMask(hitOnlyLayers)));

        if (!hasHit)
        {
            return;
        }
        updateTrace(h, t);
    }
    void updateTrace(RaycastHit h, Touch t)
    {
        if (!liveTraces.ContainsKey(t.fingerId))
        {
            return;
        }

        TouchTrace tr = liveTraces[t.fingerId];

        tr.positions.Add(h.point);
    }
	public override void AddTouch(Touch t, RaycastHit hit, Camera hitOn)
	{
		base.AddTouch(t, hit, hitOn);
		
		if(curTouch.fingerId == t.fingerId)
		{
			if (TouchStartMessege != string.Empty) BroadcastTouchMessage(TouchStartMessege, hit);
			
			heldTimer.StartCountdown(HoldTime);
		}
	}
Beispiel #29
0
    void removeTouchIcon(Touch t)
    {
        if (!touchIcons.ContainsKey(t.fingerId))
        {
            return;
        }
        GUITexture go = touchIcons[t.fingerId];

        touchIcons.Remove(t.fingerId);
        Destroy(go.gameObject);
    }
Beispiel #30
0
    public void AddTouch(Touch t, RaycastHit hit, Camera hitOn)
    {
        if (!enabled)
        {
            return;
        }

        targetCamera = hitOn;

        GameObject go  = addDragger(hit.point, t, true);
        Rigidbody  bod = attachToParent ? transform.parent.rigidbody : rigidbody;

        addJoint(bod, go, hit.point, t);
    }
Beispiel #31
0
    public void AddTouch(Touch t, RaycastHit hit, Camera hitOn)
    {
        if (enabled)
        {
            if (touches.Count == 0)
            {
                notifyObject.SendMessage(EventOnTouchDown, SendMessageOptions.DontRequireReceiver);
            }
        }

        targetCamera = hitOn;
        touches.Add(t.fingerId, t);
        touchesChanged = true;
    }
Beispiel #32
0
    GameObject addDragger(Vector3 hitPoint, Touch t, bool visible)
    {
        GameObject go = (GameObject)Instantiate(dragger);

        go.transform.position = hitPoint;

        if (go.renderer != null)
        {
            go.renderer.enabled = visible && showDraggers;
        }

        draggers.Add(t.fingerId, go);
        return(go);
    }
	public override void UpdateTouch(Touch t)
	{
		base.UpdateTouch(t);
		
		if(curTouch.fingerId != t.fingerId || !touchSet) return;
		
		if(heldTimer.RemainingTime > 0.0f) return;
		
		RaycastHit h = new RaycastHit();
		if(collider != null && !HitsOrigCollider(t, out h)) return;
		
		BroadcastTouchMessage(HeldMessage, h);
		EndHeld();
	}
Beispiel #34
0
    public override void AddTouch(Touch t, RaycastHit hit, Camera hitOn)
    {
        base.AddTouch(t, hit, hitOn);

        if (curTouch.fingerId == t.fingerId)
        {
            if (TouchStartMessege != string.Empty)
            {
                BroadcastTouchMessage(TouchStartMessege, hit);
            }

            heldTimer.StartCountdown(HoldTime);
        }
    }
Beispiel #35
0
    public void RemoveTouch(Touch t)
    {
        touches.Remove(t.fingerId);
        touchesChanged = true;

        if (!enabled)
        {
            return;
        }

        if (touches.Count == 0)
        {
            notifyObject.SendMessage(EventOnTouchUp, SendMessageOptions.DontRequireReceiver);
        }
    }
Beispiel #36
0
	public virtual void AddTouch(Touch t, RaycastHit hit, Camera hitOn)
	{
		targetCam = hitOn;
		
		// This will always keep the most recent touch
		AssignCurTouch(t);
		
		screenWidth = hitOn.pixelWidth;
		screenHeight = hitOn.pixelHeight;
		
		originalPos = new Vector2(
				t.position.x / (float)screenWidth,
			    t.position.y / (float)screenHeight);
		
		origCollider = hit.collider;
	}
Beispiel #37
0
    public virtual void AddTouch(Touch t, RaycastHit hit, Camera hitOn)
    {
        targetCam = hitOn;

        // This will always keep the most recent touch
        AssignCurTouch(t);

        screenWidth  = hitOn.pixelWidth;
        screenHeight = hitOn.pixelHeight;

        originalPos = new Vector2(
            t.position.x / (float)screenWidth,
            t.position.y / (float)screenHeight);

        origCollider = hit.collider;
    }
    public override void RemoveTouch(Touch t)
    {
        base.RemoveTouch(t);

        if (Tolerances.TriggerOnTouchDown)
        {
            return;
        }

        // Not most recent touch?
        if (curTouch.fingerId != t.fingerId)
        {
            return;
        }

        if (Tolerances.CheckHeldTime && Time.time - TimeAdded > Tolerances.MaxHeldTime)
        {
            return;
        }

        if (Tolerances.CheckMovementThreshold)
        {
            // Over the movement threshold?
            Vector2 curTouchPos = new Vector2(
                t.position.x / (float)screenWidth,
                t.position.y / (float)screenHeight);

            if (Vector2.Distance(curTouchPos, originalPos) > Tolerances.MaximumPosChange)
            {
                return;
            }
        }

        // Check if the touch still hits the same collider
        RaycastHit h = new RaycastHit();

        if (Tolerances.CheckHitsSameCollider && !HitsOrigCollider(t, out h))
        {
            return;
        }

        DoClick(h);

        ClearCurTouch();
    }
	Joint addJoint(Rigidbody attachTo, GameObject go, Vector3 hitPoint, Touch t)
	{
		Joint j = (Joint)go.GetComponent<Joint>();
		
		// Initial position of the joint is the centre of the body we pickup or the hook
		if (hook != null)
		{
			go.transform.position = hook.transform.position;
		}
		else
		{
			go.transform.position = hitPoint;
		}
		
		// Deal with centre of mass
		if (attachToCenterOfMass)
		{
			Vector3 anchor = go.transform.InverseTransformPoint(attachTo.worldCenterOfMass);
			j.anchor = anchor;
		}
		else
		{
			j.anchor = Vector3.zero;
		}
		
		initJoint(j, attachTo);		
		joints.Add(t.fingerId, j);
		return j;
	}
	public void RemoveTouch(Touch t)
	{
		if (touchCount > 0) touchCount--;
	}
	public void AddTouch(Touch t, RaycastHit hit, Camera hitOn)
	{
		if (!enabled) return;
		
		targetCamera = hitOn;
		
		GameObject go = addDragger(hit.point, t, true);
		Rigidbody bod = attachToParent ? transform.parent.rigidbody : rigidbody;
		addJoint(bod, go, hit.point, t);
	}
	public void RemoveTouch(Touch t)
	{
		if (!enabled) return;
		
		removeJoint(t.fingerId);
		removeDragger(t);
	}
	public void RemoveTouch(Touch t)
	{
		touchCount--;
	}
	public void UpdateTouch(Touch t)
	{
		if (!enabled) return;
		
		Ray touchRay = getRay(t);
		
		// Raycast against the hit layers to get new position based on touch position
		RaycastHit h = new RaycastHit();
		bool hasHit = (Physics.Raycast(touchRay, out h, Mathf.Infinity, LayerHelper.GetLayerMask(hitOnlyLayers)));
		if (!hasHit) return;
		
		Vector3 cPos = h.point.UpTowards(targetCamera.transform.position, upDir, liftBy);
		
		// Check if we are within bounds (if defined)
		if (DragBounds != null)
		{
			// Raycast from the target position to the centre of the bounds, if we hit it, we are outside it.
			Vector3 diffDir = (DragBounds.transform.position - cPos).normalized;
			RaycastHit colH;
			hasHit = DragBounds.Raycast(new Ray(cPos, diffDir), out colH, Vector3.Distance(cPos, DragBounds.transform.position)); 
			
			// If we hit the bounds, set the position to where we hit on the bounds
			if (hasHit) cPos = colH.point;
		}
		
		// Move the dragger to the new position
		updateDragger(cPos, t, hasHit);
	}
Beispiel #45
0
	protected void AssignCurTouch(Touch inTouch)
	{
		curTouch = inTouch;	
		touchSet = true;
	}
Beispiel #46
0
	protected void ClearCurTouch()
	{
		curTouch = new Touch();
		touchSet = false;
	}
Beispiel #47
0
	public void UpdateTouch(Touch t)
	{
		if (!touches.ContainsKey(t.fingerId)) return;
		touches[t.fingerId] = t;
	}
	void updateDragger(Vector3 hitPoint, Touch t, bool visible)
	{
		GameObject go = draggers[t.fingerId];
		go.transform.position = hitPoint;
		
		if (go.renderer != null) go.renderer.enabled = visible && showDraggers;
	}
	GameObject addDragger(Vector3 hitPoint, Touch t, bool visible)
	{
		GameObject go = (GameObject)Instantiate(dragger);
		go.transform.position = hitPoint;
		
		if (go.renderer != null) go.renderer.enabled = visible && showDraggers;
		
		draggers.Add(t.fingerId, go);
		return go;
	}
Beispiel #50
0
	Ray getRay(Touch t)
	{
		Vector3 touchPoint = new Vector3(t.position.x, t.position.y, 0f);
		Ray targetRay = targetCam.ScreenPointToRay(touchPoint);
		return targetRay;
	}
Beispiel #51
0
	protected bool HitsOrigCollider(Touch inTouch, out RaycastHit outHit)
	{
		if (origCollider == null) 
		{
			outHit = new RaycastHit();
			return false;
		}
		return origCollider.Raycast(getRay(inTouch), out outHit, Mathf.Infinity);		
	}
Beispiel #52
0
	public virtual void RemoveTouch(Touch t)
	{
	}
Beispiel #53
0
	public void AddTouch(Touch t, RaycastHit hit, Camera hitOn)
	{
		targetCamera = hitOn;
		touches.Add(t.fingerId, t);
		touchesChanged = true;
	}
Beispiel #54
0
	public void RemoveTouch(Touch t)
	{
		touches.Remove(t.fingerId);
		touchesChanged = true;
	}
Beispiel #55
0
	public void AddTouch(Touch t, RaycastHit hit, Camera hitOn)
	{
		if (enabled)
		{
			if (touches.Count == 0) 
			{
				notifyObject.SendMessage(EventOnTouchDown, SendMessageOptions.DontRequireReceiver);
			}
		}
		
		targetCamera = hitOn;
		touches.Add(t.fingerId, t);
		touchesChanged = true;
	}
	void removeDragger(Touch t)
	{
		GameObject go = draggers[t.fingerId];
		draggers.Remove(t.fingerId);
		Destroy(go);
	}
	public void AddTouch(Touch t, RaycastHit hit, Camera hitOn)
	{
		touchCount++;
	}
Beispiel #58
0
	public void RemoveTouch(Touch t)
	{
		touches.Remove(t.fingerId);
		touchesChanged = true;
		
		if (!enabled) return;
		
		if (touches.Count == 0)
		{
			notifyObject.SendMessage(EventOnTouchUp, SendMessageOptions.DontRequireReceiver);
		}
	}
	public void UpdateTouch(Touch t)
	{
	}
Beispiel #60
0
	public virtual void UpdateTouch(Touch t)
	{
	}