I am working on a multitouch table that a bunch of photos are layed out on. Users can then come up to the table, move the photos around, scale and rotate them. Everything is working good if one person is using the table. The issue I have is if multiple people are using the table. I was trying to go through and set up an int so anytime someone touches a game object that game object keeps track of how many fingers are touching it. This count is adding 1 on the OnFingerDown method. The issue I have is how to find out if someone removes there finger if that finger was touching the game object already or another game object. You can see OnFingerUp i tried to delete one from the fingercount but it is accounting for anyone’s finger anywhere on the table lifting and not if it was associated to that specific game object. The code I started with was from LeanFinger.
using UnityEngine;
// This script will rotate and scale the GameObject based on finger gestures
public class SimpleRotateScale : MonoBehaviour
{
public LayerMask LayerMask = UnityEngine.Physics.DefaultRaycastLayers;
private Lean.LeanFinger draggingFinger;
public GameObject LocalObject;
public GameObject ClickObject;
public int fingerCount = 0;
protected virtual void OnEnable()
{
// Hook into the OnFingerDown event
Lean.LeanTouch.OnFingerDown += OnFingerDown;
// Hook into the OnFingerUp event
Lean.LeanTouch.OnFingerUp += OnFingerUp;
}
protected virtual void OnDisable()
{
// Unhook the OnFingerDown event
Lean.LeanTouch.OnFingerDown -= OnFingerDown;
// Unhook the OnFingerUp event
Lean.LeanTouch.OnFingerUp -= OnFingerUp;
}
protected virtual void LateUpdate()
{
LocalObject = gameObject;
if (draggingFinger != null && LocalObject == ClickObject && fingerCount>2) {
// This will rotate the current transform based on a multi finger twist gesture
// Lean.LeanTouch.RotateObject (transform, Lean.LeanTouch.TwistDegrees);
RotateObjectLocal(transform, Lean.LeanTouch.TwistDegrees);
// This will scale the current transform based on a multi finger pinch gesture
ScaleObjectLocal (transform, Lean.LeanTouch.PinchScale);
}
}
public static void RotateObjectLocal(Transform transform, float deltaRotation, Camera camera = null)
{
if (transform != null && deltaRotation != 0.0f)
{
transform.rotation = RotateObjectLocalA(transform.rotation, deltaRotation, camera);
}
}
public static Quaternion RotateObjectLocalA(Quaternion worldRotation, float deltaRotation, Camera camera = null)
{
if (deltaRotation != 0.0f)
{
if (camera == null) camera = Camera.main;
if (camera != null)
{
worldRotation = Quaternion.AngleAxis(deltaRotation, camera.transform.forward) * worldRotation;
}
}
return worldRotation;
}
public static void ScaleObjectLocal(Transform transform, float scale)
{
if (transform != null && scale != 1.0f)
{
// transform.localScale *= scale;
Vector3 tempScale;
tempScale = transform.localScale;
if (transform.localScale.x * scale < 17 && transform.localScale.x * scale >3) {
tempScale.x = transform.localScale.x * scale;
tempScale.y = transform.localScale.y * scale;
transform.localScale = tempScale;
}
}
}
public void OnFingerDown(Lean.LeanFinger finger)
{
// Raycast information
var ray = finger.GetRay ();
var hit = default(RaycastHit);
// Was this finger pressed down on a collider?
if (Physics.Raycast (ray, out hit, float.PositiveInfinity, LayerMask) == true) {
// Was that collider this one?
ClickObject = hit.collider.gameObject;
if (hit.collider.gameObject == gameObject) {
// Set the current finger to this one
draggingFinger = finger;
fingerCount += 1;
}
}
}
public void OnFingerUp(Lean.LeanFinger finger)
{
// fingerCount -= 1;
// Was the current finger lifted from the screen?
if (finger == draggingFinger)
{
// Unset the current finger
draggingFinger = null;
}
}
}