/// <summary> /// Registers the gizmo. /// </summary> /// <param name="pngData">Png data.</param> /// <param name="fileName">Destination file name with extension.</param> private static void RegisterGizmo(byte[] pngData, string destinationFileNameWithExtension) { string destIconPath = Path.Combine("Assets/Gizmos", destinationFileNameWithExtension); // skip ahead if icon has already been copied and hasn't changed if (File.Exists(destIconPath) /*&& pngData.SequenceEqual(File.ReadAllBytes(destIconPath))*/) { return; } // otherwise write the icon into the Gizmos folder AssetDatabaseX.CreateFolderIfNecessary("Assets/Gizmos"); File.WriteAllBytes(destIconPath, pngData); // configure the import settings and import the asset AssetDatabase.Refresh(); TextureImporter importer = AssetImporter.GetAtPath(destIconPath) as TextureImporter; importer.filterMode = FilterMode.Trilinear; importer.textureType = TextureImporterType.GUI; importer.textureCompression = TextureImporterCompression.Uncompressed; AssetDatabase.ImportAsset(destIconPath); }
/// <summary> /// Initializes the <see cref="EditorGizmos"/> class. /// </summary> static EditorGizmos() { // find the folder with this script string scriptFolder = AssetDatabaseX.GetFolderContainingScript( typeof(EditorGizmos), "Assets/Plugins/Editor/Candlelight/Library/Gizmos" ); if (string.IsNullOrEmpty(scriptFolder)) { scriptFolder = AssetDatabaseX.GetFolderContainingScript(typeof(EditorGizmos), "Assets/Plugins"); } if (string.IsNullOrEmpty(scriptFolder)) { scriptFolder = AssetDatabaseX.GetFolderContainingScript(typeof(EditorGizmos)); } // if the folder was found, search it for icons and register them if (!string.IsNullOrEmpty(scriptFolder)) { foreach (string sourceIconPath in Directory.GetFiles(scriptFolder, "*.png")) { RegisterGizmo(File.ReadAllBytes(sourceIconPath), Path.GetFileName(sourceIconPath)); } } }
/// <summary> /// Creates a new asset in the project. /// </summary> protected static void CreateNewAssetInProject() { AssetDatabaseX.CreateNewAssetInCurrentProjectFolder <T>(); }