Code

Connecting mount points through code is just as easy.

There are several functions on the MountPoints and Mount objects to help you out.

Note: The “Mount List” component is actually the “MountPoints” class defined in the MountPoints.cs file.

Following standard Unity coding practices, you can get the MousePoints and Mount component from the GameObject using the following syntax:

MountPoints mMountPoints = rParentObject.GetComponent();
Mount lMount = rParentObject.GetComponent();

Once you have the MountPoints (or Mount) object, you can use the following functions:
CreateMountPoint
ConnectMountPoints
DisconnectMountPoints
GetMountPoint
GetSkinnedItem
AddSkinnedItem
RemoveSkinnedItem

Code Sample

In the demo, I use a C# file named SampleUI.cs. In it, you’ll find several ways in which I connect objects through code.

For ease, I’m listing key parts here so you can see how I’m using MP in code:

mMountPoints.ConnectMountPoints("Right Hand", GameObject.Find("Sword"), "Mount Point");
mMountPoints.DisconnectMountPoints(lSwordMP);
mMountPoints.ConnectMountPoints("Left Arm", GameObject.Find("Shield"), "Mount Point");
mMountPoints.ConnectMountPoints("Head", "Prefabs/Armor/Helmets/Helmet", "Head");
mMountPoints.RemoveSkinnedItem("Hair");
mMountPoints.AddSkinnedItem("Prefabs/Armor/Shirts/Shirt_02", "Prefabs/Armor/Shirts/Shirt_02_mask");
mMountPoints.RemoveSkinnedItemFromPath("Prefabs/Armor/Shirts/Shirt_02");
mMountPoints.AddSkinnedItem("Prefabs/Armor/Pants/Pants_02", "Prefabs/Armor/Pants/Pants_02_mask");
mMountPoints.AddSkinnedItem("Prefabs/Armor/Shoes/Boots_02", "Prefabs/Armor/Shoes/Boots_02_mask");

Content

In order to instantiate skinned items at run-time using code,  the prefabs and mask textures need to be placed in a ‘Resources’ subfolder. This will tell Unity to package the assets up even if they aren’t currently active in the scene.