コード例 #1
0
    private void Translate(Vector2 screenDelta)
    {
        // If camera is null, try and get the main camera, return true if a camera was found
        if (LeanTouch.GetCamera(ref Camera) == true)
        {
            // Screen position of the transform
            var screenPosition = Camera.WorldToScreenPoint(transform.position);

            // Add the deltaPosition
            screenPosition += (Vector3)screenDelta;

            // Convert back to world space
            Vector3 xPos   = Camera.ScreenToWorldPoint(screenPosition);
            Vector3 newPos = new Vector3(xPos.x, transform.position.y, transform.position.x);
            transform.position = newPos;
        }
    }
コード例 #2
0
    void OnTouch(LeanFinger finger)
    {
        var camera = LeanTouch.GetCamera(Camera, gameObject);

        // world unit -> pixel -> pixel + delta (pixel) -> unit
        if (camera != null)

        {
            // Screen position of the transform
            var screenPoint = camera.WorldToScreenPoint(transform.position);

            // Add the deltaPosition
            screenPoint += (Vector3)finger.ScreenDelta * Sensitive;

            // Convert back to world space
            transform.position = camera.ScreenToWorldPoint(screenPoint);
        }
    }
コード例 #3
0
    protected virtual void Translate(Vector2 screenDelta)
    {
        // Make sure the camera exists
        var camera = LeanTouch.GetCamera(Camera, gameObject);

        if (camera == null)
        {
            return;
        }

        // Screen position of the transform
        var screenPosition = camera.WorldToScreenPoint(transform.position);

        // Add the deltaPosition
        screenPosition += (Vector3)screenDelta;

        // Perform the translation
        transform.position = camera.ScreenToWorldPoint(screenPosition);
    }
コード例 #4
0
    private void Rotate(Vector3 center, float degrees)
    {
        if (Relative == true)
        {
            // Make sure the camera exists
            var camera = LeanTouch.GetCamera(Camera, gameObject);

            if (camera != null)
            {
                // World position of the reference point
                var worldReferencePoint = camera.ScreenToWorldPoint(center);

                // Rotate the transform around the world reference point
                transform.RotateAround(worldReferencePoint, camera.transform.forward, degrees);
            }
        }
        else
        {
            transform.rotation *= Quaternion.AngleAxis(degrees, RotateAxis);
        }
    }
コード例 #5
0
    protected override void Translate(Vector2 screenDelta)
    {
        // Make sure the camera exists
        var camera = LeanTouch.GetCamera(Camera, gameObject);

        if (camera != null)
        {
            // Screen position of the transform
            var screenPoint = camera.WorldToScreenPoint(transform.position);

            // Add the deltaPosition
            screenPoint += (Vector3)screenDelta;

            Vector3 pos         = transform.position;
            Vector3 targetPoint = camera.ScreenToWorldPoint(screenPoint);

            if (Mathf.Abs(moveForward.Direction.z) > 0.5f)
            {
                pos.x = targetPoint.x;
                if (!InRange(pos.x, moveForward.CenterPoint.x))
                {
                    return;
                }
            }
            else if (Mathf.Abs(moveForward.Direction.x) > 0.5f)
            {
                pos.z = targetPoint.z;
                if (!InRange(pos.z, moveForward.CenterPoint.z))
                {
                    return;
                }
            }

            transform.position = pos;
        }
        else
        {
            Debug.LogError("Failed to find camera. Either tag your camera as MainCamera, or set one in this component.", this);
        }
    }
