Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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 3D-Magic-VR · Mar 19, 2012 at 04:40 AM · monodevelopdllresourcescompilerimages

How to use an Image(PNG) and GUISkin inside a dll ?

Hi every one, I made a tool with a custom editor (buttons, frames, GUISkin, etc.) and compiled my tool into a dll (with Monodevelop), but, when I try to put the guiskin and the images, I can't use that inside the dll, I'm new about dll compilation and I don't understand many things, even I find some info about how to put and use resources into a dll but I get some errors like: can't convert -System.IO- to -Unityengine.Texture2D-, any help will be appreciated, thanks in advance.

Code Sample:

 using System;
 using UnityEngine;
 using UnityEditor;
 using System.IO;
 using System.Reflection;
 //
 public class MyTool : EditorWindow
 {
     Texture2D images;
     GUISkin mySkin;
     Assembly myAssembly;
     Stream imageStream;
     //
     static void Init()
     {
         // Draw the window.
     }
     //
     void OnEnable ()
     {
         myAssembly = Assembly.GetExecutingAssembly();
         images = myAssembly.GetManifestResourceStream("Images.Data.Button.png");
     }
     void OnGUI ()
     {
         GUI.skin = mySkin; // Here, I don't know how to search for the *.guiskin file inside the dll.
         GUI.Button(Rect(0, 0, 32, 32), images);
     }
 }
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

Answer by Bunny83 · Mar 20, 2012 at 05:52 PM

Unity uses their own AssetDatabase to handle all kind of assets, in the editor as well as at runtime. Things like GUISkins are stored in a custom format and can't be serialized into a custom format. Assets can only be used when they are inside the Assets folder.

However, you can load external images (only jpg and png) with Texture2D.LoadImage. All other assets need to be imported into the assetdatabase by Unity. From an editor script you can use the AssetDatabase to access and use any asset in the project.

If you made a custom editor you usually create a unitypackage by exporting all relevant stuff. When the user imports the package, all contained assets will be at the same relative position inside the Assets folder.

Compiling editor extensions into a .NET assembly is quite common but not necessary. Well it helps to protect the scripts from being altered accidentally. It does not save the code from being copied by others. .NET assemblies can easily decompiled since that's even a feature of the language itself.

Comment
Add comment · Show 4 · 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 3D-Magic-VR · Mar 20, 2012 at 06:32 PM 0
Share

Thanks for your reply, but unfortunately that's not what I need, I already do something like that ($$anonymous$$aterial Animator in AssetStore), but what I want to do now it's something like the Play$$anonymous$$akerEditor Dll by Hutong Games. Anyway thanks again for your reply

avatar image Bunny83 · Mar 20, 2012 at 07:03 PM 0
Share

It's not about what you need, it's about what is possible. A GUISkin needs the reference information of the Texture2D assets that should be used. This information is tracked by the AssetDatabase. You can't just save this information manually.

See this discussion of the Play$$anonymous$$aker author about the issue.

I don't have used the Playmaker yet, but they might have build the GUIStyles on-the-fly (like AngryAnt said) since you can't load them from outside the AssetDatabase.

If you have purchased Play$$anonymous$$aker, just use ILSpy and check out how they handle it.

btw. I don't get how your $$anonymous$$aterial Animator is related to this problem. Isn't it a runtime component?

avatar image 3D-Magic-VR · Mar 20, 2012 at 10:29 PM 0
Share

$$anonymous$$ore or Less, if you check the package of my tool there's an image (Logo) like Asset, but if you check the playmaker package you will see no images like buttons, frames and logo, you can check a preview of the package content.

avatar image Bunny83 · Mar 21, 2012 at 10:49 AM 0
Share

I don't want to spread secret code, but i've took a look into the playmakereditor.dll. Like i've guessed above they create every GUIContent on the fly like this:

 FsmEditorStyles.LeftArrow = FsmEditorUtility.LoadDllResource("leftArrow", 23, 14);

The most important lines from LoadDllResource is like this:

 Assembly executingAssembly = Assembly.GetExecutingAssembly();
 Stream manifestResourceStream = executingAssembly.Get$$anonymous$$anifestResourceStream("HutongGames.Play$$anonymous$$akerEditor.Assets.Play$$anonymous$$aker.Editor.Resources." + resourceName + ".png");
 if (manifestResourceStream != null)
 {
     texture2D.LoadImage(FsmEditorUtility.ReadToEnd(manifestResourceStream));
     manifestResourceStream.Close();
 }

Like i said, you can't load Unity specific classes (GUISkin, $$anonymous$$esh, ...) from a byte-stream since they don't have any common deserialization methods. Images can be loaded, but only manually like this.

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.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How to change the target framework to Unity 3.5 .net Subset Base Class Libraries in the MonoDevelop-Unity? 1 Answer

Import C# project into my Unity solution 1 Answer

error issues : KeyNotFoundException 1 Answer

Running pdb2mdb.exe as a MonoDevelop 2 Answers

Unhandled Exception. We Hate Them, But They Happen 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges