-
Notifications
You must be signed in to change notification settings - Fork 79
/
CustomFoodPrefab.cs
39 lines (29 loc) · 1.13 KB
/
CustomFoodPrefab.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
namespace CustomCraft2SML.SMLHelperItems
{
using CustomCraft2SML.Serialization.Entries;
using SMLHelper.V2.Assets;
using UnityEngine;
internal class CustomFoodPrefab : ModPrefab
{
public const float StandardDecayRate = 0.015f;
public readonly CustomFood FoodEntry;
public CustomFoodPrefab(CustomFood customFood)
: base(customFood.ItemID, $"{customFood.ItemID}Prefab", customFood.TechType)
{
FoodEntry = customFood;
}
public override GameObject GetGameObject()
{
GameObject prefab = CraftData.GetPrefabForTechType(FoodEntry.FoodPrefab);
GameObject obj = UnityEngine.Object.Instantiate(prefab);
Eatable eatable = obj.GetComponent<Eatable>();
if (eatable is null)
eatable = obj.AddComponent<Eatable>();
eatable.foodValue = FoodEntry.FoodValue;
eatable.waterValue = FoodEntry.WaterValue;
eatable.decomposes = FoodEntry.Decomposes;
eatable.kDecayRate = FoodEntry.DecayRateMod * StandardDecayRate;
return obj;
}
}
}