コード例 #6
0
    protected virtual void LateUpdate()
    {
        // Make sure the camera exists
        if (LeanTouch.GetCamera(ref cameraMain, gameObject) == true)
        {
            // Get the fingers we want to use
            var fingers = LeanTouch.GetFingers(IgnoreGuiFingers, RequiredFingerCount);
            //return;

//            if (fingers.Count == 0)
//            {
//                return;
//            }

            //单指操作
            if (fingers.Count == 1)
            {
                if (bDisableAll)
                {
                    return;
                }


                Vector2 screenDelta = LeanGesture.GetScreenDelta(fingers);

                if (!bIsMove && !bMouseRightDown)                 //鼠标右键按下时,不能平移
                {
                    if (Input.GetMouseButtonDown(0))
                    {
                        _cameraDest = GetCenterDistance();
                    }

                    CameraPan(screenDelta);
                }

                //鼠标右键按下时上下调整视角,左右绕中心旋转
                MouseRightUpdate();

//				if (Input.GetMouseButton (1)) {
//					MouseRightTour ();
//				}
            }

            //双指pinch捏放,缩放操作
            float pinchRatio = LeanGesture.GetPinchRatio(fingers, WheelSensitivity); //捏放比例

            //判断pinchRatio是否为1,1表示没有缩放
            if (pinchRatio != 1.0f)
            {
                CameraDistanceRatio(pinchRatio);                 //换为z轴方向移动
            }

            //双指操作
            if (fingers.Count == 2)
            {
                //双指上下移动,调整仰角
                Vector2 heightDelta = LeanGesture.GetScreenDelta(fingers); //手指移动的屏幕距离

                //双指Twist旋转,绕屏幕中心与地面交点旋转
                float twistDegree = LeanGesture.GetTwistDegrees(fingers, LeanGesture.GetScreenCenter(), LeanGesture.GetLastScreenCenter());

                //双指操作
                CameraTwistAndHeight(heightDelta.y, twistDegree);

                //双指操作,调整仰角,绕屏幕中心与地面交点旋转(双指旋转时不符合功能,弃用)
                //计算屏幕中心点
//				Vector3 centerPoint;
//				float enter;
//				if (GetInterPoint(cameraMain, new Vector3(0.5F, 0.5F, 0), out centerPoint, out enter))
//				{
//					_cameraDest = enter + 0.3f;
//
//					CameraTAndH(centerPoint, heightDelta.y, twistDegree);
//				}
            }
        }
    }
コード例 #7
0
        private void OnTrackingLost()
        {
            ModelManager._instance.offCardModelIsMoving = false;
            ModelManager._instance.currentModelisMoving = false;
            //EventManager.StopListening ("OffCard", offCardListener);
            if (ModelManager._instance.isOffCard && modelIsOffCard)
            {
                if (LeanTouch.GetCamera(ref camera1) == true)
                {
                    //float dis = go.transform.position.z - camera1.transform.position.z; //计算与相机之间的距离,确定z = 多少
                    ModelManager._instance.ModelCountMinusOne();
                    Vector3 position = new Vector3(Screen.width / 2, Screen.height / 2, zAxisDistance);                  // 经调试,这里Z直接设置成20,显示在屏幕中的模型大小比较合适
                    position = camera1.ScreenToWorldPoint(position);
                    ModelManager._instance.offCardModelTransform.position = position;
                    Animator animator2 = ModelManager._instance.offCardModelTransform.GetComponent <Animator> ();
                    if (animator2)
                    {
                        animator2.Play("Take 001");
                    }
                    //go.transform.localRotation = modelOriginQua;
                    //这个角度的模型脱卡后稍微好看一点
                    //Utility.offCardModelTransform.localRotation = Quaternion.Euler(new Vector3(-29,-29,8));
                    //Utility.offCardModelTransform.localRotation = Quaternion.Euler(new Vector3(29,151,-8));
                    return;
                }
            }
            for (int i = 0; i < this.transform.childCount; i++)
            {
                Utility.HideRendererAndCollider(this.transform.GetChild(i));
            }

            Animator animator = GetComponentInChildren <Animator> ();

            if (animator)
            {
                animator.Play("Take 001");
                //animator.Stop();
//				ParticleSystem tapParticle = GetTypeParticle (this.transform.GetChild (0),"Tap_Particle");
//				ParticleSystem foundParticle = GetTypeParticle (this.transform.GetChild (0),"Found_Particle");
//				if (tapParticle)	{	tapParticle.Stop ();	}
//				if (foundParticle)	{	foundParticle.Stop ();	}
            }
            if (this.transform.childCount > 0)
            {
                ParticleControl(false, "Found_Particle", this.transform.GetChild(0));
            }

            lostCount++;
            if (lostCount > 2)
            {
                if (ModelManager._instance.isOffCard)
                {
                    EventManager.StartListening("RecoveryModelToTarget", recoveryModelListener);
                }
                //刚加载识别图的时候,总是会先执行Lost方法两次,所以,两次之后再执行脱卡的方法,估计还得改
                ModelManager._instance.ModelCountMinusOne();                 // lost之后,found数目-1

                if (ModelManager._instance.modelCount == 0 && ModelManager._instance.currentRotationTransform)
                {
                    //ModelManager._instance.currentRotationTransform = null;
                    //ModelManager._instance.currentModelisMoving = false;
                    Utility.PrepareForSendMessage("FoundTarget", "0");
                }
            }
            Debug.Log("Trackable " + mTrackableBehaviour.TrackableName + " -------------------------------- lost");
        }
