Assuming these two things:
- The asset exposes some API from which you can read the data you need
- Your "blocks" are saved as prefabs
Then you should be able to write an editor script to bake out the data into a format you can read at runtime without having to load the blocks.
Getting each block's path data
It looks like you can use PrefabUtility.LoadPrefabContents
to obtain the block data. This will give you the root GameObject
in the prefab, upon which you can use the normal Find
/GetComponent
methods to get to the bezier curve data.
If that doesn't work, you can use AssetDatabase.OpenAsset
and PrefabStage
to obtain your data.
Serializing the data
There's a couple of ways to do this. The easiest way is to save the data to a ScriptableObject
. Simply create a subclass of ScriptableObject
with serializable fields. At bake-time, create one of these assets, e.g. with the following code (from here):
T asset = ScriptableObject.CreateInstance<T> ();
string path = AssetDatabase.GetAssetPath (Selection.activeObject);
if (path == "")
{
path = "Assets";
}
else if (Path.GetExtension (path) != "")
{
path = path.Replace (Path.GetFileName (AssetDatabase.GetAssetPath (Selection.activeObject)), "");
}
string assetPathAndName = AssetDatabase.GenerateUniqueAssetPath (path + "/New " + typeof(T).ToString() + ".asset");
AssetDatabase.CreateAsset (asset, assetPathAndName);
AssetDatabase.SaveAssets ();
AssetDatabase.Refresh();
EditorUtility.FocusProjectWindow ();
Selection.activeObject = asset;
Then you can modify the data contained inside. Make sure to use EditorUtility.SetDirty
to mark it for saving after it's modified by your script.
At runtime, any objects which need that data can take a reference to that ScriptableObject
(through inspector, Resources.Load
or singleton pattern) and use the data accordingly.
Alternatively, if you don't like ScriptableObject
s, you can always roll your own serialization using any of the various libraries out there. You can save the resulting file as a TextAsset
and read it that way at runtime.
How do I start the bake?
To run this code, I'd use a MenuItem
. Alternatively, if you have a collection of these utilities, you can create your own EditorWindow
.