图片替换工具

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

enum ImageOptions
{
    Load_AppLogo, Load_Outside, Load_Inside, Load_BG,
    Main_ArCam, Main_PDF, Main_BG,
    Content_Return, Content_Capture, Content_PlaySound, Content_PlyaAnimation, Content_Version
}

public class ArtBoot : EditorWindow
{

    bool isLoadMode = false;
    bool isMainMode = false;
    bool isContentMode = false;

    string sourcepath;
    string destpath;

    public string urlToEdit = "";
    string urlDestPath;

    [MenuItem("AR工具/美术引导")]

    static void Init()
    {
        ArtBoot filter = (ArtBoot)EditorWindow.GetWindow(typeof(ArtBoot));
        filter.Show();
    }
        
    void OnGUI()
    {  
        EditorGUILayout.LabelField("1.点击对应按钮,导入并更新对应资源。");
        EditorGUILayout.LabelField("2.填入PDF下载链接URL。");
        EditorGUILayout.LabelField("3.PS保存时,统一成Web所用格式png。");
        EditorGUILayout.LabelField("4.UI目标路径:Assets/Resources/UI。");

        EditorGUILayout.BeginHorizontal();
        GUI.color = Color.cyan;
        if(GUILayout.Button("加载界面设置"))
        {
            isLoadMode = true;
            isMainMode = false;
            isContentMode = false;
        }

        GUI.color = Color.red;
        if (GUILayout.Button("主界面设置"))
        {
            isLoadMode = false;
            isMainMode = true;
            isContentMode = false;
        }

        GUI.color = Color.yellow;
        if (GUILayout.Button("内容界面设置"))
        {
            isLoadMode = false;
            isMainMode = false;
            isContentMode = true;
        }
        EditorGUILayout.EndHorizontal();

        GUI.color = Color.white;

        if(isLoadMode)
        {
            GUI.color = Color.cyan;
            
            if(GUILayout.Button("产品LOGO图标"))
            {
                imageLoad(ImageOptions.Load_AppLogo);
            }
            if (GUILayout.Button("加载外框图标"))
            {
                imageLoad(ImageOptions.Load_Outside);
            }
            if (GUILayout.Button("加载读条图标"))
            {
                imageLoad(ImageOptions.Load_Inside);
            }
            if (GUILayout.Button("加载界面背景图片"))
            {
                imageLoad(ImageOptions.Load_BG);
            }
            GUI.color = Color.white;
        }

        if (isMainMode)
        {
            GUI.color = Color.red;
            if (GUILayout.Button("AR相机按钮图标"))
            {
                imageLoad (ImageOptions.Main_ArCam);
            }
            if (GUILayout.Button("PDF帮助按钮图标"))
            {
                imageLoad (ImageOptions.Main_PDF);
            }

            GUI.SetNextControlName ("pdfUrlText");
            urlToEdit = TextField ("PDF下载地址: ", urlToEdit).ToString ();
            

            if (GUILayout.Button("生成下载地址"))
            {
                if (urlToEdit.Length == 0) {
                    EditorUtility.DisplayDialog ("错误", "PDF下载地址不能为空!", "OK");
                } 
                else 
                {
                    urlDestPath = Application.dataPath + "/Resources/UI/url.txt";  
                    StreamWriter writer = new StreamWriter (urlDestPath,true); 
                    writer.WriteLine (urlToEdit);  //https://docs.unity3d.com/ScriptReference/menu.pdf
                    writer.Close ();

                    AssetDatabase.Refresh();
                }
            }
                

            if (GUILayout.Button("主界面背景图片"))
            {
                imageLoad (ImageOptions.Main_BG);
            }
            GUI.color = Color.white;
        }


        if (isContentMode)
        {
            GUI.color = Color.yellow;
            if (GUILayout.Button("返回按钮图标"))
            {
                imageLoad (ImageOptions.Content_Return);
            }
            if (GUILayout.Button("截取单帧按钮图标"))
            {
                imageLoad (ImageOptions.Content_Capture);
            }

            if (GUILayout.Button("播放声音按钮图标"))
            {
                imageLoad (ImageOptions.Content_PlaySound);
            }

            if (GUILayout.Button("播放动画按钮图标"))
            {
                imageLoad (ImageOptions.Content_PlyaAnimation);
            }

            if (GUILayout.Button("版本图标"))
            {
                imageLoad (ImageOptions.Content_Version);
            }
            GUI.color = Color.white;
        }
    }   

    //<summary>        
    //Load new image and override the old one in project
    //</summary>
    void imageLoad(ImageOptions ops)
    {
        sourcepath = EditorUtility.OpenFilePanel("Overwrite with png", "", "png");

        switch (ops) 
        {
        case ImageOptions.Load_AppLogo:
            destpath = Application.dataPath + "/Resources/UI/Load_AppLogo.png";
            break;
        case ImageOptions.Load_Outside:
            destpath = Application.dataPath + "/Resources/UI/Load_Outside.png";
            break;
        case ImageOptions.Load_Inside:
            destpath = Application.dataPath + "/Resources/UI/Load_Inside.png";
            break;
        case ImageOptions.Load_BG:
            destpath = Application.dataPath + "/Resources/UI/Load_BG.png";
            break;

        case ImageOptions.Main_ArCam:
            destpath = Application.dataPath + "/Resources/UI/Main_ArCam.png";
            break;
        case ImageOptions.Main_PDF:
            destpath = Application.dataPath + "/Resources/UI/Main_PDF.png";
            break;
        case ImageOptions.Main_BG:
            destpath = Application.dataPath + "/Resources/UI/Main_BG.png";
            break;

        case ImageOptions.Content_Return:
            destpath = Application.dataPath + "/Resources/UI/Content_Return.png";
            break;
        case ImageOptions.Content_Capture:
            destpath = Application.dataPath + "/Resources/UI/Content_Capture.png";
            break;
        case ImageOptions.Content_PlaySound:
            destpath = Application.dataPath + "/Resources/UI/Content_PlaySound.png";
            break;
        case ImageOptions.Content_PlyaAnimation:
            destpath = Application.dataPath + "/Resources/UI/Content_PlyaAnimation.png";
            break;
        case ImageOptions.Content_Version:
            destpath = Application.dataPath + "/Resources/UI/Content_Version.png";
            break;
        }
            

        if (!sourcepath.Equals ("")) {
            FileUtil.ReplaceFile (sourcepath, destpath);
        } else {
            EditorUtility.DisplayDialog ("错误", "图片路径不能为空!", "OK");
        }
        
        AssetDatabase.Refresh();
    }

    //<summary>        
    //Create a EditorGUILayout.TextField with no space between label and text field
    //</summary>
    string TextField(string label, string text)
    {
        var textDimensions = GUI.skin.label.CalcSize(new GUIContent(label));
        EditorGUIUtility.labelWidth = textDimensions.x;
        return EditorGUILayout.TextField(label, text);
    }
}

 

转载于:https://www.cnblogs.com/JimmyCode/p/6945051.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值