Beispiel #1
0
    private void Detect()
    {
        List <Vector2> gridPosList = new List <Vector2>();

        foreach (Vector2 off in towerDetectScope)
        {
            Vector2 pos = new Vector2((float)Mathf.Floor(transform.position.x) + 0.5f, (float)Mathf.Floor(transform.position.z) + 0.5f);
            pos += off;
            gridPosList.Add(pos);
        }

        List <Vector2>    enemyPosList = new List <Vector2>();
        List <GameObject> enemyList    = GeneralPool.get_enemyList();

        foreach (GameObject enemy in enemyList)
        {
            Vector2 pos = new Vector2((float)Mathf.Floor(enemy.transform.position.x) + 0.5f, (float)Mathf.Floor(enemy.transform.position.z) + 0.5f);
            enemyPosList.Add(pos);
        }

        //Debug.Log(gridPosList.Count.ToString() + "  " + enemyPosList.Count.ToString());

        detectedEnemyList.Clear();
        for (int i = 0; i < enemyPosList.Count; i++)
        {
            for (int j = 0; j < gridPosList.Count; j++)
            {
                if (enemyPosList[i] == gridPosList[j])
                {
                    detectedEnemyList.Add(enemyList[i]);
                }
            }
        }
    }
Beispiel #2
0
    public void Die()
    {
        dieAlready = true;
        Debug.Log("当前敌人死亡前,enemyList数量为:" + GeneralPool.get_enemyList().Count);
        GeneralPool.removeFromEnemyGroup(gameObject);

        modelAnim.Play("death");
        Invoke("destroyGameObject", 3f);
    }
Beispiel #3
0
    // Update is called once per frame
    void Update()
    {
        if (!waitflag)
        {
            if (gameStep == 0)
            {
            }
            else
            {
                List <GameObject> enemyList = GeneralPool.get_enemyList();
                //Debug.Log(enemyList.Count);
                if (enemyList.Count == 0)
                {
                    toStep0();
                }
                else
                {
                    bool stopFlag = true;
                    foreach (GameObject enemy in enemyList)
                    {
                        if (enemy.GetComponent <Enemy>().getEnemyState() != BasicInfo.enemyStates.Stop)
                        {
                            stopFlag = false;
                            break;
                        }
                    }
                    if (stopFlag)
                    {
                        toStep0();
                    }
                    else
                    {
                        if (gameStep == 1)
                        {
                            timerTime -= Time.deltaTime;
                            uiHelper.updateTimerText(timerTime);
                            if (timerTime < 0)
                            {
                                toStep2();
                            }
                        }
                        else if (gameStep == 2)
                        {
                        }
                    }
                }


                //Debug.Log(gateList.Count+","+gateCount);
                if (gateList.Count < gateCount)
                {
                    gameOver(0);
                }
            }
        }
    }
Beispiel #4
0
 public void ClearAllEnemies()
 {
     foreach (GameObject enemy in GeneralPool.get_enemyList())
     {
         Destroy(enemy);
     }
     foreach (List <GameObject> enemyGroup in GeneralPool.get_enemyGroupList())
     {
         enemyGroup.Clear();
     }
     GeneralPool.get_enemyGroupList().Clear();
 }
Beispiel #5
0
 public void ClearAll()
 {
     foreach (GameObject enemy in GeneralPool.get_enemyList())
     {
         Destroy(enemy);
     }
     foreach (GameObject tower in GeneralPool.get_towerList())
     {
         Destroy(tower);
     }
     GeneralPool.resetPool();
 }
Beispiel #6
0
 public void setGameStep(int gameStep)
 {
     this.gameStep = gameStep;
     if (gameStep == 1)
     {
         displayPath.HidePathOfEnemyGroup();
         foreach (GameObject enemy in GeneralPool.get_enemyList())
         {
             enemy.GetComponent <QuickOutline>().enabled = false;
         }
         for (int i = 0; i < enemyScrollViewContent_Prepare.childCount; i++)
         {
             Destroy(enemyScrollViewContent_Prepare.GetChild(i).gameObject);
         }
     }
 }
