static void CreateWindow() { Rect rect = new Rect(Screen.width >> 1, Screen.height >> 1, 300, 300); Tex2SpriteWindow window = (Tex2SpriteWindow)EditorWindow.GetWindowWithRect(typeof(Tex2SpriteWindow), rect, true, "图片编辑器"); //window.Init(); window.Show(); }
void OnGUI() { EditorGUILayout.BeginVertical(); GUIStyle bb = new GUIStyle(); bb.normal.background = null; //这是设置背景填充的 bb.normal.textColor = new Color(1, 0, 0); //设置字体颜色的 bb.fontSize = 24; //当然,这是字体颜色 EditorGUILayout.LabelField(string.Format("确定将{0}下的图片\n改变成图集为{1}的sprite吗?", m_path, m_atlas_name), bb); EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("是")) { Object[] m_objects = Selection.GetFiltered(typeof(Texture), SelectionMode.DeepAssets);//选择的所以对象 foreach (Object targetObj in m_objects) { string path = AssetDatabase.GetAssetPath(targetObj); TextureImporter texture = AssetImporter.GetAtPath(path) as TextureImporter; if (TextureImporterType.Sprite == texture.textureType && texture.spritePackingTag == m_atlas_name) { continue; } texture.textureType = TextureImporterType.Sprite; texture.spritePackingTag = m_atlas_name; //texture.spritePixelsPerUnit = 1; //texture.filterMode = FilterMode.Trilinear; texture.mipmapEnabled = false; //texture.textureFormat = TextureImporterFormat.AutomaticTruecolor; AssetDatabase.ImportAsset(path); } AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); this.Close(); Tex2SpriteWindow window = (Tex2SpriteWindow)EditorWindow.GetWindow(typeof(Tex2SpriteWindow)); window.Close(); } if (GUILayout.Button("否")) { this.Close(); Tex2SpriteWindow window = (Tex2SpriteWindow)EditorWindow.GetWindow(typeof(Tex2SpriteWindow)); window.Close(); } EditorGUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); }