示例#1
0
        private void UpdateScreenResolution()
        {
            if (Screen.currentResolution.Equals(_resolution))
            {
                return;
            }

            _resolution = Screen.currentResolution;

            if (maintainWidth)
            {
                Cam.orthographicSize = _defaultOrthographicSizeTimesAspect / GetCameraAspect();

                var position = Transform.position;
                var y        = (_defaultOrthographicSize - Cam.orthographicSize) * adaptPosition;
                Transform.position = new Vector3(
                    position.x,
                    y,
                    position.z);
            }
            else
            {
                var position = Transform.position;
                var x        = (_defaultOrthographicSizeTimesAspect -
                                Cam.orthographicSize * GetCameraAspect()) * adaptPosition;
                Transform.position = new Vector3(
                    x,
                    position.y,
                    position.z);
            }

            OnScreenResolutionChange?.Invoke(_resolution);
            OnTranslate?.Invoke(Transform);
        }
示例#2
0
        public void SetPosition(float x, float y)
        {
            var pos = Transform.position;

            pos.x = x;
            pos.y = y;
            Transform.position = pos;
            OnTranslate?.Invoke(Transform);
        }
        public override void OnPressed(UIElement uiElement, PointerRoutedEventArgs args)
        {
            var currentPt = args.GetCurrentPoint(uiElement).Position;

            mIsTranslating = CurrentPointIntersectsSourceRect(currentPt);

            if (mIsTranslating)
            {
                mStartPosition = currentPt;
                mPrevPosition  = mStartPosition;
                OnTranslate?.Invoke(this, null);
            }
            else
            {
                base.OnPressed(uiElement, args);
            }
        }
        public override void OnMoved(UIElement uiElement, PointerRoutedEventArgs args)
        {
            if (mIsTranslating)
            {
                var pt = args.GetCurrentPoint(uiElement).Position;

                double    dX          = pt.X - mPrevPosition.X;
                double    dY          = pt.Y - mPrevPosition.Y;
                Matrix3x2 translation = Matrix3x2.CreateTranslation((float)dX, (float)dY);

                mPrevPosition = pt;

                Vector2 newPosition = Vector2.Transform(new Vector2((float)DestRect.X, (float)DestRect.Y), translation);
                DestRect = new Rect(newPosition.X, newPosition.Y, DestRect.Width, DestRect.Height);
                OnTranslate?.Invoke(this, null);
            }
            else
            {
                base.OnMoved(uiElement, args);
            }
        }
示例#5
0
        private IEnumerator CoShake()
        {
            var pos  = Transform.position;
            var data = InPrologue ? prologueShakeData : shakeData;

            while (_shakeDuration > 0f)
            {
                var x = Random.Range(-1f, 1f) * data.magnitudeX;
                var y = Random.Range(-1f, 1f) * data.magnitudeY;

                Transform.position = new Vector3(pos.x + x, pos.y + y, pos.z);
                OnTranslate?.Invoke(Transform);

                _shakeDuration -= Time.deltaTime;

                yield return(null);
            }

            Transform.position = pos;
            OnTranslate?.Invoke(Transform);

            if (_target)
            {
                _fsm.next = State.ChaseX;
            }
            else if (_targetTemp)
            {
                _target     = _targetTemp;
                _targetTemp = null;
                _fsm.next   = State.ChaseX;
            }
            else
            {
                _fsm.next = State.Idle;
            }
        }
示例#6
0
        private IEnumerator CoChaseX()
        {
            var data = InPrologue ? prologueChaseData : chaseData;

            while (_target &&
                   _target.gameObject.activeSelf)
            {
                var pos          = Transform.position;
                var desiredPosX  = _target.position.x + data.offsetX;
                var smoothedPosX = Mathf.Lerp(
                    pos.x,
                    desiredPosX,
                    data.smoothSpeed * Time.deltaTime);
                pos.x = smoothedPosX;
                Transform.position = pos;
                OnTranslate?.Invoke(Transform);

                yield return(null);
            }

            _fsm.next = _shakeDuration > 0f
                ? State.Shake
                : State.Idle;
        }