bool InFoV()
    {
        //GameLauncher5.GetInstance().aiPlayerList
        Debug.LogError("Athis.manGroup" + this.manGroup + " " + solideIndex);
        foreach (GameObject enemy in GameLauncher5.GetInstance().aiPlayerList)
        {
            AI3DPlayer aIPlayer = enemy.GetComponent <AI3DPlayer>();
            Debug.LogError("this.manGroup@@" + this.manGroup + " " + solideIndex + " " + aIPlayer.SOLIDER_INDEX + " " + aIPlayer.belongGroup);
            if (solideIndex != aIPlayer.SOLIDER_INDEX && aIPlayer.belongGroup != manGroup)
            {
                Debug.LogError("this.manGroup" + this.manGroup + " " + solideIndex);
                Target = enemy.transform;
                Vector3 DirToTarget = Target.position - EyePoint.position;                //取得目标的方向
                float   Angle       = Vector3.Angle(EyePoint.forward, DirToTarget);       //获取正前方和目标之间的角度

                //EyePoint.right
                if (Angle <= FieldOfView)
                {
                    return(true);
                }                               //确定敌人是否在视野中,但不考虑任何物理障碍
            }
        }
        Target = null;
        return(false);
    }
示例#2
0
        public override void OnEnter(BInput input)
        {
            Debug.LogError("ActionAIShoot2");
            AI3DPlayer tinput = input as AI3DPlayer;

            this.m_ftime = Time.time;
            this.over    = false;
            tinput.Shoot();
        }
    bool ClearLineofSight()//士兵的眼睛和敌人是否存在任何物理障碍
    {
        foreach (GameObject enemy in GameLauncher5.GetInstance().aiPlayerList)
        {
            AI3DPlayer aIPlayer = enemy.GetComponent <AI3DPlayer>();



            RaycastHit Info;
//			Target = enemy.transform;
            Transform[] rect = enemy.transform.GetComponentsInChildren <Transform> ();
            foreach (Transform ts in rect)
            {
                if (ts.name == "EyePoint")
                {
                    Target = ts;
                }
            }
            if (solideIndex != aIPlayer.SOLIDER_INDEX &&
                aIPlayer.belongGroup != manGroup &&
                Physics.Raycast(EyePoint.position, (Target.position - EyePoint.position).normalized, out Info, ThisCollider.radius, layer))
            {
                Ray        ray = new Ray(EyePoint.position, (Target.position - EyePoint.position).normalized);
                RaycastHit hit;
                Physics.Raycast(ray, out hit, 1000.0f, layer);
                Debug.DrawLine(ray.origin, hit.point, Color.red);
//				Debug.DrawLine (Target.position,(EyePoint.position-Target.position).normalized,Color.red);
//				Debug.DrawLine (EyePoint.position,(Target.position-EyePoint.position).normalized,Color.yellow);
//
//				Debug.DrawLine (EyePoint.position,Target.position,Color.green);
//				if (Info.transform.CompareTag("Player") )
                if (Info.collider.transform.tag.Equals("EnemyPhy"))
                {
                    if (manGroup == AIPlayerGroup.A)
                    {
                        GameObject.Find("lab_state3").GetComponent <Text>().text = manGroup + " " + aIPlayer.SOLIDER_INDEX;
                    }
                    else
                    {
                        GameObject.Find("lab_state4").GetComponent <Text>().text = manGroup + " " + aIPlayer.SOLIDER_INDEX;
                    }

                    //Debug.LogError ("如果看到敌人");
                    Debug.LogError("如果看到敌人:" + manGroup + " " + Info.transform.gameObject.name);
                    enemyObj = Info.transform.gameObject;
                    return(true);
                }                //如果看到敌人
            }
        }
        Target = null;
        return(false);
    }
