Exemple #1
0
    void Update()
    {
        if (shedManager == null)
        {
            Debug.LogError("Forgot to add shed manager component to a game object!");
            return;
        }

        if (shedManager.GetChangeCounter() == lastChangeCounter)
        {
            //no change since last update (so we dont need to update texts)
            return;
        }

        while (this.transform.childCount > 0)
        {
            Transform c = this.transform.GetChild(0);
            c.SetParent(null);
            Destroy(c.gameObject);
        }

        string[] names = shedManager.GetPlants();

        foreach (string name in names)
        {
            GameObject go = (GameObject)Instantiate(plantEntryPrefab);
            go.transform.SetParent(this.transform, false);

            go.transform.Find("PlantName").GetComponent <Text>().text     = name;
            go.transform.Find("WaterInterval").GetComponent <Text>().text = shedManager.GetPlantFeature(name, "waterInterval").ToString() + "m";
            go.transform.Find("Experience").GetComponent <Text>().text    = shedManager.GetPlantFeature(name, "experience").ToString() + "xp";

            int      lastWatered        = shedManager.GetPlantFeature(name, "lastWatered");
            DateTime now                = DateTime.Now;
            int      currentTime        = (int)now.Subtract(DateTime.MinValue).TotalMinutes;
            int      lastWateredDisplay = currentTime - lastWatered;

            //set the last watered with hours and minutes
            int hours;
            if (lastWateredDisplay > 60)
            {
                hours = lastWateredDisplay / 60;
                lastWateredDisplay = lastWateredDisplay % 60;
                go.transform.Find("LastWatered").GetComponent <Text>().text = hours.ToString() + "h " + lastWateredDisplay.ToString() + "m";
            }
            else
            {
                go.transform.Find("LastWatered").GetComponent <Text>().text = lastWateredDisplay.ToString() + "m";
            }
        }
    }
Exemple #2
0
    //Display cloud watering for 4 seconds
    public IEnumerator makeCloud()
    {
        string currentPlant = Models[i].name;

        //Make sure the plant is ready to be rewatered
        int      waterInterval      = shedManager.GetPlantFeature(currentPlant, "waterInterval");
        int      lastWatered        = shedManager.GetPlantFeature(currentPlant, "lastWatered");
        DateTime now                = DateTime.Now;
        int      currentTime        = (int)now.Subtract(DateTime.MinValue).TotalMinutes;
        int      lastWateredDisplay = currentTime - lastWatered;

        if (waterInterval <= lastWateredDisplay)
        {
            //add experience

            int experienceGained  = shedManager.GetPlantFeature(currentPlant, "experiencePerWater");
            int currentExperience = shedManager.GetPlantFeature(currentPlant, "experience") + experienceGained;
            shedManager.SetPlantFeature(currentPlant, "experience", currentExperience);
            shedManager.Save();

            int experienceToGrow     = shedManager.GetPlantFeature(currentPlant, "experienceToGrow");
            int experienceToComplete = shedManager.GetPlantFeature(currentPlant, "experienceToComplete");

            Models[i].SetActive(false);
            Models[i + 1].SetActive(false);
            Models[i + 2].SetActive(false);

            if (currentExperience < experienceToGrow)
            {
                //play small version animation
                Models[i + 1].SetActive(true);
            }
            else if (currentExperience >= experienceToGrow && currentExperience < experienceToComplete)
            {
                //play medium animation
                Models[i + 2].SetActive(true);
            }
            else
            {
                //play full grown plant animation
                Models[i].SetActive(true);
            }

            //Water plant
            shedManager.SetPlantFeature(currentPlant, "lastWatered", currentTime);
            shedManager.Save();

            RainCloud.SetActive(true);
            yield return(new WaitForSeconds(4));

            RainCloud.SetActive(false);
        }
        else
        {
            Debug.Log("It's too early to water this plant again!");
        }
    }