Есть класс и расширение инспектора для него:
Синтаксис:
Используется csharp
using UnityEngine;
using System.Collections;
public class myClass : MonoBehaviour
{
public int test1 = 1;
public int test2 = 1;
public void testVoid()
{
test2 = 5;
}
}
using System.Collections;
public class myClass : MonoBehaviour
{
public int test1 = 1;
public int test2 = 1;
public void testVoid()
{
test2 = 5;
}
}
Синтаксис:
Используется csharp
using UnityEngine;
using System.Collections;
using UnityEditor;
[CustomEditor(typeof(myClass))]
public class myClass_Editor : Editor
{
myClass obj = null;
SerializedProperty test1Property;
public void OnEnable()
{
obj = (myClass)target;
test1Property = serializedObject.FindProperty("test1");
}
public override void OnInspectorGUI()
{
serializedObject.Update();
if (GUILayout.Button("Set"))
{
test1Property.intValue = 5;
obj.testVoid();
}
serializedObject.ApplyModifiedProperties();
}
}
using System.Collections;
using UnityEditor;
[CustomEditor(typeof(myClass))]
public class myClass_Editor : Editor
{
myClass obj = null;
SerializedProperty test1Property;
public void OnEnable()
{
obj = (myClass)target;
test1Property = serializedObject.FindProperty("test1");
}
public override void OnInspectorGUI()
{
serializedObject.Update();
if (GUILayout.Button("Set"))
{
test1Property.intValue = 5;
obj.testVoid();
}
serializedObject.ApplyModifiedProperties();
}
}
После нажатия на кнопку "Set" - переменная test1 будет равна 5, а test2 останется равна 1.
Почему? Что сделать, чтобы test2 тоже сохранилась?