- Home /
Create an array of Vector3 from Editor script
I'm looking to generate an array of Vector3 using an Editor extension script, then use that generated array in RunTime. As it stands I can generate a array using an Editor script no problem, however as soon as that function completes the array is not "saved" for use in RunTime.
Editor Extension Script
[CustomEditor( typeof(GridTest) )]
public class GridTestEditor : Editor {
GridTest gd;
public int gridSize = 10;
// Use this for initialization
void OnEnable () {
gd = (GridTest)target;
}
// Update is called once per frame
override public void OnInspectorGUI() {
gridSize = EditorGUILayout.IntField(gridSize);
if(GUILayout.Button("Generate Grid")){
GenerateGrid();
}
}
void GenerateGrid(){
gd.gridData.Clear();
for(int x = 0;x < gridSize;x++){
for(int z = 0;z < gridSize;z++){
GridPoint gp = new GridPoint();
gp.position = new Vector3(x,0,z);
gd.gridData.Add(gp);
Debug.Log(gp.position);
}
}
}
}
Grid class and GridPoint Object
public class GridTest : MonoBehaviour {
public List<GridPoint> gridData = new List<GridPoint>();
// Use this for initialization
void Start () {
foreach(GridPoint gridPoint in gridData){
Debug.Log(gridPoint.position);
}
}
}
public class GridPoint : Object {
public Vector3 position;
}
On start up the GridPoint objects loose there assigned Vector3
Could anyone point me towards what I need to be doing in order to use this generated array?
Cheers, C.
Answer by Paulius-Liekis · Oct 01, 2012 at 12:00 PM
GridPoint has to be marker as serializable and you have to store it in Array, not List, IIRC.
Your answer
Follow this Question
Related Questions
How can I assign an Array of Vector3 while seeing and editing the values in the Scene? 0 Answers
Is there a way to remove array entries in the editor? 4 Answers
How do you emulate array/List Inspector behavior with an Editor window? 0 Answers
Is it possible to drag/drop/increment into editor array? 1 Answer
instantiate problem help? 1 Answer