Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

.Net object like NSOpenPanel

Discussion in 'Editor & General Support' started by hsparra, Dec 14, 2005.

  1. hsparra

    hsparra

    Joined:
    Jul 12, 2005
    Posts:
    750
    Does .Net have an object like NSOpenPanel that can be called so the user can navigate the file system and select a file?
     
  2. hsparra

    hsparra

    Joined:
    Jul 12, 2005
    Posts:
    750
    I found it. For those that are interested it is the OpenFileDialog class.
     
  3. Jonathan Czeck

    Jonathan Czeck

    Joined:
    Mar 17, 2005
    Posts:
    1,713
    I am interested in it too. :)

    Problem is there doesn't seem to be a System.Windows.Forms namespace in Unity. There are things like http://www.mono-project.com/WinForms , but I don't know how possible it is to add to Unity's Mono without being OTEE.

    Darn, seemed soo close.

    -Jon
     
  4. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    You should be able to just add those dlls to Mono.framework and MonoCompiler.framework.
     
  5. Jonathan Czeck

    Jonathan Czeck

    Joined:
    Mar 17, 2005
    Posts:
    1,713
    I haven't gotten it working, but I thought I'd share where I am. I do not know what the missing key is, here.

    First I tried this from within Unity, then I was looking at trying it with us.exe.

    Code (csharp):
    1.  aarku$ mono us.exe
    2. UnityScript command line tool - 0.1.0.0 (C) 2005 OverTheEdge
    3. Welcome to the UnityScript interactive shell
    4. type 'globals()<ENTER>' for a list of global symbols
    5. >>> import System.Web;
    6. >>> import System.Windows.Forms;
    7. -----------^
    8. ERROR: Namespace 'System.Windows.Forms' not found, maybe you forgot to add an assembly reference?
    9. list =>>>  new ArrayList();
    10. ---------------^
    11. ERROR: Unknown identifier: 'ArrayList'.
    12. >>> import System.Collections;
    13. >>> list = new ArrayList();
    14. []
    15. >>> list.Add(2);
    16. 0
    17. >>> list[0];
    18. 2
    19. >>>
    I added System.Windows.Forms.dll is right next to System.Collections.dll and System.Web.dll. As you can see I confirmed that ArrayList worked after I imported it. However, if I for instance get rid of System.Web.dll I can still import it. :eek:

    I don't get it. :)

    -Jon
     
  6. Jonathan Czeck

    Jonathan Czeck

    Joined:
    Mar 17, 2005
    Posts:
    1,713
    I haven't gotten it working, but I thought I'd share where I am. I do not know what the missing key is, here.

    First I tried this from within Unity, then I was looking at trying it with us.exe.

    Code (csharp):
    1.  aarku$ mono us.exe
    2. UnityScript command line tool - 0.1.0.0 (C) 2005 OverTheEdge
    3. Welcome to the UnityScript interactive shell
    4. type 'globals()<ENTER>' for a list of global symbols
    5. >>> import System.Web;
    6. >>> import System.Windows.Forms;
    7. -----------^
    8. ERROR: Namespace 'System.Windows.Forms' not found, maybe you forgot to add an assembly reference?
    9. list =>>>  new ArrayList();
    10. ---------------^
    11. ERROR: Unknown identifier: 'ArrayList'.
    12. >>> import System.Collections;
    13. >>> list = new ArrayList();
    14. []
    15. >>> list.Add(2);
    16. 0
    17. >>> list[0];
    18. 2
    19. >>>
    I added System.Windows.Forms.dll is right next to System.Collections.dll and System.Web.dll. As you can see I confirmed that ArrayList worked after I imported it. However, if I for instance get rid of System.Web.dll I can still import it. :eek:

    I don't get it. :)

    -Jon
     
  7. hsparra

    hsparra

    Joined:
    Jul 12, 2005
    Posts:
    750
    Still dealing with plugins, but related to the Mac plugins. I have a plugin that creates an NSOpenPanel, and then returns the path of the selected file. The path is returned, but in the Console App I see the following error:
    Code (csharp):
    1.  
    2. malloc: ***  Deallocation of a pointer not malloced: 0x8f5e430; This could be a double free(), or free() called with the middle of an allocated block; Try setting environment variable MallocHelp to see tools to help debug
    3.  
    In the plugin on Unity I have
    Code (csharp):
    1.  
    2. [DllImport ("GetFilePathMac")]
    3. private static extern string GetFilePathMac ();
    4.  
    with the call
    Code (csharp):
    1.  
    2. string tempString = GetFilePathMac();
    3.  
    In XCode the GetFilePathMac() is declared
    Code (csharp):
    1.  
    2. char* GetFilePathMac();
    3.  
    The implementation with some of the prior hacking included
    Code (csharp):
    1.  
    2. char* GetFilePathMac()
    3. {
    4.     NSAutoreleasePool *localPool;
    5.     GetFilePath *getFilePathTemp;
    6.     static char name[1024] = {'\0'};
    7.    
    8.     localPool = [[NSAutoreleasePool alloc] init];
    9.     getFilePathTemp = [[GetFilePath alloc] init];
    10.     NSString *returnValue = [getFilePathTemp getFilePath];
    11.     //NSLog(@"Path from string %@",returnValue);
    12.  
    13.     //[[GetFilePath sharedFilePath] getFilePath];
    14.     static char cReturnValue[PATH_MAX];
    15.     [returnValue getCString:cReturnValue maxLength:PATH_MAX];
    16.    
    17.     CFStringGetCString(returnValue, name, sizeof(name), 0);
    18.    
    19.     [localPool release];
    20.     //NSLog(@"Path from string after pool release: %@",returnValue);
    21.     //return returnValue;
    22.     //return [returnValue cStringUsingEncoding:NSASCIIStringEncoding];
    23.  
    24.     //return [@"test string" cStringUsingEncoding:NSASCIIStringEncoding];
    25.    //return cReturnValue;
    26.     return name;
    27. }
    28.  
    If I change to the return value to a float, I have not error, so apparently it is with how I am handling the char*. Any ideas?
     
  8. hsparra

    hsparra

    Joined:
    Jul 12, 2005
    Posts:
    750
    So, my problem has been solved, thanks to dh0, aarku and NCarter. Mono was releasing my pointer for me, so I apparently needed to malloc. So the cleaned up code (thank you dh0) is:'
    Code (csharp):
    1.  
    2. NSAutoreleasePool *localPool =  [[NSAutoreleasePool alloc] init];
    3.     GetFilePath *getFilePathTemp;
    4.    
    5.     static char * name = NULL;
    6.     if (name)
    7.         free(name);
    8.    
    9.     getFilePathTemp = [[GetFilePath alloc] init];
    10.     NSString *returnValue = [getFilePathTemp getFilePath];
    11.    
    12.     name= malloc([returnValue length] + 1);  
    13.     [returnValue getCString:name maxLength:[returnValue length]+1 encoding:NSASCIIStringEncoding];
    14.    
    15.     [localPool release];
    16.    
    17.    
    18.     return name;
    19.  
    If there is interest, I can see about writting a little tutorial on doing plugins calling Cocoa code. Soon as I validate my Windows plugin I could add it also. Just let me know.
     
  9. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    Ok until there is a proper solution for importing .NET dlls by just putting them into the project folder, here is a workaround:
    open Unity.app/Contents/Frameworks/MonoCompiler.framework/compile_any.pl

    This allows you to add parameters to the command line compiler.
    Eg. (line 103)
    Code (csharp):
    1.  
    2. my @base_args=($mono_path, $mcs_path, '-debug',  "-r:ThePathToYourDLL", '-target:library', '-nowarn:0169', '-out:'.$output,  );
    3.  
     
  10. Jonathan Czeck

    Jonathan Czeck

    Joined:
    Mar 17, 2005
    Posts:
    1,713
    Thanks for the assistance, I think it's working as well as it will. The OpenFileDialog seems really buggy, so I wouldn't recommend even trying it. I tried it outside of Unity too. Best I got was an open dialog flash up using X11 briefly before crashing.

    -Jon