-
Notifications
You must be signed in to change notification settings - Fork 17
Creating a Part
Tommee J. Armytage edited this page Oct 25, 2023
·
3 revisions
- There are a few things you need before you can get started with creating a new part:
- A Steam copy of My Summer Car
- Install MSC Mod Loader by piotrulos. PRO is not supported.
- Install ModAPI
- A good understanding of C#, Unity 5.0.0f1, and ModLoader.
- A part idea.
- First, You will have to import a model in to the game, to do that you will have to create an asset bundle. See: How to create and use asset bundles
- To load an asset bundle, it would look something like this:
using UnityEngine;
using MSCLoader;
using TommoJProductions.ModApi.Attachable;
public class Demo : Mod
{
...
...
...
public void OnLoad()
{
// Load the asset bundle that you created.
AssetBundle ab = MSCLoader.LoadAssets.LoadBundle(this,"part.unity3d");
// Load the prefab.
GameObject prefab = ab.LoadAsset<GameObject>("test.prefab");
// unload the asset bundle after loading all objects.
ab.Unload(false);
...
...
...
}
}
- With the new ModAPI Structure ( > 0.1.2.*), you don't have to create a new class for every Part now. You can still do that to create your own parts with custom logic, as Part is completely overridable when derived from!
- See Part Settings for a list of all settings.
- To create a part, it would look something like this:
using UnityEngine;
using MSCLoader;
using TommoJProductions.ModApi.Attachable;
public class Demo : Mod
{
...
...
...
public void OnLoad()
{
...
...
...
// Instantiate the object.
Gameobject go = Object.Instantiate(prefab);
// Create the trigger data for the part. Make sure the name is UNIQUE!
TriggerData triggerData = TriggerData.createTriggerData("testTriggerData");
// Create the Part
Part part = go.AddComponent<Part>();
// Add default save data
part.defaultSaveInfo.position = new Vector3(-9.7f, 0, 6.2f); // kitchen room
// Create Part Settings
PartSettings settings = new PartSettings()
{
autoSave = true
}
// Initialize the part.
part.initPart(triggerData, settings);
...
...
...
}
}
- A Trigger is used to create an install point for a part to attach to. It can be parented on any gameobject, eg => The Satsuma, Another part, A static gameobject, etc.
- Parts can only be installed to Triggers with the same TriggerData.
using UnityEngine;
using MSCLoader;
using TommoJProductions.ModApi.Attachable;
public class Demo : Mod
{
...
...
...
public void OnLoad()
{
...
...
...
// Get an instance of the parent for the part; The object that the part 'installs' to. (in this case, the satsuma)
GameObject parent = GameObject.Find("SATSUMA(557kg, 248)");
// Create trigger for the part.
TriggerSettings triggerSettings = new TriggerSettings()
{
triggerID = "testTrigger",
triggerData = triggerData,
triggerPosition = new Vector3(0.0f, 1.3f, -0.3f)
};
Trigger trigger = new Trigger(parent, triggerSettings);
}
}