First you need a special trait for the unit design, make one up but they all need it. Then add this
<ProductionRequirement>
<Type>Resource</Type>
<Attribute>TestRes</Attribute>
<Value>1</Value>
<Provides>This unit costs 1 Testres per member</Provides>
</ProductionRequirement>
The above makes it require 1 Testres per member when you train, and it will continuously drain that resource as long as the unit lives (if damaged it still drains the max amount, ie 2/3 members alive = drain 3).
Then set up a new resource like below
<ResourceType InternalName="TestRes">
<DisplayName>Fire Shard</DisplayName>
<Type>TestRes</Type>
<Description>Increases the power of your Fire spells.</Description>
<IconColor>0,0,0</IconColor>
<Icon>Gfx//Icons//Icon_Fire.png</Icon>
<HideInHiergamenon>1</HideInHiergamenon>
<ShownInGlobalDisplay>1</ShownInGlobalDisplay>
<Global>1</Global>
<Stored>0</Stored>
<Shared>0</Shared>
<TradedByCaravans>0</TradedByCaravans>
<RummagedPerTurn>0.01</RummagedPerTurn>
<!-- AI Info -->
<AIData AIPersonality="AI_General">
<AITag>Shard</AITag>
</AIData>
</ResourceType>
Then all you need is to add the production of the resource to somewhere. Here I added 3 production to each tower of dominion a player controls:
<ImprovementType InternalName="TowerOfDominion">
<GameModifier>
<ModType>Resource</ModType>
<Attribute>TestRes</Attribute>
<Value>3</Value>
<PerTurn>1</PerTurn>
<Provides>+1 TestRes</Provides>
</GameModifier>
</ImprovementType>
This would allow you to build 1 unit with 3 members (per tower of dominion), but nothing else. As long as the unit is alive, you can't build another one.