Search Unity

[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:
    2


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

    Note: Mac users will need to rename "DialogModule.dylib" file to "DialogModule.bundle".

    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/Qt for Linux
    • Full UTF-8 Support
    • Native Win32 API on Windows
    • Native Cocoa API on Mac
    • Uses Shell Scripts on Linux
    • Permissive MIT License
    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
    9.   public static string WS_WIN32       = "Win32";
    10.   public static string WS_COCOA       = "Cocoa";
    11.   public static string WS_X11_ZENITY  = "Zenity";
    12.   public static string WS_X11_KDIALOG = "KDialog";
    13.   #endif
    14.  
    15.   #if UNITY_STANDALONE_WIN
    16.   [DllImport("DialogModule.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    17.   #elif UNITY_STANDALONE_OSX
    18.   [DllImport("DialogModule.bundle", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    19.   #elif UNITY_STANDALONE_LINUX
    20.   [DllImport("DialogModule.so", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    21.   #endif
    22.  
    23.   #if UNITY_STANDALONE
    24.   private static extern string widget_get_system();
    25.   #endif
    26.  
    27.   string WidgetGetSystem() {
    28.  
    29.     #if UNITY_STANDALONE
    30.     return widget_get_system();
    31.     #else
    32.     return "NaN";
    33.     #endif
    34.  
    35.   }
    36.  
    37.   #if UNITY_STANDALONE_WIN
    38.   [DllImport("DialogModule.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    39.   #elif UNITY_STANDALONE_OSX
    40.   [DllImport("DialogModule.bundle", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    41.   #elif UNITY_STANDALONE_LINUX
    42.   [DllImport("DialogModule.so", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    43.   #endif
    44.  
    45.   #if UNITY_STANDALONE
    46.   unsafe private static extern void* widget_get_owner();
    47.   #endif
    48.  
    49.   unsafe void* WidgetGetOwner() {
    50.  
    51.     #if UNITY_STANDALONE
    52.     return widget_get_owner();
    53.     #else
    54.     return (void*)0;
    55.     #endif
    56.  
    57.   }
    58.  
    59.   #if UNITY_STANDALONE_WIN
    60.   [DllImport("DialogModule.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    61.   #elif UNITY_STANDALONE_OSX
    62.   [DllImport("DialogModule.bundle", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    63.   #elif UNITY_STANDALONE_LINUX
    64.   [DllImport("DialogModule.so", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    65.   #endif
    66.  
    67.   #if UNITY_STANDALONE
    68.   private static extern string widget_get_icon();
    69.   #endif
    70.  
    71.   string WidgetGetIcon() {
    72.  
    73.     #if UNITY_STANDALONE
    74.     return widget_get_icon();
    75.     #else
    76.     return "NaN";
    77.     #endif
    78.  
    79.   }
    80.  
    81.   #if UNITY_STANDALONE_WIN
    82.   [DllImport("DialogModule.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    83.   #elif UNITY_STANDALONE_OSX
    84.   [DllImport("DialogModule.bundle", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    85.   #elif UNITY_STANDALONE_LINUX
    86.   [DllImport("DialogModule.so", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    87.   #endif
    88.  
    89.   #if UNITY_STANDALONE
    90.   private static extern string widget_get_caption();
    91.   #endif
    92.  
    93.   string WidgetGetCaption() {
    94.  
    95.     #if UNITY_STANDALONE
    96.     return widget_get_caption();
    97.     #else
    98.     return "NaN";
    99.     #endif
    100.  
    101.   }
    102.  
    103.   #if UNITY_STANDALONE_WIN
    104.   [DllImport("DialogModule.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    105.   #elif UNITY_STANDALONE_OSX
    106.   [DllImport("DialogModule.bundle", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    107.   #elif UNITY_STANDALONE_LINUX
    108.   [DllImport("DialogModule.so", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    109.   #endif
    110.  
    111.   #if UNITY_STANDALONE
    112.   private static extern double widget_set_system(string sys);
    113.   #endif
    114.  
    115.   double WidgetSetSystem(string Sys) {
    116.  
    117.     #if UNITY_STANDALONE
    118.     return widget_set_system(Sys);
    119.     #else
    120.     return -1;
    121.     #endif
    122.  
    123.   }
    124.  
    125.   #if UNITY_STANDALONE_WIN
    126.   [DllImport("DialogModule.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    127.   #elif UNITY_STANDALONE_OSX
    128.   [DllImport("DialogModule.bundle", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    129.   #elif UNITY_STANDALONE_LINUX
    130.   [DllImport("DialogModule.so", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    131.   #endif
    132.  
    133.   #if UNITY_STANDALONE
    134.   unsafe private static extern double widget_set_owner(void* hwnd);
    135.   #endif
    136.  
    137.   unsafe double WidgetSetOwner(void* Hwnd) {
    138.  
    139.     #if UNITY_STANDALONE
    140.     return widget_set_owner(Hwnd);
    141.     #else
    142.     return -1;
    143.     #endif
    144.  
    145.   }
    146.  
    147.   #if UNITY_STANDALONE_WIN
    148.   [DllImport("DialogModule.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    149.   #elif UNITY_STANDALONE_OSX
    150.   [DllImport("DialogModule.bundle", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    151.   #elif UNITY_STANDALONE_LINUX
    152.   [DllImport("DialogModule.so", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    153.   #endif
    154.  
    155.   #if UNITY_STANDALONE
    156.   private static extern double widget_set_icon(string icon);
    157.   #endif
    158.  
    159.   double WidgetSetIcon(string Icon) {
    160.  
    161.     #if UNITY_STANDALONE
    162.     return widget_set_icon(Icon);
    163.     #else
    164.     return -1;
    165.     #endif
    166.  
    167.   }
    168.  
    169.   #if UNITY_STANDALONE_WIN
    170.   [DllImport("DialogModule.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    171.   #elif UNITY_STANDALONE_OSX
    172.   [DllImport("DialogModule.bundle", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    173.   #elif UNITY_STANDALONE_LINUX
    174.   [DllImport("DialogModule.so", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    175.   #endif
    176.  
    177.   #if UNITY_STANDALONE
    178.   private static extern double widget_set_caption(string str);
    179.   #endif
    180.  
    181.   double WidgetSetCaption(string Str) {
    182.  
    183.     #if UNITY_STANDALONE
    184.     return widget_set_caption(Str);
    185.     #else
    186.     return -1;
    187.     #endif
    188.  
    189.   }
    190.  
    191.   #if UNITY_STANDALONE_WIN
    192.   [DllImport("DialogModule.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    193.   #elif UNITY_STANDALONE_OSX
    194.   [DllImport("DialogModule.bundle", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    195.   #elif UNITY_STANDALONE_LINUX
    196.   [DllImport("DialogModule.so", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    197.   #endif
    198.  
    199.   #if UNITY_STANDALONE
    200.   private static extern double show_message(string str);
    201.   #endif
    202.  
    203.   double ShowMessage(string Str) {
    204.  
    205.     #if UNITY_STANDALONE
    206.     return show_message(Str);
    207.     #else
    208.     return -1;
    209.     #endif
    210.  
    211.   }
    212.  
    213.   #if UNITY_STANDALONE_WIN
    214.   [DllImport("DialogModule.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    215.   #elif UNITY_STANDALONE_OSX
    216.   [DllImport("DialogModule.bundle", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    217.   #elif UNITY_STANDALONE_LINUX
    218.   [DllImport("DialogModule.so", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    219.   #endif
    220.  
    221.   #if UNITY_STANDALONE
    222.   private static extern double show_message_cancelable(string str);
    223.   #endif
    224.  
    225.   double ShowMessageCancelable(string Str) {
    226.  
    227.     #if UNITY_STANDALONE
    228.     return show_message_cancelable(Str);
    229.     #else
    230.     return -1;
    231.     #endif
    232.  
    233.   }
    234.  
    235.   #if UNITY_STANDALONE_WIN
    236.   [DllImport("DialogModule.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    237.   #elif UNITY_STANDALONE_OSX
    238.   [DllImport("DialogModule.bundle", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    239.   #elif UNITY_STANDALONE_LINUX
    240.   [DllImport("DialogModule.so", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    241.   #endif
    242.  
    243.   #if UNITY_STANDALONE
    244.   private static extern double show_question(string str);
    245.   #endif
    246.  
    247.   double ShowQuestion(string Str) {
    248.  
    249.     #if UNITY_STANDALONE
    250.     return show_question(Str);
    251.     #else
    252.     return -1;
    253.     #endif
    254.  
    255.   }
    256.  
    257.   #if UNITY_STANDALONE_WIN
    258.   [DllImport("DialogModule.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    259.   #elif UNITY_STANDALONE_OSX
    260.   [DllImport("DialogModule.bundle", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    261.   #elif UNITY_STANDALONE_LINUX
    262.   [DllImport("DialogModule.so", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    263.   #endif
    264.  
    265.   #if UNITY_STANDALONE
    266.   private static extern double show_question_cancelable(string str);
    267.   #endif
    268.  
    269.   double ShowQuestionCancelable(string Str) {
    270.  
    271.     #if UNITY_STANDALONE
    272.     return show_question_cancelable(Str);
    273.     #else
    274.     return -1;
    275.     #endif
    276.  
    277.   }
    278.  
    279.   #if UNITY_STANDALONE_WIN
    280.   [DllImport("DialogModule.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    281.   #elif UNITY_STANDALONE_OSX
    282.   [DllImport("DialogModule.bundle", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    283.   #elif UNITY_STANDALONE_LINUX
    284.   [DllImport("DialogModule.so", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    285.   #endif
    286.  
    287.   #if UNITY_STANDALONE
    288.   private static extern double show_attempt(string str);
    289.   #endif
    290.  
    291.   double ShowAttempt(string Str) {
    292.  
    293.     #if UNITY_STANDALONE
    294.     return show_attempt(Str);
    295.     #else
    296.     return -1;
    297.     #endif
    298.  
    299.   }
    300.  
    301.   #if UNITY_STANDALONE_WIN
    302.   [DllImport("DialogModule.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    303.   #elif UNITY_STANDALONE_OSX
    304.   [DllImport("DialogModule.bundle", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    305.   #elif UNITY_STANDALONE_LINUX
    306.   [DllImport("DialogModule.so", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    307.   #endif
    308.  
    309.   #if UNITY_STANDALONE
    310.   private static extern double show_error(string str, double abort);
    311.   #endif
    312.  
    313.   double ShowError(string Str, double Abort) {
    314.  
    315.     #if UNITY_STANDALONE
    316.     return show_error(Str, Abort);
    317.     #else
    318.     return -1;
    319.     #endif
    320.  
    321.   }
    322.  
    323.   #if UNITY_STANDALONE_WIN
    324.   [DllImport("DialogModule.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    325.   #elif UNITY_STANDALONE_OSX
    326.   [DllImport("DialogModule.bundle", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    327.   #elif UNITY_STANDALONE_LINUX
    328.   [DllImport("DialogModule.so", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    329.   #endif
    330.  
    331.   #if UNITY_STANDALONE
    332.   private static extern IntPtr get_string(string str, string def);
    333.   #endif
    334.  
    335.   string Getstring(string Str, string Def) {
    336.  
    337.     #if UNITY_STANDALONE
    338.     return System.Runtime.InteropServices.Marshal.PtrToStringAnsi(get_string(Str, Def));
    339.     #else
    340.     return "NaN";
    341.     #endif
    342.  
    343.   }
    344.  
    345.   #if UNITY_STANDALONE_WIN
    346.   [DllImport("DialogModule.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    347.   #elif UNITY_STANDALONE_OSX
    348.   [DllImport("DialogModule.bundle", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    349.   #elif UNITY_STANDALONE_LINUX
    350.   [DllImport("DialogModule.so", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    351.   #endif
    352.  
    353.   #if UNITY_STANDALONE
    354.   private static extern IntPtr get_password(string str, string def);
    355.   #endif
    356.  
    357.   string GetPassword(string Str, string Def) {
    358.  
    359.     #if UNITY_STANDALONE
    360.     return System.Runtime.InteropServices.Marshal.PtrToStringAnsi(get_password(Str, Def));
    361.     #else
    362.     return "NaN";
    363.     #endif
    364.  
    365.   }
    366.  
    367.   #if UNITY_STANDALONE_WIN
    368.   [DllImport("DialogModule.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    369.   #elif UNITY_STANDALONE_OSX
    370.   [DllImport("DialogModule.bundle", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    371.   #elif UNITY_STANDALONE_LINUX
    372.   [DllImport("DialogModule.so", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    373.   #endif
    374.  
    375.   #if UNITY_STANDALONE
    376.   private static extern double get_integer(string str, double def);
    377.   #endif
    378.  
    379.   double GetInteger(string Str, double Def) {
    380.  
    381.     #if UNITY_STANDALONE
    382.     return get_integer(Str, Def);
    383.     #else
    384.     return -1;
    385.     #endif
    386.  
    387.   }
    388.  
    389.   #if UNITY_STANDALONE_WIN
    390.   [DllImport("DialogModule.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    391.   #elif UNITY_STANDALONE_OSX
    392.   [DllImport("DialogModule.bundle", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    393.   #elif UNITY_STANDALONE_LINUX
    394.   [DllImport("DialogModule.so", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    395.   #endif
    396.  
    397.   #if UNITY_STANDALONE
    398.   private static extern double get_passcode(string str, double def);
    399.   #endif
    400.  
    401.   double GetPasscode(string Str, double Def) {
    402.  
    403.     #if UNITY_STANDALONE
    404.     return get_passcode(Str, Def);
    405.     #else
    406.     return -1;
    407.     #endif
    408.  
    409.   }
    410.  
    411.   #if UNITY_STANDALONE_WIN
    412.   [DllImport("DialogModule.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    413.   #elif UNITY_STANDALONE_OSX
    414.   [DllImport("DialogModule.bundle", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    415.   #elif UNITY_STANDALONE_LINUX
    416.   [DllImport("DialogModule.so", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    417.   #endif
    418.  
    419.   #if UNITY_STANDALONE
    420.   private static extern IntPtr get_open_filename(string filter, string fname);
    421.   #endif
    422.  
    423.   string GetOpenFileName(string Filter, string FName) {
    424.  
    425.     #if UNITY_STANDALONE
    426.     return System.Runtime.InteropServices.Marshal.PtrToStringAnsi(get_open_filename(Filter, FName));
    427.     #else
    428.     return "NaN";
    429.     #endif
    430.  
    431.   }
    432.  
    433.   #if UNITY_STANDALONE_WIN
    434.   [DllImport("DialogModule.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    435.   #elif UNITY_STANDALONE_OSX
    436.   [DllImport("DialogModule.bundle", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    437.   #elif UNITY_STANDALONE_LINUX
    438.   [DllImport("DialogModule.so", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    439.   #endif
    440.  
    441.   #if UNITY_STANDALONE
    442.   private static extern IntPtr get_open_filename_ext(string filter, string fname, string dir, string title);
    443.   #endif
    444.  
    445.   string GetOpenFileNameExt(string Filter, string FName, string Dir, string Title) {
    446.  
    447.     #if UNITY_STANDALONE
    448.     return System.Runtime.InteropServices.Marshal.PtrToStringAnsi(get_open_filename_ext(Filter, FName, Dir, Title));
    449.     #else
    450.     return "NaN";
    451.     #endif
    452.  
    453.   }
    454.  
    455.   #if UNITY_STANDALONE_WIN
    456.   [DllImport("DialogModule.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    457.   #elif UNITY_STANDALONE_OSX
    458.   [DllImport("DialogModule.bundle", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    459.   #elif UNITY_STANDALONE_LINUX
    460.   [DllImport("DialogModule.so", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    461.   #endif
    462.  
    463.   #if UNITY_STANDALONE
    464.   private static extern IntPtr get_open_filenames(string filter, string fname);
    465.   #endif
    466.  
    467.   string GetOpenFileNames(string Filter, string FName)
    468.   {
    469.  
    470.     #if UNITY_STANDALONE
    471.     return System.Runtime.InteropServices.Marshal.PtrToStringAnsi(get_open_filenames(Filter, FName));
    472.     #else
    473.     return "NaN";
    474.     #endif
    475.  
    476.   }
    477.  
    478.   #if UNITY_STANDALONE_WIN
    479.   [DllImport("DialogModule.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    480.   #elif UNITY_STANDALONE_OSX
    481.   [DllImport("DialogModule.bundle", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    482.   #elif UNITY_STANDALONE_LINUX
    483.   [DllImport("DialogModule.so", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    484.   #endif
    485.  
    486.   #if UNITY_STANDALONE
    487.   private static extern IntPtr get_open_filenames_ext(string filter, string fname, string dir, string title);
    488.   #endif
    489.  
    490.   string GetOpenFileNamesExt(string Filter, string FName, string Dir, string Title)
    491.   {
    492.  
    493.     #if UNITY_STANDALONE
    494.     return System.Runtime.InteropServices.Marshal.PtrToStringAnsi(get_open_filenames_ext(Filter, FName, Dir, Title));
    495.     #else
    496.     return "NaN";
    497.     #endif
    498.  
    499.   }
    500.  
    501.   #if UNITY_STANDALONE_WIN
    502.   [DllImport("DialogModule.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    503.   #elif UNITY_STANDALONE_OSX
    504.   [DllImport("DialogModule.bundle", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    505.   #elif UNITY_STANDALONE_LINUX
    506.   [DllImport("DialogModule.so", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    507.   #endif
    508.  
    509.   #if UNITY_STANDALONE
    510.   private static extern IntPtr get_save_filename(string filter, string fname);
    511.   #endif
    512.  
    513.   string GetSaveFileName(string Filter, string FName) {
    514.  
    515.     #if UNITY_STANDALONE
    516.     return System.Runtime.InteropServices.Marshal.PtrToStringAnsi(get_save_filename(Filter, FName));
    517.     #else
    518.     return "NaN";
    519.     #endif
    520.  
    521.   }
    522.  
    523.   #if UNITY_STANDALONE_WIN
    524.   [DllImport("DialogModule.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    525.   #elif UNITY_STANDALONE_OSX
    526.   [DllImport("DialogModule.bundle", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    527.   #elif UNITY_STANDALONE_LINUX
    528.   [DllImport("DialogModule.so", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    529.   #endif
    530.  
    531.   #if UNITY_STANDALONE
    532.   private static extern IntPtr get_save_filename_ext(string filter, string fname, string dir, string title);
    533.   #endif
    534.  
    535.   string GetSaveFileNameExt(string Filter, string FName, string Dir, string Title) {
    536.  
    537.     #if UNITY_STANDALONE
    538.     return System.Runtime.InteropServices.Marshal.PtrToStringAnsi(get_save_filename_ext(Filter, FName, Dir, Title));
    539.     #else
    540.     return "NaN";
    541.     #endif
    542.  
    543.   }
    544.  
    545.   #if UNITY_STANDALONE_WIN
    546.   [DllImport("DialogModule.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    547.   #elif UNITY_STANDALONE_OSX
    548.   [DllImport("DialogModule.bundle", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    549.   #elif UNITY_STANDALONE_LINUX
    550.   [DllImport("DialogModule.so", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    551.   #endif
    552.  
    553.   #if UNITY_STANDALONE
    554.   private static extern IntPtr get_directory(string dname);
    555.   #endif
    556.  
    557.   string GetDirectory(string DName) {
    558.  
    559.     #if UNITY_STANDALONE
    560.     return System.Runtime.InteropServices.Marshal.PtrToStringAnsi(get_directory(DName));
    561.     #else
    562.     return "NaN";
    563.     #endif
    564.  
    565.   }
    566.  
    567.   #if UNITY_STANDALONE_WIN
    568.   [DllImport("DialogModule.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    569.   #elif UNITY_STANDALONE_OSX
    570.   [DllImport("DialogModule.bundle", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    571.   #elif UNITY_STANDALONE_LINUX
    572.   [DllImport("DialogModule.so", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    573.   #endif
    574.  
    575.   #if UNITY_STANDALONE
    576.   private static extern IntPtr get_directory_alt(string capt, string root);
    577.   #endif
    578.  
    579.   string GetDirectoryAlt(string Capt, string Root) {
    580.  
    581.     #if UNITY_STANDALONE
    582.     return System.Runtime.InteropServices.Marshal.PtrToStringAnsi(get_directory_alt(Capt, Root));
    583.     #else
    584.     return "NaN";
    585.     #endif
    586.  
    587.   }
    588.  
    589.   #if UNITY_STANDALONE_WIN
    590.   [DllImport("DialogModule.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    591.   #elif UNITY_STANDALONE_OSX
    592.   [DllImport("DialogModule.bundle", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    593.   #elif UNITY_STANDALONE_LINUX
    594.   [DllImport("DialogModule.so", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    595.   #endif
    596.  
    597.   #if UNITY_STANDALONE
    598.   private static extern double get_color(double defcol);
    599.   #endif
    600.  
    601.   double GetColor(double DefCol) {
    602.  
    603.     #if UNITY_STANDALONE
    604.     return get_color(DefCol);
    605.     #else
    606.     return -1;
    607.     #endif
    608.  
    609.   }
    610.  
    611.   #if UNITY_STANDALONE_WIN
    612.   [DllImport("DialogModule.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    613.   #elif UNITY_STANDALONE_OSX
    614.   [DllImport("DialogModule.bundle", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    615.   #elif UNITY_STANDALONE_LINUX
    616.   [DllImport("DialogModule.so", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    617.   #endif
    618.  
    619.   #if UNITY_STANDALONE
    620.   private static extern double get_color_ext(double defcol, string title);
    621.   #endif
    622.  
    623.   double GetColorExt(double DefCol, string Title) {
    624.  
    625.     #if UNITY_STANDALONE
    626.     return get_color_ext(DefCol, Title);
    627.     #else
    628.     return -1;
    629.     #endif
    630.  
    631.   }
    632.  
    633.   void Start() {
    634.  
    635.     WidgetSetCaption("DialogModule");
    636.     string Str = ShowMessage("Hello World!").ToString();
    637.     ShowMessage(Str);
    638.  
    639.     Str = ShowMessageCancelable("Hello World!").ToString();
    640.     ShowMessage(Str);
    641.  
    642.     Str = ShowQuestion("Yes or no?").ToString();
    643.     ShowMessage(Str);
    644.  
    645.     Str = ShowQuestionCancelable("Yes, no, or cancel?").ToString();
    646.     ShowMessage(Str);
    647.  
    648.     WidgetSetCaption("Error");
    649.     Str = ShowAttempt("Hello World!").ToString();
    650.     WidgetSetCaption("DialogModule");
    651.     ShowMessage(Str);
    652.  
    653.     WidgetSetCaption("Error");
    654.     Str = ShowError("Hello World!", 0).ToString();
    655.     WidgetSetCaption("DialogModule");
    656.     ShowMessage(Str);
    657.  
    658.     Str = Getstring("Enter a string:", "Hello World!");
    659.     if (Str != "") ShowMessage(Str);
    660.  
    661.     Str = GetPassword("Enter a string password:", "Hello World!");
    662.     if (Str != "") ShowMessage(Str);
    663.  
    664.     Str = GetInteger("Enter an integer:", 0).ToString();
    665.     ShowMessage(Str);
    666.  
    667.     Str = GetPasscode("Enter an integer passcode:", 0).ToString();
    668.     ShowMessage(Str);
    669.  
    670.     string Filter = "Sprite Images (*.png *.gif *.jpg *.jpeg)|*.png;*.gif;*.jpg;*.jpeg|Background Images (*.png)|*.png|All Files (*.*)|*.*";
    671.  
    672.     Str = GetOpenFileName(Filter, "Select a File");
    673.     if (Str != "") ShowMessage(Str);
    674.  
    675.     Str = GetOpenFileNameExt(Filter, "Select a File", "", "Open Ext");
    676.     if (Str != "") ShowMessage(Str);
    677.  
    678.     Str = GetOpenFileNames(Filter, "Select Files");
    679.     if (Str != "") ShowMessage(Str);
    680.  
    681.     Str = GetOpenFileNamesExt(Filter, "Select Files", "", "Open Ext");
    682.     if (Str != "") ShowMessage(Str);
    683.  
    684.     Str = GetSaveFileName(Filter, "Untitled.png");
    685.     if (Str != "") ShowMessage(Str);
    686.  
    687.     Str = GetSaveFileNameExt(Filter, "Untitled.png", "", "Save As Ext");
    688.     if (Str != "") if (Str != "") ShowMessage(Str);
    689.  
    690.     Str = GetDirectory("");
    691.     if (Str != "") ShowMessage(Str);
    692.  
    693.     Str = GetDirectoryAlt("Get Directory Alt", "");
    694.     if (Str != "") ShowMessage(Str);
    695.  
    696.     double CRed = 255;
    697.  
    698.     Str = GetColor(CRed).ToString();
    699.     ShowMessage(Str);
    700.  
    701.     #if UNITY_STANDALONE_OSX
    702.     string title = "Colors Ext";
    703.     #else
    704.     string title = "Color Ext";
    705.     #endif
    706.  
    707.     Str = GetColorExt(CRed, title).ToString();
    708.     ShowMessage(Str);
    709.  
    710.     Application.Quit();
    711.  
    712.   }
    713.  
    714.   void Update() {
    715.  
    716.   }
    717. }
     
    Last edited: Dec 15, 2022
  2. Renan-Reis

    Renan-Reis

    Joined:
    Dec 9, 2012
    Posts:
    11
    The plugin looks amazing! But the github link is down. Please, could you make it available again?
     
  3. samuelvenable

    samuelvenable

    Joined:
    Dec 3, 2018
    Posts:
    2
    I updated the link, sorry about that.

    Here's a similar plugin which uses Dear ImGui to create File Dialogs:

    https://github.com/time-killer-games/libfiledialogs

    Code (CSharp):
    1. void ifd_load_fonts();
    2. const char *get_open_filename(const char *filter, const char *fname);
    3. const char *get_open_filename_ext(const char *filter, const char *fname, const char *dir, const char *title);
    4. const char *get_open_filenames(const char *filter, const char *fname);
    5. const char *get_open_filenames_ext(const char *filter, const char *fname, const char *dir, const char *title);
    6. const char *get_save_filename(const char *filter, const char *fname);
    7. const char *get_save_filename_ext(const char *filter, const char *fname, const char *dir, const char *title);
    8. const char *get_directory(const char *dname);
    9. const char *get_directory_alt(const char *capt, const char *root);
    These functions are called the exact same as the Dialog Module plugin on the C# side.

    To get it working on Linux, you will need to run the build script on the target distro you wish to export to to make sure the proper library versions are linked.