• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Afterbrain · Nov 20, 2019 at 10:44 AM · .netlibrarydrawing

System.Drawing or equivalent.,Getting System.Drawing to work in unity - or alternative library.

I need to draw a curve passing through a set a points. System.Drawing has the perfect function for it, Graphics.DrawCurve(), however, I cannot get it to work.

  • System.Drawing.Common.dll compiles with .Net standard 2.0, but does not seem to be supported. Error: PlatformNotSupportedException: System.Drawing is not supported on this platform.

  • With other version of the .dll/ .NET the compiler cannot find System.Drawing.Graphics.

Anyone has any idea if it is possible to get this to work (and explanation as to why not, if that is the case would also be greatly appreciated)? Or if there is any other library with a similar function? I found several options for drawing Bezier curves, but I cannot find anything that will fit a curve to a list of points the way DrawCurve does.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Bunny83 · Nov 20, 2019 at 03:44 PM

Well first of all it should be noted that the Graphics class in the System.Drawing namespace just capsulates a GDI+ rendering surface which is a Windows / Microsoft proprietary interface. Since Unity uses Mono or the IL2CPP compiler it's quite difficult to actually get it working. The classical System.Drawing.dll requires the actual .NET framework and a windows system. Mono does have it's own System.Drawing implementation however it still just capsulates the GDI+ native objects of the windows API.


Using System.Drawing, even when building for windows PCs only, would be a complete overkill. This assembly (and all dependencies) are huge. Also you would actually create a native windows object (like a bitmap or DIP image) where you would need to extract the pixel information, convert it into something Unity can use and create an actual Texture2D in Unity. Of course it's probably possible with some native code plugin magic to somehow transfer the data on a lower level. Though this is way too complicated to draw a curve.


As you can read in the documenation of DrawCurve it just draws a cardinal CatmullRom spline. The default tension is set to 0.5 unless you use an overload and specify a different one. If you don't want to work through the interpolation of such a spline yourself, the Centripetal Catmull-Rom spline wikipedia article has a rudimentary implementation. This implementation is not really well made since it should just show an example. I haven't really used the following things nor checked their quality. However I think they should provide you some code examples and snippets to get started:


https://www.habrador.com/tutorials/interpolation/1-catmull-rom-splines/
http://wiki.unity3d.com/index.php/Hermite_Spline_Controller
https://en.wikibooks.org/wiki/Cg_Programming/Unity/Hermite_Curves
https://assetstore.unity.com/detail/tools/modeling/splinemesh-104989(related forum post)


Some paid assets my google search found:
https://assetstore.unity.com/detail/tools/animation/aurora-spline-9953
https://assetstore.unity.com/detail/tools/utilities/dreamteck-splines-61926

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Bunny83 · Nov 20, 2019 at 03:45 PM 0
Share

ps: you haven't mentioned what platform(s) you actually want to target.

avatar image Afterbrain · Nov 22, 2019 at 03:18 PM 0
Share

Thank you so much! That is exactly what I wanted to know. With the Wikipedia article I should be able to get my own implementation. (platform was just windows, but agreed, Graphics looks like an overkill.)

avatar image cjgstudio · Nov 23, 2020 at 09:46 PM 0
Share

I dislike this answer. It offers alternatives due to "bad design" over the op's query regarding getting system.drawing working. Regardless if he got it working fine, ill continue trawling as this solution wont work for me.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

117 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

The classes in the module cannot be loaded? 0 Answers

Unity building error with .dll compiled in .NET 3.5. 0 Answers

How do you integrate the EPPlus library into Unity? 2 Answers

Why is there an option to choose full or subset .Net 2.0 library ? 1 Answer

Including Google Apis to Unity .Net and C# 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges