Assets/Watson/Scripts/Utilities/TouchEventManager.cs
/// <summary>
/// Registers the double tap event.
/// </summary>
/// <returns><c>true</c>, if double tap event was registered, <c>false</c> otherwise.</returns>
/// <param name="gameObjectToTouch">Game object to touch.</param>
/// <param name="callback">Callback.</param>
/// <param name="SortingLayer">Sorting layer.</param>
/// <param name="isDoubleTapInside">If set to <c>true</c> is double tap inside.</param>
/// <param name="layerMask">Layer mask.</param>
Registers the double tap event.
Registers the double tap event .
public bool RegisterDoubleTapEvent(GameObject gameObjectToTouch, string callback, int SortingLayer = 0, bool isDoubleTapInside = true, LayerMask layerMask = default(LayerMask))
        {
            bool success = false;
            if (gameObjectToTouch != null)
            {
                if (!string.IsNullOrEmpty(callback))
                {
                    Collider[] colliderList = gameObjectToTouch.GetComponentsInChildren<Collider>();
                    if (colliderList != null && colliderList.Length > 0)
                    {
                        foreach (Collider itemCollider in colliderList)
                        {
                            int layerMaskAsKey = (layerMask != default(LayerMask)) ? layerMask.value : (1 << gameObjectToTouch.layer);
                            #if ENABLE_DEBUGGING
                            Log.Debug("TouchEventManager", "RegisterDoubleTapEvent for 3D. itemCollider: {0}, callback: {1}, SortingLayer: {2}, isTapInside: {3}",itemCollider, callback, SortingLayer, isDoubleTapInside);
                            #endif
                            if (m_DoubleTapEvents.ContainsKey(layerMaskAsKey))
                            {
                                m_DoubleTapEvents[layerMaskAsKey].Add(new TouchEventData(itemCollider, callback, SortingLayer, isDoubleTapInside));
                            }
                            else
                            {
                                m_DoubleTapEvents[layerMaskAsKey] = new List<TouchEventData>() { new TouchEventData(itemCollider, callback, SortingLayer, isDoubleTapInside) };
                            }
                        }
                        success = true;
                    }
                    else
                    {
                        Log.Warning("TouchEventManager", "There is no 3D collider of given gameobjectToTouch (double-tap)");
                    }
                    if (!success)
                    {
                        Collider2D[] colliderList2D = gameObjectToTouch.GetComponentsInChildren<Collider2D> ();
                        if (colliderList2D != null && colliderList2D.Length > 0)
                        {
                            foreach (Collider2D itemCollider in colliderList2D)
                            {
                                int layerMaskAsKey = (layerMask != default(LayerMask)) ? layerMask.value : (1 << gameObjectToTouch.layer);
                                #if ENABLE_DEBUGGING
                                Log.Debug("TouchEventManager", "RegisterDoubleTapEvent For 2D. itemCollider: {0}, callback: {1}, SortingLayer: {2}, isTapInside: {3}",itemCollider, callback, SortingLayer, isDoubleTapInside);
                                #endif
                                if (m_DoubleTapEvents.ContainsKey (layerMaskAsKey))
                                {
                                    m_DoubleTapEvents [layerMaskAsKey].Add (new TouchEventData (itemCollider, callback, SortingLayer, isDoubleTapInside));
                                } else
                                {
                                    m_DoubleTapEvents [layerMaskAsKey] = new List<TouchEventData> () { new TouchEventData (itemCollider, callback, SortingLayer, isDoubleTapInside) };
                                }
                            }
                            success = true;
                        } else
                        {
                            Log.Warning ("TouchEventManager", "There is no 2D collider of given gameobjectToTouch (double-tap)");
                        }
                    }
                    #if UNITY_4_6 || UNITY_5 || UNITY_5_3_OR_NEWER
                    if (!success)
                    {
                        RectTransform[] rectTransformList = gameObjectToTouch.GetComponentsInChildren<RectTransform> (includeInactive: true);
                        if (rectTransformList != null && rectTransformList.Length > 0)
                        {
                            foreach (RectTransform itemRectTransform in rectTransformList)
                            {
                                int layerMaskAsKey = (layerMask != default(LayerMask)) ? layerMask.value : (1 << itemRectTransform.gameObject.layer);
                                #if ENABLE_DEBUGGING
                                Log.Debug("TouchEventManager", "RegisterDoubleTapEvent For 2D Event System. itemRectTransform: {0}, callback: {1}, SortingLayer: {2}, isTapInside: {3}",itemRectTransform, callback, SortingLayer, isDoubleTapInside);
                                #endif
                                if (m_DoubleTapEvents.ContainsKey (layerMaskAsKey))
                                {
                                    m_DoubleTapEvents [layerMaskAsKey].Add (new TouchEventData (itemRectTransform, callback, SortingLayer, isDoubleTapInside));
                                } else
                                {
                                    m_DoubleTapEvents [layerMaskAsKey] = new List<TouchEventData> () { new TouchEventData (itemRectTransform, callback, SortingLayer, isDoubleTapInside) };
                                }
                            }
                            success = true;
                        } else
                        {
                            Log.Warning ("TouchEventManager", "There is no Rect Transform of given gameobjectToTouch (double-tap)");
                        }
                    }
                    #endif
                }
                else
                {
                    Log.Warning("TouchEventManager", "There is no callback for double-tap event registration");
                }
            }
            else
            {
                Log.Warning("TouchEventManager", "There is no gameobject for double-tap event registration");
            }
            return success;
        }
