Beispiel #1
0
        /// <summary>
        /// 纹理代理GUI
        /// </summary>
        /// <param name="agent">纹理代理</param>
        /// <param name="isStandard">是否为标准纹理</param>
        private void OnTextureGUI(TextureResizeAgent agent, bool isStandard)
        {
            float widthHalf = _textureWidth * 0.5f;

            GUI.color = isStandard ? Color.white : Color.red;
            GUILayout.BeginHorizontal("Box", GUILayout.Width(_textureWidth), GUILayout.Height(widthHalf));

            EditorGUILayout.ObjectField(agent.Value, typeof(Texture2D), false, GUILayout.Width(widthHalf), GUILayout.Height(widthHalf));

            GUILayout.BeginVertical();
            _nameGC.text    = agent.Value.name;
            _nameGC.tooltip = agent.Path;
            GUILayout.Label(_nameGC, GUILayout.Width(widthHalf));
            _standardGC.image   = isStandard ? null : EditorGUIUtility.IconContent("console.warnicon.sml").image;
            _standardGC.text    = isStandard ? "Standard" : "Raw";
            _standardGC.tooltip = isStandard ? "This texture is standard!" : "This texture is raw!you can resize it to multiple of 4!";
            GUILayout.Label(_standardGC, GUILayout.Width(widthHalf));
            _sizeGC.text    = agent.Size;
            _sizeGC.tooltip = agent.Size;
            GUILayout.Label(_sizeGC, GUILayout.Width(widthHalf));
            GUILayout.EndVertical();

            GUILayout.EndHorizontal();
            GUI.color = Color.white;

            if (!isStandard)
            {
                MouseRightMenu(agent, GUILayoutUtility.GetLastRect());
            }
        }
Beispiel #2
0
        /// <summary>
        /// 移除纹理代理
        /// </summary>
        /// <param name="agent">纹理代理</param>
        private void RemoveAgent(TextureResizeAgent agent)
        {
            _agents.Remove(agent);
            _textureResizer.Agents.Remove(agent);

            ResetPage(false);
        }
Beispiel #3
0
        /// <summary>
        /// 创建纹理缩放代理
        /// </summary>
        /// <param name="guids">纹理GUID</param>
        /// <returns>纹理缩放代理集合</returns>
        internal static List <TextureResizeAgent> CreataResizeAgents(string[] guids)
        {
            List <TextureResizeAgent> agents = new List <TextureResizeAgent>();

            for (int i = 0; i < guids.Length; i++)
            {
                TextureResizeAgent agent = CreataResizeAgent(guids[i]);
                if (agent != null)
                {
                    agents.Add(agent);
                }
            }
            return(agents);
        }
Beispiel #4
0
 /// <summary>
 /// 纹理代理的鼠标右键点击菜单
 /// </summary>
 /// <param name="agent">纹理代理</param>
 /// <param name="rect">纹理代理的显示区域</param>
 private void MouseRightMenu(TextureResizeAgent agent, Rect rect)
 {
     if (Event.current != null && Event.current.rawType == EventType.MouseDown && Event.current.button == 1)
     {
         if (rect.Contains(Event.current.mousePosition))
         {
             GenericMenu gm = new GenericMenu();
             gm.AddItem(new GUIContent("Exclude this texture"), false, () =>
             {
                 RemoveAgent(agent);
             });
             gm.ShowAsContext();
             Event.current.Use();
         }
     }
 }
Beispiel #5
0
        /// <summary>
        /// 所有纹理代理GUI
        /// </summary>
        private void OnAgentsGUI()
        {
            if (_textureResizer != null)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label("All Texture In: " + _folderPath);
                GUILayout.FlexibleSpace();
                string nameFilter = EditorGUILayout.TextField("", _nameFilter, "SearchTextField", GUILayout.Width(180));
                if (nameFilter != _nameFilter)
                {
                    _nameFilter = nameFilter;
                    ResetDisplayAgents();
                }
                if (GUILayout.Button("", _nameFilter != "" ? "SearchCancelButton" : "SearchCancelButtonEmpty", GUILayout.Width(20)))
                {
                    if (_nameFilter != "")
                    {
                        _nameFilter = "";
                        ResetDisplayAgents();
                        GUI.FocusControl(null);
                    }
                }
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label("Total: [" + _agents.Count + "]");
                GUILayout.Space(20);
                GUILayout.Label("Current Page Raw: [" + _rawNumber + "]");
                GUILayout.FlexibleSpace();
                _isResizePng = GUILayout.Toggle(_isResizePng, "png");
                _isResizeJpg = GUILayout.Toggle(_isResizeJpg, "jpg");
                _isResizeTga = GUILayout.Toggle(_isResizeTga, "tga");
                if (GUILayout.Button("Resize To Multiple Of 4", EditorStyles.miniButton))
                {
                    if (EditorUtility.DisplayDialog("Prompt", "Are you sure you want to resize to multiple of 4 at all raw texture2d? this is maybe time consuming!", "Yes", "No"))
                    {
                        List <TextrueResizeFeedback> feedbacks = null;
                        TimeSpan timeSpan = Utility.ExecutionInTimeMonitor(() =>
                        {
                            feedbacks = _textureResizer.ResizeToMultipleOf4(_isResizePng, _isResizeJpg, _isResizeTga);
                        });
                        TextrueResizeFeedbackWindow.OpenWindow(feedbacks, timeSpan);
                    }
                }
                GUILayout.EndHorizontal();

                GUILayout.BeginVertical("HelpBox");
                _scroll    = GUILayout.BeginScrollView(_scroll);
                _rawNumber = 0;
                for (int i = 0; i < _textureCount; i += 6)
                {
                    GUILayout.BeginHorizontal();
                    for (int j = 0; j < 6; j++)
                    {
                        int index = _currentPage * _textureCount + i + j;
                        if (index < _agents.Count)
                        {
                            TextureResizeAgent agent = _agents[index];
                            if (agent.Value == null)
                            {
                                RemoveAgent(agent);
                                j--;
                                continue;
                            }
                            bool isStandard = agent.IsMultipleOf4;
                            if (!isStandard)
                            {
                                _rawNumber += 1;
                            }
                            OnTextureGUI(agent, isStandard);
                        }
                    }
                    GUILayout.EndHorizontal();
                }
                GUILayout.EndScrollView();
                GUILayout.EndVertical();

                GUILayout.BeginHorizontal();
                GUILayout.FlexibleSpace();
                if (GUILayout.Button("Prev Page", EditorStyles.miniButton))
                {
                    PrevPage();
                }
                GUILayout.Label((_currentPage + 1) + "/" + _totalPage);
                if (GUILayout.Button("Next Page", EditorStyles.miniButton))
                {
                    NextPage();
                }
                GUILayout.FlexibleSpace();
                GUILayout.EndHorizontal();

                GUILayout.Space(5);

                KeyboardEvent();
            }
            else
            {
                EditorGUILayout.HelpBox("Please select a target folder, and click 'Search' button to process all texture in target folder!", MessageType.Info);
            }
        }