What I would like to do is to show certain variables on an enum selection. This works if Recipe.cs is attached to an object, but not if you make an array of those objects within RecipeManager.cs. Can this work at all? If so, how? If not, why? Thank you!
RecipeEditor:
using UnityEngine;
using UnityEditor;
[CustomEditor(typeof(Recipe))]
publicclassRecipeEditor:Editor{
publicSerializedProperty
recipeType_prop,
addWhipCream_prop,
addHotFudge_prop,
addCroutons_prop,
addBacon_prop,
addSeaSalt_prop,
servingDish_prop;
voidOnEnable(){
//Setupthe SerializedProperties
recipeType_prop=serializedObject.FindProperty("recipeType");
addWhipCream_prop=serializedObject.FindProperty("addWhipCream");
addHotFudge_prop=serializedObject.FindProperty("addHotFudge");
addCroutons_prop=serializedObject.FindProperty("addCroutons");
addBacon_prop=serializedObject.FindProperty("addBacon");
addSeaSalt_prop=serializedObject.FindProperty("addSeaSalt");
servingDish_prop=serializedObject.FindProperty("servingDish");
}
publicoverridevoidOnInspectorGUI(){
serializedObject.Update();
EditorGUILayout.PropertyField(recipeType_prop);
Recipe.RecipeTyperType=(Recipe.RecipeType)recipeType_prop.intValue;
switch(rType){
caseRecipe.RecipeType.Dessert:
EditorGUILayout.PropertyField(addWhipCream_prop);
EditorGUILayout.PropertyField(addHotFudge_prop);
EditorGUILayout.PropertyField(addBacon_prop);
EditorGUILayout.PropertyField(addSeaSalt_prop);
break;
caseRecipe.RecipeType.MainCourse:
EditorGUILayout.PropertyField(addBacon_prop);
EditorGUILayout.PropertyField(addSeaSalt_prop);
break;
caseRecipe.RecipeType.Salad:
EditorGUILayout.PropertyField(addCroutons_prop);
EditorGUILayout.PropertyField(addBacon_prop);
EditorGUILayout.PropertyField(addSeaSalt_prop);
break;
}
EditorGUILayout.PropertyField(servingDish_prop);
serializedObject.ApplyModifiedProperties();
}
}
Recipe:
using UnityEngine;
using System.Collections;
//[System.Serializable]
public class Recipe : MonoBehaviour
{
public string name;
[System.Serializable]
public enum RecipeType { Dessert, Salad, MainCourse }
public RecipeType recipeType;
public bool addWhipCream;
public bool addHotFudge;
public bool addCroutons;
public bool addBacon;
public bool addSeaSalt;
[System.Serializable]
public enum ServingDish { Plate, SaladPlate, Bowl }
public ServingDish servingDish;
}
RecipeManager:
using UnityEngine;
using System.Collections;
public class RecipeManager : MonoBehaviour {
public string keyPrefix;
public Recipe[] recipes;
}