CustomInformationRegister
Through this class, you can register and remove custom data.
Registering Custom Data
You can add custom data using the following APIs.
Note: When using the functions provided by the NOA Debugger, always use the symbol definition of NOA_DEBUGGER.
Registering a Group
// Add a custom data group.
CustomInformationRegister.AddGroup(string name, string displayName = "", int order = Int32.MaxValue);
A key duplication exception will occur if a group name that already exists is specified.
Registering Data
// Add read-only custom data.
CustomInformationRegister.AddImmutableIntKeyValue(string groupName, string keyName, Func<int> getValue, string displayName = "", int order = Int32.MaxValue);
CustomInformationRegister.AddImmutableFloatKeyValue(string groupName, string keyName, Func<float> getValue, string displayName = "", int order = Int32.MaxValue);
CustomInformationRegister.AddImmutableStringKeyValue(string groupName, string keyName, Func<string> getValue, string displayName = "", int order = Int32.MaxValue);
CustomInformationRegister.AddImmutableBoolKeyValue(string groupName, string keyName, Func<bool> getValue, string displayName = "", int order = Int32.MaxValue);
CustomInformationRegister.AddImmutableEnumKeyValue(string groupName, string keyName, Func<Enum> getValue, string displayName = "", int order = Int32.MaxValue);
// Add mutable custom data.
CustomInformationRegister.AddMutableIntKeyValue(string groupName, string keyName, Func<int> getValue, Action<int> setValue, string displayName = "", int order = Int32.MaxValue);
CustomInformationRegister.AddMutableFloatKeyValue(string groupName, string keyName, Func<float> getValue, Action<float> setValue, string displayName = "", int order = Int32.MaxValue);
CustomInformationRegister.AddMutableStringKeyValue(string groupName, string keyName, Func<string> getValue, Action<string> setValue, string displayName = "", int order = Int32.MaxValue);
CustomInformationRegister.AddMutableBoolKeyValue(string groupName, string keyName, Func<bool> getValue, Action<bool> setValue, string displayName = "", int order = Int32.MaxValue);
CustomInformationRegister.AddMutableEnumKeyValue(string groupName, string keyName, Func<Enum> getValue, Action<Enum> setValue, string displayName = "", int order = Int32.MaxValue);
A key duplication exception will occur if a key name that already exists within the same group is specified.
Sample Code
#if NOA_DEBUGGER
using NoaDebugger;
#endif
public class Example
{
// Custom data values
private string sampleStringValue = "SampleValue";
private int sampleIntValue = 1;
void ExampleMethod()
{
#if NOA_DEBUGGER
// Add a custom data group
string groupName = "SampleGroup";
CustomInformationRegister.AddGroup(
name: groupName,
displayName: "SampleGroupDisplayName",
order: 0);
// Add read-only custom data
CustomInformationRegister.AddImmutableStringKeyValue(
groupName: groupName,
keyName: "SampleKey",
getValue: () => sampleStringValue,
displayName: "SampleDisplayName",
order: 0);
// Add mutable custom data
CustomInformationRegister.AddMutableIntKeyValue(
groupName: groupName,
keyName: "MutableSampleKey",
getValue: () => sampleIntValue,
setValue: value => sampleIntValue = value,
displayName: "MutableSampleDisplayName",
order: 1);
#endif
}
}
Removing Custom Data
You can remove added custom data by calling the following APIs.
// Remove custom data with the specified key name
CustomInformationRegister.RemoveKeyValue(string groupName, string keyName);
// Remove all custom data in the specified group
CustomInformationRegister.RemoveGroup(string groupName);
// Remove all custom data
CustomInformationRegister.RemoveAll();
Referencing Registered Custom Data
You can retrieve added custom data by calling the following APIs.
// Get custom data with the specified key name
CustomInformationRegister.GetCustomInformationIntValue(string groupName, string keyName);
CustomInformationRegister.GetCustomInformationFloatValue(string groupName, string keyName);
CustomInformationRegister.GetCustomInformationStringValue(string groupName, string keyName);
CustomInformationRegister.GetCustomInformationBoolValue(string groupName, string keyName);
CustomInformationRegister.GetCustomInformationEnumValue(string groupName, string keyName);
// Get all custom data in the specified group
CustomInformationRegister.GetCustomInformationGroup(string groupName);
// Get all custom data
CustomInformationRegister.GetCustomInformationAll();
Sample Code
using System.Collections.Generic;
using UnityEngine;
#if NOA_DEBUGGER
using NoaDebugger;
#endif
public class Example
{
void ExampleMethod()
{
#if NOA_DEBUGGER
// Get custom data
int customValue = CustomInformationRegister.GetCustomInformationIntValue(groupName: "SampleGroup", keyName: "SampleKey").Value;
// Get custom data by group
NoaCustomInformationGroup groupInfo = CustomInformationRegister.GetCustomInformationGroup(groupName: "SampleGroup");
// Get all custom data
List<NoaCustomInformationGroup> allGroups = CustomInformationRegister.GetCustomInformationAll();
// Reference all custom data in the group
foreach (KeyValuePair<string, string> keyValue in groupInfo.KeyValues)
{
Debug.Log($"Key:{keyValue.Key} Value:{keyValue.Value}");
}
// Reference int-type custom data in the group
foreach (KeyValuePair<string, NoaCustomInformationIntValue> keyValue in groupInfo.IntKeyValues)
{
Debug.Log($"Key:{keyValue.Key} Value:{keyValue.Value.Value}");
keyValue.Value.Value = keyValue.Value.Value + 1; // Update value
}
// Reference bool-type custom data in the group
foreach (KeyValuePair<string, NoaCustomInformationBoolValue> keyValue in groupInfo.BoolKeyValues)
{
Debug.Log($"Key:{keyValue.Key} Value:{keyValue.Value.Value}");
keyValue.Value.Value = !keyValue.Value.Value; // Update value
}
#endif
}
}
Refreshing the [Custom] Tab's View
When custom data is updated, the display will not refresh until the update button is pressed.
To immediately refresh the display, execute RefreshView().
Sample Code
#if NOA_DEBUGGER
using NoaDebugger;
#endif
public class Example
{
// Custom data value
private string sampleValue;
void ExampleAddMethod()
{
#if NOA_DEBUGGER
// Add a group and key-value pairs to custom data
...
#endif
}
void ExampleUpdateMethod()
{
#if NOA_DEBUGGER
// Update the value of an existing key-value pair
sampleValue = "SampleUpdateValue";
// Refresh the Custom tab's view
CustomInformationRegister.RefreshView();
#endif
}
}
