Fragment Manual - NeisesMike/VehicleFramework GitHub Wiki
Fragments are a useful way to lock modded content behind gameplay.
This is very cool.
If you want create fragments for your vehicle or upgrade, make sure you set the appropriate:
public abstract class ModVehicle
{
public virtual TechType UnlockedWith => TechType.Fragment;
}
public abstract class ModVehicleUpgrade
{
public virtual bool UnlockAtStart => false;
public virtual TechType UnlockWith => TechType.Fragment;
}
Vehicle Framework exposes one method for registering fragments:
namespace VehicleFramework.Assets
{
public struct FragmentData
{
public GameObject fragment;
public TechType toUnlock;
public int fragmentsToScan;
public float scanTime;
public string classID;
public string displayName;
public string description;
public List<Vector3> spawnLocations;
public List<Vector3> spawnRotations;
public string encyKey;
}
public static TechType RegisterFragment(FragmentData frag);
}
Explanations and examples of FragmentData fields follow.
fragment
is the model you supply for the fragment.
toUnlock
is the techtype for the vehicle or upgrade you want to unlock after scanning the fragment.
fragmentsToScan
determines how many fragments the player must scan before unlocking the vehicle or upgrade.
scanTime
is a length in seconds that describes how long it takes to finish scanning one fragment.
classID
is a unique name that describes your fragment. The player can use spawn [classID]
displayName
is a name that might show up in the PDA or crafting menu, but probably doesn't, ha ha.
description
might also show up somewhere, yet probably doesn't.
spawnLocations
is a list of world positions where your fragments will be placed. This goes hand-in-hand with spawnRotations.
spawnRotations
is a list of rotations to which your fragments will be placed. If you do not use null
for this field, this list should be exactly the same length as spawnLocations
. The first spawnLocation
will be associated with the first spawnRotation
and so on.
encyKey
is the index into the encyclopedia. I usually use classID for this. Before registering the fragment, I invoke this method:
Nautilus.Handlers.PDAHandler.AddEncyclopediaEntry(classID, ...); // the first parameter should match encyKey!
Here's an example for the Drone Station:
public static class BuildableDroneStation
{
public const string classID = "DroneStation";
public const string displayName = "Drone Station";
public const string description = "A terminal from which to control drones remotely";
public const string encyclopediaDesc = "The drone station can be used to remotely connect to and pilot any nearby drone vehicles. The drone station enhances radio technology to keep users safe from distant threats."
+ "\n "
+ " - Connection Range: ~600 meters\n"
+ " - Designed for: Compartments and Submarines\n"
+ " - Can automatically return drones to itself\n";
public static void Register()
{
VehicleAssets DSAssets = AssetBundleInterface.GetVehicleAssetsFromBundle("dronestation", "DroneStation", "DSSpriteAtlas", "", "DSCrafterSprite", "Fragment", "DSUnlockSprite");
// The following line registers the buildable. Not important for this guide!
//TechType consoleTT = RegisterConsole(DSAssets.model, DSAssets.crafter, DSAssets.unlock);
List<Vector3> spawnLocations = new List<Vector3>
{
new Vector3 (375.1f, -69.4f, -22.4f),
new Vector3 (122.4f, -38.9f, -131.4f),
new Vector3 (89.9f, -30.5f, -162.6f),
new Vector3 (30.2f, -42.4f, -217.5f),
new Vector3 (46.9f, -20.1f, -86.7f),
new Vector3 (-148.1f, -31.7f, 252.8f),
new Vector3 (-150.2f, -47.7f, 234.4f),
new Vector3 (-228.7f, -66.2f, 159.8f),
new Vector3 (172.2f, -73.6f, -7.1f),
new Vector3 (394.4f, -98.7f, 83.3f),
new Vector3 (379.4f, -117.9f, 122.3f),
new Vector3 (424.8f, -112.5f, 104.3f),
new Vector3 (375.1f, -69.4f, -22.4f),
new Vector3 (-148.1f, -31.7f, 252.8f)
};
Nautilus.Handlers.PDAHandler.AddEncyclopediaEntry(classID, "Tech/Habitats", displayName, encyclopediaDesc, DSAssets.unlock.texture, DSAssets.unlock, null, null);
FragmentData fragmentData = new FragmentData
{
fragment = DSAssets.fragment,
toUnlock = consoleTT,
fragmentsToScan = 3,
scanTime = 5f,
classID = classID + "Fragment",
displayName = displayName + " Fragment",
description = description + " ...fragment",
spawnLocations = spawnLocations,
spawnRotations = null,
encyKey = classID
};
FragmentManager.RegisterFragment(fragmentData);
}
}