﻿#if UNITY_EDITOR
using UnityEditor;
using UnityEngine;

public class DopeMenuItem : MonoBehaviour
{
    private static void CreateCustomGameObject(MenuCommand menuCommand, string name)
    {
        GameObject gameObject = null;
        string[] assets = AssetDatabase.FindAssets(name);

        if (assets.Length != 0)
        {
            string path = AssetDatabase.GUIDToAssetPath(assets[0]);
            gameObject = PrefabUtility.InstantiateAttachedAsset(AssetDatabase.LoadAssetAtPath(path, typeof(GameObject))) as GameObject;
            gameObject.name = name;
            Debug.Log($"{name} created on scene");
        }
        else
        {
            gameObject = new GameObject("Empty Game Object (See Console!)");
            Debug.LogError("Something went wrong!");
            Debug.LogWarning("Did you renamed or deleted original prefab files?");
        }
        
        GameObjectUtility.SetParentAndAlign(gameObject, menuCommand.context as GameObject);
        Undo.RegisterCreatedObjectUndo(gameObject, "Create " + gameObject.name);
        Selection.activeObject = gameObject;
    }

    [MenuItem("GameObject/DopeSFX/Skinned Mesh Renderer", false, 10)]
    static void CreateCustomGameObjectMESH(MenuCommand menuCommand)
    {
        CreateCustomGameObject(menuCommand, "SFX Skinned Mesh Renderer");
    }

    [MenuItem("GameObject/DopeSFX/Particle System", false, 11)]
    static void CreateCustomGameObjectPS(MenuCommand menuCommand)
    {
        CreateCustomGameObject(menuCommand, "SFX Particle System");
    }

    [MenuItem("GameObject/DopeSFX/Depth Light", false, 12)]
    static void CreateCustomGameObjectDL(MenuCommand menuCommand)
    {
        CreateCustomGameObject(menuCommand, "Depth Enabler Light");
    }
}
//Refactored by bkp lol
#endif