Beispiel #1
0
        ///////////////////////////////////////////////
        //////////////////PROPERTIES///////////////////
        ///////////////////////////////////////////////


        /*********************************************/


        ///////////////////////////////////////////////
        ////////////////////METHODS////////////////////
        ///////////////////////////////////////////////

        //////////////TRANSFORM_METHODS////////////////

        public override void moveTo(float x, float y)
        {
            if (OnMoveStart != null)
            {
                if (!OnMoveStart.Invoke(this, this.polyCenter.X, this.polyCenter.Y))
                {
                    return;
                }
            }

            if (OnMoving != null)
            {
                OnMoving.Invoke(this, this.polyCenter.X, this.polyCenter.Y);
            }

            GlVectorR2 delta = new GlVectorR2(x - polyCenter.X, y - polyCenter.Y);

            for (int i = 0; i < vertexes.Length; i++)
            {
                vertexes[i] = delta.fromPointToPoint(vertexes[i]);
            }

            GlPointR2 OP = new GlPointR2(this.polyCenter);

            this.polyCenter = new GlPointR2(x, y);

            if (OnMoved != null)
            {
                OnMoved.Invoke(this, OP.X, OP.Y);
            }
        }
Beispiel #2
0
    public void SetPosition(Vector3 newPosition)
    {
        // failsafe in case something teleports the player below ground collisions
        if (newPosition.y < minimumYPosition)
        {
            newPosition.y = minimumYPosition + 2f;
        }

        lastPosition = characterPosition.worldPosition;
        characterPosition.worldPosition = newPosition;
        transform.position = characterPosition.unityPosition;
        Environment.i.platform.physicsSyncController.MarkDirty();

        CommonScriptableObjects.playerUnityPosition.Set(characterPosition.unityPosition);
        CommonScriptableObjects.playerWorldPosition.Set(characterPosition.worldPosition);
        CommonScriptableObjects.playerCoords.Set(Utils.WorldToGridPosition(characterPosition.worldPosition));

        if (Moved(lastPosition))
        {
            if (Moved(lastPosition, useThreshold: true))
            {
                ReportMovement();
            }

            OnCharacterMoved?.Invoke(characterPosition);

            float distance = Vector3.Distance(characterPosition.worldPosition, lastPosition);
            if (distance > 0f && isGrounded)
            {
                OnMoved?.Invoke(distance / Time.deltaTime);
            }
        }

        lastPosition = transform.position;
    }
Beispiel #3
0
        ///////////////////////////////////////////////
        //////////////////PROPERTIES///////////////////
        ///////////////////////////////////////////////


        /*********************************************/


        ///////////////////////////////////////////////
        ////////////////////METHODS////////////////////
        ///////////////////////////////////////////////

        //////////////TRANSFORM_METHODS////////////////

        public override void moveTo(float x, float y)
        {
            if (OnMoveStart != null)
            {
                if (!OnMoveStart.Invoke(this, this.x, this.y))
                {
                    return;
                }
            }

            if (OnMoving != null)
            {
                OnMoving.Invoke(this, this.x, this.y);
            }

            float oldX = this.x, oldy = this.y;

            this.X = x;
            this.Y = y;

            if (OnMoved != null)
            {
                OnMoved.Invoke(this, oldX, oldy);
            }
        }
Beispiel #4
0
        private void Update()
        {
            if (inputDevice_ == null)
            {
                return;
            }

            if (locked_)
            {
                return;
            }

            Vector3 newPosition = this.transform.position + (inputDevice_.LeftStick.Value.Vector3XZValue() * kCursorSpeed);

            newPosition = newPosition.SetX(Mathf.Clamp(newPosition.x, -LevelEditorConstants.kArenaHalfWidth, LevelEditorConstants.kArenaHalfWidth));
            newPosition = newPosition.SetZ(Mathf.Clamp(newPosition.z, -LevelEditorConstants.kArenaHalfHeight, LevelEditorConstants.kArenaHalfHeight));

            Vector3 oldPosition = this.transform.position;

            this.transform.position = newPosition;
            if (oldPosition != this.transform.position)
            {
                OnMoved.Invoke();
            }
        }