public bool RegisterDoubleTapEvent ( GameObject gameObjectToTouch , string callback , int SortingLayer = 0 , bool isDoubleTapInside = true , LayerMask layerMask = default ( LayerMask ) ) { bool success = false ; if ( gameObjectToTouch != null ) { if ( ! string . IsNullOrEmpty ( callback ) ) { Collider [ ] colliderList = gameObjectToTouch . GetComponentsInChildren < Collider > ( ) ; if ( colliderList != null && colliderList . Length > 0 ) { foreach ( Collider itemCollider in colliderList ) { int layerMaskAsKey = ( layerMask != default ( LayerMask ) ) ? layerMask . value : ( 1 << gameObjectToTouch . layer ) ; if ENABLE_DEBUGGING Log . Debug ( " " , " " , itemCollider , callback , SortingLayer , isDoubleTapInside ) ; endif if ( m_DoubleTapEvents . ContainsKey ( layerMaskAsKey ) ) { m_DoubleTapEvents [ layerMaskAsKey ] . Add ( new TouchEventData ( itemCollider , callback , SortingLayer , isDoubleTapInside ) ) ; } else { m_DoubleTapEvents [ layerMaskAsKey ] = new List < TouchEventData > ( ) { new TouchEventData ( itemCollider , callback , SortingLayer , isDoubleTapInside ) } ; } } success = true ; } else { Log . Warning ( " " , " " ) ; } if ( ! success ) { Collider2D [ ] colliderList2D = gameObjectToTouch . GetComponentsInChildren < Collider2D > ( ) ; if ( colliderList2D != null && colliderList2D . Length > 0 ) { foreach ( Collider2D itemCollider in colliderList2D ) { int layerMaskAsKey = ( layerMask != default ( LayerMask ) ) ? layerMask . value : ( 1 << gameObjectToTouch . layer ) ; if ENABLE_DEBUGGING Log . Debug ( " " , " " , itemCollider , callback , SortingLayer , isDoubleTapInside ) ; endif if ( m_DoubleTapEvents . ContainsKey ( layerMaskAsKey ) ) { m_DoubleTapEvents [ layerMaskAsKey ] . Add ( new TouchEventData ( itemCollider , callback , SortingLayer , isDoubleTapInside ) ) ; } else { m_DoubleTapEvents [ layerMaskAsKey ] = new List < TouchEventData > ( ) { new TouchEventData ( itemCollider , callback , SortingLayer , isDoubleTapInside ) } ; } } success = true ; } else { Log . Warning ( " " , " " ) ; } } if UNITY_4_6 || UNITY_5 || UNITY_5_3_OR_NEWER if ( ! success ) { RectTransform [ ] rectTransformList = gameObjectToTouch . GetComponentsInChildren < RectTransform > ( includeInactive : true ) ; if ( rectTransformList != null && rectTransformList . Length > 0 ) { foreach ( RectTransform itemRectTransform in rectTransformList ) { int layerMaskAsKey = ( layerMask != default ( LayerMask ) ) ? layerMask . value : ( 1 << itemRectTransform . gameObject . layer ) ; if ENABLE_DEBUGGING Log . Debug ( " " , " " , itemRectTransform , callback , SortingLayer , isDoubleTapInside ) ; endif if ( m_DoubleTapEvents . ContainsKey ( layerMaskAsKey ) ) { m_DoubleTapEvents [ layerMaskAsKey ] . Add ( new TouchEventData ( itemRectTransform , callback , SortingLayer , isDoubleTapInside ) ) ; } else { m_DoubleTapEvents [ layerMaskAsKey ] = new List < TouchEventData > ( ) { new TouchEventData ( itemRectTransform , callback , SortingLayer , isDoubleTapInside ) } ; } } success = true ; } else { Log . Warning ( " " , " " ) ; } } endif } else { Log . Warning ( " " , " " ) ; } } else { Log . Warning ( " " , " " ) ; } return success ; }
Registers the double tap event.
Registers the double tap event .
None
gameObjectToTouch
GameObject
Game object to touch.
Game object to touch .
callback
string
None
SortingLayer
int
None
isDoubleTapInside
bool
If set to true
If set to true
layerMask
LayerMask
None