示例#4
0
    public virtual void initEnemy()
    {
        aiPlayerList.Clear();
        //创建队伍A
        //		foreach (GameObject enemyPos in enemyListPostion) {
        GameObject aiObject = Instantiate(Resources.Load("Prefab/V4/SoldierA")) as GameObject;

        aiObject.transform.position = new Vector3(-61.89f, 0, 65.72f);
        aiPlayerList.Add(aiObject);
        //		}
        AI3DPlayer aIPlayer1 = aiObject.transform.GetComponent <AI3DPlayer>();

        aIPlayer1.oriPosition = GameObject.Find("orig");
        aIPlayer1.soldierName = nameList[1];
        aIPlayer1.NameLabel();

        //创建队伍B
        foreach (GameObject enemyPos in enemyListPostion)
        {
            GameObject enemyObject = Instantiate(Resources.Load("Prefab/V4/SoldierB")) as GameObject;
            enemyObject.transform.position = enemyPos.transform.position;
            aiPlayerList.Add(enemyObject);
            enemyPos.SetActive(false);

            AI3DPlayer aIPlayer = enemyObject.transform.GetComponent <AI3DPlayer>();
            aIPlayer.oriPosition = GameObject.Find("GroupBBase");
            aIPlayer.soldierName = nameList[1];
            aIPlayer.NameLabel();
        }

        foreach (GameObject obj in aiPlayerList)
        {
            AI3DPlayer aIPlayer = obj.transform.GetComponent <AI3DPlayer>();
            string     fabName;
            if (aIPlayer.belongGroup == AIPlayerGroup.A)
            {
                fabName = "Prefab/GroupAHp";
            }
            else
            {
                fabName = "Prefab/GroupBHp";
            }

            GameObject hpObject = Instantiate(Resources.Load(fabName)) as GameObject;
            hpObject.transform.SetParent(GameObject.Find("HeadList").transform);
            GroupItemHP item = hpObject.transform.GetComponent <GroupItemHP> ();
            item.player = aIPlayer;
            item.updateHp();
        }
    }
示例#5
0
        //excute
        public override ActionResult Excute(BInput input)
        {
            AI3DPlayer tinput = input as AI3DPlayer;

            Debug.LogError("ActionAIShoot1" + tinput.belongGroup);
            if (Time.time - this.m_ftime > tinput.shootSpace)
            {
                this.over = true;
            }
            if (this.over)
            {
                return(ActionResult.SUCCESS);
            }
            return(ActionResult.RUNNING);
        }
示例#6
0
        //excute
        public override ActionResult Excute(BInput input)
        {
            Debug.LogError("ConditionAINotEnoughHP");
            AI3DPlayer tinput = input as AI3DPlayer;

            Debug.LogError("ConditionAINotEnoughHP" + tinput.belongGroup);
            Debug.Log("ConditionAINotEnoughHP" + tinput.hp + " " + HP);
            if (tinput.isDangerousState())
            {
                return(ActionResult.SUCCESS);
            }
            else
            {
                return(ActionResult.FAILURE);
            }
        }
示例#7
0
        //excute
        public override ActionResult Excute(BInput input)
        {
            Debug.LogError("ActionAIDie");
            AI3DPlayer tinput = input as AI3DPlayer;

            Debug.LogError("ConditionAIISDie" + tinput.belongGroup);
            if (tinput.hp > 0)
            {
                return(ActionResult.FAILURE);
            }
            else if (tinput.isDieActionRun == false)
            {
                return(ActionResult.SUCCESS);
            }
            else
            {
                return(ActionResult.RUNNING);
            }
        }
示例#8
0
        //excute
        public override ActionResult Excute(BInput input)
        {
            AI3DPlayer tinput = input as AI3DPlayer;

            Debug.LogError("ActionAIPursue" + tinput.isReachTarget());
            Debug.LogError("ActionAIPursue" + tinput.belongGroup);
            if (!tinput.isMove || tinput.isReachTarget())
            {
                return(ActionResult.SUCCESS);
            }
            if (tinput.isEnemyInShootDistance())
            {
                return(ActionResult.FAILURE);
            }
            else
            {
                return(ActionResult.RUNNING);
            }
        }
示例#9
0
    void OnTriggerEnter(Collider collider3D)
    {
        //		Debug.Log ("BulletScript1"+collider2D.gameObject.name);

        if (collider3D.transform.CompareTag("EnemyPhy"))
        {
            AI3DPlayer enemyPlayer = collider3D.transform.parent.GetComponent <AI3DPlayer> ();
            if (enemyPlayer.belongGroup != bulleGroup)
            {
                isFinish = true;
                if (tweener != null)
                {
                    tweener.Kill();
                    tweener = null;
                    this.gameObject.SetActive(false);
                }
            }
        }
    }
