タイトルでもう完結しておりますが・・・。
UnityPackageをWindowからポチポチ、カチャカチャっとで作成できる機能を実装致しました!
デモ
ソース
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
#if UNITY_EDITOR using System.IO; using UnityEngine; using UnityEditor; using System.Collections.Generic; using UnityEditorInternal; /// <summary> /// UnityPackage作成 /// https://docs.unity3d.com/ja/current/ScriptReference/ExportPackageOptions.html /// </summary> public static class UnityPackager { /// <summary> /// Create the specified outPath and targetPath. /// </summary> /// Pathに関してはUnityProjectFolderから計算。 /// <param name="targetPath">出力ターゲットFolderパス。Assets/ooooo</param> /// <param name="outputPath">出力先。xxxx/oooo</param> /// <param name="packageName">パッケージ名。xxxx.unitypackage</param> public static bool Create(string targetPath, string outputPath, string packageName) { if(!targetPath.StartsWith("Assets/")){ targetPath = "Assets/" + targetPath; } if(!packageName.EndsWith(".unitypackage")) { packageName += ".unitypackage"; } try{ AssetDatabase.ExportPackage(targetPath, outputPath + "/" + packageName, ExportPackageOptions.Recurse | ExportPackageOptions.IncludeDependencies); }catch{ return false; } return true; } } /// <summary> /// Unity packager window. /// </summary> public class UnityPackagerWindow : EditorWindow { /// <summary> /// Windowを開く /// </summary> [MenuItem ("Window/UnityPackager")] static void Open () { GetWindow<UnityPackagerWindow>(); } const int OneColumnHeight = 16; ReorderableList ro; Vector2 scrollPos = new Vector2(); UnityPackagerSetting setting; void OnEnable () { if(!System.IO.File.Exists(UnityPackagerSetting.createPath)) { UnityPackagerSetting.Create(); } setting = AssetDatabase.LoadAssetAtPath<UnityPackagerSetting>(UnityPackagerSetting.createPath); ro = new ReorderableList(new List<UnityPackagerSetting.Param>(), typeof(UnityPackagerSetting.Param)); ro.list = setting.list; ro.drawElementCallback = DrawElement; ro.elementHeight = 60; ro.drawHeaderCallback = rect => GUI.Label(rect, "Package List"); } /// <summary> /// 通常シンボルを表示. /// </summary> void DrawElement(Rect rect, int index, bool isActive, bool isFocused) { if(0 > index || ro.list.Count <= index) { return; } UnityPackagerSetting.Param current = ro.list[index] as UnityPackagerSetting.Param; if(null == current) { return; } float posY = rect.y + 5; GUI.color = Color.white; GUI.Label(rect, GUIContent.none,EditorStyles.helpBox); // TargetPath EditorGUI.LabelField(new Rect(rect.x + 10, posY, 80, OneColumnHeight), "Target Path"); current.targetPath = EditorGUI.TextField(new Rect(rect.x + 21 + 80, posY, rect.width - 110 - 30, OneColumnHeight), current.targetPath); GUIContent contentOpen = new GUIContent(EditorGUIUtility.FindTexture("project")); if (GUI.Button(new Rect(rect.x + 21 + 80 + rect.width - 100 - 30, posY, 20, 17), contentOpen, EditorStyles.label)) { EditorApplication.delayCall += () => { current.targetPath = FileUtil.GetProjectRelativePath(EditorUtility.OpenFolderPanel("Select Target Path.", "", "")); }; } // PackageName posY += OneColumnHeight; EditorGUI.LabelField(new Rect(rect.x + 10, posY, 80, OneColumnHeight), "Package Name"); current.packageName = EditorGUI.TextField(new Rect(rect.x + 21 + 80, posY, rect.width - 110, OneColumnHeight), current.packageName); // CreateButton posY += OneColumnHeight; if(GUI.Button(new Rect(rect.x + 10, posY, 50, OneColumnHeight), "Create")) { EditorApplication.delayCall += () => { bool ret = UnityPackager.Create(current.targetPath, setting.outputPath, current.packageName); string message = "Error:\n"; if(ret) { message = "Success"; }else{ message += current.packageName; } EditorUtility.DisplayDialog("Result", message, "OK"); Debug.Log("Message Info : " + message); }; } } /// <summary> /// Window全体の描画 /// </summary> void OnGUI () { // Space GUILayout.Space(10); // OutputPath EditorGUILayout.BeginHorizontal(EditorStyles.textArea); setting.outputPath = EditorGUILayout.TextField("Output Path",setting.outputPath); GUIContent contentOpen = new GUIContent(EditorGUIUtility.FindTexture("project")); if (GUILayout.Button(contentOpen, EditorStyles.label, GUILayout.Width(20), GUILayout.Height(17))) { EditorApplication.delayCall += () => { setting.outputPath = FileUtil.GetProjectRelativePath(EditorUtility.OpenFolderPanel("Select Output Path.", "", "")); }; } EditorGUILayout.EndHorizontal(); // Space GUILayout.Space(10); // List scrollPos = EditorGUILayout.BeginScrollView(scrollPos); ro.DoLayoutList(); EditorGUILayout.EndScrollView(); // AllCreate Button EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if(GUILayout.Button("All Create",GUILayout.Width(200))) { EditorApplication.delayCall += () => { string errorPackageNames = ""; for(int i = 0; i < setting.list.Count; i++){ if(!UnityPackager.Create(setting.list[i].targetPath, setting.outputPath, setting.list[i].packageName)){ errorPackageNames += setting.list[i].packageName + "\n"; } } string message = "Error:\n"; if(string.IsNullOrEmpty(errorPackageNames)) { message = "Success"; }else{ message += errorPackageNames; } EditorUtility.DisplayDialog("Result", message, "OK"); Debug.Log("Message Info : " + message); }; } GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); // Space GUILayout.Space(10); } } #endif |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
using UnityEngine; using System.Collections; using UnityEditor; using System.Collections.Generic; /// <summary> /// UnityPackagerの設定ファイル /// </summary> public class UnityPackagerSetting : ScriptableObject { /// <summary> /// 設定ファイル保存パス /// </summary> public const string createPath = "Assets/Editor/UnityPackagerSetting.asset"; /// <summary> /// 出力パス /// </summary> public string outputPath; /// <summary> /// 設定データ群 /// </summary> public List<Param> list = new List<Param>(); /// <summary> /// UnityPackger設定項目 /// </summary> [System.Serializable] public class Param{ /// <summary> /// パッケージ名 /// </summary> public string packageName; /// <summary> /// 対象パス /// </summary> public string targetPath; } /// <summary> /// ScriptableObject作成 /// </summary> public static void Create() { UnityPackagerSetting asset = CreateInstance<UnityPackagerSetting> (); AssetDatabase.CreateAsset (asset, createPath); AssetDatabase.Refresh (); } } |
GitHub
こちらもGitHubにアップしております!
是非ご活用下さい。
https://github.com/VENIEGAMES/UnityPackager-Unity
コメント