Question by
jimjames · Aug 04, 2018 at 12:00 AM ·
listcustom editor
Custom Inspector List Reset
I have a custom editor script which finds the ground tiles in my hierarchy. Then through raycasting it finds each tiles that is beside the one getting the search done for. When found the script adds those found ground tiles to the ground tile it was searching for in side a list of a script that is attached to each ground tile. Problem is when I press play the lists of all the ground tiles get reset. How do I go about making them stay? I searched and read I have to serialize them but do not know how to go about doing this. Here is a simple version of my code:
The Custom Inspector Script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
public class InspectorTileNieghboursGenerator
{
[MenuItem("My Comands/Grid Editor/Generate New Neighbours")]
private static void GenerateNewNeighbours()
{
List<GameObject> tiles = new List<GameObject>();
foreach (GameObject go in Resources.FindObjectsOfTypeAll(typeof(GameObject)) as GameObject[])
{
if (PrefabUtility.GetPrefabType(go) == PrefabType.Prefab || PrefabUtility.GetPrefabType(go) == PrefabType.ModelPrefab)
continue;
if (go.tag == "Ground Tiles")
{
tiles.Add(go);
go.SetActive(true);
}
}
//this code is broken down for ease of reader
for (int i = 0; i < tiles.Count; i++)
{
Grid tempReff = tiles[i].GetComponent<Grid>();
tempReff.gridNieghbours.Clear(); //this part wont save when i press play
if (somethingHappens)
{
tempReff.gridNieghbours.Add(GameObject) //this part wont save when i press play
}
}
}
}
This is the code for the Ground Tiles with the List:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Grid : MonoBehaviour
{
public List<GameObject> gridNieghbours;
}
Thanks: James
Comment