Beispiel #1
0
    void LoadCreatures()
    {
        //Debug.Log("LOADING CREATURES");
        string filePath = Application.persistentDataPath + fileName;

        //string filePath = fileName;

        if (File.Exists(filePath))
        {
            string        dataAsJson    = File.ReadAllText(filePath);
            JsonCreatures jsonCreatures = JsonUtility.FromJson <JsonCreatures>(dataAsJson);

            //Debug.Log(jsonCreatures.types[0]);

            for (int i = 0; i < jsonCreatures.names.Length; i++)
            {
                GameObject newCreature = Instantiate(
                    FindCreature(jsonCreatures.types[i]),
                    new Vector3(Random.Range(spawnBounds.x, spawnBounds.y), 0.5f, nextSpawnDepth) + WorldManager.Instance.islands[jsonCreatures.worldIds[i]].transform.position,
                    Quaternion.identity, WorldManager.Instance.islands[jsonCreatures.worldIds[i]].transform
                    );

                nextSpawnDepth -= 0.05f;

                creaturesInWorld.Add(newCreature);
                WorldManager.Instance.islands[jsonCreatures.worldIds[i]].GetComponent <IslandScript>().currentCreaturePopulation++;
                SavedIntelligence intelligence = new SavedIntelligence()
                {
                    rank          = jsonCreatures.intelligenceRank[i],
                    level         = jsonCreatures.intelligenceLevel[i],
                    upgradePoints = jsonCreatures.intelligenceUpgradePoints[i],
                    score         = jsonCreatures.intelligenceScore[i]
                };

                SavedAgility agility = new SavedAgility()
                {
                    rank          = jsonCreatures.agilityRank[i],
                    level         = jsonCreatures.agilityLevel[i],
                    upgradePoints = jsonCreatures.agilityUpgradePoints[i],
                    score         = jsonCreatures.agilityScore[i]
                };

                SavedStrength strength = new SavedStrength()
                {
                    rank          = jsonCreatures.strengthRank[i],
                    level         = jsonCreatures.strengthLevel[i],
                    upgradePoints = jsonCreatures.strengthUpgradePoints[i],
                    score         = jsonCreatures.strengthScore[i]
                };

                SavedStyle style = new SavedStyle()
                {
                    rank          = jsonCreatures.styleRank[i],
                    level         = jsonCreatures.styleLevel[i],
                    upgradePoints = jsonCreatures.styleUpgradePoints[i],
                    score         = jsonCreatures.styleScore[i]
                };

                SavedStamina stamina = new SavedStamina()
                {
                    rank          = jsonCreatures.staminaRank[i],
                    level         = jsonCreatures.staminaLevel[i],
                    upgradePoints = jsonCreatures.staminaUpgradePoints[i],
                    score         = jsonCreatures.staminaScore[i]
                };

                newCreature.GetComponent <CreatureScript>().SetUpCreature(
                    jsonCreatures.names[i],
                    jsonCreatures.happiness[i],
                    jsonCreatures.sizes[i],
                    jsonCreatures.stars[i],
                    intelligence,
                    agility,
                    strength,
                    style,
                    stamina
                    );
            }

            //Debug.Log("Loaded creatures");
        }
        else
        {
            SaveCreatures();
        }
    }
    public void SetUpCreature(string newName, float newHappiness, float newSize, int newStars, SavedIntelligence intelligence, SavedAgility agility, SavedStrength strength, SavedStyle style, SavedStamina stamina)
    {
        generateStats = false;
        SM            = GameObject.FindGameObjectWithTag("StatManager").GetComponent <StatManager>();

        name                       = newName;
        happiness                  = newHappiness;
        size                       = newSize;
        Stars                      = newStars;
        Intelligence.amt           = intelligence.score;
        Intelligence.level         = intelligence.level;
        Intelligence.rank          = SM.FindRank(intelligence.rank);
        Intelligence.upgradePoints = intelligence.upgradePoints;

        Agility.amt           = agility.score;
        Agility.level         = agility.level;
        Agility.rank          = SM.FindRank(agility.rank);
        Agility.upgradePoints = agility.upgradePoints;

        Strength.amt           = strength.score;
        Strength.level         = strength.level;
        Strength.rank          = SM.FindRank(strength.rank);
        Strength.upgradePoints = strength.upgradePoints;

        Style.amt           = style.score;
        Style.level         = style.level;
        Style.rank          = SM.FindRank(style.rank);
        Style.upgradePoints = style.upgradePoints;

        Stamina.amt           = stamina.score;
        Stamina.level         = stamina.level;
        Stamina.rank          = SM.FindRank(stamina.rank);
        Stamina.upgradePoints = stamina.upgradePoints;
    }