- Home /
Wanted editor extension called only when changed
Hi, I am writing up an editor extension at the moment. I was wondering whether what I wrote will be called everyframe or only when the property got changed? If this got called Everyframe, can you help me change it to called only when property got changed?
THX in advance.
using UnityEngine;
using UnityEditor;
using System.Collections;
[CanEditMultipleObjects]
[CustomEditor(typeof(Unit))]
public class UnitEditor : Editor {
Unit thisUnit;
UNITCLASS currentClass;
void OnEnable ()
{
thisUnit = (Unit)target;
}
public override void OnInspectorGUI()
{
GUILayout.BeginHorizontal();
currentClass = (UNITCLASS)EditorGUILayout.EnumPopup("Class", currentClass );
GUILayout.EndHorizontal();
thisUnit.SetClass(currentClass);
}
}
Comment
Answer by sooncat · May 06, 2013 at 01:54 PM
I Think this may help
UNITCLASS _currentClass;
UNITCLASS currentClass;
{
set{
if(_currentClass != value)
{
_currentClass = value;
thisUnit.SetClass(_currentClass);
}
}
get{
return _currentClass;
}
}
...
public override void OnInspectorGUI()
{
GUILayout.BeginHorizontal();
_currentClass = (UNITCLASS)EditorGUILayout.ObjectField("UNITCLASS", _currentClass, typeof(UNITCLASS));
GUILayout.BeginHorizontal();
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613101633im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Hiding editor extension scripts 2 Answers
How do I get the default scene GUI for a CustomEditor for RectTransform? 1 Answer
Read method from c#/js script and display in a textbox? 0 Answers
Importing 4.6 Asset ruined my 5.0 project 0 Answers
GUI Editior Script not working in ( Unity 2019.x ) 0 Answers