コード例 #1
0
    void SpawnFly()
    {
        Vector4 flyZone = new Vector4();

        flyZone.x = screenSize.x - (screenSize.x - screenSize.z) * 0.03f;
        flyZone.y = screenSize.y - (screenSize.y - screenSize.w) * 0.2f;
        flyZone.z = screenSize.z + (screenSize.x - screenSize.z) * 0.2f;
        flyZone.w = screenSize.w + (screenSize.y - screenSize.w) * 0.2f;
        for (int j = 0; j < curentLevel.flyDefList.Count; j++)
        {
            for (int i = 0; i < (curentLevel.flyDefList[j] as FlyDef).nbFly; i++)
            {
                Vector3    spawnPosition = new Vector3(Random.Range(flyZone.z, flyZone.x), Random.Range(flyZone.w, flyZone.y), 0.0f);
                Quaternion spawnRotation = Quaternion.identity;
                GameObject temp          = Instantiate(Resources.Load((curentLevel.flyDefList[j] as FlyDef).type), spawnPosition, spawnRotation) as GameObject;
                temp.name = "Fly" + flyTab.Count;
                IFlyable component = (IFlyable)temp.GetComponent(typeof(IFlyable));
                component.SetId(flyTab.Count);
                component.Init(flyZone, (curentLevel.flyDefList[j] as FlyDef).velocidadMax, (curentLevel.flyDefList[j] as FlyDef).maxAngle);
                component.SetControler(gameObject);
                if ((curentLevel.flyDefList[j] as FlyDef).CompoDef.Count > 0)
                {
                    for (int k = 0; k < (curentLevel.flyDefList[j] as FlyDef).CompoDef.Count; k++)
                    {
                        CompoDef compD = (curentLevel.flyDefList[j] as FlyDef).CompoDef[k] as CompoDef;
                        switch (compD.type)
                        {
                        case "Animator":
                            Debug.Log(compD.name.ToString() + "  " + compD.val.ToString());
                            temp.GetComponent <Animator>().SetBool((compD.name), compD.val);
                            break;
                        }
                    }
                }
                flyTab.Add(temp);
            }
        }
    }
コード例 #2
0
ファイル: Levels.cs プロジェクト: espilacopa/ChuckTheFrog_U
    public static void init(XmlDocument defGame = default(XmlDocument))
    {
        if (defGame == null)
        {
            defGame = new XmlDocument();
            defGame.LoadXml(System.IO.File.ReadAllText(Application.dataPath + "/Resources/GameLevelDef"));
        }
        levelTab = new LevelList();
        foreach (XmlElement node in defGame.SelectNodes("Game/Level"))
        {
            Level level = new Level();
            levelTab.AddLevel(level);
            level.id         = int.Parse(node.GetAttribute("id"));
            level.timer      = int.Parse(node.GetAttribute("timer"));
            level.definition = node.SelectSingleNode("Def").InnerText;
            level.img        = node.GetAttribute("img");
            foreach (XmlElement flyNode in node.SelectNodes("Flies/FlyDef"))
            {
                FlyDef fly = new FlyDef();
                fly.velocidadMax = float.Parse(flyNode.GetAttribute("velo"));
                fly.maxAngle     = float.Parse(flyNode.GetAttribute("angl"));
                fly.bonus        = float.Parse(flyNode.GetAttribute("bonus"));
                fly.type         = flyNode.GetAttribute("type");
                fly.nbFly        = int.Parse(flyNode.GetAttribute("nbFly"));
                fly.CompoDef     = new ArrayList();
                foreach (XmlElement compoDef in flyNode.SelectNodes("GetComponent/CompoDef"))
                {
                    CompoDef compD = new CompoDef();
                    compD.name = compoDef.GetAttribute("id");
                    compD.type = compoDef.GetAttribute("param");
                    compD.val  = bool.Parse(compoDef.GetAttribute("val"));
                    fly.CompoDef.Add(compD);
                }
                level.flyDefList.Add(fly);
            }
            level.waveList = new ArrayList();

            foreach (XmlElement waveNode in node.SelectNodes("Waves/Wave"))
            {
                Wave wave = new Wave();
                wave.id         = int.Parse(waveNode.GetAttribute("id"));
                wave.waveTime   = int.Parse(waveNode.GetAttribute("time"));
                wave.enemieList = new ArrayList();
                foreach (XmlElement enemieNode in waveNode.SelectNodes("Enemies/Enemy"))
                {
                    EnemieD enemie = new EnemieD();
                    enemie.nb   = int.Parse(enemieNode.GetAttribute("nbEnemie"));
                    enemie.type = enemieNode.GetAttribute("type");
                    wave.enemieList.Add(enemie);
                }
                level.AddWave(wave);
            }
            level.goal     = new Goal();
            level.goal.Def = node.SelectSingleNode("Goal/Def").InnerText;
            foreach (XmlElement goalNode in node.SelectNodes("Goal/Star"))
            {
                Debug.Log(goalNode.GetAttribute("id") + "  " + goalNode.GetAttribute("time"));
                level.goal.goals.Add(float.Parse(goalNode.GetAttribute("time")));
            }
            getLevel(0).locked = false;
        }
    }