Currently I have a script that generates prefabs by code and I'm wondering if I could show a certain "seed" of that map without actually running the game. The reason why is that I often want to tweak things, and when I run the game and alter settings for objects like lights they get reset when I stop running the game and perhaps have some kind of button where I can reset the seed and see another generation of the map.
1 Answer
\$\begingroup\$
\$\endgroup\$
You could write your own CustomEditor script for your map generation, where you show a button that will trigger the map generation with the new settings and instantiate it.
A small example:
using UnityEngine;
using System.Collections;
[CustomEditor(typeof(MyMapGenerator))]
public class MyMapGeneratorEditor : Editor
{
// cache the current map preview
Transform current;
public override void OnInspectorGUI()
{
// target is a variable that is available to scripts that derive from Editor
// and holds the Object that is being inspected
MyMapGenerator gen = (MyMapGenerator)target;
DrawDefaultInspector();
if(GUILayout.Button("Generate and preview"))
{
// Generate() should create and return the prefab
var prefab = gen.Generate();
// delete the cached preview if there is one
if(current != null)
DestroyImmediate(current);
// instantiate a new preview and cache it
current = Instantiate(prefab);
}
}
}
Please note that I have not tested this script, so there may be errors.
You can find more Information on Custom Inspectors from Unity here