Пример #1
0
        public static Catalog LoadCatalog(string fileContents)
        {
            // Extract image data, (we do this before deserialization because the JSON serializer cannot handle the size of the image data, and tends to crash)
            Dictionary <int, string> imageArray = PreDeserializeExtractImageData(ref fileContents);

            // Deserialize JSON to Catalog...
            var catalogJson = JSONClass.Parse(fileContents).AsObject;
            var newCatalog  = DeserializeIntoCatalog(catalogJson);

            // Apply image data to Catalog...
            for (var i = 0; i < newCatalog.Entries.Count(); i++)
            {
                var entry = newCatalog.Entries.ElementAt(i);
                if (!string.IsNullOrEmpty(entry.ImageInfo.ExternalPath))
                {
                    entry.ImageInfo.Texture = ImageLoader.GetFutureImageFromFile(entry.ImageInfo.ExternalPath, 1000, 1000);
                    //entry.ImageInfo.Texture = new Texture2D(1000, 1000);
                    //UnityAction<Texture2D> onImageLoadCallback = (texture) =>
                    //{
                    //	entry.ImageInfo.Texture.SetPixels(0, 0, 1000, 1000, texture.GetPixels());
                    //};
                    //ImageLoader.LoadImage(entry.ImageInfo.ExternalPath, onImageLoadCallback);
                }
                else
                {
                    if (imageArray.ContainsKey(i))
                    {
                        LoadDataTexture(imageArray[i], entry);
                    }
                }
            }
            return(newCatalog);
        }
Пример #2
0
    // 项目内部 读文件 json
    public static JSONNode LoadGameJson(string path)
    {
        string   txt  = ((TextAsset)Resources.Load(path)).text;
        JSONNode json = JSONClass.Parse(txt);

        return(json);
    }
    public List <Quest> LoadQuests()
    {
        if (PlayerPrefs.HasKey("PlayerQuests"))
        {
            _quest = new Quest(null, null, null, -1, null);
            List <Quest> quests       = new List <Quest> ();
            JSONNode     loadedQuests = JSONClass.Parse(PlayerPrefs.GetString("PlayerQuests"));

            for (int i = 0; i < loadedQuests["Quests"].Count; i++)
            {
                int[] progress = new int[loadedQuests ["Quests"] [i].Count];

                for (int j = 0; j < loadedQuests["Quests"][i].Count; j++)
                {
                    progress [j] = loadedQuests ["Quests"] [i] [j].AsInt;
                }

                Quest newQuest = _quest.AddQuestFromSave(loadedQuests ["Quests"] [i].AsInt, progress);
                quests.Add(newQuest);
            }
            return(quests);
        }

        return(null);
    }
        void DeserializeAndLoad()
        {
            string json = PlayerPrefs.GetString("fizz-meta-143", GetDefaultUser());

            JSONNode jsonClass = JSONClass.Parse(json);

            userIdInput.text       = jsonClass["userId"].Value;
            userNameInput.text     = jsonClass["userName"].Value;
            translationToggle.isOn = jsonClass["translation"].AsBool;

            JSONArray channels = jsonClass["channels"].AsArray;
            int       count    = channels.Count;

            int index = 0;

            foreach (JSONNode node in channels)
            {
                string channelId   = node["channelId"].Value;
                string channelName = node["channelName"].Value;

                UITestChannel testChannel = CreateTestChannel(channelId, channelName);

                index++;
            }
        }
Пример #5
0
    //! Loads player data as json string to PlayerPrefs \todo pseudo code -> code
    public List <InventoryItem> LoadPlayerInventory()
    {
        //create list of inventory items to hold the inventory to return
        List <InventoryItem> inventoryLoad = new List <InventoryItem>();

        //if the inventory key doesnt exist return the empty list
        if (!PlayerPrefs.HasKey("PlayerInventory"))
        {
            return(inventoryLoad);
        }

        //obtain the inventory string from the playerprefs and fill the list of inventory items
        JSONNode loadedPlayerInventory = JSONClass.Parse(PlayerPrefs.GetString("PlayerInventory"));

        List <string> keyList = loadedPlayerInventory.Keys.ToList();

        for (int count = 0; count < keyList.Count; count++)
        {
            //loads the inventory in the order the setter functions appear in the inventory item script
            string tempName        = loadedPlayerInventory["Inventory"][count][0];
            int    tempType        = loadedPlayerInventory["Inventory"][count][1].AsInt;
            string tempDescription = loadedPlayerInventory["Inventory"][count][2];
            int    tempValue       = loadedPlayerInventory["Inventory"][count][3].AsInt;
            int    tempAmount      = loadedPlayerInventory["Inventory"][count][4].AsInt;
            int    tempID          = loadedPlayerInventory["Inventory"][count][5].AsInt;

            //create the inventory item and add it to the list
            InventoryItem new_item = new InventoryItem(tempName, tempID, tempDescription, tempValue, tempAmount, tempType);
            inventoryLoad.Add(new_item);
        }

        //return the list of created inventory items
        return(inventoryLoad);
    }
Пример #6
0
    public void LoadPlayerLocation()
    {
        if (PlayerPrefs.HasKey("SaveLocation"))
        {
            GameObject player = GameObject.FindGameObjectWithTag("Player");
            JSONNode   loadedPlayerPosition = JSONClass.Parse(PlayerPrefs.GetString("SaveLocation"));

            player.transform.position = new Vector3(loadedPlayerPosition["Coordinates"][0].AsFloat, loadedPlayerPosition["Coordinates"][1].AsFloat, loadedPlayerPosition["Coordinates"][2].AsFloat);
        }
        return;
    }
