//============= Copyright (c) Ludic GmbH, All rights reserved. ==============
//
// Purpose: Part of the My Behaviour Tree Code
//
//=============================================================================

using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

namespace MyBT {
#if UNITY_EDITOR
    using UnityEditor;
    [CustomEditor(typeof(TaskController))]
    public class SingleTonTaskControllerInspector : Editor {
        public void OnEnable() {
            SingletonTaskController singletonTaskController = (SingletonTaskController)target;
            Debug.Log($"Destorying SingletonTaskController, its not needed anymore {singletonTaskController.gameObject.GetComponents<Component>()}");
            //DestroyImmediate(singletonTaskController.gameObject);
        }
    }
#endif

    // remembers the last active TaskController, so a task can access it directly without a reference to the TaskController
    [System.Serializable, ExecuteInEditMode]
    public class SingletonTaskController : MonoBehaviour {

        public void OnEnable() {
            DestroyImmediate(this.gameObject);
        }

        //static SingletonTaskController _instance = null;
        //public static SingletonTaskController Instance {
        //    get {
        //        //if (_instance != null) {
        //        //    return _instance;
        //        //}
        //        if (_instance == null) {
        //            _instance = Resources.FindObjectsOfTypeAll<SingletonTaskController>().FirstOrDefault();
        //            if (_instance == null) {
        //                _instance = new GameObject("TaskController", typeof(SingletonTaskController)).GetComponent<SingletonTaskController>();
        //            }
        //        }
        //        return _instance;
        //    }
        //}

        //[SerializeField]
        //public TaskController _current;
        //public TaskController current {
        //    set {
        //        // if (value != null) {
        //        //     Debug.Log($"TaskController.current: Set {value.GetInstanceID()}");
        //        // }
        //        _current = value;
        //    }
        //    get {
        //        return _current;
        //    }
        //}
        //public List<TaskController> history = new List<TaskController>();

        //public bool taskHasChanges = false;

        ////[SerializeField]
        //public ActionNode currentNode;
        ////[SerializeField]
        //public ActionNodeRuntimeData currentNodeRuntimeData;

        //public int currentIndex;
    }
}