Beispiel #5
0
        ///////////////////////////////////////////////
        //////////////////PROPERTIES///////////////////
        ///////////////////////////////////////////////


        /*********************************************/


        ///////////////////////////////////////////////
        ////////////////////METHODS////////////////////
        ///////////////////////////////////////////////

        //////////////TRANSFORM_METHODS////////////////

        public void moveTo(GlPointR2 newBelongsPoint)
        {
            if (newBelongsPoint == null || newBelongsPoint.isNullPoint())
            {
                return;
            }

            if (OnMoveStart != null)
            {
                if (!OnMoveStart.Invoke(this, this.pointOfLine.X, this.pointOfLine.Y))
                {
                    return;
                }
            }

            if (OnMoving != null)
            {
                OnMoving.Invoke(this, this.pointOfLine.X, this.pointOfLine.Y);
            }

            GlPointR2 OP = new GlPointR2(this.PointOfLine);

            this.pointOfLine = newBelongsPoint;

            if (OnMoved != null)
            {
                OnMoved.Invoke(this, OP.X, OP.Y);
            }
        }
Beispiel #6
0
        ///////////////////////////////////////////////
        //////////////////PROPERTIES///////////////////
        ///////////////////////////////////////////////


        /*********************************************/


        ///////////////////////////////////////////////
        ////////////////////METHODS////////////////////
        ///////////////////////////////////////////////

        //////////////TRANSFORM_METHODS////////////////

        public override void moveTo(float x, float y)
        {
            float oldX = this.Center.X;
            float oldY = this.Center.Y;

            if (OnMoveStart != null)
            {
                if (!OnMoveStart.Invoke(this, oldX, oldY))
                {
                    return;
                }
            }

            if (OnMoving != null)
            {
                OnMoving.Invoke(this, oldX, oldY);
            }

            this.systemCenter = new GlPointR2(x, y);
            updatePointsPosition();

            if (OnMoved != null)
            {
                OnMoved.Invoke(this, oldX, oldY);
            }
        }
Beispiel #7
0
    IEnumerator AnimateMove(Cell cell, MoveType moveType, Action onEnd = default)
    {
        Debug.Log("AnimateMove " + moveType);
        if (moveType == MoveType.Fall)
        {
            AnimateFall();
        }
        IsMoving = true;
        var   from    = transform.position;
        var   to      = cell.ToWorldPosition();
        float elapsed = 0;

        while (elapsed < MoveDuration)
        {
            elapsed           += Time.deltaTime;
            transform.position = Vector2.Lerp(from, to, elapsed / MoveDuration);
            yield return(null);
        }
        GetComponent <CellPosition>().SetCell(cell);
        IsMoving = false;
        OnMoved?.Invoke(moveType, cell);
        onEnd?.Invoke();
        if (moveType == MoveType.Fall)
        {
            IdleHead();
        }
    }
Beispiel #8
0
 public void OnPointerDown(PointerEventData eventData)
 {
     if (Input.touchCount == 1 || Input.GetMouseButton(0))
     {
         _movingInput = Vector2.zero;
         OnMoved?.Invoke(MovingDirection, CurrentState.Start);
     }
 }
Beispiel #9
0
 protected override void OnMouseUp(MouseEventArgs e)
 {
     base.OnMouseUp(e);
     if (isDown)
     {
         OnMoved?.Invoke(this, EventArgs.Empty);
     }
     isDown = false;
 }
Beispiel #10
0
    /// <summary>
    /// Calls a listener if transform is updated
    /// </summary>
    private void Update()
    {
        if (transform.hasChanged)
        {
            if (onMove != null)
            {
                onMove.Invoke(identifyingInformation, gameObject);
            }

            transform.hasChanged = false;
        }
    }
Beispiel #11
0
        private void UpdatePose()
        {
            if (_worldMarkers.Count == 0)
            {
                return;
            }

            Pose pose = GetAveragePose();

            transform.SetPositionAndRotation(pose.position, pose.rotation);

            OnMoved?.Invoke(this);
        }
