GameplayTags
GameplayTags copied to clipboard
Add JSON serialization support for GameplayTag and GameplayTagContainer
Fix #16
Add GameplayTagJsonConverter and GameplayTagContainerJsonConverter.
They use the same format as Unreal's convertion of FGameplayTag and FGameplayTagContainer
Formats
GameplayTag
{
"tagName": "ParentTagA.Middle.LeafA"
}
GameplayTagContainer
{
"gameplayTags": [
{
"tagName": "ParentTagA.Middle.LeafA"
},
{
"tagName": "ParentTagB.Middle.LeafC"
}
]
}
MyClass
[System.Serializable]
public class MyClass
{
public GameplayTag tag;
public GameplayTagContainer tagContainer;
}
MyClass to Json
{
"tag":
{
"tagName": "ParentTagA.Middle.LeafB"
},
"tagContainer":
{
"gameplayTags": [
{
"tagName": "ParentTagA.Middle.LeafA"
},
{
"tagName": "ParentTagB.Middle.LeafC"
}
]
}
}
Example usage
// serialize
MyClass myInstance = CreateInstance();
string JsonString = GameplayTagJsonSettings.Serialize(myInstance);
// deserialize
MyClass deserializedInstance = GameplayTagJsonSettings.Deserialize<MyClass>(jsonString);
Or the user can setup the serializer settings by themself
JsonSerializerSettings settings = new Newtonsoft.Json.JsonSerializerSettings
{
Converters = new Newtonsoft.Json.JsonConverter[]
{
new GameplayTagJsonConverter(),
new GameplayTagContainerJsonConverter()
}
};
GameplayTag is a good tool used in Unreal, and I'm glade that someone can implement it in Unity.
However, the fix makes this pakcage has a dependency to Newtonsoft.Json.
I only added the converters to my local project, but as Newtonsoft.Json is a built-in package of Unity, adding the dependency should be ok...?