Пример #1
0
    //Spawn an existing one in the save file (such as after loading)
    public static Plant Spawn(string uid)
    {
        SowedPlantData sdata = PlayerData.Get().GetSowedPlant(uid);

        if (sdata != null)
        {
            PlantData pdata = PlantData.Get(sdata.plant_id);
            if (pdata != null)
            {
                GameObject prefab = pdata.GetStagePrefab(sdata.growth_stage);
                GameObject build  = Instantiate(prefab, sdata.pos, prefab.transform.rotation);
                Plant      plant  = build.GetComponent <Plant>();
                plant.data                = pdata;
                plant.was_built           = true;
                plant.unique_id.unique_id = uid;

                Destructible destruct = plant.GetComponent <Destructible>();
                if (destruct != null)
                {
                    destruct.was_built = true;
                }
                return(plant);
            }
        }
        return(null);
    }
Пример #2
0
    //Create a totally new one that will be added to save file
    public static Plant Create(PlantData data, Vector3 pos, int stage)
    {
        SowedPlantData splant = PlayerData.Get().AddPlant(data.id, SceneNav.GetCurrentScene(), pos, stage);
        GameObject     prefab = data.GetStagePrefab(stage);
        GameObject     build  = Instantiate(prefab, pos, prefab.transform.rotation);
        Plant          plant  = build.GetComponent <Plant>();

        plant.data                = data;
        plant.was_built           = true;
        plant.unique_id.unique_id = splant.uid;

        Destructible destruct = plant.GetComponent <Destructible>();

        if (destruct != null)
        {
            destruct.was_built = true;
        }

        return(plant);
    }