I tried almost everything; SetDirty, AssetDatabase.SaveAsset, AssetDatabase.Refresh, serializedObject.Update, serializedObject.ApplyModifiedProperties.
I added a fields for saving dictionary.
Thanks for help!
Can you share your code?
1 Like
Here’s the code:
using System;
using System.Collections.Generic;
using UnityEditor;
using UnityEditor.AnimatedValues;
using UnityEngine;
[CustomEditor(typeof(Seed))]
public class SeedEditor : Editor
{
AnimBool animBool0;
float[] fertRate0 = new float[Enum.GetValues(typeof(Climate)).Length];
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
Seed seed = (Seed)target;
EditorUtility.SetDirty(seed);
EditorGUILayout.Space();
EditorGUILayout.LabelField("Fertility By Climate");
animBool0.target = EditorGUILayout.ToggleLeft("Show",animBool0.target);
if (EditorGUILayout.BeginFadeGroup(animBool0.faded))
{
bool overwrite = GUILayout.Button("Overwrite data");
if(overwrite) seed.fertilityByClimate.Clear();
EditorGUI.indentLevel++;
for (int i = 0; i < Enum.GetValues(typeof(Climate)).Length; i++)
{
Climate climate = (Climate)i;
string climateName = climate.ToString();
fertRate0[i] = EditorGUILayout.FloatField(climateName, fertRate0[i]);
fertRate0[i] = Mathf.Clamp(fertRate0[i], 0, 1);
if(overwrite) seed.fertilityByClimate.Add(climate, fertRate0[i]);
}
EditorGUILayout.Space();
EditorGUILayout.LabelField("Current Values");
for(int i = 0; i < Enum.GetValues(typeof(Climate)).Length;i++)
{
Climate climate = (Climate)i;
string climatename = climate.ToString();
}
if (overwrite)
{
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
}
EditorGUI.indentLevel--;
}
EditorGUILayout.EndFadeGroup();
if (GUILayout.Button("Return fertility rates."))
{
seed.ReturnClimateValues();
}
}
void OnEnable()
{
animBool0 = new AnimBool(true);
animBool0.valueChanged.AddListener(Repaint);
}
}