public static bool UpdateBinaryBlueprint(BinaryBlueprint binaryBlueprint, Context[] allContexts, string[] allContextNames)
{
var blueprint = binaryBlueprint.Deserialize();
var needsUpdate = false;
var contextIndex = Array.IndexOf(allContextNames, blueprint.contextIdentifier);
if(contextIndex < 0) {
contextIndex = 0;
needsUpdate = true;
}
var context = allContexts[contextIndex];
blueprint.contextIdentifier = context.contextInfo.name;
foreach(var component in blueprint.components) {
var type = component.fullTypeName.ToType();
var index = Array.IndexOf(context.contextInfo.componentTypes, type);
if(index != component.index) {
Debug.Log(string.Format(
"Blueprint '{0}' has invalid or outdated component index for '{1}'. Index was {2} but should be {3}. This will be fixed now!",
blueprint.name, component.fullTypeName, component.index, index));
component.index = index;
needsUpdate = true;
}
}
if(needsUpdate) {
Debug.Log("Updating Blueprint '" + blueprint.name + "'");
binaryBlueprint.Serialize(blueprint);
}
return needsUpdate;
}