コード例 #1
0
        private void OnGUI()
        {
            EditorGUILayout.Space();
            GUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Path:", GUILayout.MinWidth(50), GUILayout.MaxWidth(60));
            m_path = EditorGUILayout.TextField(m_path, GUILayout.MinWidth(400));
            EditorGUIUtility.labelWidth = 70;
            m_isRecursive = EditorGUILayout.Toggle("Recursive", m_isRecursive, GUILayout.MinWidth(80));
            EditorGUILayout.LabelField("NameFilter:", GUILayout.MinWidth(80), GUILayout.MaxWidth(90));
            m_filter = EditorGUILayout.TextField(m_filter, GUILayout.MinWidth(150));

            if (GUILayout.Button("Save", GUILayout.MinWidth(100)))
            {
                SaveCurSelectData();
            }
            if (GUILayout.Button("Delete", GUILayout.MinWidth(100)))
            {
                TextureImportDataManager.Instance.Delete(SelectedIndex);
            }
            if (GUILayout.Button("New Data", GUILayout.MinWidth(100)))
            {
                TextureImportData data = NewData();
                TextureImportDataManager.Instance.DataList.Add(data);
                TextureImportDataManager.Save();
                SelectedIndex = data.Index;
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            EditorGUIUtility.labelWidth = 100;
            m_textureTypeSelected       = EditorGUILayout.Popup("TextureType", m_textureTypeSelected, m_textureType);
            GUILayout.Space(100);
            m_alphaSrcSelected          = EditorGUILayout.Popup("AlphaSource", m_alphaSrcSelected, m_alphaSrc);
            EditorGUIUtility.labelWidth = 50;
            GUILayout.Space(100);
            m_androidFormatSelected = EditorGUILayout.Popup("Android", m_androidFormatSelected, m_androidFormats);
            GUILayout.Space(50);
            m_iosFormatSelected = EditorGUILayout.Popup("Ios", m_iosFormatSelected, m_iosFormats);
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            m_mipmap                    = EditorGUILayout.ToggleLeft("Mipmap", m_mipmap, GUILayout.MinWidth(100));
            m_readWriteEnable           = EditorGUILayout.ToggleLeft("ReadWriteEnable", m_readWriteEnable, GUILayout.MinWidth(150));
            EditorGUIUtility.labelWidth = 60;
            m_index = EditorGUILayout.IntField("Priority", m_index, GUILayout.MinWidth(100));
            GUILayout.Space(50);
            m_maxSize = EditorGUILayout.IntField("MaxSize", m_maxSize, GUILayout.MinWidth(100));
            GUILayout.EndHorizontal();

            int height             = (TextureImportDataManager.Instance.DataList.Count + 1) * 20;
            TextureImportData rule = TextureImportDataManager.Instance.GetRule(m_selectedIndex);

            string[] guids = null;
            if (null != rule)
            {
                guids   = AssetDatabase.FindAssets("t:Texture", new string[] { rule.AssetPath });
                height += (guids.Length + 1) * 20;
            }

            m_scrollPosition = GUI.BeginScrollView(new Rect(0, 60, position.width, position.height - 60), m_scrollPosition, new Rect(0, 0, 1000, height));
            GUILayout.BeginHorizontal();
            GUILayout.Label("AssetPath", EditorStyles.label, GUILayout.MinWidth(250));
            GUILayout.Label("FileFilter", EditorStyles.label, GUILayout.MinWidth(120));
            GUILayout.Label("Priority", EditorStyles.label, GUILayout.MinWidth(85));
            GUILayout.Label("AlphaSource", EditorStyles.label, GUILayout.MinWidth(85));
            GUILayout.Label("TextureType", EditorStyles.label, GUILayout.MinWidth(85));
            GUILayout.Label("Mipmap", EditorStyles.label, GUILayout.MinWidth(85));
            GUILayout.Label("R/W", EditorStyles.label, GUILayout.MinWidth(85));
            GUILayout.Label("MaxSize", EditorStyles.label, GUILayout.MinWidth(85));
            GUILayout.Label("Android", EditorStyles.label, GUILayout.MinWidth(125));
            GUILayout.Label("Ios", EditorStyles.label, GUILayout.MinWidth(90));
            GUILayout.Label("Recursive", EditorStyles.label, GUILayout.MinWidth(55));
            GUILayout.Label("Apply", EditorStyles.label, GUILayout.MinWidth(55));
            GUILayout.EndHorizontal();

            GUIStyle style = GUI.skin.textField;

            //style.font = new Font()
            for (int i = 0; i < TextureImportDataManager.Instance.DataList.Count; i++)
            {
                GUILayout.BeginHorizontal();
                TextureImportData data = TextureImportDataManager.Instance.DataList[i];

                if (data.Index == SelectedIndex)
                {
                    GUI.color = Color.green;
                }
                else
                {
                    GUI.color = new Color(0.8f, 0.8f, 0.8f, 1);
                }

                if (GUILayout.Button(data.AssetPath, style, GUILayout.MinWidth(250)))
                {
                    SelectedIndex = data.Index;
                }
                if (GUILayout.Button(data.FileFilter, style, GUILayout.MinWidth(120)))
                {
                    SelectedIndex = data.Index;
                }
                if (GUILayout.Button(data.Index.ToString(), style, GUILayout.MinWidth(80)))
                {
                    SelectedIndex = data.Index;
                }
                if (GUILayout.Button(data.AlphaSource.ToString(), style, GUILayout.MinWidth(80)))
                {
                    SelectedIndex = data.Index;
                }
                if (GUILayout.Button(data.TextureType.ToString(), style, GUILayout.MinWidth(80)))
                {
                    SelectedIndex = data.Index;
                }
                if (GUILayout.Button(data.Mipmap.ToString(), style, GUILayout.MinWidth(80)))
                {
                    SelectedIndex = data.Index;
                }
                if (GUILayout.Button(data.ReadWriteEnable.ToString(), style, GUILayout.MinWidth(80)))
                {
                    SelectedIndex = data.Index;
                }
                if (GUILayout.Button(data.MaxSize.ToString(), style, GUILayout.MinWidth(80)))
                {
                    SelectedIndex = data.Index;
                }
                if (GUILayout.Button(data.AndroidFormat.ToString(), style, GUILayout.MinWidth(120)))
                {
                    SelectedIndex = data.Index;
                }
                if (GUILayout.Button(data.IosFormat.ToString(), style, GUILayout.MinWidth(120)))
                {
                    SelectedIndex = data.Index;
                }
                if (GUILayout.Button(data.IsRecursive.ToString(), style, GUILayout.MinWidth(50)))
                {
                    SelectedIndex = data.Index;
                }
                if (GUILayout.Button("Apply", GUILayout.MinWidth(50)))
                {
                    TextureImportDataTool.ReimportTextures(data);
                }
                GUILayout.EndHorizontal();
            }

            if (null != guids)
            {
                int count = 0;
                for (int i = 0; i < guids.Length; i++)
                {
                    string path = AssetDatabase.GUIDToAssetPath(guids[i]);
                    if (string.IsNullOrEmpty(path))
                    {
                        continue;
                    }
                    if (!m_isRecursive)
                    {
                        string dir = path.Remove(path.LastIndexOf('/'));
                        if (!dir.Equals(m_path))
                        {
                            continue;
                        }
                    }
                    string name = path.Substring(path.LastIndexOf('/') + 1);
                    if (!Regex.IsMatch(name, m_filter))
                    {
                        continue;
                    }
                    TextureImporter ai = AssetImporter.GetAtPath(path) as TextureImporter;
                    if (null != ai)
                    {
                        GUILayout.BeginHorizontal();
                        GUILayout.Label(path, GUILayout.MinWidth(250));
                        GUILayout.Label("", GUILayout.MinWidth(120));
                        GUILayout.Label((++count).ToString(), GUILayout.MinWidth(85));
                        GUILayout.Label(ai.alphaSource.ToString(), GUILayout.MinWidth(85));
                        GUILayout.Label(ai.textureType.ToString(), GUILayout.MinWidth(85));
                        GUILayout.Label(ai.mipmapEnabled.ToString(), GUILayout.MinWidth(85));
                        GUILayout.Label(ai.isReadable.ToString(), GUILayout.MinWidth(85));
                        TextureImporterPlatformSettings settingAndroid = ai.GetPlatformTextureSettings("Android");
                        GUILayout.Label(settingAndroid.maxTextureSize.ToString(), GUILayout.MinWidth(85));
                        GUILayout.Label(settingAndroid.format.ToString(), GUILayout.MinWidth(125));
                        TextureImporterPlatformSettings settingIos = ai.GetPlatformTextureSettings("iPhone");
                        GUILayout.Label(settingIos.format.ToString(), GUILayout.MinWidth(125));
                        GUILayout.Label("", GUILayout.MinWidth(55));
                        GUILayout.EndHorizontal();
                    }
                }
            }
            GUI.EndScrollView();
        }
コード例 #2
0
        private void SaveCurSelectData()
        {
            TextureImportData data = TextureImportDataManager.Instance.GetRule(SelectedIndex);

            if (null == data)
            {
                return;
            }

            data.AssetPath   = m_path;
            data.IsRecursive = m_isRecursive;
            data.FileFilter  = m_filter;
            data.Index       = m_index;
            data.MaxSize     = m_maxSize;
            switch (m_alphaSrcSelected)
            {
            case 0:
                data.AlphaSource = TextureImporterAlphaSource.FromInput;
                break;

            case 1:
                data.AlphaSource = TextureImporterAlphaSource.None;
                break;

            case 2:
                data.AlphaSource = TextureImporterAlphaSource.FromGrayScale;
                break;
            }
            switch (m_textureTypeSelected)
            {
            case 0:
                data.TextureType = TextureImporterType.Default;
                break;

            case 1:
                data.TextureType = TextureImporterType.NormalMap;
                break;

            case 2:
                data.TextureType = TextureImporterType.Lightmap;
                break;
            }
            data.Mipmap          = m_mipmap;
            data.ReadWriteEnable = m_readWriteEnable;
            switch (m_androidFormatSelected)
            {
            case 0:
                data.AndroidFormat = TextureImporterFormat.ETC_RGB4;
                break;

            case 1:
                data.AndroidFormat = TextureImporterFormat.ETC2_RGB4;
                break;

            case 2:
                data.AndroidFormat = TextureImporterFormat.ETC2_RGB4_PUNCHTHROUGH_ALPHA;
                break;

            case 3:
                data.AndroidFormat = TextureImporterFormat.ETC2_RGBA8;
                break;

            case 4:
                data.AndroidFormat = TextureImporterFormat.RGB16;
                break;

            case 5:
                data.AndroidFormat = TextureImporterFormat.RGB24;
                break;

            case 6:
                data.AndroidFormat = TextureImporterFormat.RGBA16;
                break;

            case 7:
                data.AndroidFormat = TextureImporterFormat.RGBA32;
                break;
            }
            switch (m_iosFormatSelected)
            {
            case 0:
                data.IosFormat = TextureImporterFormat.PVRTC_RGB2;
                break;

            case 1:
                data.IosFormat = TextureImporterFormat.PVRTC_RGB4;
                break;

            case 2:
                data.IosFormat = TextureImporterFormat.PVRTC_RGBA2;
                break;

            case 3:
                data.IosFormat = TextureImporterFormat.PVRTC_RGBA4;
                break;

            case 4:
                data.IosFormat = TextureImporterFormat.RGB16;
                break;

            case 5:
                data.IosFormat = TextureImporterFormat.RGB24;
                break;

            case 6:
                data.IosFormat = TextureImporterFormat.RGBA16;
                break;

            case 7:
                data.IosFormat = TextureImporterFormat.RGBA32;
                break;

            case 8:
                data.IosFormat = TextureImporterFormat.ASTC_RGB_4x4;
                break;

            case 9:
                data.IosFormat = TextureImporterFormat.ASTC_RGB_5x5;
                break;

            case 10:
                data.IosFormat = TextureImporterFormat.ASTC_RGB_6x6;
                break;

            case 11:
                data.IosFormat = TextureImporterFormat.ASTC_RGB_8x8;
                break;

            case 12:
                data.IosFormat = TextureImporterFormat.ASTC_RGB_10x10;
                break;

            case 13:
                data.IosFormat = TextureImporterFormat.ASTC_RGB_12x12;
                break;

            case 14:
                data.IosFormat = TextureImporterFormat.ASTC_RGBA_4x4;
                break;

            case 15:
                data.IosFormat = TextureImporterFormat.ASTC_RGBA_5x5;
                break;

            case 16:
                data.IosFormat = TextureImporterFormat.ASTC_RGBA_6x6;
                break;

            case 17:
                data.IosFormat = TextureImporterFormat.ASTC_RGBA_8x8;
                break;

            case 18:
                data.IosFormat = TextureImporterFormat.ASTC_RGBA_10x10;
                break;

            case 19:
                data.IosFormat = TextureImporterFormat.ASTC_RGBA_12x12;
                break;
            }

            TextureImportDataManager.Save();
        }