Beispiel #1
0
    //シリアライズ
    public override void OnBeforeSerialize()
    {
        //パーティメンバーとかのシリアライズは親が行う
        base.OnBeforeSerialize();

        //mapdataのシリアライズ
        mapsavedata = ScriptReader.CreateMapSaveData(mapdata);

        //unitlistのシリアライズ
        unitsavelist  = new List <UnitSaveData>();
        unitdirection = new List <Vector3>();
        foreach (Unitdata unit in unitlist)
        {
            unitsavelist.Add(new UnitSaveData(unit));
            unitdirection.Add(unit.gobj.transform.forward);
        }

        //id2indexのシリアライズ
        id2indexkeys   = new List <string>();
        id2indexvalues = new List <UnitSaveData>();
        foreach (KeyValuePair <string, Unitdata> kvp in id2index)
        {
            id2indexkeys.Add(kvp.Key);
            id2indexvalues.Add(new UnitSaveData(kvp.Value));
        }

        //Action Stackのシリアライズ
        Stack <Action> temp = new Stack <Action>();

        while (actions.Count > 0)
        {
            temp.Push(actions.Pop());
        }

        actionslist = new List <ActionSaveData>();
        while (temp.Count > 0)
        {
            actionslist.Add(new ActionSaveData(temp.Pop()));
        }

        //actionsを元に戻す
        foreach (ActionSaveData act in actionslist)
        {
            actions.Push(new Action(act, id2index));
        }
    }