-
Notifications
You must be signed in to change notification settings - Fork 5
Home
CustomComponents - is a library that allows you to create custom ComponentsDef, that can contain any custom data and load them from JSON definitions.
Loading each type of resource controled by apopriate DataManager.%%DefLoadRequest class. after loading Def file stored in DataManager and can be retrieved by id. its unchanged throughout the life time. So library hooks to
- DataManager.%%DefLoadRequest method OnLoadedWithJSON(string json), check if loading json have "CustomType" tag and then load custom component according this tag.
- %%Def.ToJSON(), where check if component is cutomized and send customized object to serialization.
Inherite it from apopriate Custom%%Def class. There is implemented 5 types of custom ressources based on default component types.
- CustomAmmunitionBoxDef : BattleTech.AmmunitionBoxDef
- CustomJumpJetDef : BattleTech.JumpJetDef
- CustomHeatSinkDef : BattleTech.HeatSinkDef
- CustomUpgradeDef : BattleTech.UpgradeDef
- CustomWeaponDef : BattleTech.WeaponDef
add CustomAttribute with unique name for type add any fields/properties to class
[Custom("Engine")]
public class EngineDef : CustomHeatSinkDef<EngineDef>
{
public int EngineRating {get;set;}
public String SomeValue;
}
and now you can take HeatSinkTemplate.json from game, add your parameters to main scope and change standard parameters (at least Description.Id) for your needs
{
"CustomType" : "Engine",
"EngineRating" : 200,
"SomeValue" : "Custom String",
// rest of heatsink deffinition
}
now you can check if component is Engine and cast it to Engine using standart C# operators is and as
if (componentDef is EngineDef)
{
var engine = componentDef as EngineDef;
movementSpeed = engine.EngineRating / mechTonnage
}
You can create and implement interfaces to create some general component behaviour. For example build-in IColorComponent interface, that change color of component in component list or mech equipment
interface IColorComponent
{
UIColor Color { get; }
}
for example to make Engine orange all you need is add to it definition
[Custom("Engine")]
public class EngineDef : CustomHeatSinkDef<MyComponentDef>, IColorComponent
{
UIColor Color {get;set;}
...
}
and add color to JSon
"Color" : "Orange"
note: UIColor is buildin enum with pretty limited set of colors and most of them are unusable, it has element UIColor.Custom, but i dont found how to define custom colors. also it have Half variants (e.g. UIColor.RedHalf) with semitransparent alpha
under construction
under construction