예제 #1
0
    public void SaveGameVariables()
    {
        try {
            LuaScriptBinder.Set(null, "PlayerPosX", DynValue.NewNumber(GameObject.Find("Player").transform.position.x));
            LuaScriptBinder.Set(null, "PlayerPosY", DynValue.NewNumber(GameObject.Find("Player").transform.position.y));
            LuaScriptBinder.Set(null, "PlayerPosZ", DynValue.NewNumber(GameObject.Find("Player").transform.position.z));
        } catch {
            LuaScriptBinder.Set(null, "PlayerPosX", DynValue.NewNumber(SaveLoad.savedGame.playerVariablesNum["PlayerPosX"]));
            LuaScriptBinder.Set(null, "PlayerPosY", DynValue.NewNumber(SaveLoad.savedGame.playerVariablesNum["PlayerPosY"]));
            LuaScriptBinder.Set(null, "PlayerPosZ", DynValue.NewNumber(SaveLoad.savedGame.playerVariablesNum["PlayerPosZ"]));
        }

        playerHeader = CYFAnimator.specialPlayerHeader;

        string mapName;

        if (UnitaleUtil.MapCorrespondanceList.ContainsKey(SceneManager.GetActiveScene().name))
        {
            mapName = UnitaleUtil.MapCorrespondanceList[SceneManager.GetActiveScene().name];
        }
        else if (GlobalControls.nonOWScenes.Contains(SceneManager.GetActiveScene().name) || GlobalControls.isInFight)
        {
            mapName = SaveLoad.savedGame.lastScene;
        }
        else
        {
            mapName = SceneManager.GetActiveScene().name;
        }
        lastScene = mapName;

        soundDictionary = MusicManager.hiddenDictionary;
        controlpanel    = ControlPanel.instance;
        player          = PlayerCharacter.instance;

        inventory.Clear();
        foreach (UnderItem item in Inventory.inventory)
        {
            inventory.Add(item.Name);
        }

        try {
            foreach (string key in LuaScriptBinder.GetSavedDictionary().Keys)
            {
                DynValue dv;
                LuaScriptBinder.GetSavedDictionary().TryGetValue(key, out dv);
                switch (dv.Type)
                {
                case DataType.Number: playerVariablesNum.Add(key, dv.Number); break;

                case DataType.String: playerVariablesStr.Add(key, dv.String); break;

                case DataType.Boolean: playerVariablesBool.Add(key, dv.Boolean); break;

                default: UnitaleUtil.WriteInLogAndDebugger("SaveLoad: This DynValue can't be added to the save because it is unserializable."); break;
                }
            }
        } catch { }

        mapInfos = GlobalControls.MapData;
    }