示例#1
0
    void Update()
    {
        RaycastHit hit;

        Physics.Raycast(new Ray(transform.position, Vector3.down), out hit, Mathf.Infinity, GameMaster.singleton.groundOnly);
        if (mover.agent == null)
        {
            transform.position = new Vector3(transform.position.x, hit.point.y + prefferedHeight + (bcollider.center.y + bcollider.bounds.size.y), transform.position.z);
        }
        visVision.transform.position = new Vector3(transform.position.x, hit.point.y + 0.01f, transform.position.z);
        orderLine.Hide();
        myTile.transform.position  = GameMaster.singleton.calculateTilePosition(gameObject);
        zosIcon.transform.position = myTile.transform.position;
        // bool move = true;
        if (msa == MSA_Type.StopOnShoot && (ds.closest != null || target != null) && shootType != ShootType.NoShoot)
        {
            mover.SetIsStopped(true);
        }
        else
        {
            mover.SetIsStopped(false);
        }
        if (ds.closest != null && (msa != MSA_Type.ShootAndAimOnlyIfStoped || mover.GetIsStopped() || mover.getVelocity() == 0 || (currentOrder == null && subscribedOrders.Count == 0)) && shootType != ShootType.NoShoot && ds.closest.seenByWhom[team.num] != 0)
        {
            target = ds.closest;
        }
        else
        {
            target = null;
        }
        //Велосити остановка

        if (rb.velocity.x != 0)
        {
            if (Mathf.Abs(rb.velocity.x) < velStoper)
            {
                rb.velocity = new Vector3(0, rb.velocity.y, rb.velocity.z);
            }
            else
            {
                rb.velocity = new Vector3((Mathf.Abs(rb.velocity.x) - velStoper) * (rb.velocity.x / Mathf.Abs(rb.velocity.x)), rb.velocity.y, rb.velocity.z);
            }
        }
        if (rb.velocity.z != 0)
        {
            if (Mathf.Abs(rb.velocity.z) < velStoper)
            {
                rb.velocity = new Vector3(rb.velocity.x, rb.velocity.y, 0);
            }
            else
            {
                rb.velocity = new Vector3(rb.velocity.x, rb.velocity.y, (Mathf.Abs(rb.velocity.z) - velStoper) * (rb.velocity.z / Mathf.Abs(rb.velocity.z)));
            }
        }
        //Постараемся пополнять приказы по мере выполнения
        if (currentOrder == null && subscribedOrders.Count > 0)
        {
            currentOrder = subscribedOrders[0];
            subscribedOrders.Remove(currentOrder);
            //   meshAgent.st
        }

        //Если приказ есть
        if (currentOrder != null)
        {
            switch (currentOrder.type)
            {
            case OrderType.Move:
                if (isSelected)
                {
                    orderLine.Appear();
                }
                var act = (transform.position - currentOrder.positionTarget);
                act.y = 0;
                if (act.magnitude < mover.GetStoppingDistance())
                {
                    currentOrder.Unsubscribe(this);
                    currentOrder      = null;
                    hasProceededOrder = false;
                    FixOrderOverwrites();
                }
                else if (!hasProceededOrder)
                {
                    hasProceededOrder = true;
                    orderLine.SecondPosition(currentOrder.thing.transform);
                    mover.SetDestination(currentOrder.positionTarget);
                }
                break;

            case OrderType.UseAbility:
                if (currentAbility == null)
                {
                    currentAbility = thinker.abilities[currentOrder.abilityId];
                    switch (currentAbility.type)
                    {
                    case AbilityType.Choose:
                        currentAbility.chooseTarget = currentOrder.unitTarget;
                        break;

                    case AbilityType.SkillShot:
                        currentAbility.skillShotTarget = currentOrder.positionTarget;
                        break;
                    }
                    currentAbility.Start();
                }
                else
                {
                    if (currentAbility.canMoveOn)
                    {
                        currentAbility.canMoveOn = false;
                        hasProceededOrder        = false;
                        currentOrder.Unsubscribe(this);
                        currentAbility = null;
                        currentOrder   = null;
                        FixOrderOverwrites();
                    }
                }
                break;

            case OrderType.Attack:
                if (isSelected)
                {
                    orderLine.Appear();
                }
                if (!hasProceededOrder && currentOrder.unitTarget != null)
                {
                    orderLine.SecondPosition(currentOrder.unitTarget.transform);
                    hasProceededOrder = true;
                    shootType         = ShootType.NoShoot;
                    msa = MSA_Type.StopOnShoot;
                }
                else if (currentOrder.unitTarget == null)
                {
                    currentOrder.Unsubscribe(this);
                    currentOrder      = null;
                    hasProceededOrder = false;
                    FixOrderOverwrites();
                }
                else
                {
                    var found = false;
                    mover.SetDestination(currentOrder.unitTarget.transform.position);
                    List <Unit> arr;
                    if (team.IsMyEnemy(currentOrder.unitTarget.team))
                    {
                        arr = ds.zoneOfSight.enemiesInSight;
                    }
                    else
                    {
                        arr = ds.zoneOfSight.friendsInSight;
                    }
                    foreach (var p in arr)
                    {
                        if (p == currentOrder.unitTarget)
                        {
                            found = true;
                            break;
                        }
                    }
                    if (found)
                    {
                        shootType = orderOverwriteST;
                        target    = currentOrder.unitTarget;
                    }
                    else
                    {
                        shootType = ShootType.NoShoot;
                        target    = null;
                    }
                }
                break;

            case OrderType.Chase:
                if (isSelected)
                {
                    orderLine.Appear();
                }
                if (!hasProceededOrder)
                {
                    hasProceededOrder = true;
                    orderLine.SecondPosition(currentOrder.unitTarget.transform);
                }
                else
                {
                    mover.SetDestination(currentOrder.unitTarget.transform.position);
                }
                break;
            }
        }
    }