Sub Name Decals - NeisesMike/VehicleFramework GitHub Wiki
The SubName Decals display the configurable name of the vehicle.
They are updated whenever the vehicle's name is edited via the Moonpool or onboard ColorPicker.
Overview
ModVehicle has the field:
public virtual List<TMPro.TextMeshProUGUI> SubNameDecals => null;
A TMPro.TextMeshProUGUI
is a special object used to display text in the world. It has a lot of special properties, and I won't go into them deeply here. But there are a few key things you need to know.
In Unity, you can easily add a TextMeshProUGUI object by right clicking and going to UI > Text - TextMeshPro. Like this:
This will actually add two objects: a parent with a Canvas
and a child with a Canvas Renderer
.
On the top object (the one with a Canvas
), it will also add a Canvas Scaler
and a Graphic Raycaster
. Those aren't necessary, and I delete them.
Then you must take four steps:
- Change the
Layer
toDefault
on the parent object. You should propagate this change to the child object too (Unity will ask if that's what you want). If you leave it on UI, the text will not be displayed in the game. - Change the
Render Mode
on theCanvas
toWorld Space
. This will allow you to move and scale the text. - Update the Pos X, Pos Y, and Pos Z to position your text. Using a Rect Transform is a little different than using a Transform.
- Update the Scale and Rotation to finish positioning your text. For ease of use, DO NOT change any size or position settings on the child object. It's best and easiest to change them on the parent in the ways I've just described.
Once your Canvas is in the right place is and is the right size (white box), you must also size your TextMeshProUGUI (yellow box). You can simply click-and-drag the little squares on the borders of the yellow box. Make the yellow box be about the same size as the white box, but don't overflow it.
You should consider changing some options in the TextMeshProUGUI. Namely, you probably want to enable Auto Size
and setup good and permissive Auto Size Options
, particularly a Min and Max. You should also choose a default color using Vertex Color
, and you can configure the default alignment options too.
Example
The Blossom implements its name decals like this.
public override List<TMPro.TextMeshProUGUI> SubNameDecals => new List<TMPro.TextMeshProUGUI>
{
transform.Find("SubNameDecals/PortCanvas/Text (TMP)").GetComponent<TMPro.TextMeshProUGUI>(),
transform.Find("SubNameDecals/StarboardCanvas/Text (TMP)").GetComponent<TMPro.TextMeshProUGUI>()
};
That's it.