Search Unity

Wacom Plugin Work: not working in editor/ what is eating my events!

Discussion in 'Editor & General Support' started by holyjewsus, Feb 15, 2012.

  1. holyjewsus

    holyjewsus

    Joined:
    Mar 7, 2011
    Posts:
    624
    I've been attempting for a while to get wacom tablet data into my unity app for my thesis work on a conceptual design tool.

    I'm not a programmer by training so this as been more difficult than it should be :p.

    I was forwarded to this blog post :

    http://www.reigndesign.com/blog/unity-native-plugins-os-x/

    that goes into native plugins and trackpad events... works great.

    I extended it a bit with some code from the wacom developer guide and got pressure data coming into the editor, but with a crux. I don't receive NSMouse events within the editor when pressing on the play view. I only receive the events from my plugin when pressing on empty areas of the editor, like directly under the menubar or in an empty inspector window.

    I receive all events within a build, but not in fullscreen mode, only when windowed, does this point to anything, I really can't test my project without using the editor, it's really cumbersome to have to build and run each time to test.

    heres my code to share, I give almost all credit for this to that blog posted listed above and the wacom sample code.



    Code (csharp):
    1. #import "Plugin.h"
    2. #import "XCodePlugin-Prefix.pch"
    3.  
    4. MonoDomain *domain;
    5. NSString *assemblyPath;
    6. MonoAssembly *monoAssembly;
    7. MonoImage *monoImage;
    8.  
    9. MonoMethodDesc *tabletPointDesc;
    10. MonoMethod *tabletPointMethod;
    11.  
    12.  
    13. MonoMethodDesc *mouseDraggedDesc;
    14. MonoMethod *mouseDraggedMethod;
    15.  
    16. MonoMethodDesc *mouseUpDesc;
    17. MonoMethod *mouseUpMethod;
    18.  
    19.  
    20. MonoMethodDesc *mouseDownDesc;
    21. MonoMethod *mouseDownMethod;
    22.  
    23.  
    24. NSView* view = nil;
    25.  
    26. @interface TrackingObject : NSResponder
    27. {
    28. }
    29. - (void)mouseDragged:(NSEvent *)event;
    30. - (void)mouseUp:(NSEvent *)event;
    31. - (void)mouseDown:(NSEvent *)event;
    32. - (void)tabletPoint:(NSEvent *)event;
    33.  
    34.  
    35. @end
    36.  
    37. @implementation TrackingObject
    38.  
    39.  
    40.  
    41. - (void)mouseDown:(NSEvent *)event
    42. {      
    43.     float mPressure = 0.0f;
    44.  
    45.        
    46.     mPressure = [event pressure];    
    47.  
    48.     void *args[] = { &mPressure };
    49.     mono_runtime_invoke(mouseDownMethod, NULL, args , NULL);
    50.  
    51. }
    52. - (void)mouseDragged:(NSEvent *)event
    53. {      
    54.     float mPressure = 0.0f;
    55.    
    56.    
    57.     mPressure = [event pressure];    
    58.    
    59.     void *args[] = { &mPressure };
    60.     mono_runtime_invoke(mouseDownMethod, NULL, args , NULL);
    61.  
    62. }
    63.  
    64. - (void)mouseUp:(NSEvent *)event
    65. {      
    66.     float mPressure = 0.0f;
    67.    
    68.    
    69.     mPressure = [event pressure];    
    70.    
    71.    void *args[] = { &mPressure };
    72.   mono_runtime_invoke(mouseUpMethod, NULL, args , NULL);
    73.    
    74. }
    75.  
    76.  
    77. - (void)tabletPoint:(NSEvent *)event
    78. {      
    79.     float mPressure = 0.0f;
    80.     float mTiltX = 0.0f;
    81.     float mTiltY = 0.0f;
    82.  NSPoint tilt;
    83. tilt = [event tilt];
    84.     mTiltX = tilt.x;
    85.     mTiltY = tilt.y;
    86.    
    87.    
    88.     mPressure = [event pressure];    
    89.    
    90.     void *args[] = { &mPressure,&mTiltX,&mTiltY };
    91.     mono_runtime_invoke(tabletPointMethod, NULL, args , NULL);
    92.    
    93. }
    94.  
    95.  
    96.  
    97.  
    98. @end
    99.  
    100. TrackingObject* pTrackMgr = nil;
    101.  
    102.  
    103. void SetupTrackingObject()
    104. {
    105.     NSLog(@"Native plugin -> SetupTrackingObject");
    106.    
    107.     NSApplication* app = [NSApplication sharedApplication];
    108.     NSWindow* window = [app mainWindow];
    109.     view = [window contentView];
    110.    
    111.     if(pTrackMgr != nil)
    112.     {
    113.         [pTrackMgr release];
    114.         pTrackMgr = nil;
    115.     }
    116.    
    117.     pTrackMgr = [TrackingObject alloc];
    118.     //[view setAcceptsTouchEvents:YES];
    119.     //[pTrackMgr setNextResponder:[view nextResponder]];
    120.     [view setNextResponder:pTrackMgr];
    121.    
    122. }
    123.  
    124.  
    125. void PluginInit(bool isDevice)
    126. {
    127.     NSLog(@"Native plugin -> PluginInit - device? : %d", isDevice);
    128.    
    129.     SetupTrackingObject();
    130.    
    131.     //We do this so it also works while we work on the Editor
    132.     if(isDevice)
    133.     {
    134.         assemblyPath = [[[NSBundle mainBundle] bundlePath]
    135.                         stringByAppendingPathComponent:@"Contents/Data/Managed/Assembly-CSharp.dll"];
    136.     }
    137.     else
    138.     {
    139.         assemblyPath = @"/Users/Mike/Freerunner/Library/ScriptAssemblies/Assembly-CSharp.dll";
    140.     }
    141.    
    142.     NSLog(@"Native plugin -> assembly path: %@", assemblyPath);
    143.    
    144.     domain = mono_domain_get();
    145.     monoAssembly = mono_domain_assembly_open(domain, assemblyPath.UTF8String);
    146.     monoImage = mono_assembly_get_image(monoAssembly);
    147.    
    148.     //Note here that "MyNativePlugin" is the name of the unity class and "TrackPadTouchBegan" is the name of the static method we defined before.
    149.    
    150.     tabletPointDesc = mono_method_desc_new("MyNativePlugin:tabletPoint", FALSE);
    151.     tabletPointMethod = mono_method_desc_search_in_image(tabletPointDesc, monoImage);
    152.     mono_method_desc_free(tabletPointDesc);
    153.  
    154.    
    155.     mouseDownDesc = mono_method_desc_new("MyNativePlugin:mouseDown", FALSE);
    156.     mouseDownMethod = mono_method_desc_search_in_image(mouseDownDesc, monoImage);
    157.     mono_method_desc_free(mouseDownDesc);
    158.  
    159.     mouseDraggedDesc = mono_method_desc_new("MyNativePlugin:mouseDragged", FALSE);
    160.     mouseDraggedMethod = mono_method_desc_search_in_image(mouseDraggedDesc, monoImage);
    161.     mono_method_desc_free(mouseDraggedDesc);
    162.    
    163.     mouseUpDesc = mono_method_desc_new("MyNativePlugin:mouseUp", FALSE);
    164. mouseUpMethod = mono_method_desc_search_in_image(mouseUpDesc, monoImage);
    165.     mono_method_desc_free(mouseUpDesc);
    166.    
    167.    
    168.    
    169.    
    170. }
    If anyone wants it I can send the whole Xcode project and unity package.
     
  2. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    Unity eats the events. If its in the active editor it will be taken and transformed into an Event object and those are limited to what Unity knows.

    You can't create input plugins that work in the editor as long as you want them to run inside (and not as distinct application routing in the informations someway), as sorry as I am to say that. You can only create input plugins that work in the players.
     
  3. holyjewsus

    holyjewsus

    Joined:
    Mar 7, 2011
    Posts:
    624
    thanks for the info dreamora.
     
  4. holyjewsus

    holyjewsus

    Joined:
    Mar 7, 2011
    Posts:
    624
    I've noticed I get a lot of crashes of the unity editor when testing builds and then going back into the editor and clicking on the editor window will cause a crash when I lift the mouse button.

    Any idea what could be causing this, when I watched the unity plugin unite demo there was something about unity keeping the plugin open even when not playing, any idea if i can turn that off somehow?
     
  5. holyjewsus

    holyjewsus

    Joined:
    Mar 7, 2011
    Posts:
    624
  6. holyjewsus

    holyjewsus

    Joined:
    Mar 7, 2011
    Posts:
    624
    I'm now getting a very strange bug in my builds, if anyone knows any good way to trace it down it would be great.

    after a minute of use using the wacom tablet the entire build freezes up and will not respond to input, nothing moves, after a another minute it freezes again, and on and on with greater frequency.

    When running the builds with the editor closed this behavior seems to go away. Any ideas?

    bug reported here 450319
     
    Last edited: Mar 13, 2012
  7. holyjewsus

    holyjewsus

    Joined:
    Mar 7, 2011
    Posts:
    624
    Implemented drawing tablet pressure input support on Windows (it was already working on Macs).
    May 25, 2012 13:15

    ninjacamp quote

    ??
     
  8. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    3,527
    Yes I would love this to work, wacom in the editor, how to do it?
     
  9. piotrus04

    piotrus04

    Joined:
    Aug 18, 2013
    Posts:
    21