mirror of
https://github.com/All-Of-Us-Mods/MiraAPI.git
synced 2026-10-19 15:51:48 +00:00
readme updates
This commit is contained in:
1 parent
826e172a3a
commit
62ec462e79
1 file changed
+40
-3
@@ -34,13 +34,25 @@ Options are also very simple in Mira API. Options are split up into Groups and O
|
||||
|
||||
To create a group, you need to create a class that implements the `IModdedOptionGroup` interface. Groups contain 4 properties, `GroupName`, `GroupColor`, `GroupVisible`, and `AdvancedRole`. Only the `GroupName` is required.
|
||||
|
||||
Here is an example of a group class:
|
||||
```csharp
|
||||
public class MyOptionsGroup : IModdedOptionGroup
|
||||
{
|
||||
public string GroupName => "My Options"; // this is required
|
||||
|
||||
[ModdedNumberOption("My Number Option", min: 0, max: 10)]
|
||||
public float MyNumberOption { get; set; } = 5f;
|
||||
}
|
||||
```
|
||||
|
||||
You can access any group class using the `ModdedGroupSingleton` class like this:
|
||||
```
|
||||
// MyOptionsGroup is a class that implements IModdedOptionGroup
|
||||
var myGroup = ModdedGroupSingleton<MyOptionsGroup>.Instance;
|
||||
var myGroup = ModdedGroupSingleton<MyOptionsGroup>.Instance; // gets the instance of the group
|
||||
System.Out.Console.WriteLine(myGroup.MyNumberOption); // prints the value of the option to the console
|
||||
```
|
||||
|
||||
There are two ways to make options inside a group:
|
||||
Once you have an options group, there are two ways to make the actual options:
|
||||
- Use an Option Attribute with a property.
|
||||
- Create a ModdedOption property.
|
||||
|
||||
@@ -66,7 +78,32 @@ To see a full example of an options class, see [this file](https://github.com/Al
|
||||
|
||||
### Role Options
|
||||
|
||||
Options can also be used within a Role class to show up in that Role's settings. To set the role for an entire group, set the `AdvancedRole` property on that group. To set the role for individual options, specify the `roleType` parameter in the option.
|
||||
Options can also be used within a Role class to show up in that Role's settings.
|
||||
|
||||
To set the role for an entire group, set the `AdvancedRole` property on that group like this:
|
||||
```csharp
|
||||
public class MyOptionsGroup : IModdedOptionGroup
|
||||
{
|
||||
public string GroupName => "My Options";
|
||||
public Type AdvancedRole => typeof(MyRole); // this is the role that will have these options
|
||||
|
||||
[ModdedNumberOption("Ability Uses", min: 0, max: 10)]
|
||||
public float AbilityUses { get; set; } = 5f;
|
||||
}
|
||||
```
|
||||
|
||||
To set the role for individual options, specify the `roleType` parameter in the option like this:
|
||||
```csharp
|
||||
// this group doesnt specify a role, so it will show up in the global settings
|
||||
public class MyOptionsGroup : IModdedOptionGroup
|
||||
{
|
||||
public string GroupName => "My Options";
|
||||
|
||||
// this option will only show up in the settings for MyRole
|
||||
[ModdedNumberOption("Ability Uses", min: 0, max: 10, roleType: typeof(MyRole))]
|
||||
public float AbilityUses { get; set; } = 5f;
|
||||
}
|
||||
```
|
||||
|
||||
An example can be found [here](https://github.com/All-Of-Us-Mods/MiraAPI/blob/master/MiraAPI.Example/Options/Roles/CustomRoleSettings.cs).
|
||||
|
||||
|
||||
Reference in new issue
Block a user