﻿using System.Collections;
using System.Collections.Generic;
using System;
using UnityEngine;
using UnityEditor;

[CustomPropertyDrawer(typeof(VariableToggle))]
public class VariableToggleDrawer : PropertyDrawer {

	public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) {
		if (!HideVariable (property)) {
			EditorGUI.PropertyField (position, property, label, true);
		}
	}

	public override float GetPropertyHeight (SerializedProperty property, GUIContent label) {
		if (HideVariable (property)) {
			return 0;
		} else {
			return base.GetPropertyHeight (property, label);
		}
	}

	private bool HideVariable (SerializedProperty property) {
		VariableToggle toggle = attribute as VariableToggle;
		SerializedProperty varToCheck = property.serializedObject.FindProperty (toggle.variableName);

		if (varToCheck == null) {
			Debug.Log (toggle.variableName);
			return false;
		}

		if (toggle.hideByBool)
			return varToCheck.boolValue == toggle.hideBool;
		else if (toggle.hideByInt)
			return varToCheck.intValue < toggle.hideInt;
		else
			return true;


	}
}
