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

namespace ArborEditor.BehaviourTree
{
	using Arbor;
	using Arbor.BehaviourTree;

	public class BehaviourTreeInternalInspector : Editor
	{
		private static readonly GUIContent _NameContent = new GUIContent( "Name" );

		BehaviourTreeInternal _BehaviourTree;

		[System.Reflection.Obfuscation(Exclude = true)]
		void OnEnable()
		{
			_BehaviourTree = target as BehaviourTreeInternal;
		}

		public override void OnInspectorGUI()
		{
			serializedObject.Update ();

			EditorGUILayout.PropertyField( serializedObject.FindProperty ("graphName"),_NameContent );
			EditorGUILayout.PropertyField( serializedObject.FindProperty ("playOnStart") );
			EditorGUILayout.PropertyField( serializedObject.FindProperty ("restartOnFinish") );

			EditorGUILayout.PropertyField( serializedObject.FindProperty("updateSettings") );
			EditorGUILayout.PropertyField( serializedObject.FindProperty("executionSettings") );

			serializedObject.ApplyModifiedProperties();

			if( GUILayout.Button ( "Open Editor" ) )
			{
				ArborEditorWindow.Open(_BehaviourTree);
			}
		}

		[System.Reflection.Obfuscation(Exclude = true)]
		void OnDestroy()
		{
			if (!target && (object)_BehaviourTree != null && !Application.isPlaying )
			{
				_BehaviourTree.DestroySubComponents();
			}
		}
	}		
}