/** ********************************************************************************
 * @summary 子を削除
 ***********************************************************************************/
 public void RemoveChild(TextureTreeElement child)
 {
     if (Children.Contains(child))
     {
         Children.Remove(child);
         child.Parent = null;
     }
 }
        /** ********************************************************************************
        * @summary 子を追加
        ***********************************************************************************/
        internal void AddChild(TextureTreeElement child)
        {
            // 既に親がいたら削除
            if (child.Parent != null)
            {
                child.Parent.RemoveChild(child);
            }

            // 親子関係を設定
            Children.Add(child);
            child.Parent = this;
        }
        /** ********************************************************************************
        * @summary 列の行を描画
        ***********************************************************************************/
        private void DrawRowColumn(RowGUIArgs args, Rect rect, int columnIndex)
        {
            if (args.item.id < 0)
            {
                return;
            }                                  // 検索がヒットしない場合はid=-999のダミー(DummyTreeViewItem)が入ってくる。ここでは描画をスキップする

            TextureTreeElement element = baseElements[args.item.id];

            if (element == null)
            {
                return;
            }

            var texture         = element.Texture;
            var textureImporter = element.TextureImporter;

            if (texture == null || textureImporter == null)
            {
                EditorGUI.LabelField(rect, "(null)");
                return;
            }

            //GUIStyle labelStyle = EditorStyles.label;
            GUIStyle labelStyle = EditorStyles.label;

            switch ((EHeaderColumnId)columnIndex)
            {
            case EHeaderColumnId.TextureName:
                rect.x += 2f;

                // アイコンを描画する
                Rect toggleRect = rect;
                toggleRect.y   += 2f;
                toggleRect.size = new Vector2(12f, 12f);
                GUI.DrawTexture(toggleRect, texture);

                // テキストを描画する
                Rect labelRect = new Rect(rect);
                labelRect.x += toggleRect.width;
                EditorGUI.LabelField(labelRect, args.label);
                break;

            default:
                var text  = element.GetDisplayText((EHeaderColumnId)columnIndex);
                var style = element.GetLabelStyle((EHeaderColumnId)columnIndex);
                EditorGUI.LabelField(rect, text, style);
                break;
            }
        }
        /** ********************************************************************************
        * @summary フィルタリングにマッチするか判定
        ***********************************************************************************/
        public bool DoesItemMatch(EHeaderColumnId headerId, TextureTreeElement element)
        {
            int typeAsBit       = -1;
            var textureImporter = element.TextureImporter;
            var texture         = element.Texture;

            switch (headerId)
            {
            case EHeaderColumnId.TextureName:
                return(DoesStringMatch(searchString, element.Texture.name));

            case EHeaderColumnId.TextureType:
                typeAsBit = (int)TypeBitConverter.ConvertTextureImpoterType(textureImporter.textureType);
                break;

            case EHeaderColumnId.NPot:
                typeAsBit = (int)TypeBitConverter.ConvertTextureImporterNPOTScale(textureImporter.npotScale);
                break;

            case EHeaderColumnId.MaxSize:
                typeAsBit = (int)TypeBitConverter.ConvertMaxTextureSize(textureImporter.maxTextureSize);
                break;

            case EHeaderColumnId.GenerateMips:
                typeAsBit = (int)TypeBitConverter.ConvertMipMapEnabled(textureImporter.mipmapEnabled);
                break;

            case EHeaderColumnId.AlphaIsTransparency:
                typeAsBit = (int)TypeBitConverter.ConvertAlphaIsTransparency(textureImporter.alphaIsTransparency);
                break;

            case EHeaderColumnId.TextureSize:
                return(DoesStringMatch(searchString, element.Texture.name));

            case EHeaderColumnId.DataSize:
                typeAsBit = (int)TypeBitConverter.ConvertDataSizeUnit(element.TextureByteLength);
                //return DoesSizeMatch(unit, element.TextureByteLength);
                break;

            default:
                return(true);
            }

            return((searchFilter & typeAsBit) > 0);
        }
        /** ********************************************************************************
        * @summary TreeView初期化
        ***********************************************************************************/
        public void SetTexture(Texture2D[] textures, TextureImporter[] importers)
        {
            // TreeViewの要素を作成
            baseElements = new TextureTreeElement[textures.Length];
            for (int i = 0; i < baseElements.Length; i++)
            {
                var path = AssetDatabase.GetAssetPath(textures[i]);
                baseElements[i] = new TextureTreeElement
                {
                    AssetPath       = path,
                    AssetName       = System.IO.Path.GetFileNameWithoutExtension(path),
                    Texture         = textures[i],
                    TextureImporter = importers[i],
                };
            }

            for (int i = 0; i < baseElements.Length; i++)
            {
                var element = baseElements[i];
                element.Index = i;
                element.UpdateDataSize();
            }
        }
 /** ********************************************************************************
 * @summary 要素を作成
 ***********************************************************************************/
 private TreeViewItem CreateTreeViewItem(TextureTreeElement model)
 {
     return(new TextureTreeViewItem {
         id = model.Index, displayName = model.AssetName
     });
 }