Simple Submersible - NeisesMike/VehicleFramework GitHub Wiki
A Vehicle Framework vehicle mod typically has at least two files: the main patcher and the vehicle class. Here I'll call those MainPatcher.cs and GupB.cs for clarity. The GupB is a part of a new collection of vehicles I'm working on now.
The Main Patcher is the entry point for our mod into the game. This is the first file that BepInEx sees, and we use it to load our asset bundle and register our vehicle with Vehicle Framework.
using BepInEx;
using VehicleFramework;
using VehicleFramework.VehicleTypes;
using VehicleFramework.Assets;
namespace Guppies
{
[BepInPlugin(MainPatcher.PLUGIN_GUID, MainPatcher.PLUGIN_NAME, MainPatcher.PLUGIN_VERSION)]
[BepInDependency(VehicleFramework.PluginInfo.PLUGIN_GUID)]
public class MainPatcher : BaseUnityPlugin
{
const string PLUGIN_GUID = "uniquestringthatnooneelsewouldwrite";
const string PLUGIN_NAME = "MyCoolSubmersible";
const string PLUGIN_VERSION = "1.0.0";
public static VehicleAssets MyVehicleAssets;
public void Start()
{
MyVehicleAssets = AssetBundleInterface.GetVehicleAssetsFromBundle("assets/gupb", "GupB");
Submersible gupB = MyVehicleAssets.model.AddComponent<GupB>() as Submersible;
VehicleRegistrar.RegisterVehicleLater(gupB); // I don't care to do anything after registration.
}
}
}
This provides a simple implementation of a Submersible. The GupB has a Collision Model, a PilotSeat, a Hatch, a Canopy Window, a Bounding Box Collider, and a set of Water Clip Proxies. I think this is the minimal collection of things that make a vehicle sensible and usable in the game.
Everywhere you see "transform.Find" is somewhere I'm traversing the transform hierarchy of my vehicle's GameObject to find a specific GameObject within it. For reference, my vehicle has a transform hierarchy like this:
GupB
> Hatch
> Seat
> model
>> Bone
>>> Windshield
> BoundingBox
> WaterClipProxies
But your vehicle is probably setup differently. So pay close attention to your vehicle's transform hierarchy and the names you gave the objects inside your vehicle!
using System.Collections.Generic;
using UnityEngine;
using VehicleFramework.VehicleParts;
using VehicleFramework.VehicleTypes;
namespace Guppies
{
public class GupB : Submersible
{
public override GameObject VehicleModel => MainPatcher.MyVehicleAssets.model;
public override GameObject CollisionModel => transform.Find("Hatch").gameObject; // The GupB's hatch covers the whole vehicle.
public override VehiclePilotSeat PilotSeat => new VehiclePilotSeat {
Seat = transform.Find("Seat").gameObject,
ExitLocation = transform,
LeftHandLocation = null,
RightHandLocation = null,
SitLocation = transform.Find("Seat").gameObject
};
public override List<VehicleHatchStruct> Hatches => new List<VehicleHatchStruct> {
new VehicleHatchStruct {
Hatch = transform.Find("Hatch").gameObject,
ExitLocation = transform,
EntryLocation = transform,
SurfaceExitLocation = transform
}
};
public override List<GameObject> CanopyWindows => new List<GameObject> {
transform.Find("model/Bone/Windshield").gameObject
};
public override BoxCollider BoundingBoxCollider => transform.Find("BoundingBox").gameObject.GetComponent<BoxCollider>();
public override List<GameObject> WaterClipProxies => new List<GameObject> {
transform.Find("WaterclipProxies").gameObject
};
}
}