//#define UNITY_5 //#define DEVELOPER using System; using System.Collections.Generic; using System.IO; using System.Linq; using UnityEditor; using UnityEngine; using Object = UnityEngine.Object; namespace P4Connect { #if DEVELOPER public class PackageIcons { private static string _p4ConnectBundle = "P4Connect"; private static string _iconAssetPath = Path.GetFullPath(Main.RootPath + "Assets/P4Connect/Editor"); [MenuItem("Assets/CopyIcons")] static void CopyIconsIntoAssets() { string sourceIconsPath = Path.GetFullPath(Main.RootPath + "../src/Icons/"); string assetIconsPath = Path.GetFullPath(Main.RootPath + "Assets/Icons/"); 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); } } // 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() { // 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(); string assetIconsPath = Path.GetFullPath(Main.RootPath + "Assets/Icons/"); 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); #if UNITY_5 var importer = AssetImporter.GetAtPath(assetPath); importer.assetBundleName = _p4ConnectBundle; names.Add(assetPath); #else Object thisobj = AssetDatabase.LoadAssetAtPath(assetPath, typeof (Object)); if (thisobj == null) { Debug.Log("failed to load asset at: " + assetPath); } else { objs.Add(thisobj); names.Add(assetPath); } #endif } else { Debug.Log("skipping non texture: " + f); } } #if UNITY_5 var build = new AssetBundleBuild { assetBundleName = _p4ConnectBundle, assetNames = names.ToArray() }; BuildPipeline.BuildAssetBundles(_iconAssetPath, new[]{ build }, BuildAssetBundleOptions.UncompressedAssetBundle, BuildTarget.StandaloneWindows); #else BuildPipeline.BuildAssetBundleExplicitAssetNames(objs.ToArray(), names.ToArray(), "Assets/P4Connect/Editor/P4Connect1.icons", BuildAssetBundleOptions.UncompressedAssetBundle); #endif } } // PackageIcons public class XYZZY : EditorWindow { static XYZZY() { } // Add menu named "Styles" to the Window menu [MenuItem("Window/Styles", false, 1000)] public static void ShowWindow() { // Get existing open window or if none, make a new one: XYZZY window = EditorWindow.GetWindow(typeof(XYZZY), false, "Styles") as XYZZY; #if UNITY_5 window.titleContent = new GUIContent("Styles"); #else window.title = "Styles"; #endif window.name = "Styles"; } static Vector2 _scrollPosition = new Vector2(); void OnGUI() { EditorGUILayout.BeginVertical(); _scrollPosition = GUILayout.BeginScrollView(_scrollPosition, false, true, GUI.skin.horizontalScrollbar, GUI.skin.verticalScrollbar, GUI.skin.box); ShowStyles(GUI.skin); GUILayout.EndScrollView(); EditorGUILayout.EndVertical(); } public static void ShowStyles(GUISkin skin) { foreach (GUIStyle style in skin.customStyles) { GUILayout.Button(style.name, style); } } } #endif // DEVELOPER }