Unity之EditorUtility.DisplayDialogComplex-六

Unity编辑器类创建复合对话框

在工具栏床架按钮,点击按钮弹出复合框


选择一个图片,点击 “Save Texture to file”,跳出如下窗口




Editor文件夹下创建脚本


using UnityEngine;
using System.Collections;
using UnityEditor;
using System.IO;

public class TestEditor : EditorWindow
{
    [MenuItem("Examples/Save Texture to file")]
    static void Apply()
    {
        Texture2D texture = Selection.activeObject as Texture2D;

        if (!texture)
        {
            //如果没有选择图片,则显示对话框
            EditorUtility.DisplayDialog("Select Texture",
                            "You Must Select a Texture first!",
                            "Ok");
            return;
        }
        //显示保存文件面板,path为得到的选择位置的本地路径
        var path = EditorUtility.SaveFilePanelInProject("Save texture as PNG",
                                texture.name + ".png",
                                "png",
                                "Please enter a file name to save the texture to");
        if (path.Length != 0)
        {
            // Convert the texture to a format compatible with EncodeToPNG
            if (texture.format != TextureFormat.ARGB32 && texture.format != TextureFormat.RGB24)
            {
                Texture2D newTexture = new Texture2D(texture.width, texture.height);
                newTexture.SetPixels(texture.GetPixels(0), 0);
                texture = newTexture;
            }
            var pngData = texture.EncodeToPNG();
            if (pngData != null)
            {
                File.WriteAllBytes(path, pngData);
                // As we are saving to the asset folder, tell Unity to scan for modified or new assets
                AssetDatabase.Refresh();
            }
        }
    }
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Newtonsoft.Json-for-Unity是一种用于Unity开发环境的Json库。该库提供了处理和解析Json数据的功能。 你的引用内容中提到了对于该库在代码中的using的更改以及与其他变体的兼容性问题。根据你的引用内容中的建议,你可以使用Newtonsoft.Json库,并将using语句更改为using Newtonsoft.Json; using Newtonsoft.Json.Linq;来确保正确引用和使用该库。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [Unity2020.3.33使用Newtonsoft.Json.dll用IL2CPP打包PC出错](https://blog.csdn.net/qq_42429534/article/details/126674788)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [Newtonsoft.Json-for-Unity.Converters:Newtonsoft.Json的常见Unity类型的转换器。 与jilleJrNewtonsoft....](https://download.csdn.net/download/weixin_42112894/18775229)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [认真CS☀️Unity中Newtonsoft.Json的使用](https://blog.csdn.net/weixin_38239050/article/details/93474066)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值