-
Notifications
You must be signed in to change notification settings - Fork 0
Home
glennuke1 edited this page Feb 26, 2025
·
2 revisions
Welcome to the ModAPI wiki!
Below is an example of how to create and attach a custom part (a carburetor) using this API.
using eightyseven.ModApi.Attachable;
using UnityEngine;
public class ExamplePartSetup : MonoBehaviour
{
private GameObject carburetor;
private Part carburetorPart;
void Start()
{
// Create trigger data
TriggerData carburetorTriggerData = TriggerData.createTriggerData("customCarburetorTrigger");
// Create part object
carburetor = new GameObject("CustomCarburetor");
carburetorPart = carburetor.AddComponent<Part>();
// Define part settings
PartSettings partSettings = new PartSettings()
{
autoSave = true,
assembleType = AssembleType.static_rigidbodyDelete,
setPositionRotationOnInitialisePart = false,
assemblyTypeJointSettings = new AssemblyTypeJointSettings()
{
breakForce = float.PositiveInfinity,
},
collisionSettings = new CollisionSettings()
{
notInstalledCollisionDetectionMode = CollisionDetectionMode.ContinuousDynamic
}
};
// Define trigger settings
TriggerSettings carbTriggerSettings = new TriggerSettings()
{
triggerID = "customCarburetorTrigger",
useTriggerTransformData = true,
triggerData = carburetorTriggerData,
triggerPosition = new Vector3(0.25f, 0.48f, -1.5f),
triggerEuler = Vector3.zero
};
BoltSettings carbBoltSettings = new BoltSettings()
{
size = BoltSize._8mm,
type = BoltType.nut,
posDirection = Vector3.up,
posStep = 0.0025f,
rotDirection = Vector3.forward,
rotStep = 30f,
canUseRachet = true,
highlightWhenActive = true,
};
// Create trigger
new Trigger(GameObject.Find("Random Car Name").transform.gameObject, carbTriggerSettings);
Bolt[] bolts = new Bolt[1]
{
new Bolt(carbBoltSettings, new Vector3(0.1425f, 0.335f, -0.03f), new Vector3(90, 0, 0))
};
// Initialize part
carburetorPart.initPart(carburetorTriggerData, partSettings, bolts);
}
}