Exemplo n.º 1
0
    private void start(FightRoomModel value)
    {
        room = value;

        int myTeam = -1;

        foreach (AbsFightModel item in value.teamOne)
        {
            if (item.id == GameData.user.id)
            {
                myTeam = item.team;
            }
        }
        if (myTeam == -1)
        {
            foreach (AbsFightModel item in value.teamTwo)
            {
                if (item.id == GameData.user.id)
                {
                    myTeam = item.team;
                }
            }
        }


        foreach (AbsFightModel item in value.teamOne)
        {
            GameObject go;
            if (item.type == ModelType.HUMAN)
            {
                go = (GameObject)Instantiate(Resources.Load <GameObject>("prefab/Player/" + item.code), startPosition.position + new Vector3(Random.Range(0.5f, 1.5f), 0, Random.Range(0.5f, 1.5f)), startPosition.rotation);

                PlayerCon pc = go.GetComponent <PlayerCon>();
                pc.init((FightPlayerModel)item, myTeam);
            }
            else
            {
                go = (GameObject)Instantiate(Resources.Load <GameObject>("prefab/build/1_" + item.code), positions[item.code - 1].position, positions[item.code - 1].rotation);
            }

            this.models.Add(item.id, go);
            if (item.id == GameData.user.id)
            {
                FightScene.instance.initView((FightPlayerModel)item, go);
                FightScene.instance.lookAt();
            }
        }

        foreach (AbsFightModel item in value.teamTwo)
        {
            GameObject go;
            if (item.type == ModelType.HUMAN)
            {
                go = (GameObject)Instantiate(Resources.Load <GameObject>("prefab/Player/" + item.code), startPosition1.position + new Vector3(Random.Range(5, 15), 0, Random.Range(5, 15)), startPosition1.rotation);
                PlayerCon pc = go.GetComponent <PlayerCon>();
                pc.init((FightPlayerModel)item, myTeam);
            }
            else
            {
                go = (GameObject)Instantiate(Resources.Load <GameObject>("prefab/build/2_" + item.code), positions1[item.code - 1].position, positions1[item.code - 1].rotation);
            }

            this.models.Add(item.id, go);
            if (item.id == GameData.user.id)
            {
                FightScene.instance.initView((FightPlayerModel)item, go);
                FightScene.instance.lookAt();
            }
        }
    }
Exemplo n.º 2
0
    public void start(FightRoomModel model)
    {
        int MyTeam = -1;

        foreach (AbsFightModel item in model.teamOne)
        {
            if (item.id == GameData.user.id)
            {
                MyTeam = item.team;
            }
        }
        foreach (AbsFightModel item in model.teamTwo)
        {
            if (item.id == GameData.user.id)
            {
                MyTeam = item.team;
            }
        }
        int team1 = 0;

        foreach (AbsFightModel item in model.teamOne)
        {
            GameObject go = null;
            GameObject hp = null;
            PlayerCon  pc = null;
            if (item.type == ModelType.HUMAN)
            {
                //实例化英雄
                go = LoadPlayer(item.code, teamOnePoints[team1]);
                pc = go.GetComponent <PlayerCon>();
                pc.init((FightPlayerModel)item, MyTeam);
                hp = LoadHP(go, (FightPlayerModel)item);
                gohpDic.Add(item.id, hp);
                if (item.id == GameData.user.id)
                {
                    FightUI._instance.initView((FightPlayerModel)item, go);
                    FightUI._instance.LookAt();
                }
                team1++;
            }
            else if (item.type == ModelType.BUILD)
            {
                //实例化防御塔
                FightBuildModel build = (FightBuildModel)item;
                go = Instantiate(Resources.Load("Prefab/Build/1-" + item.code)) as GameObject;
                go.transform.position = new Vector3(build.defaultVec.x, build.defaultVec.y, build.defaultVec.z);
                pc = go.GetComponent <PlayerCon>();
            }
            this.teamOne.Add(item.id, go);
            this.models.Add(item.id, pc);
        }
        int team2 = 0;

        foreach (AbsFightModel item in model.teamTwo)
        {
            GameObject go;
            PlayerCon  pc;
            GameObject hp = null;
            if (item.type == ModelType.HUMAN)
            {
                //实例化英雄
                go = LoadPlayer(item.code, teamTwoPoints[team2]);
                pc = go.GetComponent <PlayerCon>();
                pc.init((FightPlayerModel)item, MyTeam);
                hp = LoadHP(go, (FightPlayerModel)item);
                gohpDic.Add(item.id, hp);
                if (item.id == GameData.user.id)
                {
                    FightUI._instance.initView((FightPlayerModel)item, go);
                    FightUI._instance.LookAt();
                }
                team2++;
            }
            else
            {
                FightBuildModel build = (FightBuildModel)item;
                go = Instantiate(Resources.Load("Prefab/build/2-" + item.code)) as GameObject;
                go.transform.position = new Vector3(build.defaultVec.x, build.defaultVec.y, build.defaultVec.z);
                pc = go.GetComponent <PlayerCon>();
            }
            this.teamTwo.Add(item.id, go);
            this.models.Add(item.id, pc);
        }
    }