Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Resolved How do I use System.Drawing? (Can I?)

Discussion in 'Scripting' started by JasonC_, Mar 28, 2022.

  1. JasonC_

    JasonC_

    Joined:
    Oct 27, 2019
    Posts:
    66
    I want to use System.Drawing.Icon in an Editor script. Can I do this and, if so, how?

    I tried adding a reference to the System.Drawing assembly in VS, and it made VS happy, but Unity didn't see it. Also, on reimporting assets, the reference disappeared in VS.

    I also tried adding a reference to the System.Drawing.dll that ships with Unity but, same results, and also I'd rather not have to set that up again every time I update the editor. I found this thread, but I can't really understand it (they talk about copying files but I'm not sure where they're copying them to).

    I don't actually now how to add references to arbitrary assemblies to a Unity project (well, really, I only need it for Editor scripts).

    How do I do this?

    2020.3.31f1, Windows 10
     
  2. GroZZleR

    GroZZleR

    Joined:
    Feb 1, 2015
    Posts:
    3,201
    What are you trying to do that you can't accomplish with the built-in editor drawing?
     
    Bunny83 likes this.
  3. JasonC_

    JasonC_

    Joined:
    Oct 27, 2019
    Posts:
    66
    What I'm trying to do is add a reference to System.Drawing so that I can use System.Drawing.Icon. :)

    What I'm also trying to do is figure out how to add references to non-builtin assemblies in general; especially in a non-Windows-specific way (and ideally in a way that's immune to Unity Editor updates as well).
     
    Last edited: Mar 29, 2022
  4. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,580
    I think @GroZZleR is more asking WHY you need System.Drawing.Icon? What does it do that you need to import the entire System.Drawing dll into your project?

    As for adding libraries, you just need to get the dll and drop it into your project folder (preferably an editor folder since you only want it at editor time). Check out the plug-ins documentation for more info:
    https://docs.unity3d.com/Manual/Plugins.html

    Note though that System.Drawing provides access to the GDI+ api:
    https://docs.microsoft.com/en-us/dotnet/api/system.drawing?view=net-6.0
    Go to that link though and checkout the 'Remarks' section!!!

    See GDI+ is a native Win32 api. This means it's not on macos, linux, android, ios, consoles... or any of that. There is the System.Drawing.Common package which gives .net core functionality across other operating system via the libgdiplus library (see: mono). And that functionality may vary across platforms.

    Basically...

    Unless you really, truly, definitely, most certainly, can't get around depending on gdi+... you probably shouldn't depend on it.

    Especially considering that Unity is its own graphics engine! Why would you mix/match graphics in that way?

    Which brings us back to what @GroZZleR asked...

    What are you trying to do that you can't accomplish with the built-in Unity stuff?
     
    Bunny83 and JasonC_ like this.
  5. JasonC_

    JasonC_

    Joined:
    Oct 27, 2019
    Posts:
    66
  6. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,580
    Still no reason as to why you need System.Drawing.Icon........
     
    Bunny83 likes this.
  7. JasonC_

    JasonC_

    Joined:
    Oct 27, 2019
    Posts:
    66
    Correct, and I wouldn't hold my breath waiting for one, either. Thanks again for your help!

    \o
     
    Last edited: Mar 29, 2022
  8. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,580
    I wouldn't hold your breathe waiting for help from us again in the future...
     
    Munchy2007 likes this.
  9. JasonC_

    JasonC_

    Joined:
    Oct 27, 2019
    Posts:
    66
    Hey man, so here's the thing. I've got the Icon usage thing under control, and actually don't need or want any help with that. It's a whole complicated thing that would take a lot of time and energy to explain, with a whole bunch of context, that's already been thought about and re-thought about and tossed around and planned and re-planned on my end, and so I just don't need any advice there.

    The other thing is, this post has the question "how do I add such-and-such assembly", and a good concise answer (yours). Anything else becomes noise that somebody Googling for the same question some day would have to sift through.

    So I took the concise option of not adding more noise to the internet and just hoping that you'd get the hint. You did not. I believe I was polite in my first replies. Post #5 ended the informative part of this thread. Post #6 did not need to be posted. So there is a lesson to be learned about taking hints here. Also, I don't know (or want to know) why you're being insistent on providing unsolicited advice to a complete stranger. I don't know if that's good or bad, but it was certainly nonproductive here, and so it may be something to think about.

    I had a question. It was concise and the relevant info was included. You answered it. It was a clear and useful answer. I appreciate that, seriously. :) And ... that's that.

    Sometimes, people just don't need help with certain things, and generally, you don't need to receive justification for that. So please, take the hint and let it go. You helped, and again, thanks, and now the topic is resolved.
     
    Last edited: Mar 29, 2022
    domFC, Talsidor, ink13 and 2 others like this.
  10. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,580
    Hey that's fine. You don't need to "justify" anything.

    Was just letting you know, using your own words, that I likely won't be offering you assistance in the future.

    :)