public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();

        if (GUILayout.Button("Generate"))
        {
            Texture2DArrayData component      = (Texture2DArrayData)target;
            Texture2D[]        textures       = component.textures;
            Texture2DArray     texture2DArray = new Texture2DArray(
                textures[0].width, textures[0].height, textures.Length, TextureFormat.RGBA32, true);

            for (int i = 0; i < textures.Length; i++)
            {
                texture2DArray.SetPixels32(textures[i].GetPixels32(), i);
            }
            texture2DArray.Apply();

            AssetDatabase.CreateAsset(texture2DArray, "Assets/Textures/" + component.name + ".asset");

            GameObject exampleMesh = GameObject.Find("ExampleTerrainMesh");
            Shader     texturedDynamicTerrainShader = exampleMesh.GetComponent <Shader>();

            component.NotifyOfUpdatedValues();
            EditorUtility.SetDirty(target);
        }
    }
    /// <summary>
    /// Setup reorderable list.
    /// </summary>
    private void OnEnable()
    {
        SerializedProperty serializedProperty = serializedObject.FindProperty("m_textures");

        m_arrayData = (Texture2DArrayData)target;

        m_list = new ReorderableList(serializedObject, serializedProperty, true, true, true, true)
        {
            drawHeaderCallback = (Rect rect) =>
            {
                EditorGUI.LabelField(rect, new GUIContent("Texture Array"));
            },

            drawElementCallback = (Rect rect, int index, bool isActive, bool hasFocus) =>
            {
                SerializedProperty property = m_list.serializedProperty.GetArrayElementAtIndex(index);
                Texture2D          texture  = property.objectReferenceValue as Texture2D;

                GUIContent label = new GUIContent(texture == null ? "None" : texture.name);
                int        state = (int)m_arrayData.GetTextureState(texture);

                EditorGUI.BeginChangeCheck();
                EditorGUI.PropertyField(new Rect(rect.x, rect.y + 2, 36, 16), property, GUIContent.none);
                EditorGUI.LabelField(new Rect(rect.x + 40, rect.y + 2, rect.width - 60, 16), label);
                EditorGUI.LabelField(new Rect(rect.width, rect.y + 2, 20, 16), m_texture2DState [state]);

                if (EditorGUI.EndChangeCheck())
                {
                    m_isModified = true;
                }
            },

            onAddCallback = (ReorderableList list) =>
            {
                list.serializedProperty.arraySize++;
                m_isModified = true;
            },

            onRemoveCallback = (ReorderableList list) =>
            {
                list.serializedProperty.GetArrayElementAtIndex(list.index).objectReferenceValue = null;
                list.serializedProperty.DeleteArrayElementAtIndex(list.index);
                m_isModified = true;
            },

            onChangedCallback = (ReorderableList list) =>
            {
                m_isModified = true;
            },
        };
    }
    private static void TextureArrayItem()
    {
        Texture2DArrayData texture2DArray = CreateInstance <Texture2DArrayData> ();

        texture2DArray.Initialize(Selection.GetFiltered <Texture2D> (SelectionMode.TopLevel));

        string assetPath = AssetDatabase.GetAssetPath(texture2DArray.m_textures [0]);

        assetPath = assetPath.Remove(assetPath.LastIndexOf('/')) + "/Texture2DArray.asset";

        AssetDatabase.CreateAsset(texture2DArray, assetPath);
        AssetDatabase.SaveAssets();

        Selection.activeObject = texture2DArray;
        texture2DArray.Rebuild();
    }