Hello everyone, I’ve been looking around for info on editor scripts / menu items, but I just have not come across the information I need to get this done.
What I’m trying to do:
I would like to be able to feed a editor script prefabs and transform locations (the transforms already exist in the game scene as empty game objects), and then have the script position the elements of the prefabs based on the transform data (and of course save the data).
From what I’ve read, the prefabs can be loaded and I’m fine with adjusting the prefabs according to the transform data once they are created. But as far as feeding the transform locations into an array, I have no solution for that, and I’m still confused on exactly what I would need to make serializeable so that everything isn’t lost when the game is played.
If anyone would point me in the right direction, I would appreciate it.
You want to load prefabs to transform locations?
try something like this:
(note i havent tested this)
public Transform[] transformArray;
That creates an array that can hold a collection of the type - transform. Then in the inspector, place your transforms into it. ‘Lists’ can also be used, you’ll find them both in the docs.
Then when you load a prefab ( feed it some element of the array
e.g.
Instantiate is what you use to load a prefab from script, if you use resources.load to find an object via script, you need to have your prefabs in a folder titled ‘Resources’
so your project folder would look like this:
ProjectFolder > Assets > Resources.
The for loop just iterates through the length of the array. (This may not be the desired functionality, but you should be able to get it from this
for(int i = 0; i < transformArray.length; i++){
GameObject object = Instantiate(Resources.Load("object"), transformArray*, Quaternion.identity) as GameObject;*
}
Hope that helps, if not let me know.
EDIT:
From your comment, I thought i’d post it here so we can get this solved asap.
From experience only in arrays (which is limited) - You will lose the inspector functionality that you would have as public.
Solution:
Try creating a public array, and then a second static array, and having the second = the first.
E.g.
-
public Transform firstArray;*
-
public static Transform secondArray;*
-
void Start(){*
-
secondArray = firstArray;*
-
for (int i = 0; i < secondArray.Length; i++) {*
_ GameObject newObject = Instantiate(Resources.Load(“Cube”), secondArray*.position, Quaternion.identity) as GameObject;*_
* }*
* }*