Hello everyone,
generally, I would like to create ChangeCheck (BeginChangeCheck, EndChangeCheck) for only one property. Ok but I will you show what I have and I want.
It is my class:
[Serializable]
public class Enemy
{
public string Name;
public Sprite Icon;
public List<CharacterAttribute> Attributes;
}
and my a MonoBehaviour class:
public class EnemyMap : MonoBehaviour
{
public Enemy Enemy;
public string Something;
}
Now is everything is ok because I see all my properties in the inspector
But the problem is when I try to create a “trigger” for only one property.
[CustomEditor(typeof(EnemyMap))]
public class EnemyMapEditor : Editor
{
SerializedProperty icon;
EnemyMap currentTarget;
private void OnEnable()
{
icon = serializedObject.FindProperty("Enemy.Icon");
currentTarget = (EnemyMap)target;
}
public override void OnInspectorGUI()
{
EditorGUI.BeginChangeCheck();
EditorGUILayout.PropertyField(icon);
if (EditorGUI.EndChangeCheck())
{
currentTarget.Enemy.Icon = (Sprite)icon.objectReferenceValue;
currentTarget.GetComponent<SpriteRenderer>().sprite = (Sprite)icon.objectReferenceValue;
}
}
}
and when I see into the inspector, I see:
So, what should I do to make other properties? Should I create properties separately? I would like to create the change rule for only one property but other properties should make automatically.