コード例 #1
0
        /// <summary>
        /// 缩放纹理尺寸为4的倍数
        /// </summary>
        /// <param name="isResizePng">是否处理png格式纹理</param>
        /// <param name="isResizeJpg">是否处理jpg格式纹理</param>
        /// <param name="isResizeTga">是否处理tga格式纹理</param>
        /// <returns>处理的反馈信息</returns>
        public List <TextrueResizeFeedback> ResizeToMultipleOf4(bool isResizePng, bool isResizeJpg, bool isResizeTga)
        {
            List <TextrueResizeFeedback> feedbacks = new List <TextrueResizeFeedback>();

            for (int i = 0; i < Agents.Count; i++)
            {
                if (!isResizePng && Agents[i] is PngResizeAgent)
                {
                    continue;
                }
                if (!isResizeJpg && Agents[i] is JpgResizeAgent)
                {
                    continue;
                }
                if (!isResizeTga && Agents[i] is TgaResizeAgent)
                {
                    continue;
                }

                TextrueResizeFeedback feedback = Agents[i].ResizeToMultipleOf4();
                if (feedback != null)
                {
                    feedbacks.Add(feedback);
                }

                if (EditorUtility.DisplayCancelableProgressBar("Textrue Resize", Agents[i].Path, (float)i / Agents.Count))
                {
                    break;
                }
            }
            EditorUtility.ClearProgressBar();
            return(feedbacks);
        }
コード例 #2
0
        /// <summary>
        /// 缩放纹理尺寸为4的倍数
        /// </summary>
        /// <returns>处理结果</returns>
        public virtual TextrueResizeFeedback ResizeToMultipleOf4()
        {
            //加载原纹理
            LoadValue();

            if (IsMultipleOf4)
            {
                return(null);
            }

            //读取原纹理设置
            ReadSettings();

            //开启纹理的可读、可写模式
            Utility.SetReadableEnable(Importer);

            //反馈信息:记录原纹理信息
            TextrueResizeFeedback feedback = new TextrueResizeFeedback();

            feedback.Name             = Path;
            feedback.RawStorageMemory = Utility.GetStorageMemorySize(Value);
            feedback.RawRuntimeMemory = Utility.GetRuntimeMemorySize(Value);
            feedback.RawWidth         = Value.width;
            feedback.RawHeight        = Value.height;

            //计算新纹理尺寸
            int widthDiff  = Value.width % 4;
            int heightDiff = Value.height % 4;
            int width      = widthDiff == 0 ? Value.width : (Value.width + (4 - widthDiff));
            int height     = heightDiff == 0 ? Value.height : (Value.height + (4 - heightDiff));

            //构造新纹理
            Texture2D texture = new Texture2D(width, height, GetFormat(), false);

            SetNewTexturePixels(width, height, texture, Value);
            WriteToFile(texture);

            //应用新纹理设置
            ApplySettings();

            //加载新纹理
            LoadValue(true);

            //反馈信息:记录新纹理信息
            feedback.Value         = Value;
            feedback.StorageMemory = Utility.GetStorageMemorySize(Value);
            feedback.RuntimeMemory = Utility.GetRuntimeMemorySize(Value);
            feedback.Width         = Value.width;
            feedback.Height        = Value.height;

            //关闭纹理的可读、可写模式
            Utility.SetReadableDisabled(Importer);

            return(feedback);
        }
コード例 #3
0
        /// <summary>
        /// 缩放纹理尺寸为4的倍数
        /// </summary>
        /// <returns>处理的反馈信息</returns>
        public List <TextrueResizeFeedback> ResizeToMultipleOf4()
        {
            List <TextrueResizeFeedback> feedbacks = new List <TextrueResizeFeedback>();

            for (int i = 0; i < Agents.Count; i++)
            {
                TextrueResizeFeedback feedback = Agents[i].ResizeToMultipleOf4();
                if (feedback != null)
                {
                    feedbacks.Add(feedback);
                }

                if (EditorUtility.DisplayCancelableProgressBar("Textrue Resize", Agents[i].Path, (float)i / Agents.Count))
                {
                    break;
                }
            }
            EditorUtility.ClearProgressBar();
            return(feedbacks);
        }