Search Unity

  1. Calling all beginners! Join the FPS Beginners Mods Challenge until December 13.
    Dismiss Notice
  2. It's Cyber Week at the Asset Store!
    Dismiss Notice

[FREE] [OPEN-SOURCE] Dialog Module

Discussion in 'Assets and Asset Store' started by samuelvenable, Mar 18, 2019.

  1. samuelvenable

    samuelvenable

    Joined:
    Dec 3, 2018
    Posts:
    1




    Online Documentation: http://dialogmodule.weebly.com/
    GitHub: https://github.com/time-killer-games/DialogModule/

    Mac and Linux Testers needed!

    So far, I've only tested this with Unity's Windows export. It works beautifully on there. Although the multi-select dialog has some strange behavior that is Windows-specific, and does not occur on Mac or Linux. My MacBook has a case-sensitive file-system, so Unity won't run on that, and I'm still in the process of trying to figure out a workaround. Mac users will need to rename "DialogModule.dylib" file to "DialogModule.bundle" to be used. I have tested this on Mac and Linux with a couple other software and so I'm sure it'll be fine.

    Features
    • For Windows/Mac/Linux
    • Seamlessly Cross-Platform
    • 32-bit/64-bit Support
    • OKOnly MsgBox
    • OK/Cancel MsgBox
    • Yes/No QuestionBox
    • Yes/No/Cancel QuestionBox
    • Retry/Cancel ErrorMsg
    • Abort/Retry/Ignore ErrorMsg
    • String InputBox
    • Number InputBox
    • String PasswordBox
    • Number PasswordBox
    • Open File Dialog
    • Multi-Select File Dialog
    • Save File Dialog
    • Choose Folder Dialog
    • Color Picker Dialog
    • Multiple File Filters
    • GTK+/KDE for Linux
    • Full UTF-8 Support
    • Native Win32 API on Windows
    • Native Cocoa API on Mac
    • Uses Shell Scripts on Linux
    • Permissive MIT License
    • Demo Executables Included
    • Online Docs
    Here's an example C# script that demonstrates most of the functions available, please refer to the exported functions in the source code for using any additional functions not listed here:

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Runtime.InteropServices;
    3. using System.Diagnostics;
    4. using System;
    5.  
    6. public class DialogModule : MonoBehaviour {
    7.  
    8.     #if UNITY_STANDALONE_WIN
    9.     [DllImport("DialogModule.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    10.     #elif UNITY_STANDALONE_OSX
    11.     [DllImport("DialogModule.bundle", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    12.     #elif UNITY_STANDALONE_LINUX
    13.     [DllImport("DialogModule.so", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    14.     #endif
    15.  
    16.     #if UNITY_STANDALONE
    17.     private static extern double show_message(string str);
    18.     #endif
    19.  
    20.     double ShowMessage(string Str) {
    21.  
    22.         #if UNITY_STANDALONE
    23.         return show_message(Str);
    24.         #else
    25.         return -1;
    26.         #endif
    27.  
    28.     }
    29.  
    30.     #if UNITY_STANDALONE_WIN
    31.     [DllImport("DialogModule.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    32.     #elif UNITY_STANDALONE_OSX
    33.     [DllImport("DialogModule.bundle", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    34.     #elif UNITY_STANDALONE_LINUX
    35.     [DllImport("DialogModule.so", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    36.     #endif
    37.  
    38.     #if UNITY_STANDALONE
    39.     private static extern double show_question(string str);
    40.     #endif
    41.  
    42.     double ShowQuestion(string Str) {
    43.  
    44.         #if UNITY_STANDALONE
    45.         return show_question(Str);
    46.         #else
    47.         return -1;
    48.         #endif
    49.  
    50.     }
    51.  
    52.     #if UNITY_STANDALONE_WIN
    53.     [DllImport("DialogModule.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    54.     #elif UNITY_STANDALONE_OSX
    55.     [DllImport("DialogModule.bundle", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    56.     #elif UNITY_STANDALONE_LINUX
    57.     [DllImport("DialogModule.so", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    58.     #endif
    59.  
    60.     #if UNITY_STANDALONE
    61.     private static extern double show_error(string str, double abort);
    62.     #endif
    63.  
    64.     double ShowError(string Str, double Abort) {
    65.  
    66.         #if UNITY_STANDALONE
    67.         return show_error(Str, Abort);
    68.         #else
    69.         return -1;
    70.         #endif
    71.  
    72.     }
    73.  
    74.     #if UNITY_STANDALONE_WIN
    75.     [DllImport("DialogModule.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    76.     #elif UNITY_STANDALONE_OSX
    77.     [DllImport("DialogModule.bundle", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    78.     #elif UNITY_STANDALONE_LINUX
    79.     [DllImport("DialogModule.so", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    80.     #endif
    81.  
    82.     #if UNITY_STANDALONE
    83.     private static extern IntPtr get_string(string str, string def);
    84.     #endif
    85.  
    86.     string GetString(string Str, string Def) {
    87.  
    88.         #if UNITY_STANDALONE
    89.         return System.Runtime.InteropServices.Marshal.PtrToStringAnsi(get_string(Str, Def));
    90.         #else
    91.         return "NaN";
    92.         #endif
    93.  
    94.     }
    95.  
    96.     #if UNITY_STANDALONE_WIN
    97.     [DllImport("DialogModule.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    98.     #elif UNITY_STANDALONE_OSX
    99.     [DllImport("DialogModule.bundle", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    100.     #elif UNITY_STANDALONE_LINUX
    101.     [DllImport("DialogModule.so", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    102.     #endif
    103.  
    104.     #if UNITY_STANDALONE
    105.     private static extern IntPtr get_password(string str, string def);
    106.     #endif
    107.  
    108.     string GetPassword(string Str, string Def) {
    109.  
    110.         #if UNITY_STANDALONE
    111.         return System.Runtime.InteropServices.Marshal.PtrToStringAnsi(get_password(Str, Def));
    112.         #else
    113.         return "NaN";
    114.         #endif
    115.  
    116.     }
    117.  
    118.     #if UNITY_STANDALONE_WIN
    119.     [DllImport("DialogModule.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    120.     #elif UNITY_STANDALONE_OSX
    121.     [DllImport("DialogModule.bundle", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    122.     #elif UNITY_STANDALONE_LINUX
    123.     [DllImport("DialogModule.so", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    124.     #endif
    125.  
    126.     #if UNITY_STANDALONE
    127.     private static extern double get_integer(string str, double def);
    128.     #endif
    129.  
    130.     double GetInteger(string Str, double Def) {
    131.  
    132.         #if UNITY_STANDALONE
    133.         return get_integer(Str, Def);
    134.         #else
    135.         return -1;
    136.         #endif
    137.  
    138.     }
    139.  
    140.     #if UNITY_STANDALONE_WIN
    141.     [DllImport("DialogModule.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    142.     #elif UNITY_STANDALONE_OSX
    143.     [DllImport("DialogModule.bundle", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    144.     #elif UNITY_STANDALONE_LINUX
    145.     [DllImport("DialogModule.so", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    146.     #endif
    147.  
    148.     #if UNITY_STANDALONE
    149.     private static extern double get_passcode(string str, double def);
    150.     #endif
    151.  
    152.     double GetPasscode(string Str, double Def) {
    153.  
    154.         #if UNITY_STANDALONE
    155.         return get_passcode(Str, Def);
    156.         #else
    157.         return -1;
    158.         #endif
    159.  
    160.     }
    161.  
    162.     #if UNITY_STANDALONE_WIN
    163.     [DllImport("DialogModule.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    164.     #elif UNITY_STANDALONE_OSX
    165.     [DllImport("DialogModule.bundle", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    166.     #elif UNITY_STANDALONE_LINUX
    167.     [DllImport("DialogModule.so", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    168.     #endif
    169.  
    170.     #if UNITY_STANDALONE
    171.     private static extern IntPtr get_open_filename(string filter, string fname);
    172.     #endif
    173.  
    174.     string GetOpenFileName(string Filter, string FName) {
    175.  
    176.         #if UNITY_STANDALONE
    177.         return System.Runtime.InteropServices.Marshal.PtrToStringAnsi(get_open_filename(Filter, FName));
    178.         #else
    179.         return "NaN";
    180.         #endif
    181.  
    182.     }
    183.  
    184.     #if UNITY_STANDALONE_WIN
    185.     [DllImport("DialogModule.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    186.     #elif UNITY_STANDALONE_OSX
    187.     [DllImport("DialogModule.bundle", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    188.     #elif UNITY_STANDALONE_LINUX
    189.     [DllImport("DialogModule.so", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    190.     #endif
    191.  
    192.     #if UNITY_STANDALONE
    193.     private static extern IntPtr get_open_filename_ext(string filter, string fname, string dir, string title);
    194.     #endif
    195.  
    196.     string GetOpenFileNameExt(string Filter, string FName, string Dir, string Title) {
    197.  
    198.         #if UNITY_STANDALONE
    199.         return System.Runtime.InteropServices.Marshal.PtrToStringAnsi(get_open_filename_ext(Filter, FName, Dir, Title));
    200.         #else
    201.         return "NaN";
    202.         #endif
    203.  
    204.     }
    205.  
    206.     #if UNITY_STANDALONE_WIN
    207.     [DllImport("DialogModule.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    208.     #elif UNITY_STANDALONE_OSX
    209.     [DllImport("DialogModule.bundle", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    210.     #elif UNITY_STANDALONE_LINUX
    211.     [DllImport("DialogModule.so", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    212.     #endif
    213.  
    214.     #if UNITY_STANDALONE
    215.     private static extern IntPtr get_open_filenames(string filter, string fname);
    216.     #endif
    217.  
    218.     string GetOpenFileNames(string Filter, string FName)
    219.     {
    220.  
    221.         #if UNITY_STANDALONE
    222.         return System.Runtime.InteropServices.Marshal.PtrToStringAnsi(get_open_filenames(Filter, FName));
    223.         #else
    224.         return "NaN";
    225.         #endif
    226.  
    227.     }
    228.  
    229.     #if UNITY_STANDALONE_WIN
    230.     [DllImport("DialogModule.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    231.     #elif UNITY_STANDALONE_OSX
    232.     [DllImport("DialogModule.bundle", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    233.     #elif UNITY_STANDALONE_LINUX
    234.     [DllImport("DialogModule.so", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    235.     #endif
    236.  
    237.     #if UNITY_STANDALONE
    238.     private static extern IntPtr get_open_filenames_ext(string filter, string fname, string dir, string title);
    239.     #endif
    240.  
    241.     string GetOpenFileNamesExt(string Filter, string FName, string Dir, string Title)
    242.     {
    243.  
    244.         #if UNITY_STANDALONE
    245.         return System.Runtime.InteropServices.Marshal.PtrToStringAnsi(get_open_filenames_ext(Filter, FName, Dir, Title));
    246.         #else
    247.         return "NaN";
    248.         #endif
    249.  
    250.     }
    251.  
    252.     #if UNITY_STANDALONE_WIN
    253.     [DllImport("DialogModule.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    254.     #elif UNITY_STANDALONE_OSX
    255.     [DllImport("DialogModule.bundle", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    256.     #elif UNITY_STANDALONE_LINUX
    257.     [DllImport("DialogModule.so", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    258.     #endif
    259.  
    260.     #if UNITY_STANDALONE
    261.     private static extern IntPtr get_save_filename(string filter, string fname);
    262.     #endif
    263.  
    264.     string GetSaveFileName(string Filter, string FName) {
    265.  
    266.         #if UNITY_STANDALONE
    267.         return System.Runtime.InteropServices.Marshal.PtrToStringAnsi(get_save_filename(Filter, FName));
    268.         #else
    269.         return "NaN";
    270.         #endif
    271.  
    272.     }
    273.  
    274.     #if UNITY_STANDALONE_WIN
    275.     [DllImport("DialogModule.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    276.     #elif UNITY_STANDALONE_OSX
    277.     [DllImport("DialogModule.bundle", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    278.     #elif UNITY_STANDALONE_LINUX
    279.     [DllImport("DialogModule.so", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    280.     #endif
    281.  
    282.     #if UNITY_STANDALONE
    283.     private static extern IntPtr get_save_filename_ext(string filter, string fname, string dir, string title);
    284.     #endif
    285.  
    286.     string GetSaveFileNameExt(string Filter, string FName, string Dir, string Title) {
    287.  
    288.         #if UNITY_STANDALONE
    289.         return System.Runtime.InteropServices.Marshal.PtrToStringAnsi(get_save_filename_ext(Filter, FName, Dir, Title));
    290.         #else
    291.         return "NaN";
    292.         #endif
    293.  
    294.     }
    295.  
    296.     #if UNITY_STANDALONE_WIN
    297.     [DllImport("DialogModule.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    298.     #elif UNITY_STANDALONE_OSX
    299.     [DllImport("DialogModule.bundle", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    300.     #elif UNITY_STANDALONE_LINUX
    301.     [DllImport("DialogModule.so", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    302.     #endif
    303.  
    304.     #if UNITY_STANDALONE
    305.     private static extern IntPtr get_directory(string dname);
    306.     #endif
    307.  
    308.     string GetDirectory(string DName) {
    309.  
    310.         #if UNITY_STANDALONE
    311.         return System.Runtime.InteropServices.Marshal.PtrToStringAnsi(get_directory(DName));
    312.         #else
    313.         return "NaN";
    314.         #endif
    315.  
    316.     }
    317.  
    318.     #if UNITY_STANDALONE_WIN
    319.     [DllImport("DialogModule.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    320.     #elif UNITY_STANDALONE_OSX
    321.     [DllImport("DialogModule.bundle", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    322.     #elif UNITY_STANDALONE_LINUX
    323.     [DllImport("DialogModule.so", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    324.     #endif
    325.  
    326.     #if UNITY_STANDALONE
    327.     private static extern IntPtr get_directory_alt(string capt, string root);
    328.     #endif
    329.  
    330.     string GetDirectoryAlt(string Capt, string Root) {
    331.  
    332.         #if UNITY_STANDALONE
    333.         return System.Runtime.InteropServices.Marshal.PtrToStringAnsi(get_directory_alt(Capt, Root));
    334.         #else
    335.         return "NaN";
    336.         #endif
    337.  
    338.     }
    339.  
    340.     #if UNITY_STANDALONE_WIN
    341.     [DllImport("DialogModule.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    342.     #elif UNITY_STANDALONE_OSX
    343.     [DllImport("DialogModule.bundle", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    344.     #elif UNITY_STANDALONE_LINUX
    345.     [DllImport("DialogModule.so", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    346.     #endif
    347.  
    348.     #if UNITY_STANDALONE
    349.     private static extern double get_color(double defcol);
    350.     #endif
    351.  
    352.     double GetColor(double DefCol) {
    353.  
    354.         #if UNITY_STANDALONE
    355.         return get_color(DefCol);
    356.         #else
    357.         return -1;
    358.         #endif
    359.  
    360.     }
    361.  
    362.     #if UNITY_STANDALONE_WIN
    363.     [DllImport("DialogModule.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    364.     #elif UNITY_STANDALONE_OSX
    365.     [DllImport("DialogModule.bundle", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    366.     #elif UNITY_STANDALONE_LINUX
    367.     [DllImport("DialogModule.so", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    368.     #endif
    369.  
    370.     #if UNITY_STANDALONE
    371.     private static extern double get_color_ext(double defcol, string title);
    372.     #endif
    373.  
    374.     double GetColorExt(double DefCol, string Title)
    375.     {
    376.  
    377.         #if UNITY_STANDALONE
    378.         return get_color_ext(DefCol, Title);
    379.         #else
    380.         return -1;
    381.         #endif
    382.  
    383.     }
    384.  
    385.     void Start() {
    386.  
    387.         string Str;
    388.  
    389.         Str = ShowMessage("Hello World!").ToString();
    390.         ShowMessage(Str);
    391.  
    392.         Str = ShowQuestion("Yes or no?").ToString();
    393.         ShowMessage(Str);
    394.  
    395.         Str = ShowError("Hello World!", 0).ToString();
    396.         ShowMessage(Str);
    397.  
    398.         Str = GetString("Enter a string:", "Hello World!");
    399.         if (Str != "") ShowMessage(Str);
    400.  
    401.         Str = GetPassword("Enter a string password:", "Hello World!");
    402.         if (Str != "") ShowMessage(Str);
    403.  
    404.         Str = GetInteger("Enter an integer:", 0).ToString();
    405.         ShowMessage(Str);
    406.  
    407.         Str = GetPasscode("Enter an integer passcode:", 0).ToString();
    408.         ShowMessage(Str);
    409.  
    410.         string Filter = "Sprite Images (*.png *.gif *.jpg *.jpeg)|*.png;*.gif;*.jpg;*.jpeg|Background Images (*.png)|*.png|All Files (*.*)|*.*";
    411.  
    412.         Str = GetOpenFileName(Filter, "Select a File");
    413.         if (Str != "") ShowMessage(Str);
    414.  
    415.         Str = GetOpenFileNameExt(Filter, "Select a File", "", "Open Ext");
    416.         if (Str != "") ShowMessage(Str);
    417.  
    418.         Str = GetOpenFileNames(Filter, "Select Files");
    419.         if (Str != "") ShowMessage(Str);
    420.  
    421.         Str = GetOpenFileNamesExt(Filter, "Select Files", "", "Open Ext");
    422.         if (Str != "") ShowMessage(Str);
    423.  
    424.         Str = GetSaveFileName(Filter, "Untitled.png");
    425.         if (Str != "") ShowMessage(Str);
    426.  
    427.         Str = GetSaveFileNameExt(Filter, "Untitled.png", "", "Save As Ext");
    428.         if (Str != "") if (Str != "") ShowMessage(Str);
    429.  
    430.         Str = GetDirectory("");
    431.         if (Str != "") ShowMessage(Str);
    432.  
    433.         Str = GetDirectoryAlt("Get Directory Alt", "");
    434.         if (Str != "") ShowMessage(Str);
    435.  
    436.         double CRed = 255;
    437.  
    438.         Str = GetColor(CRed).ToString();
    439.         ShowMessage(Str);
    440.  
    441.         #if UNITY_STANDALONE_OSX
    442.         string title = "Colors Ext";
    443.         #else
    444.         string title = "Color Ext";
    445.         #endif
    446.  
    447.         Str = GetColorExt(CRed, title).ToString();
    448.         ShowMessage(Str);
    449.  
    450.         Application.Quit();
    451.  
    452.     }
    453.  
    454.     void Update() {
    455.  
    456.     }
    457. }
    458.  

    Also I'm aware the get_integer() function doesn't take or return an integer, but rather, a double. This is based on GameMaker Studio's retarded function naming choices; I didn't change it because I wanted it to override GameMaker's built-in function as these functions do with that engine. Don't blame me; blame YoYoGames.

    I hope more people find this useful here. It's not getting much attention on the GameMaker Community, so I thought to share it here, since it offers quite a few things that Unity can't do on it's own, just like GameMaker.
     
    Last edited: Nov 9, 2019