Example #1
0
    public void initUnits()
    {
        GameBattleStage stage = GameBattleManager.instance.ActiveBattleStage;


        units = new GameBattleUnit[stage.Man.Length];

        for (int i = 0; i < stage.Man.Length; i++)
        {
            GameUnit unit = GameUnitData.instance.getData(stage.Man[i].UnitBase.UnitID);

            string path = "Prefab/Sprite/man" + GameDefine.getString3(unit.Sprite) + "/";
            path += (GameDefine.getString3(unit.Sprite) + "man");

            GameObject    obj = Instantiate <GameObject>(Resources.Load <GameObject>(path));
            GameAnimation ani = obj.GetComponent <GameAnimation>();
            obj.name = "man" + GameDefine.getString3(unit.Sprite) + " " + i + " " + stage.Man[i].UnitBase.UnitID;

            Transform trans = obj.transform;
            trans.SetParent(unitTransform);
            trans.localScale = new Vector3(1.0f, 1.0f, 1.0f);

            GameBattleMovement movement   = obj.AddComponent <GameBattleMovement>();
            GameBattleUnit     battleUnit = obj.AddComponent <GameBattleUnit>();

            battleUnit.init(unit, stage.Man[i].clone());

            if (battleUnit.UnitID < GameDefine.MAX_USER)
            {
                battleUnit.setUnitBase(GameUserData.instance.getUnitBase(battleUnit.UnitID));
            }

            battleUnit.updateUnitData();
            battleUnit.initHPMP();
            battleUnit.clearMove();

            if (battleUnit.IsUser)
            {
                addUser(battleUnit);
            }
            else if (battleUnit.IsEnemy)
            {
                addEnemy(battleUnit);
            }
            else if (battleUnit.IsNpc)
            {
                addNpc(battleUnit);
            }

            units[i] = battleUnit;

            if (stage.XY.Length <= i)
            {
            }
            else
            {
                GameBattleXY xy = stage.XY[i];
                movement.setPos(xy.X, xy.Y);
            }
        }
    }