void DrawDebugline()
    {
        if (true)
        {
            float cur_angle = transform.rotation.eulerAngles.y;
//			upAngle.setCurrentAngle(cur_angle);
            rightAngle.setCurrentAngle(cur_angle + 90);

//			Debug.DrawLine(transform.position, upAngle.GetPosition(detect_radius,false), Color.blue);
//			Debug.DrawLine(transform.position, upAngle.GetPosition(detect_radius,true), Color.blue);

            Debug.DrawLine(transform.position, rightAngle.GetPosition(detect_radius, false), Color.blue);
            Debug.DrawLine(transform.position, rightAngle.GetPosition(detect_radius, true), Color.blue);

            for (int i = 0; i < 6; i++)
            {
                Vector3 endPoint = transform.position;
                if (i < 2)
                {
                    endPoint.x += i < 1 ? detect_radius : detect_radius * -1;
                }
                else if (i < 4)
                {
                    endPoint.z += i < 3 ? detect_radius : detect_radius * -1;
                }
                else
                {
                    endPoint.y += i < 5 ? detect_radius : detect_radius * -1;
                }
                Debug.DrawLine(transform.position, endPoint, Color.red);
            }
        }
    }
Esempio n. 2
0
    public void AIAction(bool isAttack)
    {
        UnitProperty comp = GetComponent <UnitProperty>();

        if (comp != null)
        {
            if (comp.type_init == UnitProperty.UnitType.AI ||
                comp.type_init == UnitProperty.UnitType.PlayerSupport)
            {
                if (target != null)
                {
                    //after found new target, lookat that
                    if (isTargetInSearchRange(target))
                    {
                        //do check the target is out of my attack range
                        bool isTargetInAttackRange = isTargetinRange(target, comp.attack_radius, false);

                        if (isTargetInAttackRange)
                        {
                            if (isAttack)
                            {
                                //be still and make attack
                                LookAtWithTarget(target);
                                comp.moveEnd();                                 //call MoveEnd() to do checkAttack()
                            }
                            else
                            {
                                //move out of Attack Range
//								Vector3 n_pos = GetRefactPosition(target,comp.attack_radius/2);

                                if (myDetectionHelper.haveWaysToGoOut(myAngle))
                                {
                                    //check backward possibility
                                    comp.AIActionMoveTo(myAngle.GetPosition(comp.attack_radius / 2, false));
                                }
                                else
                                {
                                    //try to Attack , as no way to go away
                                    comp.moveEnd();
                                }
                            }
                        }
                        else
                        {
                            if (isAttack)
                            {
                                //go and make attack
                                LookAtWithTarget(target);
                                comp.AIActionMoveTo(GetTendPosition(target, comp.attack_radius / 2));
                            }
                            else
                            {
                                //be still to wait
                                LookAtWithTarget(target);
                                comp.moveEnd();
                            }
                        }
                    }
                    else
                    {
                        //do search
                        GetClosestUnit();
                    }
                }
                else
                {
                    GetClosestUnit();
                }
            }
            else
            {
                //should UnitType.Player
            }
        }
        else
        {
            Debug.Log("A.I missing basic Component ( UnitProperty ) ");
        }
    }