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

[ExecuteInEditMode]
public class DevTools : EditorWindow
{

    string input = "Input";

    [MenuItem("Battle Royale/Advanced/Dev Tools")]
    public static void Create()
    {
        GetWindow<DevTools>("Developer Tools");
    }

    void OnGUI()
    {
        input = GUILayout.TextField(input);

        if (GUILayout.Button("Find Object With Tag"))
        {
            try
            {
                Selection.activeGameObject = GameObject.FindGameObjectWithTag(input);
                Debug.Log(Selection.activeGameObject ? "Found object with name " + Selection.activeGameObject.name + "!" : "No object with tag " + input + " found.");
            }
            catch (Exception e)
            {
                Debug.LogException(e);
            }

        }

        if (GUILayout.Button("Destory Objects with Tag"))
        {
            GameObject[] _selections;

            try
            {
                _selections = GameObject.FindGameObjectsWithTag(input);

                foreach (GameObject _selection in _selections)
                    Debug.Log(Selection.activeGameObject ? "Found object with name " + Selection.activeGameObject.name + "!" : "No object with tag " + input + " found.");
            }
            catch (Exception e)
            {
                Debug.LogException(e);
            }
        }
    }
}