Okay straight to the point.
I need to be able to see and save a List<List> in the inspector/editor
I need to do this because I need a 2 dimensional dynamic array, and the tool I wrote for the Editor saves the values of a certain object in the prefab of that object,
some visual help:
this is the object I need to save the List<List> to:
public class Pather : MonoBehaviour
{
Transform car;
public List<List<Transform>> roads = new List<List<Transform>>();
public static int usingRoad = 0;
Transform target;
public int PATHLENGTH = 999;
public bool move = true;
public int speed= 20;
public Vector3 heightDifference = new Vector3(0,5,0);
enum RoadSide{Out,Inner}
RoadSide roadSide = RoadSide.Inner;
Vector3 finalPosObj;
void Start()
{
if(roads.Count > Pather.usingRoad)
{
target = roads[Pather.usingRoad][0];
transform.position = target.position-heightDifference;
}
else
{
throw new UnityException("No Begin Path found (Empty array in Car Inspector?)");
}
}
}
And I do this from the editorwindow with this: //note this is not the whole code
public class CarPath : EditorWindow
{
[HideInInspector]
static public int currentPathNumber = 0;
[HideInInspector]
static public Transform car;
[HideInInspector]
static public bool carSelected = false;
[HideInInspector]
static public Pather p;
[HideInInspector]
List<Transform> road = new List<Transform>();
[MenuItem ("Window/CarPath")]
static void Init ()
{
CarPath window = (CarPath)EditorWindow.GetWindow (typeof (CarPath));
}
void AddToPatherRTycoon(Transform t)
{
if(t.tag != "Bend2x90" t.tag != "Bend3x90")
{
RaycastHit hit0;
if(Physics.Raycast(t.position,Vector3.forward,out hit0,t.collider.bounds.size.x/2+1))
{
if(GUI.Button(new Rect(20,0,20,20),"F"))
{
while(CarPath.p.roads.Count < Pather.usingRoad+1)
{
CarPath.p.roads.Add(new List<Transform>());
}
if(CarPath.p.roads[Pather.usingRoad].Count > 0)
{
SetTurn(CarPath.p.roads[Pather.usingRoad][CarPath.p.roads[Pather.usingRoad].Count-1],t,hit0.transform);
}
CarPath.p.roads[Pather.usingRoad].Add(t); //<----------------- see this
Selection.activeTransform = car;
EditorApplication.ExecuteMenuItem("GameObject/Apply Changes To Prefab"); //<----------------- see this (this won't work because the List<List<Transform>> is not showing in the inspector thus it won't save it to the current prefab, (all changes are lost when I press Play))
Selection.activeTransform = hit0.transform;
}
}
}
}
}
note: EditorApplication.ExecuteMenuItem(“GameObject/Apply Changes To Prefab”); DOES work with the other showable values… so if I edit a integer with the function and use this… it will get saved and stay when I press Play
…
So can anyone help me get this to work?..
Basically I figured out… If I can manually add a List to the List<List> in the inspector and then edit loose Transforms in for example List[0][×] it will get saved and stay that way…