Exemplo n.º 1
0
    public override void mPhoneUpdate()
    {
        base.mPhoneUpdate();
        if (uguiHitUI.uiHited == true)
        {
            if (Input.touchCount == 1)
            {
                Touch   touch = Input.GetTouch(0);
                Vector3 v3    = touch.position;
                oldPos1 = v3;
            }
            return;
        }
        bool changed             = false;
        bool isUnnormalRotate    = inputMachine.CurrentState is SetMaterialState || inputMachine.CurrentState is PlaceGoodsState3D;// || inputMachine.CurrentState is SelectState3D;
        SelectGoodsState3D state = inputMachine.CurrentState as SelectGoodsState3D;

        if (state != null)
        {
            isUnnormalRotate = state.canMove || state.onhandle;
        }

        if (currentCount != Input.touchCount)
        {
            currentCount = Input.touchCount;
            if (currentCount == 1)
            {
                Touch touch0 = Input.GetTouch(0);
                oldPos1 = touch0.position;
            }
            else if (currentCount == 2)
            {
                Touch touch0 = Input.GetTouch(0);
                Touch touch1 = Input.GetTouch(1);
                oldDis = (touch0.position - touch1.position).magnitude;
                oldPos = (touch0.position + touch1.position) / 2f;
            }
            changed = true;
        }


        if (Input.touchCount == 1)
        {
            Touch   touch = Input.GetTouch(0);
            Vector3 v3    = touch.position;
            if (touch.phase == TouchPhase.Began)
            {
                oldPos1 = v3;
                offsetList.Clear();
                MyMono.MyStopCoroutine(MoveRotate, this);
            }
            else if ((touch.phase == TouchPhase.Moved || touch.phase == TouchPhase.Ended) && isUnnormalRotate == false)
            {
                if (oldPos1.x == v3.x && oldPos1.y == v3.y)
                {
                    return;
                }
                Vector2 offset = v3 - oldPos1;
                offsetList.Add(offset);
                if (offsetList.Count > offsetCount)
                {
                    offsetList.RemoveAt(0);
                }
                oldPos1 = v3;
                Rotate(offset);
                changed = true;
                if (touch.phase == TouchPhase.Ended)
                {
                    MyMono.MyStartCoroutine(MoveRotate, this);
                }
            }
        }
        else if (Input.touchCount == 2)
        {
            Touch touch0 = Input.GetTouch(0);
            Touch touch1 = Input.GetTouch(1);
            if (touch0.phase == TouchPhase.Began || touch1.phase == TouchPhase.Began)
            {
                oldDis = (touch0.position - touch1.position).magnitude;
                ///移动时的旧位置
                oldPos  = (touch0.position + touch1.position) / 2f;
                changed = true;
                MyMono.MyStopCoroutine(MoveRotate, this);
            }
            else if (touch0.phase == TouchPhase.Moved || touch1.phase == TouchPhase.Moved)
            {
                float dis   = (touch0.position - touch1.position).magnitude;
                float delta = (dis - oldDis) / 100f;
                if (delta != 0)
                {
                    Vector3 pos    = target.transform.position;
                    float   curdis = Vector3.Distance(pos, cameraFocasCenter);
                    float   f      = (curdis - settings.minFreeViewDis) / (settings.maxFreeViewDis - settings.minFreeViewDis);
                    float   speed  = 0.005f;
                    if (f * scaleMulti > speed)
                    {
                        speed = f * scaleMulti;
                    }
                    f     -= delta * speed;
                    curdis = Mathf.Lerp(settings.minFreeViewDis, settings.maxFreeViewDis, f);
                    pos    = cameraFocasCenter + curdis * (pos - cameraFocasCenter).normalized;
                    SetMainCameraPos(pos);
                    changed = true;
                    machine.dispatchEvent(new CameraEvent(CameraEvent.ScaleChange));
                    machine.dispatchEvent(new CameraEvent(CameraEvent.ViewChange));
                }
                oldDis = dis;

                Vector2 curpos   = (touch0.position + touch1.position) / 2f;
                Vector2 deltaPos = curpos - (Vector2)oldPos;
                if (deltaPos != Vector2.zero)
                {
                    Vector3 pos       = target.transform.position;
                    float   focaseDis = Vector3.Distance(pos, focaseP);
                    Vector3 offset    = GetRayPoint(curpos, focaseDis) - GetRayPoint(oldPos, focaseDis);
                    Vector3 moved     = -offset;
                    oldPos = curpos;
                    Vector3 modedPos = pos + moved;
                    modedPos.y = modedPos.y < settings.minFreeViewDis ? settings.minFreeViewDis : modedPos.y;
                    modedPos.y = modedPos.y > settings.maxFreeViewDis ? settings.maxFreeViewDis : modedPos.y;
                    SetMainCameraPos(modedPos, false);
                    moved    = modedPos - pos;
                    focaseP += moved;
                    changed  = true;
                    machine.dispatchEvent(new CameraEvent(CameraEvent.PositionChange));
                    machine.dispatchEvent(new CameraEvent(CameraEvent.ViewChange));
                }
            }
        }

        //if (changed && state != null)
        //{
        //    state.LookAt();
        //}

        //Vector3 v3 = Input.mousePosition;

        //if (Input.GetMouseButtonDown(2))
        //{
        //    oldPos = v3;
        //}
        //if (Input.GetMouseButton(2))
        //{
        //    if (oldPos == v3)
        //    {
        //        return;
        //    }
        //    Vector3 pos = target.transform.position;
        //    float dis = Vector3.Distance(pos, focaseP);
        //    Vector3 offset = GetRayPoint(v3, dis) - GetRayPoint(oldPos, dis);
        //    Vector3 moved = -offset;
        //    oldPos = v3;
        //    Vector3 modedPos = pos + moved;
        //    modedPos.y = modedPos.y < settings.minFreeViewDis ? settings.minFreeViewDis : modedPos.y;
        //    modedPos.y = modedPos.y > settings.maxFreeViewDis ? settings.maxFreeViewDis : modedPos.y;
        //    SetMainCameraPos(modedPos, false);
        //    moved = modedPos - pos;
        //    focaseP += moved;
        //}
    }
