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

public class FbxImporter
{
    //[MenuItem("DEETools/Import FBX")]
    public static GameObject ImportFbx()
    {
        string path = EditorUtility.OpenFilePanel("Select the fbx file to import", "", "fbx");
        if (string.IsNullOrEmpty(path))
        {
            return null;
        }

        string fileName = Path.GetFileName(path);
        string destinationPath = "Assets/DEETools/Res/Models/" + fileName;

        if (!Directory.Exists("Assets/DEETools/Res/Models"))
        {
            Directory.CreateDirectory("Assets/DEETools/Res/Models");
        }
        //Ƿͬļżһ
        while (File.Exists(destinationPath))
        {
            destinationPath = "Assets/DEETools/Res/Models/" + Path.GetFileNameWithoutExtension(destinationPath) + "_1" + Path.GetExtension(fileName);
        }
        File.Copy(path, destinationPath, true);
        AssetDatabase.Refresh();
        AssetDatabase.SaveAssets();
        Debug.Log("FBX file has been successfully imported to: " + destinationPath);
        return AssetDatabase.LoadAssetAtPath<GameObject>(destinationPath);
    }
}
