示例#1
0
    private IEnumerator CreateMonsters(int[] monsters, WaveConfigData configData)
    {
        Dictionary <string, ResourceRequest> loader = new Dictionary <string, ResourceRequest>();

        for (int i = 0; i < monsters.Length; i++)
        {
            int monsterId = monsters[i];
            if (monsterId != 0 && i < _map.MonsterBornPositions.Length)
            {
                RoleTplData roleTpl = TemplateManager.GetRoleTplData(monsterId);
                if (roleTpl != null && !loader.ContainsKey(roleTpl.Prefabname))
                {
                    ResourceRequest rr = Resources.LoadAsync("Prefabs/Roles/" + roleTpl.Prefabname);
                    loader.Add(roleTpl.Prefabname, rr);
                    yield return(rr);
                }
            }
        }
        //List<int> points = new List<int>(new int[] {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20 });
        for (int i = 0; i < monsters.Length; i++)
        {
            int monsterId = monsters[i];
            if (monsterId != 0 && configData.Param.Length > 0 && configData.Param[0] == Wave.PARAM_TYPE_RANDOM_SNEAK)
            {
                RoleTplData roleTpl = TemplateManager.GetRoleTplData(monsterId);
                if (roleTpl == null)
                {
                    Debug.LogError(string.Format("WaveConfig表中找不到怪物模板,monsterId={0}", monsterId));
                }
                else
                {
                    GameObject go      = (GameObject)Instantiate(loader[roleTpl.Prefabname].asset);
                    Monster    monster = go.GetComponent <Monster>();
                    monster.RoleId = monsterId;
                    monster.SetPosition(_map.GetRandomBornPosition(configData.Param.Length > 1? configData.Param[1]:-1));
                    _map.AddMonster(monster, 0);

                    _map.addEffect("Prefabs/Effects/MonsterAppearEf", monster.transform.position);

                    yield return(new WaitForSeconds(0.01f));
                }
            }
            else
            {
                if (monsterId != 0 && i < _map.MonsterBornPositions.Length)
                {
                    RoleTplData roleTpl = TemplateManager.GetRoleTplData(monsterId);
                    if (roleTpl == null)
                    {
                        Debug.LogError(string.Format("WaveConfig表中找不到怪物模板,monsterId={0}", monsterId));
                    }
                    else
                    {
                        int pos = i;
                        if (configData.Param.Length > 1 && configData.Param[0] == Wave.PARAM_TYPE_RANDOM_NUM)
                        {
                            pos = Random.Range(0, _map.MonsterBornPositions.Length);
                        }
                        GameObject go      = (GameObject)Instantiate(loader[roleTpl.Prefabname].asset);
                        Monster    monster = go.GetComponent <Monster>();
                        monster.RoleId = monsterId;
                        monster.SetPosition(_map.MonsterBornPositions[pos].position);
                        _map.AddMonster(monster, pos);
                        yield return(new WaitForSeconds(0.01f));
                    }
                }
            }
        }
        _creatingMonsterCount--;
    }
示例#2
0
    public void Update()
    {
        if (_paused)
        {
            return;
        }

        if (_arriveTime > 0)
        {
            if (_counting)
            {
                __arriveTimeLeft -= Time.deltaTime;
                int sec = Mathf.CeilToInt(__arriveTimeLeft);
                if (_arriveTime > sec)
                {
                    _arriveTime = sec;
                    dispatch(new WaveEvent(WaveEvent.COUNT));
                }
                if (_arriveTime < 1)
                {
                    _arrived  = true;
                    _pastTime = 0f;
                    dispatch(new WaveEvent(WaveEvent.COUNT_STATE));
                }
            }
        }
        if (_arrived)
        {
            _pastTime += Time.deltaTime;
            while (_waveConfigs.Count > 0 && _waveConfigs[0].Time < _pastTime)
            {
                WaveConfigData configData = _waveConfigs[0];
                if (configData.Param.Length > 2 && configData.Param[0] == PARAM_TYPE_RANDOM_NUM)
                {
                    List <int> idsA        = new List <int>(configData.Monsters);
                    List <int> selectedIds = new List <int>();
                    int        c           = UnityEngine.Random.Range(configData.Param[1], configData.Param[2] + 1);
                    if (c > 0 && idsA.Count > c)
                    {
                        while (selectedIds.Count < c)
                        {
                            int idx       = UnityEngine.Random.Range(0, idsA.Count);
                            int monsterId = idsA[idx];
                            idsA.RemoveAt(idx);
                            selectedIds.Add(monsterId);
                        }
                        dispatch(new WaveEvent(WaveEvent.MONSTERS_ARRIVED, selectedIds.ToArray(), configData));
                    }
                    else if (idsA.Count > 0)
                    {
                        dispatch(new WaveEvent(WaveEvent.MONSTERS_ARRIVED, configData.Monsters, configData));
                    }
                }
                else
                {
                    dispatch(new WaveEvent(WaveEvent.MONSTERS_ARRIVED, configData.Monsters, configData));
                }
                _waveConfigs.RemoveAt(0);
            }
        }
    }