Exemplo n.º 2
0
    public override void mUpdate()
    {
        base.mUpdate();
        Vector3 v3 = Input.mousePosition;

        if (uguiHitUI.uiHited == true)
        {
            oldPos1 = v3;
            return;
        }
        float delta = Input.GetAxis("Mouse ScrollWheel");

        if (delta != 0)
        {
            Vector3 pos   = target.transform.position;
            float   dis   = Vector3.Distance(pos, cameraFocasCenter);
            float   f     = (dis - settings.minFreeViewDis) / (settings.maxFreeViewDis - settings.minFreeViewDis);
            float   speed = 0.005f;
            if (f * scaleMultiEditor > speed)
            {
                speed = f * scaleMultiEditor;
            }
            //Debug.LogWarning("speed = " + speed);
            f  -= delta * speed;
            dis = Mathf.Lerp(settings.minFreeViewDis, settings.maxFreeViewDis, f);
            pos = cameraFocasCenter + dis * (pos - cameraFocasCenter).normalized;
            SetMainCameraPos(pos);
            machine.dispatchEvent(new CameraEvent(CameraEvent.ScaleChange));
            machine.dispatchEvent(new CameraEvent(CameraEvent.ViewChange));
        }

        bool changed            = false;
        bool isRightPointRotate = inputMachine.CurrentState is SetMaterialState || inputMachine.CurrentState is PlaceGoodsState3D;// || inputMachine.CurrentState is SelectState3D;

        SelectGoodsState3D state = inputMachine.CurrentState as SelectGoodsState3D;

        if (state != null)
        {
            isRightPointRotate = state.canMove || state.onhandle;
        }

        if (Input.GetMouseButtonDown(0) || (isRightPointRotate == true && Input.GetMouseButtonDown(1)))
        {
            oldPos1 = v3;
            offsetList.Clear();
            MyMono.MyStopCoroutine(MoveRotate, this);
        }
        if (
            (isRightPointRotate == false && (Input.GetMouseButton(0) || Input.GetMouseButtonUp(0)))
            ||
            (isRightPointRotate == true && (Input.GetMouseButton(1) || Input.GetMouseButtonUp(1)))
            )
        {
            if (oldPos1 == v3)
            {
                return;
            }
            Vector2 offset = v3 - oldPos1;
            offsetList.Add(offset);
            if (offsetList.Count > offsetCount)
            {
                offsetList.RemoveAt(0);
            }
            oldPos1 = v3;
            Rotate(offset);
            if (
                (isRightPointRotate == false && Input.GetMouseButtonUp(0))
                ||
                (isRightPointRotate == true && Input.GetMouseButtonUp(1))
                )
            {
                MyMono.MyStartCoroutine(MoveRotate, this);
            }
            //Vector3 pos = target.transform.position;
            //float dis = Vector3.Distance(pos, focaseP);
            //Vector3 euler = target.transform.rotation.eulerAngles;
            //euler.x -= offset.y/2 * rotateMultiYEditor;
            //euler.y += offset.x/2 * rotateMultiXEditor;
            //euler.y = euler.y > 360 ? euler.y - 360 : euler.y;
            //euler.y = euler.y < -360 ? euler.y + 360 : euler.y;
            //if (euler.x < 180)
            //{
            //    euler.x = euler.x > settings.maxFreeViewAngle ? settings.maxFreeViewAngle : euler.x;
            //}
            //else
            //{
            //    euler.x -= 360;
            //}
            //euler.x = euler.x < settings.minFreeViewAngle ? settings.minFreeViewAngle : euler.x;
            //target.transform.rotation = Quaternion.Euler(euler);
            //Vector3 rotatePos = GetRayPoint(Screen.width / 2 * Vector2.right + Screen.height / 2 * Vector2.up, dis - target.nearClipPlane);
            //target.transform.position += focaseP - rotatePos;
            //MyCallLater.Add(0.5f, RefreshView);
            changed = true;
        }

        if (Input.GetMouseButtonDown(2))
        {
            ///记录移动时输入的旧位置
            oldPos  = v3;
            changed = true;
            MyMono.MyStopCoroutine(MoveRotate, this);
        }
        if (Input.GetMouseButton(2))
        {
            if (oldPos == v3)
            {
                return;
            }
            Vector3 pos    = target.transform.position;
            float   dis    = Vector3.Distance(pos, focaseP);
            Vector3 offset = GetRayPoint(v3, dis) - GetRayPoint(oldPos, dis);
            Vector3 moved  = -offset;
            oldPos = v3;
            Vector3 modedPos = pos + moved;
            modedPos.y = modedPos.y < settings.minFreeViewDis ? settings.minFreeViewDis : modedPos.y;
            modedPos.y = modedPos.y > settings.maxFreeViewDis ? settings.maxFreeViewDis : modedPos.y;
            SetMainCameraPos(modedPos, false);
            moved    = modedPos - pos;
            focaseP += moved;
            changed  = true;
            machine.dispatchEvent(new CameraEvent(CameraEvent.PositionChange));
            machine.dispatchEvent(new CameraEvent(CameraEvent.ViewChange));
        }


        //if (changed && state != null)
        //{
        //    state.LookAt();
        //}
    }