#define UNITY_5 #if Unity_4_0 using UnityEditor; using UnityEngine; using System.Collections; public class PackageIcons { // This code is only used to package icons into an asset to be included in the distribution // It only runs under unity 4.X, Tha AssetBundle code has changed under unity 5.X // We build p4connect in Unity 4.X so it is portable to either 4.X or 5.X [MenuItem("Assets/PackageIcons")] static void DoPackageIcons() { Debug.Log("running 4.X asset packager"); // Build the resource file from the active selection. string [] assetNames = new string[Selection.objects.Length]; for (int i = 0; i < Selection.objects.Length; ++i) { assetNames[i] = System.IO.Path.GetFileName(Selection.objects[i].name); } BuildPipeline.BuildAssetBundleExplicitAssetNames(Selection.objects, assetNames, "Assets/P4Connect/Editor/Icons.pack", BuildAssetBundleOptions.UncompressedAssetBundle); } } #endif #if UNITY_5 using UnityEditor; using UnityEngine; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; using P4Connect; using Perforce.P4; public class PackageIcons { // This code is only used to package icons into an asset to be included in the distribution // It only runs under unity 4.X, Tha AssetBundle code has changed under unity 5.X // We build p4connect in Unity 4.X so it is portable to either 4.X or 5.X [MenuItem("Assets/CopyIcons")] static void CopyIconsIntoAssets() { string fromDir = Path.GetFullPath(Main.RootPath + "../src/Icons/"); string toDir = Path.GetFullPath(Main.RootPath + "Assets/Icons/"); //Debug.Log("fromDir: " + fromDir); //Debug.Log("toDir: " + toDir); Directory.CreateDirectory(toDir); var files = Directory.GetFiles(fromDir); foreach (var file in files) { string fileName = Path.GetFileName(file); if (fileName != null) { System.IO.File.Copy(file, Path.Combine(toDir, fileName)); } } } [MenuItem("Assets/PackageIcons")] static void DoPackageIcons() { // Build the resource file from the images in the p4connect/main/src/Icons directory Debug.Log("running 5.X asset packager"); IList names = new List(); IList objs = new List(); var srcdir = Path.GetFullPath(Main.RootPath + "Assets/Icons/"); Debug.Log("srcdir: " + srcdir); var files = Directory.GetFiles(srcdir); foreach (string f in files) { string assetPath = Utils.FullPathToAssetPath(f); var extension = Path.GetExtension(assetPath); if (string.Equals(extension, "jpg") || string.Equals(extension, "png")) { Debug.Log("processing: " + assetPath); AssetDatabase.ImportAsset(assetPath); //objs.Add(AssetDatabase.LoadAssetAtPath(assetPath)); names.Add(f); } else { Debug.Log("skipping non texture: " + f); } } var build = new AssetBundleBuild { assetBundleName = "P4Connect", assetNames = names.ToArray() }; AssetBundleBuild[] buildArray = new AssetBundleBuild[1]; buildArray[0] = build; BuildPipeline.BuildAssetBundles("Assets/P4Connect/myasset.pack", buildArray, BuildAssetBundleOptions.None, BuildTarget.StandaloneWindows); } [MenuItem("Assets/Get AssetBundle names")] static void GetNames() { var names = AssetDatabase.GetAllAssetBundleNames(); foreach(var name in names) Debug.Log("AssetBundle: " + name); } } #endif