private void OnDeath() { if (data != null) { foreach (PlayerCharacter character in PlayerCharacter.GetAll()) { character.Data.AddKillCount(data.id); //Add kill count } } PlayerData.Get().RemovePlant(GetUID()); if (!was_spawned) { PlayerData.Get().RemoveObject(GetUID()); } if (HasFruit()) { Item.Create(fruit, transform.position, 1); } if (data != null && regrow_on_death) { SowedPlantData sdata = PlayerData.Get().GetSowedPlant(GetUID()); Create(data, transform.position, transform.rotation, 0); } }
public void GrowPlant(int grow_stage) { if (data != null && growth_stage >= 0 && growth_stage < nb_stages) { 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_spawned) { PlayerData.Get().RemoveObject(GetUID()); //Remove Unique id } sdata = PlayerData.Get().AddPlant(data.id, SceneNav.GetCurrentScene(), transform.position, transform.rotation, grow_stage); } else { //Grow current plant from data PlayerData.Get().GrowPlant(GetUID(), grow_stage); } growth_progress = 0f; PlayerData.Get().SetCustomValue(GetProgressUID(), 0); plant_list.Remove(this); //Remove from list so spawn works! Spawn(sdata.uid); Destroy(gameObject); } }
private void OnBuild() { if (data != null) { SowedPlantData splant = PlayerData.Get().AddPlant(data.id, SceneNav.GetCurrentScene(), transform.position, transform.rotation, growth_stage); unique_id.unique_id = splant.uid; } }
public SowedPlantData AddPlant(string plant_id, string scene, Vector3 pos, Quaternion rot, int stage) { SowedPlantData citem = new SowedPlantData(); citem.uid = UniqueID.GenerateUniqueID(); citem.plant_id = plant_id; citem.scene = scene; citem.pos = pos; citem.rot = rot; citem.growth_stage = stage; sowed_plants[citem.uid] = citem; return(citem); }
//Spawn an existing one in the save file (such as after loading) public static Plant Spawn(string uid, Transform parent = null) { SowedPlantData sdata = PlayerData.Get().GetSowedPlant(uid); if (sdata != null && sdata.scene == SceneNav.GetCurrentScene()) { PlantData pdata = PlantData.Get(sdata.plant_id); if (pdata != null) { GameObject prefab = pdata.GetStagePrefab(sdata.growth_stage); GameObject build = Instantiate(prefab, sdata.pos, sdata.rot); build.transform.parent = parent; Plant plant = build.GetComponent <Plant>(); plant.data = pdata; plant.growth_stage = sdata.growth_stage; plant.was_spawned = true; plant.unique_id.unique_id = uid; return(plant); } } return(null); }