惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

P
Proofpoint News Feed
H
Hacker News: Front Page
C
CXSECURITY Database RSS Feed - CXSecurity.com
C
Cisco Blogs
P
Palo Alto Networks Blog
Know Your Adversary
Know Your Adversary
D
Darknet – Hacking Tools, Hacker News & Cyber Security
C
Cybersecurity and Infrastructure Security Agency CISA
AWS News Blog
AWS News Blog
Spread Privacy
Spread Privacy
S
Schneier on Security
The Hacker News
The Hacker News
Cyberwarzone
Cyberwarzone
T
Tenable Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
T
Tailwind CSS Blog
S
Secure Thoughts
N
Netflix TechBlog - Medium
T
The Exploit Database - CXSecurity.com
I
Intezer
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Help Net Security
Help Net Security
K
Kaspersky official blog
Google Online Security Blog
Google Online Security Blog
L
LangChain Blog
Martin Fowler
Martin Fowler
L
LINUX DO - 热门话题
Hacker News: Ask HN
Hacker News: Ask HN
www.infosecurity-magazine.com
www.infosecurity-magazine.com
有赞技术团队
有赞技术团队
P
Privacy International News Feed
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Recent Announcements
Recent Announcements
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
The Register - Security
The Register - Security
云风的 BLOG
云风的 BLOG
Google DeepMind News
Google DeepMind News
阮一峰的网络日志
阮一峰的网络日志
WordPress大学
WordPress大学
Recorded Future
Recorded Future
The Last Watchdog
The Last Watchdog
G
Google Developers Blog
T
Threatpost
小众软件
小众软件
S
Securelist
Recent Commits to openclaw:main
Recent Commits to openclaw:main
O
OpenAI News

博客园 - kingBook

git patch git 修改最后一次提交的日期 Win10 修改特定格式文件的右键快捷菜单 TypeScript async、 await、Promise LayaAir3.x 侦听程序退出 旋转力学例子 旋转力学公式 凹多边形碰撞检测 LayaAir3.x 侦听键盘事件 URP 阴影 TypeScript 里的 override TypeScript 类的自身类型 Unity 二维数组序列化 C# 匿名对象、动态属性 Cocos Creator 安卓模拟器中无法运行 LayaAir3.2.0-beta.2 设置2d刚体线性速度,在不同设备(分辨率)下,表现不一致的问题 LayaAir3.x 物理2D碰撞事件 TypeScirpt 声明Map类型变量 TypeScript 声明函数类型变量
Unity Editor 保存图片、缩放纹理
kingBook · 2024-08-16 · via 博客园 - kingBook
using System.IO;
using UnityEditor;
using UnityEngine;

public class ConvertIconToMultipleSizes : Editor {
    [MenuItem("Assets/Convert Icon To Multiple Sizes", true)]
    private static bool ValidateSplitFbxAnimation() {
        if (Selection.count == 1) {
            if (Selection.activeObject is Texture2D) {
                return true;
            }
        }
        return false;
    }

    [MenuItem("Assets/Convert Icon To Multiple Sizes")]
    private static void SplitFbxAnimation() {
        if (Selection.count == 1) {
            if (Selection.activeObject is Texture2D) {
                Texture2D source = Selection.activeObject as Texture2D;
                string sourcePath = AssetDatabase.GUIDToAssetPath(Selection.assetGUIDs[0]);

                Texture2D result = ScaleTexture(source, 36, 36);
                byte[] bytes = result.EncodeToPNG();

                string sourceFolderPath = Path.GetDirectoryName(sourcePath).Replace("\\", "/");
                string newFolderPath = sourceFolderPath + "/Icons";

                if (!File.Exists(newFolderPath)) {
                    Directory.CreateDirectory(newFolderPath);
                }

                string outputPath = $"{newFolderPath}/icon36x36.png";
                File.WriteAllBytes(outputPath, bytes);
                AssetDatabase.Refresh();
            }
        }
    }


    /// <summary>
    /// 缩放纹理
    /// <para>
    /// 注意:
    /// source 源纹理的 Read/Write 开关需要在 Inspector 中打开,
    /// 不能勾选 Use Crunch Compression
    /// </para>
    /// </summary>
    public static Texture2D ScaleTexture(Texture2D source, int targetWidth, int targetHeight) {
        Texture2D result = new(targetWidth, targetHeight);
        Color[] rpixels = new Color[targetWidth * targetHeight];
        float incX = ((float)1 / source.width) * ((float)source.width / targetWidth);
        float incY = ((float)1 / source.height) * ((float)source.height / targetHeight);
        for (int px = 0; px < rpixels.Length; px++) {
            rpixels[px] = source.GetPixelBilinear(incX * ((float)px % targetWidth), incY * (Mathf.Floor((float)px / targetWidth)));
        }
        result.SetPixels(rpixels, 0);
        result.Apply();
        return result;
    }
}