コード例 #1
0
    public void MapSerializationTest()
    {
        MapModel map1 = new MapModel(new MapArrangement());

        map1._zoneModels.Add(new ZoneModel(MapModel.Party.P1, AllianceType.Team1, new WorldPosition(-5, 0)));
        map1._zoneModels.Add(new ZoneModel(MapModel.Party.AIOnly, AllianceType.Team2, new WorldPosition(5, 0)));
        map1._zoneModels[0].zonePieceModels
        .Add(new ZzFragModel(ZzFragModel.PieceType.circle, new WorldPosition(0, 0), new WorldPosition(5, 10)));
        map1._zoneModels[0].zonePieceModels.Add(new ZzFragModel(ZzFragModel.PieceType.rectangle, new WorldPosition(-3, 2),
                                                                new WorldPosition(3, 3)));
        map1._zoneModels[1].zonePieceModels
        .Add(new ZzFragModel(ZzFragModel.PieceType.circle, new WorldPosition(0, 0), new WorldPosition(5, 10)));

        map1._creator            = "Emerson";
        map1._mapName            = "mymap1";
        map1._mapInfo            = "this is the map info";
        map1._mapDescription     = "hi Im a map description";
        map1._formationResources = 500;
        map1.position            = new WorldPosition(30, 30);
        map1.scale = new WorldPosition(1, 1);


        //Unit Toggles
        UnitTogglesAll containerIn = new UnitTogglesAll();

        containerIn._togglesAll = new List <UnitToggleParty>(); //creates list
        UnitToggleParty party1 = new UnitToggleParty();         //creates object for list
        UnitToggleParty party2 = new UnitToggleParty();

        containerIn._togglesAll.Add(party2);
        containerIn._togglesAll.Add(party1);
        party2._togglesParty = new List <UnitToggle>();
        party1._togglesParty = new List <UnitToggle>();        //creates new unit toggles list in it
        UnitToggle unit1 = new UnitToggle();
        UnitToggle unit2 = new UnitToggle();

        unit1.unit   = "Barbarian";
        unit1.toggle = false;
        unit2.unit   = "Spartan";
        unit2.toggle = true;
        party1._togglesParty.Add(unit1);
        party1._togglesParty.Add(unit2);
        party2._togglesParty.Add(unit2);
        party2._togglesParty.Add(unit1);

        map1.UnitToggles = containerIn;

        map1._preFormationUnits.Add(new Model.Units.UnitPrep("Spartan", AllianceType.Team1, new WorldPosition(5, 5)));
        map1._preFormationUnits.Add(new Model.Units.UnitPrep("Barbarian", AllianceType.Team2, new WorldPosition(-3, 3)));

        string map1JSONtest = JsonUtility.ToJson(map1);

        Debug.Log(map1JSONtest);
    }
コード例 #2
0
    public void togglesContainerJSON()
    {
        UnitTogglesAll containerIn = new UnitTogglesAll();

        containerIn._togglesAll = new List <UnitToggleParty>(); //creates list
        UnitToggleParty party1 = new UnitToggleParty();         //creates object for list
        UnitToggleParty party2 = new UnitToggleParty();

        containerIn._togglesAll.Add(party2);
        containerIn._togglesAll.Add(party1);
        party2._togglesParty = new List <UnitToggle>();
        party1._togglesParty = new List <UnitToggle>();        //creates new unit toggles list in it
        UnitToggle unit1 = new UnitToggle();
        UnitToggle unit2 = new UnitToggle();

        unit1.unit   = "Barbarian";
        unit1.toggle = false;
        unit2.unit   = "Spartan";
        unit2.toggle = true;
        party1._togglesParty.Add(unit1);
        party1._togglesParty.Add(unit2);
        party2._togglesParty.Add(unit2);
        party2._togglesParty.Add(unit1);
        //
        //
        string         convert      = JsonUtility.ToJson(containerIn);
        UnitTogglesAll containerOut = JsonUtility.FromJson <UnitTogglesAll>(convert);

        Debug.Log(convert);
        Assert.AreEqual(containerIn._togglesAll[0]._togglesParty[0].unit, containerOut._togglesAll[0]._togglesParty[0].unit);
        Assert.AreEqual(containerIn._togglesAll[0]._togglesParty[1].unit, containerOut._togglesAll[0]._togglesParty[1].unit);
        Assert.AreEqual(containerIn._togglesAll[0]._togglesParty[0].toggle,
                        containerOut._togglesAll[0]._togglesParty[0].toggle);
        Assert.AreEqual(containerIn._togglesAll[0]._togglesParty[1].toggle,
                        containerOut._togglesAll[0]._togglesParty[1].toggle);
    }