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

System.Drawing Question

Discussion in 'Scripting' started by RDot, Sep 5, 2008.

  1. RDot

    RDot

    Joined:
    Mar 21, 2008
    Posts:
    23
    Hi -

    As a test I want to see if I can utilize System.Drawing objects from Unity.

    Here is what i've done...
    1. Create a script which utilizes System.Drawing objects.

    2. Copied System.Drawing.dll from the mono framework included with Unity into my projects Standard Assets folder.

    3. When I run the code I get the error 'TypeInitializationException: An exception was thrown by the type initializer for System.Drawing.GDIPlus.

    System.Drawing calls into the file libgdiplus.dylib.

    So i've included libgdiplus.dylib and all other libgdiplus files in my Standard Assets folder. I've also places these files into the Mono Framework folder included with Unity.

    Still same error.

    Anyone have any ideas?

    thanks -
     
  2. MatthewW

    MatthewW

    Joined:
    Nov 30, 2006
    Posts:
    1,356
    What do you want to draw?
     
  3. RDot

    RDot

    Joined:
    Mar 21, 2008
    Posts:
    23
    I've attached what I would like to draw. This can be done pretty easily using the GraphicsPath class availabe in GDI+. I'm not sure how to do this in Unity.

    The image is used to display a chat bubble above my characters head. The size of the image is dynamic based on the size of the text in the image. The text can be almost anything although it will not be larger then N characters where N is still being defined.

    The image is basically four arcs and 4 lines.

    Thanks -
     

    Attached Files:

  4. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    The problem is that none of "standard drawing libraries" (System.Drawing, ...) will integrate well with actual game drawing that is done via OpenGL/Direct3D.

    What you should do, I think: use regular Unity GUI. Make a style for your text bubble with this background, and set up it's borders so that bubble shape is correct no matter what's the size.
     
  5. RDot

    RDot

    Joined:
    Mar 21, 2008
    Posts:
    23
    What I planned on doing was create the bitmap using System.Drawing, then save the bitmap to a memory stream.

    Once in a memory stream I would convert to a byte array which I would load into a texture, using texture.LoadImage.

    I didn't plan on using the System.Drawing stuff to draw directly into Unity.

    Does this make sense?

    I understand what you are saying to make a style with this background, but how would I setup the bubble shape's borders so it is correct no matter what the size?

    I would rather do what your suggesting if I can understand it better. Keeping it all in Unity will be easier to maintain!

    Thanks -
     
  6. ProtonOne

    ProtonOne

    Joined:
    Mar 8, 2008
    Posts:
    406
    Download the Networking example project. Run it and type something into the chat window.

    The chat messages are contained within a speech bubble using this technique.
     
  7. RDot

    RDot

    Joined:
    Mar 21, 2008
    Posts:
    23
    Thanks for the networking tutorial! The chat is exactly what I want visually. I've actually got it working in my project.

    The problem is I want the chat bubble to be billboarded so it always faces the camera. Plus I want the chat bubble to slowly fade away after a specified interval. I'm not sure I can do this using the GUILayout which is used in the tutorial.

    I will keep plugging away using the chat bubble from the tutorial to see what I can get.

    Thanks again for the help!
     
  8. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Anything done with OnGUI is only 2D, so you don't have a choice--it will always face the camera no matter what. ;) You can use GUI.color.a to fade things out.

    --Eric
     
  9. Eowyn27

    Eowyn27

    Joined:
    Oct 22, 2013
    Posts:
    8
    Can I use System.Drawing library in Unity now? I want to manipulate my contrast script faster than the way that Unity does it pixel by pixel. I want to use a ColorMatrix or LockBits to adjust contrast/brightness of my image faster.
     
  10. NKidd

    NKidd

    Joined:
    Sep 16, 2015
    Posts:
    22
    Still have problem. Wonder if anybody could help me!

    I can copy System.Drawing.dll to asset to do something with Bitmap. Works perfectly on Editor, but fail on build!