示例#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
    public SowedPlantData AddPlant(string plant_id, string scene, Vector3 pos, int stage)
    {
        SowedPlantData citem = new SowedPlantData();

        citem.uid               = UniqueID.GenerateUniqueID();
        citem.plant_id          = plant_id;
        citem.scene             = scene;
        citem.pos               = pos;
        citem.growth_stage      = stage;
        sowed_plants[citem.uid] = citem;
        return(citem);
    }
示例#3
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);
    }
示例#4
0
    public void GrowPlant()
    {
        if (!IsFullyGrown())
        {
            SowedPlantData sdata = PlayerData.Get().GetSowedPlant(GetUID());
            if (sdata == null)
            {
                //Remove this plant and create a new one (this one probably was already in the scene)
                if (!was_built)
                {
                    PlayerData.Get().RemoveObject(GetUID()); //Remove Unique id
                }
                sdata = PlayerData.Get().AddPlant(data.id, SceneNav.GetCurrentScene(), transform.position, growth_stage + 1);
            }
            else
            {
                //Grow current plant from data
                PlayerData.Get().GrowPlant(GetUID(), growth_stage + 1);
            }

            Plant plant = Spawn(sdata.uid);
            Destroy(gameObject);
        }
    }