コード例 #8
0
        private void OnTrackingFound()
        {
            if (ModelManager._instance.isOffCard && modelIsOffCard)
            {
                Debug.Log("handle reFound");
                ModelManager._instance.offCardModelIsMoving = false;
                if (LeanTouch.GetCamera(ref camera1) == true)
                {
                    ModelManager._instance.ModelCountPlusOne();                                         //发现的模型数目+1
                    //float dis = go.transform.position.z - camera1.transform.position.z; //计算与相机之间的距离,确定z = 多少
                    Vector3 position = new Vector3(Screen.width / 2, Screen.height / 2, zAxisDistance); // 经调试,这里Z直接设置成20,显示在屏幕中的模型大小比较合适
                    position = camera1.ScreenToWorldPoint(position);
                    ModelManager._instance.offCardModelTransform.position = position;
                    //go.transform.localRotation = modelOriginQua;
                    //这个角度的模型脱卡后稍微好看一点
                    //Utility.offCardModelTransform.localRotation = Quaternion.Euler(new Vector3(-29,-29,8));
                    ModelManager._instance.offCardModelTransform.localRotation = Quaternion.Euler(new Vector3(29, 151, -8));
                    return;
                }                                               //return;
            }

            if (!isModelLoaded)
            {             //if no model bind
                StartCoroutine(LoadModel());
            }
            ModelManager._instance.ModelCountPlusOne();            //发现的模型数目+1
            if (ModelManager._instance.modelCount == 1)
            {
                Utility.PrepareForSendMessage("FoundTarget", "1");
            }
            else
            {
                Debug.Log("----current model count ----" + ModelManager._instance.modelCount);
            }
            if (ModelManager._instance.isOffCard)
            {
                EventManager.StopListening("RecoveryModelToTarget", recoveryModelListener);
                EventManager.TriggerEvent("RecoveryModelToTarget");                 //还原其他模型到target。因为脱卡只留一个模型
            }
            //RecoveryModelToTarget();
            if (this.transform.childCount >= 1)
            {
                //show the first child transform
                Transform foundTransform = this.transform.GetChild(0);
                if (isFirstFound)
                {
                    EventManager.StartListening("OffCard", offCardListener);
                    //这行代码是方便测试用的,正式使用应该要用LoadModel方法中的。
                    AssMemoryManager.AddGOToMemoryManager(mTrackableBehaviour.TrackableName, this.gameObject);
                    //这里记录初始位置,便于以后各种手势之后可以恢复原来的状态。第一次found的时候肯定是初始状态了
                    modelOriginLocalPos = foundTransform.localPosition;
                    modelOriginLocalQua = foundTransform.localRotation;
                    modelOriginPos      = foundTransform.position;
                    modelOriginQua      = foundTransform.rotation;
                    modelOriginScale    = foundTransform.localScale;
                    isFirstFound        = false;
                }
                else
                {
                    foundTransform.localPosition = modelOriginLocalPos;
                    foundTransform.localRotation = modelOriginLocalQua;
                    foundTransform.localScale    = modelOriginScale;
                }
                Utility.ShowRendererAndCollider(foundTransform);
                //ParticleSystem foundParticle = GetTypeParticle (foundTransform, "Found_Particle");
                Animator            animator        = GetComponentInChildren <Animator> ();
                LeanRotationControl rotationControl = GetComponentInChildren <LeanRotationControl> ();
                if (rotationControl)
                {
                    rotationControl.enabled = true;
                }
                //if (foundParticle)		{	foundParticle.Play ();			}
                if (animator)
                {
                    animator.Play("Take 001", 0, 0);
                }
                ParticleControl(true, "Found_Particle", this.transform.GetChild(0));

                if (!ModelManager._instance.isOffCard)
                {
                    ModelManager._instance.currentRotationTransform = this.transform.GetChild(0);
                }
            }
            else
            {
                Debug.Log("child count is 0");
            }
            //每次扫描过后,更新model的Index值,后面AssMemoryManager会根据这个值来管理这些模型
            //AssMemoryManager.UpdateModelIndex(mTrackableBehaviour.TrackableName);
            if (ModelManager._instance.isOffCard)
            {
                EventManager.TriggerEvent("OffCard");
            }

            Debug.Log("Trackable " + mTrackableBehaviour.TrackableName + " --------------------------------  found");
        }