• Unity3D 调用模态对话框/Unity3D MessageBox


    Unity模态对话框/Unity MessageBox

    很多时候,我们需要将Unity的exe产品发布到某一个平台。比如某某斗地主发布到某Q游戏。
    这时候如果需要调试肿么办。办法无外乎那几个。
    1:源码调试,前提是整套系统全都是你们家公司的。
    2:附加进程,对启动运行的游戏,在monodevelop中进行附加进程调试,如果不是毕现的,这也是很蛋疼。
    3:日志,unity的日志功能很渣渣,稍不注意就会出现日志内容字符混乱,神龙见首不见尾,漫漫日志中找内
    容,无比蛋疼,最坑爹的是不一定在最后崩溃时刻能成功记录讯息。
    4:本次重点啊:MessageBox,爽快的模态对话框,这个东西就可以达到,仅在异常的时候出现模态对话框,

    锁定程序进程,其他时候程序随便跑啦。。。下面开始了:

    怎么用呢,MessageBox存在于System.Windows.Forms.dll中,这个东西请各位看官别漏了啊。
    把它放到Unity工程Assets/Plugins/下这时候程序就自动添加引用的。
    接下来就是把unity的PlayerSettings中 Api Compatibility Level改为NET2.0。
    这样子,侬才能在程序using了。
    在使用【using System.Windows.Forms.MessageBox】后某些地方会提示类冲突。比如Application类;
    这时候可以使用【using MsgBoxBase = System.Windows.Forms.MessageBox】替代,笔者就是这么凑合用的呢;

    介个时候就可以使用MessageBox鸟。下面看看他给我们提供了什么呢?

    ==============================================================

    namespace System.Windows.Forms
    {
        public class MessageBox
        {
            public static DialogResult Show(string text);
            public static DialogResult Show(IWin32Window owner, string text);
            public static DialogResult Show(string text, string caption);
            public static DialogResult Show(IWin32Window owner, string text, string caption);
            public static DialogResult Show(string text, string caption, MessageBoxButtons buttons);
            public static DialogResult Show(IWin32Window owner, string text, string caption, MessageBoxButtons buttons);
            public static DialogResult Show(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon);
            public static DialogResult Show(IWin32Window owner, string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon);
            public static DialogResult Show(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton);
            public static DialogResult Show(IWin32Window owner, string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton);
            public static DialogResult Show(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, MessageBoxOptions options);
            public static DialogResult Show(IWin32Window owner, string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, MessageBoxOptions options);
        }
    }

    ==============================================================

    这样子 ,你就可以

    if(5<6){

    MsgBoxBase.Show("Unity启禀大人,帖子又成功传播知识鸟!", this.GetType().Name, WinForms.MessageBoxButtons.OK, WinForms.MessageBoxIcon.Error);

    }

    就这样,就可以在程序中只针对异常错误跳出模态对话框,你不关闭,程序也就老老实实的等着你呢。

    MessageBoxButtons 枚举参考:

    http://msdn.microsoft.com/zh-cn/library/system.windows.forms.messageboxbuttons%28v=vs.110%29.aspx

    MessageBoxIcon 枚举参考:

    http://msdn.microsoft.com/zh-cn/library/system.windows.forms.messageboxicon.aspx

  • 相关阅读:
    高效的多维空间点索引算法 — Geohash 和 Google S2
    Geohash距离估算
    位图(BitMap)索引
    深入浅出空间索引:为什么需要空间索引
    harbor rest api 转graphql api
    ringojs java jar 集成使用
    ringojs 使用rp 包管理web 应用依赖
    ringojs 的包管理
    ringojs 基于jvm 的javascript 平台试用
    graphql cli 开发graphql api flow
  • 原文地址:https://www.cnblogs.com/2Yous/p/5079965.html
Copyright © 2020-2023  润新知