Пример #7
0
    public static JSONNode ReadJsonFromFile(string fileName)
    {
        if (Path.GetExtension(fileName) != ".json")
        {
            return(null);
        }

        string input = ReadStringFromFile(fileName);

        JSONNode converted = JSONClass.Parse(input);

        return(converted);
    }
    public bool CompletedQuest(int questID)
    {
        return(false);   // TODO The list of completed quest only contained one entry, no matter how many were added

        if (PlayerPrefs.HasKey("CompletedQuests") == true)
        {
            JSONNode completedQuests = JSONClass.Parse(PlayerPrefs.GetString("CompletedQuests"));
            for (int i = 0; i < completedQuests["CompletedQuests"].Count; i++)
            {
                if (completedQuests["CompletedQuests"][i] == questID.ToString())
                {
                    return(true);
                }
            }
        }
        else
        {
            return(false);
        }
        return(true);
    }
    public void SaveCompletedQuest(Quest questToSave)
    {
        if (PlayerPrefs.HasKey("CompletedQuests") == true)
        {
            JSONNode completedQuests = JSONClass.Parse(PlayerPrefs.GetString("CompletedQuests"));
            for (int i = 0; i < completedQuests["CompletedQuest"].Count; i++)
            {
                if (completedQuests["CompletedQuests"][i] == questToSave.GetID().ToString())
                {
                    completedQuests["CompletedQuests"][-1] = questToSave.GetID().ToString();
                    PlayerPrefs.SetString("CompletedQuests", completedQuests.ToString());
                    return;
                }
            }
        }

        JSONClass completedQuestJSONNode = new JSONClass();

        completedQuestJSONNode ["CompletedQuests"] [0] = questToSave.GetID().ToString();
        PlayerPrefs.SetString("CompletedQuests", completedQuestJSONNode.ToString());
        return;
    }
Пример #10
0
    void PopulateLevel()
    {
        jsonFile = Resources.Load("testLevel") as TextAsset; // load file from "Resources" folder
        jsonData = JSONClass.Parse(jsonFile.text);           // parse data from text file



        for (int i = 0; i < jsonData.Count; i++)
        {
            for (int j = 0; j <= 29; j++)               // loop through json file and retrieve tile data.
            {
                switch (RemoveQuotesAndSpaces(jsonData[i]["val" + j]))
                {
                case "Plat":                 // if the tile in space (i, j) is a wall tile, instantiate wall tile at (i,j)
                    GameObject plat = Instantiate(PlatPrefab, new Vector3(j, -i), Quaternion.identity) as GameObject;
                    break;

                case "Spawn":                                                                                             // if the tile in space (i, j) is a spawner tile, instantiate spawner tile at (i,j)
                    GameObject player = Instantiate(PlayerPrefab, new Vector3(j, -i), Quaternion.identity) as GameObject; // instantiate spawner object
                    break;

                case "YellowBox":
                    GameObject yellowBox = Instantiate(YellowBoxPrefab, new Vector3(j, -i), Quaternion.identity) as GameObject;
                    break;

                case "RedSpike":
                    GameObject redSpike = Instantiate(RedSpikePrefab, new Vector3(j, -i), Quaternion.identity) as GameObject;
                    break;

                case "RedBox":
                    GameObject redBox = Instantiate(RedBoxPrefab, new Vector3(j, -i), Quaternion.identity) as GameObject;
                    break;

                case "YellowBar":
                    GameObject yellowBar = Instantiate(YellowBarPrefab, new Vector3(j, -i), Quaternion.identity) as GameObject;
                    break;

                case "MovePlat":
                    GameObject movePlat = Instantiate(MovePlatPrefab, new Vector3(j, -i), Quaternion.identity) as GameObject;
                    movePlat.GetComponent <MovingPlatformScript> ().platType = MovingPlatformScript.movePlatType.neither;
                    break;

                case "MovePlatLeft":
                    GameObject movePlatLeft = Instantiate(MovePlatPrefab, new Vector3(j, -i), Quaternion.identity) as GameObject;
                    movePlatLeft.GetComponent <MovingPlatformScript> ().platType = MovingPlatformScript.movePlatType.left;
                    break;

                case "MovePlatRight":
                    GameObject movePlatRight = Instantiate(MovePlatPrefab, new Vector3(j, -i), Quaternion.identity) as GameObject;
                    movePlatRight.GetComponent <MovingPlatformScript> ().platType = MovingPlatformScript.movePlatType.right;
                    break;

                case "ChangePlat":
                    GameObject changePlat = Instantiate(ChangePlatPrefab, new Vector3(j, -i), Quaternion.identity) as GameObject;
                    changePlat.GetComponent <ChangePlatScript> ().cPlatType = ChangePlatScript.changePlatType.stat;
                    break;

                case "ChangePlatLeft":
                    GameObject changePlatLeft = Instantiate(ChangePlatPrefab, new Vector3(j, -i), Quaternion.identity) as GameObject;
                    changePlatLeft.GetComponent <ChangePlatScript> ().cPlatType = ChangePlatScript.changePlatType.left;
                    break;

                case "ChangePlatRight":
                    GameObject changePlatRight = Instantiate(ChangePlatPrefab, new Vector3(j, -i), Quaternion.identity) as GameObject;
                    changePlatRight.GetComponent <ChangePlatScript> ().cPlatType = ChangePlatScript.changePlatType.right;
                    break;

                default:
                    break;
                }
            }
        }
        //sets size of walls on either side
        LeftWall.GetComponentInChildren <BoxCollider2D> ().size = new Vector2(1, jsonData.Count);
        LeftWall.transform.position = new Vector2(-1, jsonData.Count / -2);
        RightWall.GetComponentInChildren <BoxCollider2D> ().size = new Vector2(1, jsonData.Count);
        RightWall.transform.position = new Vector2(30, jsonData.Count / -2);
    }