-
Notifications
You must be signed in to change notification settings - Fork 5
Dll Modding
- Download and instal BTML and ModTek here
- Download lib and unpack it to Battletech mod folder
- Add reference to Mods/CustomComponents/CustomComponents.dll in your project
- Add dependency for Modtek in your mod.json at
"DependsOn": [ "CustomComponents" ],
- Register your Custom classes to loader using
CustomComponents.Registry.RegisterSimpleCustomComponents(Assembly.GetExecutingAssembly())
Custom Component must be inherited from SimpleCustomComponent class and have CustomComponent attribute with string, which be used for define its name in Custom section. Each field or propery can be loaded from json. To force ignore value use [fastJSON.JsonIgnore] attribute. If field skipped in Json it will have its default value
[CustomComponent("Example")]
public class ExampleComponent : SimpleCustomComponent
{
public string String1;
private int Value1;
public float Value2 {get;set;}
[JsonIgnore]
public string DontLoadMe;
}
will turn into "Example" : { "String1" : "some text", "Value1" : 10, "Value2" : 0.4, "DontLoadMe" : "will be ignored, so DontLoadMe after load is empty string" }
We implement Unity way to access components - call GetComponent() on ComponentDef or ComponentRef and it will give you null or component of this type or his child (i.e. if you create class Example2 : ExampleComponent
GetComponent<ExampleComponent>
return first Example2 or ExampleComponent it found, but GetComponent<Example2>
will return only Example2). This done using C# Extentions.
Main differnece beetwin ComponentRef.GetComponent() and ComponentDef.GetComponent() that MechComponentRef populate its Def value only when game really need it and GetComponent() force to do this. In same cases(for example mechlab workorders after load game) ComponentRef will be empty cose in this time it dont requere values from MechComponentDef and this lead to wrong null result for ComponentDef.GetComponent();
Return T or null
Return enumarable sequence of T. Used mostly for event with Interfaces
Just check if this componentDef/Ref have T-type custom.
Check if this componentDef/Ref have T-type custom and return it in out component parameter.
Just check if this componentDef/Ref have Category with given CategoryID.
Check if this componentDef/Ref have Category with given CategoryID and return it in out component parameter.
Interfaces used to implement event handling. Most of them described in own article, there i just notice this one, cose it included to cclight
- void OnLoaded();
Called after component Loaded, so any initialization logic can be put here
Attribute to mark your class as custom component
[CustomComponent("MyComponent")]
public class MyComponent : SimpleCustomComponent { }
Mark class as simple custom component - only one of this time allowed on object
[CustomComponent("MyComponent", true)]
public class MyComponent : SimpleCustomComponent { }
Mark class as multicomponent, allow few instances of component exist on object. In object json it will look like
{
"Custom" : {
"MyComponent" : [
{ //options// },
{ //options// },
...
]
}
//rest of json
}
Standart single item definition "MyComponent" : { //options// }
will work too
[CustomComponent("MyComponent", group: "GroupName")]
public class MyComponent : SimpleCustomComponent { }
Mark component as member of a group. Components of same group replace each other even having different types. Can be used when you need components with different options, that have same functionality and only one can be present on object. For example - Color Components from Predefined Components