Export
Last updated
Was this helpful?
Was this helpful?
void HandleElementExport(Gum.DataTypes.ElementSave element)
{
StringBuilder stringBuilder = new StringBuilder();
foreach(var instance in element.Instances)
{
stringBuilder.AppendFormat("{0} {1} = new {0}();",
instance.BaseType, instance.Name);
}
stringBuilder.AppendLine();
// We'll just use the default state for this example:
foreach(var variable in element.DefaultState.Variables)
{
if(variable.Value != null && variable.SetsValue)
{
// You may want to process the Value. For example,
// if it's a float, the string representation of the
// value might be "1.23", but you may want to convert that to
// "1.23f"
// Similarly strings may need to be wrapped in quotes, and values like
// coordinate types may need to be qualified as enumerations or
// translated into whatever system the given engine uses.
string rightSideOfEquals = variable.Value.ToString();
stringBuilder.AppendFormat("{0} = {1};",
variable.Name, rightSideOfEquals);
}
}
string textToSave = stringBuilder.ToString();
// Now the textToSave would get saved to disk wherever you want it exported
}Sprite SpriteInstance1 = new Sprite();
Sprite SpriteInstance2 = new Sprite();
Text TextInstance1 = new Text();
SpriteInstance1.X = 3;
SpriteInstance1.Y = 4;
SpriteInstance2.Width = 10;
Text.X = 3;