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

[CustomPropertyDrawer(typeof(BoolToButton))]
public class BoolToButtonDrawer : PropertyDrawer {

	public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) {

		#if UNITY_EDITOR_WIN
		Rect varLabel =  new Rect ((Screen.width/4f)*(96f/Screen.dpi), position.y, Screen.width/2f*(96f/Screen.dpi), position.height*2);
		#endif

		#if UNITY_EDITOR_OSX
		Rect varLabel =  new Rect ((Screen.width/4f)*(72f/Screen.dpi), position.y, Screen.width/2f*(72f/Screen.dpi), position.height*2);
		#endif

		BoolToButton btb = attribute as BoolToButton;

		if (btb.variableName != "") {
			SerializedProperty varToCheck = property.serializedObject.FindProperty (btb.variableName);
			if (btb.variableName == "makeLevel") {
				if (GUI.Button (varLabel, "Create New Level")) {
					varToCheck.boolValue = true;
				}
			}

			if (btb.variableName == "savePrefab") {
				if (GUI.Button (varLabel, "Save Level Prefab")) {
					varToCheck.boolValue = true;
				}
			}
		}


	}
		
	IEnumerator Switch (bool myBool) {
		myBool = true;
		yield return new WaitForSeconds (1f);
		myBool = false;
		yield return null;
	}
}
