How do you save variables pulled in from a custom inspector?

I have a custom inspector script for an Ability class that just shows and hides variables that my groupmates can edit in a more intuitive way than the default inspector allows. How do I get the inspector to save the data so that it doesn’t get wiped on play or closing out the current scene? The script is question is below.

using UnityEngine;
using UnityEditor;
using System;
using System.Collections;
//using System.Collections.Generic;

[CustomEditor(typeof(AbilityManager))]
public class AbilityInspector : Editor {

	AbilityManager targetAbilities;
	
	//IList<Ability> abilityHousing;
	//Ability[] abilitahs;
	int abilityCount;
	
	void OnEnable() {
		targetAbilities = target as AbilityManager;

        // If the AbilityManager hasn't been used yet, we will give it a 
        // starting Ability to work with.
        if(targetAbilities.abilities == null) {
		    targetAbilities.abilities = new Ability[1];
            targetAbilities.abilities[0] = new Ability();
        }
		
		abilityCount = targetAbilities.abilities.Length;
		
		// We need to populate our abilityHousing with all of the data
		// in the current script before continuing.
		/*for(int i=0; i < abilityCount; i++) {
			abilityHousing.Add(targetAbilities.abilities*);*

_ }*/_

  • }*

  • public override void OnInspectorGUI ()*

  • {*

  •  GUI.changed = false;*
    
  •  // This section allows us to add abilities to the Manager*
    
  •  if(GUILayout.Button("Add Ability", GUILayout.Width(255))) {*
    
  •  	// Create a new temporary array with the new number of cells*
    
  •  	Ability[] temp = new Ability[++abilityCount];*
    
  •  	// Copy the old array into temp and add the new item*
    
  •  	Array.Copy(targetAbilities.abilities, temp, abilityCount-1);*
    
  •  	temp[abilityCount-1] = new Ability();*
    
  •  	// Set the abilities array in targetAbilities*
    
  •  	targetAbilities.abilities = temp;*
    
  •  }*
    
  •  if(targetAbilities.abilities[0] != null) {*
    
  •  	for (int i = 0; i < abilityCount; i++) {*
    
  •  		EditorGUILayout.Separator();*
    
  •  		// show abilities logic here*
    
  •  		GUILayout.BeginVertical();*
    
  •  		// Name*
    
  •  		GUILayout.BeginHorizontal();*
    
  •  		GUILayout.Label("Name");*
    

targetAbilities.abilities_.name = EditorGUILayout.TextField(targetAbilities.abilities*.name, GUILayout.Width(150));
GUILayout.EndHorizontal();*_

* // Cast Time*
* GUILayout.BeginHorizontal();*
* GUILayout.Label(“Cast Time”);*
targetAbilities.abilities_.castTime = EditorGUILayout.FloatField(targetAbilities.abilities*.castTime, GUILayout.Width(150));
GUILayout.EndHorizontal();*_

* // Cooldown Length*
* GUILayout.BeginHorizontal();*
* GUILayout.Label(“Cooldown Time”);*
targetAbilities.abilities_.cooldownLength = EditorGUILayout.FloatField(targetAbilities.abilities*.cooldownLength, GUILayout.Width(150));
GUILayout.EndHorizontal();*_

* // Here we handle all damage-related variables*
* GUILayout.BeginHorizontal();*
* GUILayout.Label(“Does Damage”);*
targetAbilities.abilities_.canDamage = EditorGUILayout.Toggle(targetAbilities.abilities*.canDamage, GUILayout.Width(150));
GUILayout.EndHorizontal();*_

_ if (targetAbilities.abilities*.canDamage) {
GUILayout.BeginHorizontal();
GUILayout.Label(“Damage Amount”);
targetAbilities.abilities.damageAmount = EditorGUILayout.IntField(targetAbilities.abilities.damageAmount, GUILayout.Width(150));
GUILayout.EndHorizontal();
}*_

* // Here we handle whether or not the ability spawns something*
* GUILayout.BeginHorizontal();*
* GUILayout.Label(“Does Spawn”);*
targetAbilities.abilities_.canSpawn = EditorGUILayout.Toggle(targetAbilities.abilities*.canSpawn, GUILayout.Width(150));
GUILayout.EndHorizontal();*_

_ if (targetAbilities.abilities*.canSpawn) {
// Spawn Object*

* GUILayout.BeginHorizontal();
GUILayout.Label(“Spawn Object”);
targetAbilities.abilities.spawnObject = EditorGUILayout.ObjectField(targetAbilities.abilities.spawnObject, typeof(GameObject), false, GUILayout.Width(150)) as GameObject;
GUILayout.EndHorizontal();
}*_

* if(GUILayout.Button(“Remove Ability”, GUILayout.Width(255))) {*
* // TODO: delete abilities*
* }*

* GUILayout.EndVertical();*
* }*
* }*

* if(GUI.changed) {*
* EditorUtility.SetDirty(targetAbilities);*
* }*
* //base.OnInspectorGUI ();*
* }*
}

http://unity3d.com/support/documentation/ScriptReference/EditorPrefs.html

this also might help you

As you make changes to the fields in the inspector, and assign new values to the fields of your target object, Unity detects that you’re changing the object and flags it as ‘dirty’ so that it will be written out to disk the next time you save the scene or project. This detection is limited: it only picks up direct assignment to public properties. If you’re changing the target object through properties or through calling methods on it, you may need to call EditorUtility.SetDirty yourself.