コード例 #1
0
    public void SetUpAllEmails(EmailListJSON loadedEmails) // Called from XMLSaveLoad
    {
        foreach (EmailEntry email in loadedEmails.emailEntries)
        {
            if (email.entryID != "____") // Only continue if this is not a blank entry
            {
                allEmailsInData.Add(email);
                Debug.Log("loaded email entryID = " + email.entryID + " | conversationID = " + email.conversationID);

                // Make new EmailConversations if not already made
                if (emailConversationsDictionary.ContainsKey(email.conversationID) == false)
                {
                    EmailConversation newConversation = new EmailConversation();
                    newConversation.conversationID = email.conversationID;

                    emailConversationsDictionary.Add(newConversation.conversationID, newConversation);
                    Debug.Log("Created New Email Conversation: " + newConversation.conversationID);

                    // Add the initial email
                    newConversation.AddNextEmail(email);
                }

                // Check if player has received this email before. If so, add it to the conversation
                if (email.received)
                {
                    emailConversationsDictionary[email.conversationID].AddNextEmail(email);
                }

                // Find Max stage for each conversation
                emailConversationsDictionary[email.conversationID].CheckMaxStage(email.stage);
            }
        }

        CheckNotifications();
    }
コード例 #2
0
    public void LoadEmailsFromJSON() // Called from Game Manager to ensure they are loaded before loading Delivered Items
    {
        Debug.Log("Loading Emails...");

        string dataAsJson;

        if (GetComponent <GameManager>().playerData.newGame || resetEmailData)
        {
            // If it's a new game, load all the starting emails from Resources
            // Weird workaround so Android can load and read the JSON
            Debug.Log("Resetting email data to original file in Assets/Data");
            TextAsset jsonFile = Resources.Load("emailData") as TextAsset;
            string    jsonText = jsonFile.ToString();
            Debug.Log(jsonText);

            dataAsJson = jsonText;
        }
        else // Else load player's current emails from Persistent
        {
            Debug.Log("Loading player's saved email data");
            string jsonFile = File.OpenText(Application.persistentDataPath + "/data/" + "playerEmails.json").ReadToEnd();
            dataAsJson = jsonFile;

            //TextAsset jsonFile = Resources.Load("playerEmails") as TextAsset;
            //string jsonText = jsonFile.ToString();
            //dataAsJson = jsonText;
        }

        string JsonString = fixJson(dataAsJson);

        EmailListJSON newJSONList = JsonUtility.FromJson <EmailListJSON>(dataAsJson);

        foreach (EmailEntry email in newJSONList.emailEntries)
        {
            email.loadedToGame = false;
        }


        GetComponent <EmailManager>().SetUpAllEmails(newJSONList);
        Debug.Log("Loaded Emails");
    }