public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            lineHeight = EditorGUIUtility.singleLineHeight;
            Rect mainPropertyRect = new Rect(position.x, position.y, position.width - previewPadding, lineHeight);

            EditorGUI.PropertyField(mainPropertyRect, property, label);

            VariableInt intVariableSO = null;

            if (property.objectReferenceValue != null)
            {
                intVariableSO = EditorUtils.GetTargetObjectOfProperty(property) as VariableInt;
            }

            if (intVariableSO == null)
            {
                property.isExpanded = false;
                return;
            }

            if (intVariableSO != null)
            {
                float previewX    = position.x + position.width - previewPadding;
                Rect  previewRect = new Rect(previewX, position.y, previewPadding, lineHeight);
                EditorGUI.LabelField(previewRect, intVariableSO.RuntimeValue.ToString());
            }
            var foldoutButtonRect = new Rect(position.x, position.y, EditorGUIUtility.labelWidth, EditorGUIUtility.singleLineHeight);
            var foldoutGuiContent = new GUIContent(property.displayName);

            property.isExpanded = EditorGUI.Foldout(foldoutButtonRect, property.isExpanded, foldoutGuiContent, true);


            // Foldout
            if (property.isExpanded)
            {
                Rect foldoutRect = new Rect(position.x + foldoutX, position.y + lineHeight, position.width, lineHeight);

                EditorGUI.indentLevel = 1;

                // runtime value
                EditorGUI.PrefixLabel(foldoutRect, new GUIContent("Runtime Value"));
                foldoutRect.x += foldoutRightX;
                EditorGUI.LabelField(foldoutRect, intVariableSO.RuntimeValue.ToString());

                // initial value
                foldoutRect.y += lineHeight;
                foldoutRect.x -= foldoutRightX;
                EditorGUI.PrefixLabel(foldoutRect, new GUIContent("Initial Value"));
                foldoutRect.x += foldoutRightX;
                intVariableSO.initialValue = EditorGUI.IntField(foldoutRect, intVariableSO.initialValue);

                // always positive
                foldoutRect.y += lineHeight;
                foldoutRect.x -= foldoutRightX;
                EditorGUI.PrefixLabel(foldoutRect, new GUIContent("Always Positive"));
                foldoutRect.x += foldoutRightX;
                intVariableSO.alwaysPositive = EditorGUI.Toggle(foldoutRect, intVariableSO.alwaysPositive);
            }
        }
Esempio n. 2
0
 public VariableIntListenerClass(VariableInt variable)
 {
     if (variable == null)
     {
         Debug.Log("variable is null");
         return;
     }
     this.variable              = variable;
     onVariableChanged          = new UnityEventInt();
     onVariableIncreased        = new UnityEventInt();
     onVariableChangedAboveZero = new UnityEventInt();
     onVariableZero             = new UnityEvent();
     Init();
 }
Esempio n. 3
0
 public VariableIntListenerClass(
     VariableInt variable,
     ref UnityEventInt onVariableChanged,
     ref UnityEventInt onVariableIncreased,
     ref UnityEventInt onVariableChangedAboveZero,
     ref UnityEvent onVariableZero)
 {
     if (variable == null)
     {
         Debug.Log("variable is null");
         return;
     }
     this.variable                   = variable;
     this.onVariableChanged          = onVariableChanged;
     this.onVariableIncreased        = onVariableIncreased;
     this.onVariableChangedAboveZero = onVariableChangedAboveZero;
     this.onVariableZero             = onVariableZero;
     Init();
 }
 public void SetVariableSO(VariableInt variableSo)
 {
     this.variableSO = variableSo;
     InitListener();
 }