Way to access prefab ID, name, description, and sprite from the PrefabInfo or CustomPrefab
RamuneNeptune opened this issue · 2 comments
RamuneNeptune commented
Describe the feature
A way to fetch your CustomPrefab's ID, name, description, and sprite. Like PrefabInfo.ID
PrefabInfo.DisplayName
etc or something
Usage
How would modders use this feature?
public static CustomPrefab WithOutcrop(this CustomPrefab prefab, TechType outcropToCopy, int dropAmount, LootDistributionData.BiomeData[] biomeData, Dictionary<TechType, float> drops)
{
var clone = new CloneTemplate(prefab.Info, outcropToCopy)
{
ModifyPrefab = go =>
{
if(go.TryGetComponent<BreakableResource>(out var breakable))
breakable.breakText = "Break " + go.name.ToLower();
if(!go.TryGetComponentInChildren<Renderer>(out var renderer))
return;
// here, prefab.Info.ID
renderer.material.SetTexture(ShaderPropertyID._MainTex, ImageUtils.GetTexture(prefab.Info.Id + "_MainTex");
renderer.material.SetTexture(ShaderPropertyID._SpecTex, ImageUtils.GetTexture(prefab.Info.Id + "_SpecTex");
renderer.material.SetTexture(ShaderPropertyID._Illum, ImageUtils.GetTexture(prefab.Info.Id + "_Illum");
}
};
prefab.SetGameObject(clone);
prefab.SetSpawns(biomeData);
return prefab;
}
RamuneNeptune commented
Currently I gotta add an extra parameter to my extension methods for the ID & name
RamuneNeptune commented
You can use the following code to achieve this
public static class TechTypeExtensions
{
public static string DisplayName(this TechType techType) => Language.main.Get(techType);
public static string Tooltip(this TechType techType) => Language.main.Get("Tooltip_" + techType);
public static Atlas.Sprite Sprite(this TechType techType) => SpriteManager.Get(techType);
}
public static class CustomPrefabExtensions
{
public static string Id(this CustomPrefab customPrefab) => customPrefab.Info.ClassID;
public static string DisplayName(this CustomPrefab customPrefab) => Language.main.Get(customPrefab.Info.TechType);
public static string Tooltip(this CustomPrefab customPrefab) => Language.main.Get("Tooltip_" + customPrefab.Info.TechType);
public static Atlas.Sprite Sprite(this CustomPrefab customPrefab) => SpriteManager.Get(customPrefab.Info.TechType);
}