public void AccelDrag( GameObject go, Vector2 delta )
{
// Check if user dragged his finger passed the treshold,
// and update which UI Element was dragged on
HandleTouchTreshold( accelBtn );
// Turn accel on if we dragged onto it
if( UICamera.lastHit.collider != null && !accelOn )
{
// Send a message instead of "accelOn = true" to re-play button OnPress animations/events
accelBtn.SendMessage("OnPress", true, SendMessageOptions.DontRequireReceiver);
}
}
public void BrakeDrag( GameObject go, Vector2 delta )
{
// Check if user dragged his finger passed the treshold,
// and update which UI Element was dragged on
HandleTouchTreshold( brakeBtn, UICamera.currentTouchID );
// Turn brake on if we dragged onto it
if( UICamera.lastHit.collider != null )
{
// Send a message instead of "brakeOn = true" to re-play button OnPress animations/events
brakeBtn.SendMessage("OnPress", true, SendMessageOptions.DontRequireReceiver);
}
}
// =================== Function to handle touch treshold ================= //
public void HandleTouchTreshold( GameObject lastGameObject )
{
// Store the last hit gameobject.
// If it's null, send OnPress(false) to the lastGameObject, and stop execution.
Collider hitCollider = UICamera.lastHit.collider;
if( !hitCollider )
{
// Debug.LogWarning("DRAGGED PAST TRESHOLD");
lastGameObject.SendMessage( "OnPress", false, SendMessageOptions.DontRequireReceiver );
return;
}
// Detect which UI element we dragged onto
GameObject activeGameObject = null;
foreach( GameObject go in availableUIElements )
{
if( hitCollider == go.collider ) activeGameObject = go;
else go.SendMessage( "OnPress", false, SendMessageOptions.DontRequireReceiver );
}
// Now that we know the last hit object AND the active object( the one we dragged onto )
// we can switch focus to the new object, and activate it.
if( hitCollider != lastGameObject.collider )
{
Debug.LogWarning("DRAGGED ONTO NEW OBJECT: " + UICamera.currentTouch.current);
if( hitCollider == activeGameObject.collider )
{
UICamera.currentTouch.pressed = activeGameObject;
activeGameObject.SendMessage( "OnPress", true, SendMessageOptions.DontRequireReceiver );
Debug.Log("SENDING ONPRESS TO: " + activeGameObject.name);
}
else activeGameObject.SendMessage( "OnPress", false, SendMessageOptions.DontRequireReceiver );
}
}