I’ve made CustomEditor for one of my classes and it works great except of one little detail: when I edit properties of prefab’s instance, those are reverted to prefab’s values at the start. But I can modify properties of other classes that don’t have CustomEditor with help of inspector and they behave just as expected. What am I missing?
Here is some code for those who will ask for it:
using UnityEngine;
using System.Collections;
using UnityEditor;
[CustomEditor(typeof(Controller))]
public class ControllerEditorScript : Editor
{
bool info = false;
bool gameSettings = false;
Controller thatController;
void Awake()
{
thatController = (Controller)target;
specElemSize = thatController.goal_specialElementsList.Count;
packagesSize = thatController.goal_packagesList.Count;
}
public override void OnInspectorGUI()
{
thatController = (Controller)target;
#region Info
info = EditorGUILayout.Foldout(info, "Info");
if(info)
{
thatController.score = EditorGUILayout.IntField("Current Score:", thatController.score);
}
EditorGUILayout.Space();
#endregion
#region Settings
gameSettings = EditorGUILayout.Foldout(gameSettings, "Game Settings");
if(gameSettings)
{
thatController.mode = EditorGUILayout.TextField("Current mode", thatController.mode);
thatController.spawnCounter = EditorGUILayout.IntField("Spawning at once:", thatController.spawnCounter);
thatController.delayTime = EditorGUILayout.FloatField("Delay between spawns:", thatController.delayTime);
thatController.startSpawn = EditorGUILayout.IntField("Spawning at start:", thatController.startSpawn);
thatController.AmountCap = EditorGUILayout.IntField("Max food:", thatController.AmountCap);
thatController.maxDistance = EditorGUILayout.FloatField("Con. distance:", thatController.maxDistance);
thatController.charge = EditorGUILayout.FloatField("Charge :", thatController.charge);
thatController.ExplosionForce = EditorGUILayout.FloatField("Explosion Force:", thatController.ExplosionForce);
thatController.helper = EditorGUILayout.ObjectField("Helper :", thatController.helper, typeof(GameObject), true) as GameObject;
}
EditorGUILayout.Space();
#endregion
}
}