1. 程式人生 > 其它 >Unity 從網上下載Package程式碼匯入到專案中

Unity 從網上下載Package程式碼匯入到專案中

說明:使用程式碼從網上下載的unity Package格式的檔案,想一步到位,編寫程式碼把該格式的檔案直接匯入到當前專案中

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

*/
public class ExprotPackageWin :EditorWindow
{
    static EditorWindow window;
    //static Dictionary<string, string> dicFolderName = new Dictionary<string, string>();
    [MenuItem("***輔助功能***/匯入包")]
    public static void CreateFileFloder()
    {
        window = EditorWindow.GetWindow<ExprotPackageWin>();
        window.titleContent = new GUIContent("匯入包");
        window.maxSize = new Vector2(550, 350);
       // if (dicFolderName.Count <= 0)
       // {
          //  dicFolderName.Add("匯入包", "匯入包"); 
       // }
    }
    private void OnGUI()
    {
		//迴圈建立窗體的內容,
        //foreach (var item in dicFolderName)
        //{
         //   EditorGUILayout.BeginVertical();
         //   EditorGUILayout.TextField(item.Key, item.Value);
         //   EditorGUILayout.Space();
          //  EditorGUILayout.EndVertical();
       // }
        if (GUILayout.Button("匯入"))
        {
            ExportOrdinaryPck();
        }
    }
    public static void ExportOrdinaryPck()
    {     
	    // 1 需要匯入包的全路徑, 2 是否顯示再次確定匯入介面
		//該AssetDatabase下有相應的事件屬性,可參考使用
        AssetDatabase.ImportPackage(@"需要匯入包的全路徑", false);     
        AssetDatabase.SaveAssets();
        AssetDatabase.Refresh();
        EditorWindow.GetWindow<ExprotPackageWin>().Close();
    }
}