Ejemplo n.º 1
0
    private void CacheWaveMonster()
    {
        List <int>    ids    = _wave.GetMonsterIds();
        List <string> addeds = new List <string>();
        int           count  = 0;

        foreach (var monsterId in ids)
        {
            RoleTplData roleTpl = TemplateManager.GetRoleTplData(monsterId);
            if (addeds.IndexOf(roleTpl.Prefabname) == -1)
            {
                addeds.Add(roleTpl.Prefabname);

                GameObject go      = (GameObject)Instantiate(Resources.Load("Prefabs/Roles/" + roleTpl.Prefabname));
                Monster    monster = go.GetComponent <Monster>();
                monster.RoleId = monsterId;
                Vector2 pt = Vector2.zero;
                pt.x = 100; //Random.Range(MonsterBornPositions[0].position.x, MonsterBornPositions[1].position.x);
                pt.y = 100; //Random.Range(MonsterBornPositions[1].position.y, MonsterBornPositions[0].position.y);
                go.transform.position = pt;
                monster.IsModel       = true;
            }
            count++;
            if (count > 2)
            {
                break;
            }
        }
    }
Ejemplo n.º 2
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--;
    }