2
\$\begingroup\$

I am writing an editor tool that is supposed to generate prefab objects from a parsed TMX file.

Since this is a special case because I don't want to instantiate objects, but rather create them there are not much documentation on how to do this.

I have come up with a way that actually creates an .prefab file from a gameobject. But the problem is that when I do this, the gameobject itself is created and put into the hierarchy. I only want the .prefab asset file.

This is they way I am doing it now.

static void ConvertFile(string filepath) {
    // This function returns a "new GameObject()" with attached components
    // However, this function still puts the new game object in the scene & hierarchy
    // which is not what I want
    GameObject mapObject = mapLoader.fromFile (filepath);
    string filename = System.IO.Path.GetFileNameWithoutExtension (filepath);

    // Create prefab file from an object
    PrefabUtility.CreatePrefab ("Assets/" + filename + ".prefab", mapObject);
}

public GameObject fromFile(string filepath) {
    // Removed code that parses file for easy read
    GameObject gameObject = new GameObject ();
    return gameObject;
}
\$\endgroup\$

0

You must log in to answer this question.

Browse other questions tagged .