Stratkit Units Shadows Entity Graphics¶
This package contains logic for units shadows entities creation and positional updates. The entities are rendered with Entities Graphics.
How To Create Shadow Mesh¶
- You can manually create a shadow mesh in software like Blender, or use the tool
Assets/Create/Stratkit/Armies/Units Shadows Polygon Mesh
. In the window, specify how many vertices you want around the shadow mesh and clickCreate
. - The mesh prefab must contain:
MeshFilter
,MeshRenderer
, andUnitShadowAuthor
with the attached configuration files (store configs in separate files for sharing purposes).
How To Add Shadow to a Unit¶
- Simply drag and drop the shadow prefab into a unit prefab as a child.
How To Automatically Add Shadows to All Unit Prefabs¶
To automatically set shadows for all units, create a scriptable object asset of type UnitShadowsPrefabsHelper
and click Create Unit Shadows Prefabs.
The script will:
- Iterate through all units' balancing data.
- Find all corresponding prefabs, if they're missing shadows.
- Add the appropriate shadow to each unit prefab.
- Automatically scale the shadow by comparing the units' renderer bounds.
How To Specify Shadows Y-Offset¶
Since these are not real shadows but 2D objects, it’s crucial to display them slightly above other map decorations like mountains. For this reason, you can configure the offsets in UnitShadowZoomConfigAuthor
for specific zoom levels.
How To Disable Shadows¶
If you want to disable shadows but keep them in the project, you can switch off the Enabled
option in UnitShadowConfigAuthor
. During baking, the BakingOnlyEntity
tag will be added to each shadow entity, preventing the shadow from appearing in the live game world.
How To disable Shadows at Runtime¶
You can disable shadows at runtime, for example, to check if shadows affect FPS or to investigate other performance-related issues. Open the Jahro cheat console and use the "Remove units shadows" cheat. This invokes the UnitShadowUtilsSystem.RemoveUnitShadows()
function.
Baking Shadows¶
Shadows are baked using UnitShadowBaker
along with UnitShadowAuthor
. The baking process essentially adds only two components to the shadow entity: UnitShadowTag
and UnitShadowOffset
(which contains yOffsets for specific zoom levels). The rest of the required entity graphics components are automatically handled since the shadow is attached as a child of the unit prefab. This ensures that the appearance, removal, and culling of shadows is managed in the same way as the units' models.
Transform Update¶
Since the shadow is attached to the unit prefab as a child, it inherits all its translations and rotations. However, to prevent the shadow from rotating with the unit and to properly align the shadow with the ground, the UpdateUnitsShadowsPositionsSystem
handles the position updates accordingly.