Skip to content

Instantly share code, notes, and snippets.

@hiroki-o
Created February 21, 2017 07:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hiroki-o/6574e93836d298ec79a07d92a18a120c to your computer and use it in GitHub Desktop.
Save hiroki-o/6574e93836d298ec79a07d92a18a120c to your computer and use it in GitHub Desktop.
AssetBundleGraphTool custom filter class/Filter by texture's alpha channel info
using UnityEngine;
using UnityEditor;
using System;
using System.Linq;
using System.IO;
using System.Collections.Generic;
using System.Reflection;
using System.Text.RegularExpressions;
using UnityEngine.AssetBundles.GraphTool;
using Model=UnityEngine.AssetBundles.GraphTool.DataModel.Version2;
[CustomFilter("Filter By Texture Alpha")]
public class FilterByTextureAlpha : IFilter {
[SerializeField] private bool m_hasAlpha;
public string Label {
get {
return m_hasAlpha ? "With Alpha" : "No Alpha";
}
}
public FilterByTextureAlpha() {
m_hasAlpha = false;
}
public bool FilterAsset(AssetReference a) {
if(a.filterType != typeof(TextureImporter)) {
return false;
}
var textureImporter = AssetImporter.GetAtPath(a.importFrom) as TextureImporter;
return textureImporter.DoesSourceTextureHaveAlpha() == m_hasAlpha;
}
public void OnInspectorGUI (Action onValueChanged) {
using (new EditorGUILayout.HorizontalScope()) {
var newValue = EditorGUILayout.ToggleLeft("Texture has Alpha channel", m_hasAlpha);
if (newValue != m_hasAlpha) {
m_hasAlpha = newValue;
onValueChanged();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment