-
Notifications
You must be signed in to change notification settings - Fork 37
/
CustomPrefabExamples.cs
70 lines (62 loc) · 3.13 KB
/
CustomPrefabExamples.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using BepInEx;
using Nautilus.Assets;
using Nautilus.Assets.Gadgets;
using Nautilus.Assets.PrefabTemplates;
using UnityEngine;
using BiomeData = LootDistributionData.BiomeData;
namespace Nautilus.Examples;
[BepInPlugin("com.snmodding.nautilus.customprefab", "Nautilus Custom Prefab Example Mod", Nautilus.PluginInfo.PLUGIN_VERSION)]
[BepInDependency("com.snmodding.nautilus")]
public class CustomPrefabExamples : BaseUnityPlugin
{
private void Awake()
{
/*
* Here we're setting up an instance of PrefabInfo.
* The parameters we are assigning respectively are the following:
* - Class ID: The class identifier used internally in the game, especially for the PrefabIdentifier component
* - Display Name: The name of this item when hovered on in the world, or in inventory
* - Description: The tooltip of this item
*
* Every custom prefab will require an instance of PrefabInfo, which ultimately has all the info required to
* make this item work in the game.
*/
PrefabInfo copperCloneInfo = PrefabInfo.WithTechType("CopperClone", "Copper Ore Clone", "Copper Ore clone that makes me go yes.");
/*
* Here we're assigning the Copper icon for our item.
* You may also use a custom image as your icon by calling the ImageUtils.LoadSpriteFromFile method.
*/
copperCloneInfo.WithIcon(SpriteManager.Get(TechType.Copper));
/*
* Here we are setting up an instance of CustomPrefab.
* CustomPrefab is where you actually add logic and birth to your item.
* Here you will be able to add a game object for your item, set spawns, recipe, etc.. for your item.
*/
CustomPrefab copperClone = new CustomPrefab(copperCloneInfo);
/*
* Here we are creating a clone of the Copper game object.
* Additionally, we are also changing the color of the clone to red.
*/
PrefabTemplate cloneTemplate = new CloneTemplate(copperCloneInfo, TechType.Copper)
{
// Callback to change all material colors of this clone to red.
ModifyPrefab = prefab => prefab.GetComponentsInChildren<Renderer>().ForEach(r => r.materials.ForEach(m => m.color = Color.red))
};
/*
* Here we are setting the Copper clone we created earlier as our item's prefab.
*/
copperClone.SetGameObject(cloneTemplate);
/*
* Then we added biome spawns for our item.
*/
copperClone.SetSpawns(new BiomeData { biome = BiomeType.SafeShallows_Grass, count = 4, probability = 0.1f },
new BiomeData { biome = BiomeType.SafeShallows_CaveFloor, count = 1, probability = 0.4f });
/*
* And finally, we register it to the game.
* Now we can spawn our item to the world manually by using the command 'spawn copperclone', or
* simply looking around in the Safe shallows.
* Refrain from modifying the item further more or adding more gadgets after Register is called as they will not be called.
*/
copperClone.Register();
}
}