- Home /
Execute a Runtime LevelGenerator in Edit-Mode
I created a simple LevelGenerator where I can insert a a Level-Definition as a JSON File and the Generator creates the level by instantiating the Prefabs and I can play the level. Like so
public GameObject CreateLevel(JSONObject levelDefinition)
{
...
return level;
}
But unfortunately I only can edit the Level via the JSON File and not in the Editor, because its only loaded at runtime.
Is there a way to execute my script with a specific parameter (the json file) in Editor-Mode and then rewrite the changes back to the file?
Answer by Bunny83 · Oct 07, 2017 at 10:21 AM
Well, it's possible, but you have to create the reverse as well. You have created custom code to create the level based on the json data. You would also need some custom code to do the reverse. However this might be more difficult than it sounds. It highly depends on what kind of information you actually store in your json file and if that information can actually be recovered from the gameobjects in the scene.
I know. I have to iterate over all objects and create or update the JSON-Object, but it is not much. $$anonymous$$ostly transform-position, rotation and some vars for my customscripts. Like that
{
"name": "Start A",
"unfreeze_on_load": true,
"startlevel": true,
"objects": [
{
...
},{
"prefabName": "planet_base_pingpong",
"options": {
"transform": {
"position": {"x": 0,"y": 12,"z": 0}
},
"movement": {
"type": "position",
"options": {
"start": {"x": -2.6},
"end": {"x": 2.6}
}
}
}
}
]
}
Your answer
Follow this Question
Related Questions
(Editor Scripting) Is it possible to generate MenuItems? 2 Answers
How to get an asset name to be prompted with auto-correct/intellisense in monodevelop 0 Answers
Can I get a callback when scripts have finished compiling? 3 Answers
How to resave generated meshes with Editor Scripts? 0 Answers
C#: Include Custom Editor features for a custom Classes while avoiding dependencies? 0 Answers