//Load the card data from the JSON file, the second parameter doesn't do anything except identify the load type
    public PartyMembersContainer LoadData(string pathString, PartyMembersContainer partyMembersContainer)
    {
        PartyMembersContainer data = null;

        JsonUtility.FromJsonOverwrite(pathString, data);
        return(data);
    }
Beispiel #2
0
 void Awake()
 {
     if (instance == null)
     {
         //...set this one to be it...
         instance = this;
     }
     //...otherwise...
     else if (instance != this)
     {
         //...destroy this one because it is a duplicate.
         Destroy(gameObject);
     }
 }
    public void JSONEncode(string JSONFilePath, PartyMembersContainer file)
    {
        //Check if the Save file exists, and if it does then delete it
        if (File.Exists(JSONFilePath))
        {
            File.Delete(JSONFilePath);
        }

        //Save the level to a JSON string
        string json = JsonUtility.ToJson(file, true);

        //And then write it to an actual textfile
        File.WriteAllText(JSONFilePath, json);
    }
    // Use this for initialization
    void Start()
    {
        //Find the path to the StreamingAssets folder based on platform
        if (Application.isEditor)
        {
            basePath               = Path.Combine(Application.dataPath, "//StreamingAssets");
            partiesJSONString      = Path.Combine(basePath, "//Parties.txt");
            partyMembersJSONString = Path.Combine(basePath, "//PartyMembers.txt");
        }
        //Android exception
        else if (Application.platform == RuntimePlatform.Android)
        {
            basePath               = "jar:file://" + Application.dataPath + "//Raw";
            partiesJSONString      = basePath + "//Parties.txt";
            partyMembersJSONString = basePath + "//PartyMembers.txt";
        }
        //IOs exception
        else if (Application.platform == RuntimePlatform.IPhonePlayer)
        {
            partiesJSONString      = Path.Combine(Application.dataPath, "//Raw//Parties.txt");
            partyMembersJSONString = Path.Combine(Application.dataPath, "//Raw//PartyMembers.txt");
        }

        //If the file already exists then load it, if not then create a new one at that location
        if (File.Exists(partiesJSONString))
        {
            parties = LoadData(partiesJSONString, parties);
        }
        else
        {
            JSONEncode(partiesJSONString, parties);
        }
        //Load the data in from files
        parties      = LoadData(partiesJSONString, parties);
        partyMembers = LoadData(partyMembersJSONString, partyMembers);
    }