示例#10
0
        public override ActionResult Excute(BInput input)
        {
            Debug.LogError("ActionAIRandomMove");
            AI3DPlayer tinput = input as AI3DPlayer;

            Debug.LogError("ActionAIRandomMove" + tinput.belongGroup);
            if (tinput.isMove == false)
            {
                return(ActionResult.SUCCESS);
            }
            else
            {
                if (tinput.isEnemyInView() || tinput.routePoint == null)
                {
                    return(ActionResult.FAILURE);
                }
                else
                {
                    return(ActionResult.RUNNING);
                }
            }
        }
示例#11
0
    // Update is called once per frame
    void Update()
    {
        bool isNeedUpdateView = false;

        foreach (GameObject obj in aiPlayerList)
        {
            AI3DPlayer aIPlayer = obj.transform.GetComponent <AI3DPlayer>();
            if (aIPlayer.isDie)
            {
                aiPlayerList.Remove(aIPlayer.gameObject);
                Destroy(aIPlayer.gameObject);
                isNeedUpdateView = true;
                break;
            }
        }

        if (isNeedUpdateView)
        {
            foreach (GameObject obj in aiPlayerList)
            {
                AI3DPlayer aIPlayer = obj.transform.GetComponent <AI3DPlayer>();
                aIPlayer.updateView();
            }
        }


        foreach (GameObject obj in buffetList)
        {
            if (obj.GetComponent <BulletScript3D> ().isFinish)
            {
                buffetList.Remove(obj);
                Destroy(obj);
                break;
            }
        }
    }
    //执行射击
    public override void Shoot()
    {
        refreshStateLabel("射击");
        if (ThisLineSight.enemyObj != null)
        {
            ammoNum--;
            refreshStateLabel("执行射击 子弹数量:" + ammoNum);
            Debug.LogError("ThisLineSight.enemyObj." + ThisLineSight.enemyObj.name + " " + this.transform.name);
            Transform realPhy = ThisLineSight.enemyObj.transform.parent.Find("EyePoint");
            transform.LookAt(realPhy);

            Debug.LogError("shoot function");
            animator.SetBool("Walk", false);
            animator.SetBool("Run", false);
            animator.Play("Shoot");
            //animator.SetBool("Shoot", true);

            //		shootTimer -= Time.deltaTime;
            //        if (shootTimer <= 0)
            //        {
            //SetAmmo(1);
            //            shootTimer = 0.9f;
            // 用一个RaycastHit对象保存射线的碰撞结果
            RaycastHit info;
            // 从枪口所在位置向摄像机面向的正前方发出一条射线
            // 该射线只与layer指定的层发生碰撞
            Transform origal = this.transform.Find("EyePoint");


            bool hit = Physics.Raycast(origal.position, (realPhy.position - origal.position).normalized * 1000, out info, 1000, layer);

            //Debug.Log(info.point);
            Debug.DrawLine(origal.position, (realPhy.position - origal.position).normalized * 1000);


            GameObject bulletObject = Instantiate(Resources.Load("Prefab/Bullet3D")) as GameObject;

            bulletObject.transform.position = origal.position;
            bulletObject.GetComponent <BulletScript3D> ().bulleGroup = belongGroup;
            bulletObject.GetComponent <BulletScript3D> ().RuningBullet(origal.position, origal.position + (realPhy.position - origal.position).normalized * 1000);
            GameLauncher5.GetInstance().buffetList.Add(bulletObject);

            if (hit)
            {
                Debug.LogError("大众敌人了-1@" + info.collider.transform.name);
                // 判断是否射中Tag为enemy的物体
                if (info.collider.transform.tag.Equals("EnemyPhy"))
                {
                    Debug.LogError("大众敌人了1");
                    AI3DPlayer aIPlayer = info.transform.GetComponent <AI3DPlayer>();
                    if (aIPlayer.belongGroup != belongGroup)
                    {
                        aIPlayer.hp = aIPlayer.hp - 20;
                        Debug.LogError("大众敌人了2");
                    }
                    // 敌人减少生命
                    //info.transform.GetComponent<Enemy>().OnDamage(1);
                    //                    Instantiate(fx, info.point, info.transform.rotation);
                }
                //            }
                // 在射中的地方释放一个粒子效果

                Debug.Log(info.point);
            }
        }

        //装填子弹
    }
示例#13
0
        public override void OnEnter(BInput input)
        {
            AI3DPlayer tinput = input as AI3DPlayer;

            tinput.MoveBackHome();
        }