Created
February 21, 2017 07:25
-
-
Save hiroki-o/6574e93836d298ec79a07d92a18a120c to your computer and use it in GitHub Desktop.
AssetBundleGraphTool custom filter class/Filter by texture's alpha channel info
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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