//#define UNITY_5 //#define DEVELOPER namespace P4Connect { #if DEVELOPER #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 System; using UnityEditor; using UnityEngine; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; using P4Connect; using Perforce.P4; using Object = UnityEngine.Object; public class PackageIcons { private static string _p4ConnectBundle = "P4Connect"; private static string _iconAssetPath = Path.GetFullPath(Main.RootPath + "Assets/P4Connect/Editor"); private static string _sourceIconsPath = Path.GetFullPath(Main.RootPath + "../src/Icons/"); private static string _assetIconsPath = Path.GetFullPath(Main.RootPath + "Assets/Icons/"); // 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() { //Debug.Log("fromDir: " + _sourceIconsPath); //Debug.Log("toDir: " + _assetIconsPath); Directory.CreateDirectory(_assetIconsPath); var files = Directory.GetFiles(_sourceIconsPath); foreach (var file in files) { var filename = Path.GetFileName(file); var newfile = System.IO.Path.Combine(_assetIconsPath, filename); if (System.IO.File.Exists(newfile)) // Make sure I can overwrite the file. { System.IO.File.SetAttributes(newfile, FileAttributes.Normal); } System.IO.File.Copy(file, newfile, true); } } [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(); Debug.Log("srcdir: " + _assetIconsPath); var files = Directory.GetFiles(_assetIconsPath); foreach (string f in files) { string assetPath = Utils.FullPathToAssetPath(f); var textureName = Path.GetFileNameWithoutExtension(assetPath); var extension = Path.GetExtension(assetPath); if (string.Equals(extension, ".jpg", StringComparison.InvariantCultureIgnoreCase) || string.Equals(extension, ".png", StringComparison.InvariantCultureIgnoreCase)) { Debug.Log("processing: " + textureName); var importer = AssetImporter.GetAtPath(assetPath); importer.assetBundleName = _p4ConnectBundle; names.Add(assetPath); } else { Debug.Log("skipping non texture: " + f); } } var build = new AssetBundleBuild { assetBundleName = _p4ConnectBundle, assetNames = names.ToArray() }; BuildPipeline.BuildAssetBundles(_iconAssetPath, new[]{ build }, BuildAssetBundleOptions.UncompressedAssetBundle, BuildTarget.StandaloneWindows); } } #endif #endif // DEVELOPER }