private void FindTouchReferences()
 {
     touch            = FindObjectOfType <LeanTouch>();
     fingerSwipeLeft  = GameObject.Find("SwipeLeft").GetComponent <LeanFingerSwipe>();
     fingerSwipeRight = GameObject.Find("SwipeRight").GetComponent <LeanFingerSwipe>();
     fingerTap        = GameObject.Find("LeanTouch").GetComponent <LeanFingerTap>();
 }
Ejemplo n.º 2
0
 private void CacheLeanComponents()
 {
     _ltd  = GetComponent <LeanThresholdDelta>();
     _lmr  = GetComponent <LeanManualRotate>();
     _lmu  = GetComponent <LeanMultiUpdate>();
     _lft  = GetComponent <LeanFingerTap>();
     _ldta = GetComponent <LeanDragTranslateAlong>();
 }
Ejemplo n.º 3
0
 private void Start()
 {
     director               = overallDirector.Instance;
     onTreeAnim             = GetComponent <Animation>();
     tapManager             = GameObject.Find("LeanCtrl").GetComponent <LeanFingerTap>();
     tools                  = GeneralTools.Instance;
     pickActivityRegistered = false;
 }
        /// <summary>
        /// Registers a Tap event on a specific object
        /// </summary>
        /// <param name="gameObject"></param>
        /// <param name="includeChildren"></param>
        /// <param name="callback"></param>
        public void RegisterTap(GameObject gameObject, bool includeChildren, OnTouchDelegate callback)
        {
            if (gameObject == null)
            {
                // Register a global tap event
                RegisterTap(callback);
                return;
            }

            GameObject target = gameObject;

            if (gameObject.transform is RectTransform)
            {
            }
            else
            {
                Collider collider = gameObject.GetComponentInChildren <Collider>();

                if (collider == null)
                {
                    DebugLogger.LogWarning("Touch : Could not register tap. No Collider found on {0}", gameObject.name);
                    return;
                }
                target = collider.gameObject;
            }


            LeanFingerTap tap = target.GetComponent <LeanFingerTap>();

            if (tap == null)
            {
                tap = target.AddComponent <LeanFingerTap>();
            }

            tap.IgnoreStartedOverGui = false;

            LeanSelectable selectable = AddSelectableComponent(target);

            // Check if it exists in the dictionary
            if (registeredTapCallbacks.ContainsKey(tap))
            {
                // Check if this particular callback is already registered
                if (registeredTapCallbacks[tap].Contains(callback))
                {
                    return;
                }
            }
            else
            {
                registeredTapCallbacks.Add(tap, new List <OnTouchDelegate>());
            }

            registeredTapCallbacks[tap].Add(callback);

            selectable.DeselectOnUp = true;
            tap.RequiredSelectable  = selectable;
            tap.OnFinger.AddListener(OnTap);
        }
Ejemplo n.º 5
0
    void Start()
    {
        myParticleSystem = GetComponent <ParticleSystem>();

        LeanController = GameObject.Find("LeanTouch");
        LeanFingerTap tapCtrl = LeanController.GetComponent <LeanFingerTap>();

        tapCtrl.OnFinger.AddListener(OnTap);
    }
