0

Firstly i am unable to use System.Drawing in my c# script for some reason . I'm working in Unity3d and the library reference gets kicked out each time i load the script.

i am access the resources of my dll using this method

//DaiM.Reality is the namespace 
// fgla is a class

            Assembly asm = typeof(DaiM.Reality.fgla).Assembly;
        string resourcename = asm.GetName().Name + ".Properties.Resources";
        ResourceManager rm = new ResourceManager(resourcename, asm);
        Texture2D imh = (Texture2D)rm.GetObject("flag"); // the problem
// error :: InvalidCastException: Cannot cast from source type to destination type.

if I could used System.Drawing then i could just read the pixels from the bitmap and apply them to a new Texture2D. but unity wont let me use System.Drawing . I guess that is because some of the classes in the System.Drawing library and UnityEngine library conflict

1 Answers1

0

1) System.Drawing is not included in Unity's default libraries. You should import System.Drawing.dll to your project yourself. For more information:

http://answers.unity3d.com/questions/53170/using-drawing-package-like-systemdrawing.html

2) The DLL you are trying to import should be compiled with Target Framework option set to some version that Unity understands (which is currently 2.0). Make sure it is set correctly.

3) Take a look at this post for importing images from a DLL:

http://forum.unity3d.com/threads/resources-load-in-c-dll.62561/#post-403356

Hope this helps.

Can Baycay
  • 875
  • 6
  • 11
  • I'm seeing the System.Drawing library is version 2.0 Okay sure thing , I will . thanks a lot that was very helpful –  Apr 02 '15 at 20:53
  • just one thing . i'm seeing ` Stream myStream = myAssembly.GetManifestResourceStream("HutongGames.PlayMakerEditor.Editor.Resources." + resourceName + ".png"); ` he says it woks but i'm not seeing where he points to Properties then Resources and this script is run from inside the dll ? –  Apr 02 '15 at 22:29
  • okay, it pointing directly to the resources folder. it keeps saying that my stream is null . could this be a problem on the dll side ? –  Apr 02 '15 at 22:39
  • I am sorry. I was missing a '.' –  Apr 02 '15 at 22:57