private TextureImportData NewData()
        {
            TextureImportData data = new TextureImportData();

            data.Index = TextureImportDataManager.Instance.GetNextIndex();
            return(data);
        }
示例#2
0
        public TextureImportData GetRule(string path, string name)
        {
            TextureImportData rule = null;

            for (int i = 0; i < DataList.Count; i++)
            {
                if (path.StartsWith(DataList[i].AssetPath))
                {
                    if (rule == null)
                    {
                        if (DataList[i].IsMatch(name))
                        {
                            rule = DataList[i];
                        }
                    }
                    else if (rule.Index < DataList[i].Index)
                    {
                        if (DataList[i].IsMatch(name))
                        {
                            rule = DataList[i];
                        }
                    }
                }
            }
            return(rule);
        }
示例#3
0
        public static void TextureImport(AssetImporter importer)
        {
            if (null == importer)
            {
                return;
            }
            string            dir  = importer.assetPath.Remove(importer.assetPath.LastIndexOf('/'));
            string            name = importer.assetPath.Substring(importer.assetPath.LastIndexOf('/') + 1);
            TextureImportData rule = TextureImportDataManager.Instance.GetRule(dir, name);

            if (null != rule)
            {
                Debug.Log("apply rule:" + rule.AssetPath + "," + rule.Index);
                ApplyRulesToTexture(importer, rule);
            }
        }
示例#4
0
        public static void ApplyRulesToTexture(AssetImporter importer, TextureImportData data)
        {
            if (null == importer)
            {
                return;
            }
            TextureImporter tImporter = importer as TextureImporter;

            if (null == tImporter)
            {
                return;
            }
            if (tImporter.textureType != data.TextureType)
            {
                tImporter.textureType = data.TextureType;
            }
            tImporter.isReadable    = data.ReadWriteEnable;
            tImporter.mipmapEnabled = data.Mipmap;

            if (data.MaxSize > 0)
            {
                tImporter.maxTextureSize = data.MaxSize;
            }

            TextureImporterPlatformSettings settingAndroid = tImporter.GetPlatformTextureSettings("Android");

            settingAndroid.overridden     = true;
            settingAndroid.format         = data.AndroidFormat;
            settingAndroid.maxTextureSize = tImporter.maxTextureSize;
            tImporter.SetPlatformTextureSettings(settingAndroid);

            TextureImporterPlatformSettings settingIos = tImporter.GetPlatformTextureSettings("iPhone");

            settingIos.overridden     = true;
            settingIos.format         = data.IosFormat;
            settingIos.maxTextureSize = tImporter.maxTextureSize;
            tImporter.SetPlatformTextureSettings(settingIos);

            tImporter.SaveAndReimport();
        }
示例#5
0
        public static void ReimportTextures(TextureImportData data)
        {
            if (data == null)
            {
                return;
            }
            string[] guids = AssetDatabase.FindAssets("t:Texture", new string[] { data.AssetPath });
            for (int i = 0; i < guids.Length; i++)
            {
                string path = AssetDatabase.GUIDToAssetPath(guids[i]);

                if (string.IsNullOrEmpty(path))
                {
                    continue;
                }

                if (!data.IsRecursive)
                {
                    string dir = path.Remove(path.LastIndexOf('/'));
                    if (!dir.Equals(data.AssetPath))
                    {
                        continue;
                    }
                }

                string name = path.Substring(path.LastIndexOf('/') + 1);
                if (data.IsMatch(name))
                {
                    AssetImporter ai = AssetImporter.GetAtPath(path);
                    if (null != ai)
                    {
                        ApplyRulesToTexture(ai, data);
                    }
                }
            }
        }
        private void TextureImportDataToUI(TextureImportData data)
        {
            if (null == data)
            {
                return;
            }

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

            case TextureImporterAlphaSource.None:
                m_alphaSrcSelected = 1;
                break;

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

            case TextureImporterType.NormalMap:
                m_textureTypeSelected = 1;
                break;

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

            case TextureImporterFormat.ETC2_RGB4:
                m_androidFormatSelected = 1;
                break;

            case TextureImporterFormat.ETC2_RGB4_PUNCHTHROUGH_ALPHA:
                m_androidFormatSelected = 2;
                break;

            case TextureImporterFormat.ETC2_RGBA8:
                m_androidFormatSelected = 3;
                break;

            case TextureImporterFormat.RGB16:
                m_androidFormatSelected = 4;
                break;

            case TextureImporterFormat.RGB24:
                m_androidFormatSelected = 5;
                break;

            case TextureImporterFormat.RGBA16:
                m_androidFormatSelected = 6;
                break;

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

            case TextureImporterFormat.PVRTC_RGB4:
                m_iosFormatSelected = 1;
                break;

            case TextureImporterFormat.PVRTC_RGBA2:
                m_iosFormatSelected = 2;
                break;

            case TextureImporterFormat.PVRTC_RGBA4:
                m_iosFormatSelected = 3;
                break;

            case TextureImporterFormat.RGB16:
                m_iosFormatSelected = 4;
                break;

            case TextureImporterFormat.RGB24:
                m_iosFormatSelected = 5;
                break;

            case TextureImporterFormat.RGBA16:
                m_iosFormatSelected = 6;
                break;

            case TextureImporterFormat.RGBA32:
                m_iosFormatSelected = 7;
                break;

            case TextureImporterFormat.ASTC_RGB_4x4:
                m_iosFormatSelected = 8;
                break;

            case TextureImporterFormat.ASTC_RGB_5x5:
                m_iosFormatSelected = 9;
                break;

            case TextureImporterFormat.ASTC_RGB_6x6:
                m_iosFormatSelected = 10;
                break;

            case TextureImporterFormat.ASTC_RGB_8x8:
                m_iosFormatSelected = 11;
                break;

            case TextureImporterFormat.ASTC_RGB_10x10:
                m_iosFormatSelected = 12;
                break;

            case TextureImporterFormat.ASTC_RGB_12x12:
                m_iosFormatSelected = 13;
                break;

            case TextureImporterFormat.ASTC_RGBA_4x4:
                m_iosFormatSelected = 14;
                break;

            case TextureImporterFormat.ASTC_RGBA_5x5:
                m_iosFormatSelected = 15;
                break;

            case TextureImporterFormat.ASTC_RGBA_6x6:
                m_iosFormatSelected = 16;
                break;

            case TextureImporterFormat.ASTC_RGBA_8x8:
                m_iosFormatSelected = 17;
                break;

            case TextureImporterFormat.ASTC_RGBA_10x10:
                m_iosFormatSelected = 18;
                break;

            case TextureImporterFormat.ASTC_RGBA_12x12:
                m_iosFormatSelected = 19;
                break;
            }
        }
        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();
        }
        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();
        }
示例#9
0
 public static void ApplyRulesToTexture(string path, TextureImportData data)
 {
     ApplyRulesToTexture(AssetImporter.GetAtPath(path), data);
 }