Ejemplo n.º 6
0
    // Start is called before the first frame update
    void Start()
    {
        // 魔药锅的参数缓存
        myParticleSystem = colorObj.GetComponent <ParticleSystem>();
        colorModule      = myParticleSystem.colorOverLifetime;

        // 把响应加到场景的Lean控制器
        LeanController = GameObject.Find("LeanTouch");
        LeanFingerTap tapCtrl = LeanController.GetComponent <LeanFingerTap>();

        tapCtrl.OnFinger.AddListener(OnTap);
    }
        /// <summary>
        ///
        /// </summary>
        /// <param name="leanFinger"></param>
        private void OnTap(LeanFinger leanFinger)
        {
            GameObject    go  = leanFinger.gameObject;
            LeanFingerTap tap = go.GetComponent <LeanFingerTap>();

            if (tap == null)
            {
                return;
            }


            float   nsx = leanFinger.ScreenPosition.x / Screen.width;
            float   nsy = leanFinger.ScreenPosition.y / Screen.height;
            Vector2 normalisedScreenPosition = new Vector2(
                nsx,
                nsy
                );


            Vector2       objectPosition           = new Vector2();
            Vector2       normalisedObjectPosition = new Vector2();
            RectTransform rt = go.transform as RectTransform;

            if (rt != null)
            {
                // Flip the y axis
                Vector2 rtPos = rt.anchoredPosition;
                rtPos.y = -rtPos.y;
                Vector2 flippedScreenPos = leanFinger.ScreenPosition;
                flippedScreenPos.y = Screen.height - leanFinger.ScreenPosition.y;

                objectPosition             = flippedScreenPos - rtPos;
                normalisedObjectPosition.x = objectPosition.x / rt.sizeDelta.x;
                normalisedObjectPosition.y = objectPosition.y / rt.sizeDelta.y;
            }


            if (registeredTapCallbacks.ContainsKey(tap))
            {
                registeredTapCallbacks[tap].ForEach(i => i.Invoke(new TouchCallbackVO
                {
                    gameObject               = go,
                    screenPosition           = leanFinger.ScreenPosition,
                    normalisedScreenPosition = normalisedScreenPosition,
                    objectPosition           = objectPosition,
                    normalisedObjectPosition = normalisedObjectPosition
                }));
            }
        }
        void Awake()
        {
            fingerTap = GetComponentInChildren <LeanFingerTap>();
            layerMask = layerMask.value == LayerMask.NameToLayer("Default") ? LayerMask.NameToLayer("UI") : layerMask.value;
            cam       = LeanTouch.GetCamera(cam);
            vibration = GetComponent <VibrationComponent>();

            if (vibrateOn.touchScreen || vibrateOn.uiElement)
            {
                if (vibration == null)
                {
                    string msg = "The vibrate on touch is enabled, but you not add '{0}' component. Add it to '{1}' gameObject";
                    Debug.LogErrorFormat(msg, "VibrationCustom", gameObject.name.ToUpper());
                }
            }

            touchUI = new LeanTouchUI {
                FingerTap      = fingerTap,
                layerToRaycast = layerMask
            };

            screenWorldPos = cam.ScreenToWorldPoint(new Vector2(Screen.width, Screen.height));

            directionsActions = new Dictionary <SideDirection, DirectionData>()
            {
                { SideDirection.LEFT, new DirectionData {
                      OnTapDirection = (Vector3 pos, LeanFinger finger) => OnTapScreenSide?.Invoke(pos, SideDirection.LEFT, finger)
                  } },
                { SideDirection.RIGHT, new DirectionData {
                      OnTapDirection = (Vector3 pos, LeanFinger finger) => OnTapScreenSide?.Invoke(pos, SideDirection.RIGHT, finger)
                  } },
                { SideDirection.TOP_LEFT, new DirectionData {
                      IndicatorSidePos = new Vector2(-screenWorldPos.x, screenWorldPos.y),
                      OnTapDirection   = (Vector3 pos, LeanFinger finger) => OnTapScreenDiagonal?.Invoke(pos, SideDirection.TOP_LEFT, finger)
                  } },
                { SideDirection.TOP_RIGHT, new DirectionData {
                      IndicatorSidePos = new Vector2(screenWorldPos.x, screenWorldPos.y),
                      OnTapDirection   = (Vector3 pos, LeanFinger finger) => OnTapScreenDiagonal?.Invoke(pos, SideDirection.TOP_RIGHT, finger)
                  } },
                { SideDirection.DOWN_LEFT, new DirectionData {
                      IndicatorSidePos = new Vector2(-screenWorldPos.x, -screenWorldPos.y),
                      OnTapDirection   = (Vector3 pos, LeanFinger finger) => OnTapScreenDiagonal?.Invoke(pos, SideDirection.DOWN_LEFT, finger)
                  } },
                { SideDirection.DOWN_RIGHT, new DirectionData {
                      IndicatorSidePos = new Vector2(screenWorldPos.x, -screenWorldPos.y),
                      OnTapDirection   = (Vector3 pos, LeanFinger finger) => OnTapScreenDiagonal?.Invoke(pos, SideDirection.DOWN_RIGHT, finger)
                  } }
            };
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="gameObject"></param>
        /// <param name="callback"></param>
        public void UnRegisterTap(GameObject gameObject, OnTouchDelegate callback)
        {
            LeanFingerTap tap = gameObject.GetComponent <LeanFingerTap>();

            if (tap == null)
            {
                return;
            }

            if (registeredTapCallbacks.ContainsKey(tap))
            {
                if (registeredTapCallbacks[tap].Contains(callback))
                {
                    registeredTapCallbacks[tap].Remove(callback);
                }
            }
        }
        public void Initialize()
        {
            registeredSwipeDeltaCallbacks = new Dictionary <GameObject, List <OnTouchDelegate> >();
            registeredTapCallbacks        = new Dictionary <LeanFingerTap, List <OnTouchDelegate> >();

            leanTouch      = gameObject.AddComponent <LeanTouch>();
            leanSelect     = gameObject.AddComponent <LeanSelect>();
            leanFingerTap  = gameObject.AddComponent <LeanFingerTap>();
            leanFingerDown = gameObject.AddComponent <LeanFingerDown>();
            leanFingerUp   = gameObject.AddComponent <LeanFingerUp>();

            leanFingerTap.OnFinger.AddListener(leanSelect.SelectScreenPosition);
            leanFingerDown.OnFinger.AddListener(leanSelect.SelectScreenPosition);

            leanSelect.LayerMask     &= ~(1 << LayerMask.NameToLayer("PostProcessing"));
            leanSelect.SelectUsing    = LeanSelect.SelectType.CanvasUI;
            leanSelect.SelectUsingAlt = LeanSelect.SelectType.Raycast3D;

            leanFingerDown.IgnoreStartedOverGui = false;
            leanFingerUp.IgnoreStartedOverGui   = false;
            leanFingerTap.IgnoreStartedOverGui  = false;
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="gameObject"></param>
        public void UnRegisterAll(GameObject gameObject)
        {
            LeanFingerTap     tap  = gameObject.GetComponent <LeanFingerTap>();
            LeanFingerDown    down = gameObject.GetComponent <LeanFingerDown>();
            LeanFingerUp      up   = gameObject.GetComponent <LeanFingerUp>();
            LeanDragTranslate drag = gameObject.GetComponent <LeanDragTranslate>();

            if (drag != null)
            {
                GameObject.Destroy(drag);
            }
            if (down != null)
            {
                down.OnFinger.RemoveAllListeners();
                down.OnPosition.RemoveAllListeners();
            }
            if (up != null)
            {
                up.OnFinger.RemoveAllListeners();
                up.OnPosition.RemoveAllListeners();
            }
            if (tap != null)
            {
                tap.OnFinger.RemoveAllListeners();
                tap.OnPosition.RemoveAllListeners();

                if (registeredTapCallbacks.ContainsKey(tap))
                {
                    registeredTapCallbacks.Remove(tap);
                }
            }

            if (registeredSwipeDeltaCallbacks.ContainsKey(gameObject))
            {
                registeredSwipeDeltaCallbacks.Remove(gameObject);
            }
        }
Ejemplo n.º 12
0
        private IEnumerator LoadModel()
        {
            string path = modelSource;

            Debug.Log("DynamicModelTrackableEventHandler LoadModel " + path);
            if (File.Exists(path))
            {
                Utility.PrepareForSendMessage("LoadAssetBundle", "0", targetInfo ["targetName"]);
                string path1  = "file://" + modelSource;
                WWW    bundle = new WWW(path1);
                yield return(bundle);

                GameObject [] gos = bundle.assetBundle.LoadAllAssets <GameObject>();
                for (int i = 0; i < gos.Length; ++i)
                {
                    GameObject go;
                    yield return(go = Instantiate(gos [i]));

                    if (go)
                    {
                        //Instantiate success
                        go.transform.SetParent(this.gameObject.transform);
                        if (i == 0)
                        {
                            continue;                                   // the first gameobject needn't hidden
                        }
                        Utility.HideRendererAndCollider(go.transform);
                    }
                    else
                    {
                        Debug.Log("model loaded but instantiate fail");
                    }
                }
                #region MultiTargetManager
                for (int i = 0; i < this.transform.childCount - 1; ++i)
                {
                    LeanFingerTap tap = this.transform.GetChild(i).GetComponentInChildren <LeanFingerTap> (true);
                    tap.nextARObject = this.transform.GetChild(i + 1).gameObject;
                }
                if (this.transform.childCount > 1)
                {
                    GameObject    startGo = this.transform.GetChild(0).gameObject;
                    LeanFingerTap tap     = this.transform.GetChild(this.transform.childCount - 1).GetComponentInChildren <LeanFingerTap> (true);
                    tap.nextARObject = startGo;
                }
                #endregion                 //MultiTargetManager

                bundle.assetBundle.Unload(false);
                isModelLoaded = true;
                Debug.Log("DynamicModelTrackableEventHandler LoadModel Created");

                #region ass memorymanager

                /*
                 * 这里AssetBundle的管理形式是:当程序中已经加载的AssetBundle已经超过一定数目时(现在暂定5个),就从中删除一个index最小的模型,此时在对应加载最新的模型
                 */
                if (AssMemoryManager.instance.dicCount >= 5)
                {
                    Debug.Log("need to delete some model from memory");
                    AssMemoryManager.RemoveGoFromMemoryManager();
                }
                AssMemoryManager.AddGOToMemoryManager(mTrackableBehaviour.TrackableName, this.gameObject);
                Utility.LogPrint("add gameobject to target,the trackName is:" + mTrackableBehaviour.TrackableName);
                #endregion                 //memorymanager end

                //notify mobile load ass success
                Utility.PrepareForSendMessage("LoadAssetBundle", "1", targetInfo);
            }
            else
            {
                //file not exist,notify mobile to load the ass;
                Utility.LogPrint("load model error,because the file path is not exist");
                Utility.PrepareForSendMessage("DownAssetBundle", "1", targetInfo);
            }
        }
Ejemplo n.º 13
0
 public void OnAwake(MonoBehaviour monoBehaviour)
 {
     leanTouch     = monoBehaviour.transform.Find("LeanTouch").GetComponent <LeanTouch>();
     leanSelect    = monoBehaviour.transform.Find("LeanTouch").GetComponent <LeanSelect>();
     leanFingerTap = monoBehaviour.transform.Find("LeanTouch").GetComponent <LeanFingerTap>();
 }