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
prefabGameObject- The prefab to operate on.
classIdstring- The class ID associated with the specified prefab.
techTypeTechType- Ignored if TechType.None is inputted.
cellLevelLargeWorldEntity.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
prefabGameObject- The prefab to operate on.
techTypeTechType- The tech type associated with the specified prefab.
constructableFlagsConstructableFlags- A bitmask comprised of one or more ConstructableFlags that specify how the prefab should be treated during placement.
modelGameObjectThe 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.
AddConstructable<T>(GameObject, TechType, ConstructableFlags, GameObject)
public static T AddConstructable<T>(GameObject prefab, TechType techType, ConstructableFlags constructableFlags, GameObject model = null) where T : Constructable
Parameters
prefabGameObject- The prefab to operate on.
techTypeTechType- The tech type associated with the specified prefab.
constructableFlagsConstructableFlags- A bitmask comprised of one or more ConstructableFlags that specify how the prefab should be treated during placement.
modelGameObjectThe 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
- T
- A reference to the added Constructable instance.
Type Parameters
T
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
prefabRootGameObject- The root of the prefab object, where the component is added.
storageRootClassIdstring- A unique string for the ChildObjectIdentifier component.
defaultBatteryTechType- The TechType of the battery that is added by default. If there should be no default, set this value to TechType.None.
compatibleBatteriesList<TechType>- The list of all compatible batteries. By default is typically TechType.Battery and TechType.PrecursorIonBattery. Must not be null!
batteryModelsBatteryModels[]- 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.
storageRootNamestring- The name of the object that internally holds all of the batteries.
Returns
- EnergyMixin
- A reference to the added EnergyMixin instance.
AddEnergyMixin<T>(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 T AddEnergyMixin<T>(GameObject prefabRoot, string storageRootClassId, TechType defaultBattery, List<TechType> compatibleBatteries, EnergyMixin.BatteryModels[] batteryModels = null, string storageRootName = "BatterySlot") where T : EnergyMixin
Parameters
prefabRootGameObject- The root of the prefab object, where the component is added.
storageRootClassIdstring- A unique string for the ChildObjectIdentifier component.
defaultBatteryTechType- The TechType of the battery that is added by default. If there should be no default, set this value to TechType.None.
compatibleBatteriesList<TechType>- The list of all compatible batteries. By default is typically TechType.Battery and TechType.PrecursorIonBattery. Must not be null!
batteryModelsBatteryModels[]- 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.
storageRootNamestring- The name of the object that internally holds all of the batteries.
Returns
- T
- A reference to the added EnergyMixin instance.
Type Parameters
T
AddResourceTracker(GameObject, TechType)
public static ResourceTracker AddResourceTracker(GameObject gameObject, TechType categoryTechType)
Parameters
gameObjectGameObject- the game object to add the resource tracker component to.
categoryTechTypeTechType- 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
prefabRootGameObject- 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.
storageRootNamestring- The name of the object that internally holds all of the items.
storageRootClassIdstring- A unique string for the ChildObjectIdentifier component.
widthint- The width of this container's face.
heightint- The height of this container's interface.
preventDeconstructionIfNotEmptybool- If true, you cannot destroy this prefab unless all of its storage containers are empty.
Returns
- StorageContainer
- A reference to the added StorageContainer instance.
AddStorageContainer<T>(GameObject, string, string, int, int, bool)
Adds a component of the type StorageContainer or a derived class 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 T AddStorageContainer<T>(GameObject prefabRoot, string storageRootName, string storageRootClassId, int width, int height, bool preventDeconstructionIfNotEmpty = true) where T : StorageContainer
Parameters
prefabRootGameObject- 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.
storageRootNamestring- The name of the object that internally holds all of the items.
storageRootClassIdstring- A unique string for the ChildObjectIdentifier component.
widthint- The width of this container's face.
heightint- The height of this container's interface.
preventDeconstructionIfNotEmptybool- If true, you cannot destroy this prefab unless all of its storage containers are empty.
Returns
- T
- A reference to the added StorageContainer instance.
Type Parameters
T
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
prefabRootGameObject- The prefab object that this is applied to.
pathToModelstring- 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`.
minYfloatThe relative y position of where the ghost effect begins, in global coordinates relative to the model's center, taking the
posOffsetinto 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.
maxYfloatThe relative y position of where the ghost effect ends, in global coordinates relative to the model's center, taking the
posOffsetinto 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.
posOffsetVector3- 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.
scaleFactorfloat- The relative scale of the model. Generally is 1x for most items.
eulerOffsetVector3- Rotational offset.
Returns
- VFXFabricating
- A reference to the added VFXFabricating instance.
AddWorldForces(GameObject, float, float, float, bool)
public static WorldForces AddWorldForces(GameObject prefab, float mass, float underwaterGravity = 1, float underwaterDrag = 1, bool isKinematic = false)
Parameters
prefabGameObject- The prefab to modify.
massfloat- The mass of the new rigidbody (only if a rigidbody is being added). If the prefab already has a Rigidbody, this has NO EFFECT.
underwaterGravityfloat- The underwater gravity in m/s/s.
underwaterDragfloat- The underwater drag coefficient (using Unity's arbitrary unit for drag).
isKinematicbool- If true, the Rigidbody will be kinematic when spawned and therefore immovable. Note that if the player picks up an item and drops it, its kinematic state will be reset to false.
Returns
- WorldForces
- A reference to the newly added (or previously existing) WorldForces component.