Beispiel #7
0
    void AttackTimer()
    {
        if (detectedEnemyList.Count > 0)
        {
            //Debug.Log("攻击一次");

            if (towerAttackScope > 0)//攻击范围大于0
            {
                List <Vector2> offList = new List <Vector2>();
                for (int i = 1; i <= towerAttackScope; ++i)
                {
                    for (int j = 0; j <= i; ++j)
                    {
                        int k = i - j;
                        if (j > 0 && k == 0)
                        {
                            offList.Add(new Vector2(j, k));
                            offList.Add(new Vector2(-j, k));
                        }
                        else if (j == 0 && k > 0)
                        {
                            offList.Add(new Vector2(j, k));
                            offList.Add(new Vector2(j, -k));
                        }
                        else if (j > 0 && k > 0)
                        {
                            offList.Add(new Vector2(j, k));
                            offList.Add(new Vector2(-j, k));
                            offList.Add(new Vector2(j, -k));
                            offList.Add(new Vector2(-j, -k));
                        }
                    }
                }
                List <Vector2> gridPosList = new List <Vector2>();
                foreach (Vector2 off in offList)
                {
                    Vector2 pos = new Vector2((float)Mathf.Floor(detectedEnemyList[0].transform.position.x) + 0.5f, (float)Mathf.Floor(transform.position.z) + 0.5f);
                    pos += off;
                    gridPosList.Add(pos);
                }

                List <Vector2>    enemyPosList = new List <Vector2>();
                List <GameObject> enemyList    = GeneralPool.get_enemyList();
                foreach (GameObject enemy in enemyList)
                {
                    Vector2 pos = new Vector2((float)Mathf.Floor(enemy.transform.position.x) + 0.5f, (float)Mathf.Floor(enemy.transform.position.z) + 0.5f);
                    enemyPosList.Add(pos);
                }

                List <GameObject> detectedEnemyList_inAttackScope = new List <GameObject>();
                detectedEnemyList_inAttackScope.Add(detectedEnemyList[0]);
                for (int i = 0; i < enemyPosList.Count; i++)
                {
                    for (int j = 0; j < gridPosList.Count; j++)
                    {
                        if (enemyPosList[i] == gridPosList[j])
                        {
                            detectedEnemyList_inAttackScope.Add(enemyList[i]);
                        }
                    }
                }
                foreach (GameObject detectedEnemy_inAttackScope in detectedEnemyList_inAttackScope)
                {
                    Enemy detectedEnemyComp_inAttackScope = detectedEnemy_inAttackScope.GetComponent <Enemy>();
                    float towerAttackPower_final          = BasicInfo.calcuteAttackPower(towerAttackPower, this.towerAttr, detectedEnemyComp_inAttackScope.enemyAttr);
                    detectedEnemy_inAttackScope.GetComponent <Enemy>().GetAttacked(towerAttackPower_final);
                }
            }
            else
            {
                Enemy detectedEnemyComp      = detectedEnemyList[0].GetComponent <Enemy>();
                float towerAttackPower_final = BasicInfo.calcuteAttackPower(towerAttackPower, this.towerAttr, detectedEnemyComp.enemyAttr);
                detectedEnemyComp.GetAttacked(towerAttackPower_final);
            }
        }
        else
        {
            TimersManager.ClearTimer(AttackTimer);
        }
    }
Beispiel #8
0
    // Update is called once per frame
    void Update()
    {
        if (loadedflag_inner)
        {
            if (CheckGuiRaycastObjects())
            {
                return;
            }
            if (Input.GetMouseButtonDown(0))
            {
                Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition); // 定义射线
                RaycastHit rayHit;
                if (Physics.Raycast(ray, out rayHit, 200))                          // 参数1 射线,参数2 碰撞信息, 参数3 碰撞层
                {
                    GameObject rayHitObject = rayHit.collider.gameObject;
                    //Debug.Log(rayHitObject.name);
                    if (rayHitObject.name == "Road1" || rayHitObject.name == "Road2")
                    {
                        Vector3 hitpoint   = rayHit.point;
                        float   hitpoint_x = hitpoint.x;
                        float   hitpoint_y = hitpoint.y;
                        float   hitpoint_z = hitpoint.z;
                        hitpoint_x_center = Mathf.Floor(hitpoint_x) + 0.5f;
                        hitpoint_z_center = Mathf.Floor(hitpoint_z) + 0.5f;
                        displayPath.HidePathOfEnemyGroup();
                        foreach (GameObject enemy in GeneralPool.get_enemyList())
                        {
                            enemy.GetComponent <QuickOutline>().enabled = false;
                        }
                    }
                    else if (rayHitObject.tag == "Tower" || rayHitObject.tag == "BuildablePlane")
                    {
                    }
                    else
                    {
                        hitpoint_x_center = 1000f;
                        hitpoint_z_center = 1000f;
                        displayPath.HidePathOfEnemyGroup();
                        foreach (GameObject enemy in GeneralPool.get_enemyList())
                        {
                            enemy.GetComponent <QuickOutline>().enabled = false;
                        }
                    }
                }

                List <GameObject> insideEnemyList = new List <GameObject>();
                foreach (GameObject enemy in GeneralPool.get_enemyList())
                {
                    //displayPath.HidePathOfEnemyGroup();
                    //enemy.GetComponent<QuickOutline>().enabled = false;
                    if (Mathf.Floor(enemy.transform.position.x) + 0.5f == hitpoint_x_center && Mathf.Floor(enemy.transform.position.z) + 0.5f == hitpoint_z_center)
                    {
                        insideEnemyList.Add(enemy);
                    }
                }
                //List<int> insideEnemyGroupIndexs = new List<int>();
                foreach (GameObject insideEnemy in insideEnemyList)
                {
                    insideEnemy.GetComponent <QuickOutline>().enabled = true;
                    //int enemyGroupIndex = GeneralPool.get_enemyGroupIndex(insideEnemy);
                    //if (enemyGroupIndex == -1)
                    //{
                    //    Debug.Log("存在Bug:某一enemy没有加入军团");
                    //}
                    //else
                    //{
                    //    if (!insideEnemyGroupIndexs.Contains(enemyGroupIndex))
                    //        insideEnemyGroupIndexs.Add(enemyGroupIndex);
                    //}
                }

                changeEnemyScrollView_and_DisplayPath(insideEnemyList);
            }
            updateEnemyScrollView();
        }
    }