Esempio n. 1
0
//         public void OnMove() {
//             if (clickTarget != null) {//取消按下事件, click事件无效
//                 GameObject nowTarget = ClickScene();
//                 if (nowTarget != clickTarget) {
//                     EventMultiArgs args = new EventMultiArgs();
//                     args.AddArg("target", clickTarget);
//                     EventSystem.CallEvent(EventID.PRESS_CANCEL_SCENE_TARGET, args, true);
//                     clickTarget = null;
//                 }
//             }
//         }

        public MovePathMono AddCameraPath(string pathName, bool willResetPos = true, DragCameraByPath.EDragType eType = DragCameraByPath.EDragType.MOMENTUM, List <float> listPagePoint = null)
        {
            if (movePath != null && movePath.PathName == pathName)
            {
                return(null);
            }
            GameObject camObj = _sceneCamera;

            if (camObj == null)
            {
                return(null);
            }

            //movePath = camObj.GetComponent<MovePathMono>();
            //if (movePath != null)
            //    RemoveCameraPath();

            movePath = camObj.AddComponent <MovePathMono>();

            movePath.CreatePath(pathName);
            SetCameraDragble(movePath, fCurCameraPos, eType, listPagePoint);//给镜头拖动表现指定轨迹
            if (willResetPos)
            {
                sceneCamera.transform.position = movePath.GetPointAtTime(fCurCameraPos);
                movePath.UpdateRotation();
                OnDragScene(fCurCameraPos);
            }

            return(movePath);
        }
Esempio n. 2
0
        public MovePathMono AddCameraPath(string pathName, PathConfig config, DragCameraByPath.EDragType eType = DragCameraByPath.EDragType.MOMENTUM, List <float> listPagePoint = null)
        {
            GameObject camObj = _sceneCamera;

            if (camObj == null)
            {
                return(null);
            }

            movePath = camObj.GetComponent <MovePathMono>();
            if (movePath != null)
            {
                RemoveCameraPath();
            }

            movePath = camObj.AddComponent <MovePathMono>();
            movePath.CreatePath(pathName, config);
            sceneCamera.transform.position = movePath.GetPointAtTime(fCurCameraPos);
            movePath.UpdateRotation();
            SetCameraDragble(movePath, fCurCameraPos, eType, listPagePoint);//给镜头拖动表现指定轨迹
            OnDragScene(fCurCameraPos);

            return(movePath);
        }
