Пример #1
0
    public void SaveData(string name)
    {
        // change loaded data
        loadedData.honeyScore    = honeyScore.harvestedHoney;
        loadedData.honeyCurrency = honeyCurrency.currency;
        //loadedData.musicOn = musicSource.volume;
        loadedData.musicOn = false;
        if (musicSource.volume != 0)
        {
            loadedData.musicOn = true;
        }

        for (int i = 0; i < loadedData.units.Length; i++)
        {
            if (loadedData.units[i].name == name)
            {
                // called from HoneyHandler, so only change data for unit with name given as parameter
                GameObject   temp         = GameObject.Find(loadedData.units[i].name);
                HoneyHandler honeyHandler = temp.GetComponent <HoneyHandler>();

                loadedData.units[i].honeyFullImage = honeyHandler.honeyFull.sprite.name;
                loadedData.units[i].isActivated    = honeyHandler.isActivated;
            }
        }
        // write loaded data to file
        string dataAsJson = JsonUtility.ToJson(loadedData);

        System.IO.File.WriteAllText(Application.persistentDataPath + "/" + savedDataFile, dataAsJson);
        //Debug.Log("DATA SAVED");
    }
Пример #2
0
    /* For expanding the honey comb */

    public void DisplayUnpurchasedHoney()
    {
        // display honeyUnits that can be bought, called by button and when a unit is bought

        // check all units
        foreach (Transform child in beehive.transform)
        {
            HoneyHandler temp = child.gameObject.GetComponent <HoneyHandler>();
            // check if surrounding units are active, if any of them is then display
            for (int i = 0; i < temp.otherSix.Count; i++)
            {
                if (temp.otherSix[i].isActivated)
                {
                    child.gameObject.SetActive(true);
                }
            }
        }

        additionsVisible = true;
    }
Пример #3
0
    // TODO on scene load ?
    void Update()
    {
        // done here and not in LoadGameData since the scene name must first be loaded (.....)
        if (!dataLoaded && loadedData != null && SceneManager.GetActiveScene().name == "GameScene")
        {
            dataLoaded = true;              // so this wont be repeated
            // then load from file

            // get the objects that data will be loaded into
            //GameObject[] unitObjects = GameObject.FindGameObjectsWithTag("honeyUnit");
            honeyScore    = GameObject.Find("HoneyScore").GetComponent <HoneyScore>();
            honeyCurrency = GameObject.Find("HoneyCurrency").GetComponent <HoneyCurrency>();

            for (int i = 0; i < loadedData.units.Length; i++)
            {
                // get honey unit and its name
                GameObject   temp         = GameObject.Find(loadedData.units[i].name);
                HoneyHandler honeyHandler = temp.GetComponent <HoneyHandler>();
                string       currName     = loadedData.units[i].honeyFullImage;
                // fill the unit's HoneyHandler with data from honeyDict about the honey type
                honeyHandler.fillTime          = honeyDict[currName].time;
                honeyHandler.points            = honeyDict[currName].points;
                honeyHandler.price             = honeyDict[currName].price;
                honeyHandler.honeyEmpty.sprite = Resources.Load <Sprite>("Sprites/" + honeyDict[currName].emptySprite);
                honeyHandler.honeyFull.sprite  = Resources.Load <Sprite>("Sprites/" + honeyDict[currName].fullSprite);
                honeyHandler.isActivated       = loadedData.units[i].isActivated;

                if (!honeyHandler.isActivated)
                {
                    // change sprite to the empty one and deactivate the gameobject
                    honeyHandler.honeyEmpty.sprite = Resources.Load <Sprite>("Sprites/hexhoneyADD");
                    temp.SetActive(false);
                }
                honeyHandler.honeyEmpty.enabled = true;
                honeyHandler.honeyFull.enabled  = false;
            }
            honeyScore.harvestedHoney = loadedData.honeyScore;
            honeyCurrency.currency    = loadedData.honeyCurrency;
            //musicSource.volume = loadedData.musicOn; // TODO won't work since data is loaded after music
        }
    }