Exemplo n.º 1
0
    void MainSteeringBehaviors()
    {
        ResetOrientation();

        switch (choiceOfBehavior)
        {
        case SteeringBehaviors.Arrive:
            arrive.target = newTarget;

            if (newTarget != null)
            {
                if ((newTarget.transform.position - transform.position).magnitude < 1.5f)
                {
                    OnArrived?.Invoke();
                }
            }

            if (newTarget != null)
            {
                //steeringUpdate = new SteeringOutput();
                steeringUpdate = arrive.getSteering();
            }
            if (steeringUpdate != null)
            {
                linear  += steeringUpdate.linear * Time.deltaTime;
                angular += steeringUpdate.angular * Time.deltaTime;
            }
            break;
        }
    }
Exemplo n.º 2
0
        protected override async ValueTask UpdateCore(GameContext game)
        {
            if (_path is null || (!_path.Any() && _currPathNode is null))
            {
                return;
            }

            _currPathNode ??= _path.Next();

            var tilePos = _mapRenderer.GetTilePos(_currPathNode);
            var newPos  = Vector2Utils.MoveTowards(_transform.World.Position, tilePos, Speed);

            _transform.Local.Position = newPos;

            var dist = Vector2.DistanceSquared(newPos, tilePos);

            if (dist < Speed)
            {
                _currPathNode             = null;
                _transform.Local.Position = tilePos;

                if (!_path.Any())
                {
                    _path = null;
                    OnArrived?.Invoke(this);
                }
            }
        }
Exemplo n.º 3
0
    // Update is called once per frame
    protected override void Update()
    {
        myMoveType.target = myTarget;

        if (myTarget != null)
        {
            if ((myTarget.transform.position - transform.position).magnitude < 1.5f)
            {
                OnArrived?.Invoke();
            }
        }

        if (myTarget != null)
        {
            steeringUpdate = myMoveType.getSteering();
        }
        base.Update();
    }
Exemplo n.º 4
0
    // Update is called once per frame
    protected override void Update()
    {
        myMoveType.target = target;

        if (target != null)
        {
            if ((target.transform.position - transform.position).magnitude < 1.5f)
            {
                OnArrived?.Invoke();
            }
        }

        if (target != null)
        {
            //steeringUpdate = new SteeringOutput();
            controlledSteeringUpdate = myMoveType.getSteering();
        }
        base.Update();
    }
Exemplo n.º 5
0
    public IEnumerator Move()
    {
        while (transform.position != new Vector3(targetX, targetY, 0))
        {
            if (targetX != (int)transform.position.x)
            {
                int dif = (targetX > (int)transform.position.x) ? 1 : -1;

                characterSprite.sprite = xSprite;
                characterSprite.flipX  = (dif > 0) ? false : true;
                transform.Translate(dif, 0, 0);
            }
            else if (targetY != (int)transform.position.y)
            {
                int dif = (targetY > (int)transform.position.y) ? 1 : -1;

                characterSprite.sprite = (dif > 0) ? ySpriteUp: ySpriteDown;
                transform.Translate(0, dif, 0);
            }
            yield return(new WaitForSeconds(0.3f));
        }
        OnArrived?.Invoke(this);
    }
Exemplo n.º 6
0
 public void MoveSnaping()
 {
     transform.position = new Vector3(targetX, targetY, transform.position.z);
     OnArrived?.Invoke(this);
     //AnswerManager.Instance.SumQuestion();
 }
Exemplo n.º 7
0
 public void Send(string target, string content, OnArrived callbackFn)
 {
     Console.WriteLine($"向{target}派送的{content}已到达");
     callbackFn();//调用传入的方法,向发件者发送已到达的信息
 }