Esempio n. 3
0
    void Update()
    {
        if (_disableDrag)
        {
            return;
        }

        if (_movePath == null)
        {
            return;
        }

        if (_bPressed)
        {
            Vector3 mousePose = Input.mousePosition;//cam.ScreenToWorldPoint(Input.mousePosition);//hitt.transform.position; //
            float   offsetX   = mousePose.x - _pressedMousePos.x;
            if (Mathf.Abs(offsetX) >= 10f)
            {
                if (_bDragDirReverse)
                {
                    _curCameraPos = _pressedCameraPos + offsetX / 2000f;
                }
                else
                {
                    _curCameraPos = _pressedCameraPos - offsetX / 2000f;
                }


                _curCameraPos      = Mathf.Clamp(_curCameraPos, 0f, 1f);
                transform.position = _movePath.GetPointAtTime(_curCameraPos);
                _movePath.UpdateRotation();
                if (_onDragEvent != null)
                {
                    _onDragEvent(_curCameraPos);
                }


                if (_lastFrameMousePos != Vector3.zero)
                {
                    _deltaDrag.x = _lastFrameMousePos.x - mousePose.x;
                    _deltaDrag.y = _lastFrameMousePos.y - mousePose.y;
                    Vector2 offset = Vector2.Scale(_deltaDrag, -_scale);
                    // Adjust the momentum
                    if (_bDragDirReverse)
                    {
                        _mMomentum = Vector2.Lerp(_mMomentum, _mMomentum + offset * (0.01f * momentumAmount), 0.67f);
                    }
                    else
                    {
                        _mMomentum = Vector2.Lerp(_mMomentum, _mMomentum - offset * (0.01f * momentumAmount), 0.67f);
                    }

                    // Utils.LogSys.Log("mMomentum" + _mMomentum.ToString() + ", " + offset.ToString());
                }
                _lastFrameMousePos = mousePose;
                _bDrag             = true;
            }
            NGUIMath.SpringDampen(ref _mMomentum, 9f, RealTime.deltaTime);
        }
        else
        {
            if (_dragType == EDragType.MOMENTUM)
            {
                //惯性运动
                if (_mMomentum.magnitude > 0.01f)
                {
                    // Apply the momentum
                    Vector3 offsetPos = (Vector3)NGUIMath.SpringDampen(ref _mMomentum, 10f, RealTime.deltaTime);
                    _curCameraPos     += offsetPos.x / 2000f;
                    _curCameraPos      = Mathf.Clamp(_curCameraPos, 0f, 1f);
                    transform.position = _movePath.GetPointAtTime(_curCameraPos);
                    _movePath.UpdateRotation();
                    if (_onDragEvent != null)
                    {
                        _onDragEvent(_curCameraPos);
                    }
                }
                else
                {
                    NGUIMath.SpringDampen(ref _mMomentum, 9f, RealTime.deltaTime);
                }
            }
            else if (_dragType == EDragType.PAGEVIEW)
            {
                //滑到指定点
                if (_pageViewTargetPoint != -1f)
                {
                    bool bStop = false;
                    if (_mMomentum.magnitude > 0.01f)//正在滑动
                    {
                        float distance = _pageViewTargetPoint - _curCameraPos;
                        if (Mathf.Abs(distance) > 0.01f)
                        {
                            float dir = _bDragDirReverse?-1f:1f;
                            if (Mathf.Abs(distance) < _pageViewBeginSlowDistance)
                            {
                                Vector3 offsetPos = (Vector3)NGUIMath.SpringDampen(ref _mMomentum, 10f, RealTime.deltaTime);
                                _curCameraPos -= dir * offsetPos.x / 2000f;
                            }
                            else
                            {
                                _curCameraPos -= dir * _mMomentum.x / 2000f;
                            }
                            _curCameraPos = Mathf.Clamp(_curCameraPos, 0f, 1f);
                            float newDistance = _pageViewTargetPoint - _curCameraPos;
                            if (newDistance * distance > 0f)//还没到目标
                            {
                                transform.position = _movePath.GetPointAtTime(_curCameraPos);
                                _movePath.UpdateRotation();
                            }
                            else//超过目标点了
                            {
                                bStop = true;
                            }
                        }
                        else//已接近目标
                        {
                            bStop = true;
                        }
                    }
                    else//停止滑动
                    {
                        bStop = true;
                    }

                    if (bStop)
                    {
                        _curCameraPos      = _pageViewTargetPoint;
                        transform.position = _movePath.GetPointAtTime(_curCameraPos);
                        _movePath.UpdateRotation();
                        if (_onDragEvent != null)
                        {
                            _onDragEvent(_curCameraPos);
                        }
                        _mMomentum           = Vector2.zero;
                        _pageViewTargetPoint = -1f;
                    }
                }
            }
        }

        if (Input.GetMouseButtonDown(0))                              //点下去
        {
            if (!UtilTools.ClickUI() && UtilTools.ClickInValidArea()) //没点到UI && 点的是有效区
            {
                if (_dragType != EDragType.NONE)
                {
                    //还在滑动
                    if (_mMomentum.magnitude > 1f)
                    {
                        _bDrag = true;
                    }
                    else
                    {
                        _bDrag = false;
                    }
                }
                else
                {
                    _bDrag = false;
                }

                _bPressed          = true;
                _pressedMousePos   = Input.mousePosition;
                _pressedCameraPos  = _curCameraPos;
                _mMomentum         = Vector2.zero;
                _deltaDrag         = Vector2.zero;
                _lastFrameMousePos = Vector3.zero;
            }
        }
        else if (Input.GetMouseButtonUp(0))//弹起
        {
            _bPressed = false;
            if (_dragType == EDragType.PAGEVIEW)
            {
                if (_pageViewPoints.Count == 0)
                {
                    _pageViewTargetPoint = -1;
                }
                else
                {
                    int     dir       = 1;
                    Vector3 offsetPos = (Vector3)NGUIMath.SpringDampen(ref _mMomentum, 10f, RealTime.deltaTime);
                    if (Mathf.Abs(offsetPos.x) > 1f)  //拖动时,翻到拖动方向的那一页

                    {
                        int offPage = -1;//-1表示前一页,1表示后一页
                        if (_mMomentum.x > 0f)
                        {
                            offPage = 1;
                        }
                        _pageViewTargetPoint = GetTargetPage(_curCameraPos, offPage, ref dir);
                    }
                    else//原地弹起时,靠近哪页就滚动到哪一页
                    {
                        _pageViewTargetPoint = GetTargetPage(_curCameraPos, 0, ref dir);
                    }
                    if (_pageViewTargetPoint == -1f || Mathf.Abs(_curCameraPos - _pageViewTargetPoint) <= 0.01f)
                    {
                        _mMomentum = Vector2.zero;
                    }
                    else
                    {
                        _mMomentum = new Vector2(dir * _pageMomentum, 0f);
                    }
                }
            }
            //Utils.LogSys.Log("camera path value " + _curCameraPos);
        }
    }