Class PrefabUtils
public static class PrefabUtils
- Inheritance
-
PrefabUtils
- Inherited Members
Methods
AddBasicComponents(GameObject, string, TechType, CellLevel)
prefab
.- PrefabIdentifier: Required for an object to be considered a prefab.
- TechTag: Required for inventory items, crafting, scanning, etc.
- LargeWorldEntity: Required for objects to persist after saving and exiting.
- SkyApplier: Added if Renderers exist in the hierarchy. Applies the correct lighting onto an object.
public static void AddBasicComponents(GameObject prefab, string classId, TechType techType, LargeWorldEntity.CellLevel cellLevel)
Parameters
prefab
GameObject- The prefab to operate on.
classId
string- The class ID associated with the specified prefab.
techType
TechType- Ignored if TechType.None is inputted.
cellLevel
LargeWorldEntity.CellLevel- Level of distance this prefab can stay visible before unloading.
AddConstructable(GameObject, TechType, ConstructableFlags, GameObject)
public static Constructable AddConstructable(GameObject prefab, TechType techType, ConstructableFlags constructableFlags, GameObject model = null)
Parameters
prefab
GameObject- The prefab to operate on.
techType
TechType- The tech type associated with the specified prefab.
constructableFlags
ConstructableFlags- A bitmask comprised of one or more ConstructableFlags that specify how the prefab should be treated during placement.
model
GameObjectThe child GameObject that holds all the renderers that are used for the ghost model. If assigned, this parameter will control the Constructable.model field. This field MUST BE ASSIGNED A VALUE to avoid errors when building!
This should be a child of
prefab
, and NOT the root. If it is the same value asprefab
, you have done something wrong!
Returns
- Constructable
- A reference to the added Constructable instance.
AddEnergyMixin(GameObject, string, TechType, List<TechType>, BatteryModels[], string)
Adds the EnergyMixin component to an object that is expected to have a slot for one battery or other power source.
Due to how this component needs to be initialized, this method will disable the object and re-enable it after the component is added (assuming it was already active). This all happens within the same frame and will not be seen.
public static EnergyMixin AddEnergyMixin(GameObject prefabRoot, string storageRootClassId, TechType defaultBattery, List<TechType> compatibleBatteries, EnergyMixin.BatteryModels[] batteryModels = null, string storageRootName = "BatterySlot")
Parameters
prefabRoot
GameObject- The root of the prefab object, where the component is added.
storageRootClassId
string- A unique string for the ChildObjectIdentifier component.
defaultBattery
TechType- The TechType of the battery that is added by default. If there should be no default, set this value to TechType.None.
compatibleBatteries
List<TechType>- The list of all compatible batteries. By default is typically TechType.Battery and TechType.PrecursorIonBattery. Must not be null!
batteryModels
BatteryModels[]- If assigned a value, allows different models to appear with different battery TechTypes. Also consider EnergyMixin.controlledObjects for a more basic version of this that is not TechType-dependent.
storageRootName
string- The name of the object that internally holds all of the batteries.
Returns
- EnergyMixin
- A reference to the added EnergyMixin instance.
AddResourceTracker(GameObject, TechType)
public static ResourceTracker AddResourceTracker(GameObject gameObject, TechType categoryTechType)
Parameters
gameObject
GameObject- the game object to add the resource tracker component to.
categoryTechType
TechType- TechType of the category in which this object will be displayed under in the Scanner Room.
Returns
- ResourceTracker
- A reference to the added ResourceTracker instance.
AddStorageContainer(GameObject, string, string, int, int, bool)
Adds the StorageContainer component to the given prefab, for basic use cases with lockers and such.
Due to how this component needs to be initialized, this method will disable the object and re-enable it after the component is added (assuming it was already active). This all happens within the same frame and will not be seen.
public static StorageContainer AddStorageContainer(GameObject prefabRoot, string storageRootName, string storageRootClassId, int width, int height, bool preventDeconstructionIfNotEmpty = true)
Parameters
prefabRoot
GameObject- The prefab that the component is added onto. This does not necessarily NEED to be the "prefab root". You can set it to a child collider if you want a smaller area of interaction or to have multiple storage containers on one prefab.
storageRootName
string- The name of the object that internally holds all of the items.
storageRootClassId
string- A unique string for the ChildObjectIdentifier component.
width
int- The width of this container's face.
height
int- The height of this container's interface.
preventDeconstructionIfNotEmpty
bool- If true, you cannot destroy this prefab unless all of its storage containers are empty.
Returns
- StorageContainer
- A reference to the added StorageContainer instance.
AddVFXFabricating(GameObject, string, float, float, Vector3, float, Vector3)
pathToModel
.public static VFXFabricating AddVFXFabricating(GameObject prefabRoot, string pathToModel, float minY, float maxY, Vector3 posOffset = default, float scaleFactor = 1, Vector3 eulerOffset = default)
Parameters
prefabRoot
GameObject- The prefab object that this is applied to.
pathToModel
string- Leave as null or empty to point to the prefab root. Otherwise this is the path to the crafting model Transform, relative to the prefab's root Transform. For example, the Repair Tool's would be `welder_scaled/welder`.
minY
floatThe relative y position of where the ghost effect begins, in global coordinates relative to the model's center, taking the
posOffset
into account.Typically a negative value because the bottom of an object is below its center. You may need to adjust this at runtime with Subnautica Runtime Editor to get desired results.
maxY
floatThe relative y position of where the ghost effect ends, in global coordinates relative to the model's center, taking the
posOffset
into account.Typically a positive value because the top of an object is above its center. You may need to adjust this at runtime with Subnautica Runtime Editor to get desired results.
posOffset
Vector3- The offset of the model when being crafted (in METERS). This is generally around zero, but the y value may be adjusted up or down a few millimeters to fix clipping/floating issues.
scaleFactor
float- The relative scale of the model. Generally is 1x for most items.
eulerOffset
Vector3- Rotational offset.
Returns
- VFXFabricating
- A reference to the added VFXFabricating instance.