Exemplo n.º 1
0
        static bool PackAtlas_OneDir(string folderPath_)
        {
            List <Texture2D> textures = new List <Texture2D>();
            Texture2D        tex;

            string suffix = ".png";

            string[] fs = Directory.GetFiles(folderPath_);
            foreach (string f in fs)
            {
                if (f.EndsWith(".png"))
                {
                    //suffix = ".png";
                }
                else if (f.EndsWith(".tga"))
                {
                    suffix = ".tga";
                }
                else
                {
                    continue;
                }

                tex = AssetDatabase.LoadAssetAtPath <Texture2D>(f);
                if (tex)
                {
                    textures.Add(tex);
                }
            }

            if (textures.Count <= 0)
            {
                return(false);
            }


            string atlasPath = PackTextures(textures, folderPath_, suffix);   //打包图集

            AssetDatabase.Refresh();

            SpriteAtlasClipUtility.ApplyClipData(atlasPath);   //还原切片数据到图集中

            GenAsset_OneFile(atlasPath);

            return(true);
        }
Exemplo n.º 2
0
        void TypeReadJson()
        {
            if (m_texture != null && m_clipType != null)
            {
                //图集改变时,尝试获取json里的尺寸
                string   path = AssetDatabase.GetAssetPath(m_texture);
                JsonData data = SpriteAtlasClipUtility.GetClipJsonDataTypical(path, m_clipType);
                if (data != null)
                {
                    JsonData rect = data["rect"];
                    int      w    = (int)rect["width"];
                    int      h    = (int)rect["height"];
                    m_input_w = w.ToString();
                    m_input_h = h.ToString();
                    return;
                }
            }

            m_input_w = m_clipW_df;
            m_input_h = m_clipH_df;
        }
Exemplo n.º 3
0
        void OnGUI()
        {
            //try
            //{
            GUILayout.Space(5);
            GUILayout.BeginHorizontal();
            GUILayout.Label("图集文件:", GUILayout.Width(70));
            texture = EditorGUILayout.ObjectField(texture, typeof(Texture2D), false, GUILayout.Width(200)) as Texture2D;
            GUILayout.EndHorizontal();

            GUILayout.Space(5);
            GUILayout.BeginHorizontal();
            GUILayout.Label("选择尺寸类型:", GUILayout.Width(100));
            m_typeIndex = EditorGUILayout.Popup(m_typeIndex, SpriteAtlasClipUtility.typeList, GUILayout.Width(120));
            clipType    = SpriteAtlasClipUtility.typeList[m_typeIndex];
            GUILayout.EndHorizontal();

            GUILayout.Space(5);
            GUILayout.BeginHorizontal();
            GUILayout.Label("请输入切片尺寸:", GUILayout.Width(110));
            GUILayout.EndHorizontal();

            GUILayout.Space(5);
            GUILayout.BeginHorizontal();
            GUILayout.Label("width:", GUILayout.Width(70));
            m_input_w = EditorGUILayout.TextField(m_input_w, GUILayout.Width(80));
            GUILayout.EndHorizontal();

            GUILayout.Space(5);
            GUILayout.BeginHorizontal();
            GUILayout.Label("height:", GUILayout.Width(70));
            m_input_h = EditorGUILayout.TextField(m_input_h, GUILayout.Width(80));
            GUILayout.EndHorizontal();

            GUILayout.Space(5);
            GUILayout.BeginHorizontal();
            if (GUILayout.Button("生成切片", GUILayout.Width(80)))
            {
                if (texture == null)
                {
                    Debug.Log("没有选择图集文件");
                }
                else
                {
                    //Debug.Log("aaa");
                    //Debug.Log(select_index);
                    //Debug.Log(_typeExts[select_index]);
                    //Debug.Log(_typeNames[select_index]);

                    float  width  = float.Parse(m_input_w);
                    float  height = float.Parse(m_input_h);
                    string path   = AssetDatabase.GetAssetPath(texture);
                    SpriteAtlasClipUtility.ClipAtlas(path, width, height, clipType);

                    SpriteAtlasWnd.GenAsset_OneFile(path);       //重新生成图集Asset

                    Debug.Log("切片完成:" + path + " --> " + width + ", " + height + ", " + clipType);
                }
            }
            GUILayout.EndHorizontal();

            GUILayout.Space(15);
            GUILayout.BeginVertical();
            GUILayout.Label("手动修改切片后一定要记得保存记录!", GUILayout.ExpandHeight(false));
            if (GUILayout.Button("保存修改记录", GUILayout.Width(80)))
            {
                if (texture == null)
                {
                    Debug.Log("没有选择图集文件");
                }
                else
                {
                    string path = AssetDatabase.GetAssetPath(texture);
                    Debug.Log("开始保存记录:" + path);
                    SpriteAtlasClipUtility.SaveJsonData(path);
                    TypeReadJson();
                }
            }
            GUILayout.EndVertical();
            //}
            //catch (System.Exception e)
            //{
            //    Debug.LogException(e);
            //}
        }