Example #1
0
    IEnumerator Move()
    {
        //float startTime = Time.time;
        //Vector3 startPos = _agent.Pos;

        while (!_death)
        {
            if (_agent.entity != null && (_agent.entity is EntityGrp))
            {
                _hp = 0.0f;

                if (!_death)
                {
                    OnDeath(null, null);
                }

                yield break;
            }

            Vector3 pos    = _siege.assemblyPosition;
            float   radius = _siege.assemblyRadius;

            if (_target != null && PETools.PEUtil.SqrMagnitude(_target.position, pos) > radius * radius)
            {
                _target = null;
            }

            if (_target == null || _target.IsDeath())
            {
                //startTime = Time.time;
                //startPos = _agent.Pos;

                _target = _siege.GetClosestEntity(_agent);
            }

            if (_agent.entity == null && _target != null && _target.hasView && _agent.Pos.y <= Mathf.Epsilon)
            {
                if (PETools.PEUtil.SqrMagnitude(_agent.Pos, _target.position, false) > 5.0f * 5.0f)
                {
                    Vector3 moveDir = _target.position - _agent.Pos;
                    moveDir.y = 0.0f;

                    _agent.Pos += (moveDir.normalized * moveDir.magnitude * 0.5f);
                }
            }

            if (_target != null && _target.hasView)
            {
                if (_agent.entity != null)
                {
                    if (!_agent.entity.hasView)
                    {
                        Vector3 fixedPos = PETools.PEUtil.GetRandomPositionOnGround(_target.position, 3.0f, 8.0f, false);
                        if (fixedPos != Vector3.zero)
                        {
                            _agent.entity.position = fixedPos;
                        }
                    }
                }
                else
                {
                    if (_agent.Step == SceneEntityPosAgent.EStep.Created && !death)
                    {
                        ApplyDamage(_hpMax + 100000f);
                    }
                    else
                    {
                        if (_agent.Pos.y > Mathf.Epsilon)
                        {
                            Vector3 fixedPos = PETools.PEUtil.GetRandomPositionOnGround(_target.position, 3.0f, 8.0f, false);
                            if (fixedPos != Vector3.zero)
                            {
                                _agent.Pos = fixedPos;
                                SceneMan.SetDirty(_agent);
                            }
                        }
                    }
                }
            }

            yield return(new WaitForSeconds(1f));
        }
    }