Beispiel #12
0
        public virtual void Move(float direction)
        {
            var velocity = _rigidbody.velocity;

            _rigidbody.velocity = new Vector2(direction * _model.Speed, velocity.y);

            OnMoved?.Invoke(_rigidbody.position);

            if (IsMoving == true)
            {
                _view.Move();
            }
            else
            {
                _view.Stop();
            }
        }
 void Update()
 {
     if (Cursor.lockState == CursorLockMode.Locked)
     {
         var delta = new Vector2(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y"));
         delta *= 0.002f * Mathf.Pow(4f, CameraControlSettings.Sensitivity);
         if (CameraControlSettings.InvertHorizontal)
         {
             delta.x = -delta.x;
         }
         if (CameraControlSettings.InvertVertical)
         {
             delta.y = -delta.y;
         }
         OnMoved?.Invoke(delta);
     }
 }
Beispiel #14
0
        public void OnPointerUp(PointerEventData eventData)
        {
            int curTouches = Input.touchCount - 1;

            if (curTouches <= 0)
            {
                if (eventData.IsPointerMoving())
                {
                    _movingInput = eventData.delta;

                    int count = _movingAcceleration.Count;
                    for (int i = 0; i < count; i++)
                    {
                        _movingAcceleration.TryDequeue(out var moving);
                        _movingInput += moving;
                    }
                }

                OnMoved?.Invoke(MovingDirection, CurrentState.End);
            }
        }
Beispiel #15
0
    private IEnumerator Move(List <Vector2Int> path)
    {
        if (!anim.GetBool("fly"))
        {
            anim.SetBool("fly", true);
        }

        var pathCount      = path.Count - 1;
        var startPosition  = transform.localPosition;
        var targetPosition = new Vector3(path[pathCount].x, path[pathCount].y, 0);
        var time           = 0f;

        while (pathCount >= 0)
        {
            time += Time.deltaTime;

            if (time > 1 / speedMovement)
            {
                time = 0f;
                pathCount--;
                if (pathCount == -1)
                {
                    break;
                }

                startPosition = transform.localPosition;
            }
            else
            {
                targetPosition          = new Vector3(path[pathCount].x, path[pathCount].y, 0);
                transform.localPosition = Vector3.Lerp(startPosition, targetPosition, speedMovement * time);
            }

            yield return(null);
        }

        transform.localPosition = targetPosition;

        OnMoved?.Invoke(this, path[0]);
    }
        void Update()
        {
            if (Cursor.lockState == CursorLockMode.Locked)
            {
                if (Input.GetKeyDown(KeyCode.Escape))
                {
                    // カーソルロックが解除されなくなった時の念の為
                    Cursor.lockState = CursorLockMode.None;
                    return;
                }

                var delta = new Vector2(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y"));
                delta *= 0.002f * Mathf.Pow(4f, CameraControlSettings.Sensitivity);
                if (CameraControlSettings.InvertHorizontal)
                {
                    delta.x = -delta.x;
                }
                if (CameraControlSettings.InvertVertical)
                {
                    delta.y = -delta.y;
                }
                OnMoved?.Invoke(delta);
            }
        }
Beispiel #17
0
        public void OnDrag(PointerEventData eventData)
        {
            if (Input.touchCount == 1 || Input.touchCount == 0)
            {
                _movingInput = eventData.delta;
                _movingAcceleration.Enqueue(_movingInput);

                OnMoved?.Invoke(MovingDirection, CurrentState.Change);
            }
            else if (Input.touchCount == 2)
            {
                _movingInput = eventData.delta;
                _movingAcceleration.Enqueue(_movingInput);

                OnMoved?.Invoke(MovingDirection, CurrentState.Change);

                var distance = Vector2.Distance(Input.touches[0].position, Input.touches[1].position) /
                               Vector2.Distance(Input.touches[0].position - Input.touches[0].deltaPosition, Input.touches[1].position - Input.touches[1].deltaPosition);

                _zoomInput = distance - 1;

                OnZoomed?.Invoke(ZoomDelta, Vector2.Lerp(Input.touches[0].position, Input.touches[1].position, 0.5f));
            }
        }
Beispiel #18
0
 // Update is called once per frame
 void Update()
 {
     if (Input.GetMouseButtonDown(0))
     {
         status   = Status.Touch;
         beginPos = Input.mousePosition;
     }
     if (status == Status.Touch)
     {
         if (Vector2.Distance(Input.mousePosition, beginPos) >= triggerDistance)
         {
             Vector2       direction     = new Vector2(Input.mousePosition.x, Input.mousePosition.y) - beginPos;
             MoveDirection moveDirection = MoveDirection.Down;
             //左右
             if (Mathf.Abs(direction.x) > Mathf.Abs(direction.y))
             {
                 if (direction.x > 0)
                 {
                     moveDirection = MoveDirection.Right;
                 }
                 else
                 {
                     moveDirection = MoveDirection.Left;
                 }
             }
             //上下
             else
             {
                 if (direction.y > 0)
                 {
                     moveDirection = MoveDirection.Up;
                 }
                 else
                 {
                     moveDirection = MoveDirection.Down;
                 }
             }
             OnMoved?.Invoke(moveDirection);
             status = Status.Trigger;
         }
     }
     if (Input.GetMouseButtonUp(0))
     {
         status = Status.Null;
     }
     if (Input.GetKeyDown(KeyCode.LeftArrow))
     {
         OnMoved?.Invoke(MoveDirection.Left);
     }
     else if (Input.GetKeyDown(KeyCode.RightArrow))
     {
         OnMoved?.Invoke(MoveDirection.Right);
     }
     else if (Input.GetKeyDown(KeyCode.UpArrow))
     {
         OnMoved?.Invoke(MoveDirection.Up);
     }
     else if (Input.GetKeyDown(KeyCode.DownArrow))
     {
         OnMoved?.Invoke(MoveDirection.Down);
     }
 }
Beispiel #19
0
 public void SetPosition(Point newPosition)
 {
     CurrentPosition = newPosition;
     OnMoved?.Invoke();
 }
Beispiel #20
0
        /// <summary>
        /// Handles the logic of Dragging/Dropping/Zooming the map.
        /// This is basically said the logic handler of the control.
        /// It is called quite a lot of times, the delta of two calls may be calculated out of the passed GameTime parameter.
        /// </summary>
        /// <param name="time">The time passed since the game started.</param>
        public void Update(GameTime time, InputArgs input)
        {
            // Clean up icon texture cache...
            var keys = _markerTextures.Keys;

            foreach (string key in keys)
            {
                if (Markers.All(m => m.TextureIdentifier != key))
                {
                    _markerTextures[key].Dispose();
                    _markerTextures.Remove(key);
                }
            }

            // drag&drop handling
            MouseState currentState = input.MouseState;

            MapVector mousePos = new MapVector()
            {
                X = currentState.X, Y = currentState.Y
            };

            if (_dragging && CanMove)
            {
                MapVector oldVector = new MapVector()
                {
                    X = _oldMouseState.X, Y = _oldMouseState.Y
                };

                MapVector offset = (oldVector - mousePos) / _map.CoordinateScale;

                MapVector centerMapVector    = _map.LatLonToMapPoint(_map.Position);
                MapVector newCenterMapVector = centerMapVector + offset;

                // real a mod b:
                // a mod b = (a % b + b) % b
                // https://de.wikipedia.org/wiki/Division_mit_Rest#Modulo
                // We do this to allow scrollen over the maps borders.
                newCenterMapVector.X = ((newCenterMapVector.X % _map.MapCoordinatesWidth) + _map.MapCoordinatesWidth) % _map.MapCoordinatesWidth;
                newCenterMapVector.Y = ((newCenterMapVector.Y % _map.MapCoordinatesHeight) + _map.MapCoordinatesHeight) % _map.MapCoordinatesHeight;


                MapPointLatLon newCenterGeoPoint = _map.MapPointToLatLon(newCenterMapVector);

                _map.Position = newCenterGeoPoint;

                OnMoved?.Invoke(this, _map.Position);
            }

            int wheel = _oldMouseState.ScrollWheelValue - currentState.ScrollWheelValue;

            bool zoom    = false;
            int  newZoom = 0;

            if (wheel < 0)
            {
                if (_map.Zoom < _map.MaxZoom)
                {
                    zoom    = true;
                    newZoom = _map.Zoom + 1;
                }
            }
            else if (wheel > 0)
            {
                if (_map.Zoom > _map.MinZoom)
                {
                    zoom    = true;
                    newZoom = _map.Zoom - 1;
                }
            }

            if (zoom && CanZoom)
            {
                switch (ZoomMode)
                {
                case ZoomingType.Center:
                    SetZoomCenter(newZoom);
                    break;

                case ZoomingType.Mouse:
                    MapVector viewPos = mousePos -
                                        _map.ViewBounds.Location;
                    SetZoomMouse(newZoom, viewPos);
                    break;
                }

                OnZoomed?.Invoke(this, _map.Zoom);
            }

            if ((_oldMouseState.LeftButton == ButtonState.Pressed) && currentState.LeftButton == ButtonState.Released)
            {
                // Mouse up
                _dragging = false;
            }
            else if ((_oldMouseState.LeftButton == ButtonState.Released) && currentState.LeftButton == ButtonState.Pressed)
            {
                // Mouse down
                _dragging = true;
            }

            if (_oldMouseState.RightButton == ButtonState.Pressed && currentState.RightButton == ButtonState.Released)
            {
                OnRightClick?.Invoke(this, _map.ViewPointToLatLon(mousePos));
            }

            _oldMouseState = currentState;
        }
Beispiel #21
0
 protected void Moved()
 {
     OnMoved?.Invoke(this);
 }
 public void RaiseMoved()
 {
     OnMoved?.Invoke(this);
 }