Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Jiraiyah · Oct 12, 2015 at 01:40 PM · shaderruntimegenerationguiskin

Generating GUISkin by code?

Hi I am trying to make my code into a dll, I managed to patch the png images into the solution, but as much as i understand, now i need to generate all the custom styles and the gui skin by the code myself, this is what i have :

 public static GUISkin DarkSkin;
         public static GUISkin LightSkin;
 
         static GuiStyleUtility()
         {
             DarkSkin = GetDarkSkin();
             LightSkin = GetLightSkin();
         }
 
         private static GUISkin GetDarkSkin()
         {
             GUISkin skin = ScriptableObject.CreateInstance<GUISkin>();
             List<GUIStyle> styles = new List<GUIStyle>();
 GUIStyle style = new GUIStyle
             {
                 name = "ToolsViewBackground",
                 normal =
                 {
                     background = Resource.ViewBackNormalDark,
                     textColor = GraphicUtility.ColorFrom256(193, 193, 193, 75)
                 },
                 border = new RectOffset(2, 2, 2, 2),
                 fontSize = 18,
                 alignment = TextAnchor.MiddleCenter,
                 stretchWidth = true
             };
             styles.Add(style);
 
             skin.customStyles = styles.ToArray();
             skin.hideFlags = HideFlags.HideAndDontSave;
             return skin;
         }
     }


As much as I understand, this should generate the Gui skin and assign it to the public constant DarkSKin and i should be able to access it outside of the static class, but, when i generate the custom editor window that is using this skin it yells that the custom style is not found, of course i triple checked the typing and there is no error there. so how can i make this work? or how can I make a gui skin totally by code myself?

Comment
Add comment · Show 2
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 Jiraiyah · Oct 12, 2015 at 02:30 PM 0
Share

actually let me correct myself, it is generating the gui now, but, the problem is that the editor view is behaving strange, you see, there is 0 warning, 0 error, but the editor window is not loading images at all, to make things worse, i can't see the skin in hierarchy and i can't even make sure my images are being loaded properly or not :/

avatar image AceWillNeverDie Jiraiyah · Oct 27, 2015 at 01:07 PM 0
Share

When you die i cried very, very, very long!!!!! Why you didn`t escape????

2 Replies

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

Answer by DaiMangouDev · Oct 28, 2015 at 07:37 PM

         ProjectWindowUtil.CreateNewGUISkin();

someone exposed the code here

or you can do this. which give you more control over creation. best method

             GUISkin myGUISkin = new GUISkin();
 
             myGUISkin.name = "MyGUISkin";
 
            // set you box, button, slider ... values 
           // myGUISkin.box.hover.background  = SOME TEXTURE
 
            GUISkin gs = ScriptableObject.CreateInstance<GUISkin>();
            gs = myGUISkin;
            // create the new skin in the Assets folder
            AssetDatabase.CreateAsset(gs, "Assets");

now , I must say ... our projects look eerily similar . I am working with light and dark skins for my project too.I found a great way to work with images in the dll. you want to get you want to read the font files from your dll next right ?

Comment
Add comment · 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
0

Answer by Jiraiyah · Oct 29, 2015 at 03:52 AM

@DMDev I figured out the problem with my code, can't believe a single typo passed me after 4 times of code check. and yes I tried to use fonts as resources in my project but I couldn't figure out a way that would accept the font as byte[] and produce the font within the code, you know something that may work? right now, I can only think about some static script that uses InitializeOnLoad to copy the font from resources and put it into a resources folder by using system.io not unity itself and i don't like that solution :/

Comment
Add comment · Show 5 · 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 DaiMangouDev · Oct 29, 2015 at 12:56 PM 0
Share

You should post this reply as a comment to my answer. If i didn't check this question again I would never have known that you replied. Oh and if my answer is correct , you should accept it so that others know the answer too. As for fonts , I have a method that i'm working on that will get fonts from the resx but i haven't gotten any solid results yet.

But you can find a bunch of functions online that show how to convert byte arrays to objects

then you can try converting the object to a font . which is what i'm doing

avatar image Jiraiyah DaiMangouDev · Oct 29, 2015 at 01:09 PM 0
Share

Can we actually convert the .net object (not Unity.Object) to Unity Font??? hmm never thought about that one, i will do some research on both.net object and Unity.Object tomorrow, 2 point to u as reward for opening a new window for me there.

avatar image Jiraiyah DaiMangouDev · Oct 29, 2015 at 02:01 PM 1
Share

Actually I think I found a neat solution not only for font but anything that needs to be handled on unity side, take a look http://answers.unity3d.com/answers/437566/view.html with unity 5.x having all the features for free, this is no more problem, make asset bundles, add them to the dll project, stream it as bytes, instantiate it and get access to what ever is inside of it :D

avatar image DaiMangouDev Jiraiyah · Oct 29, 2015 at 03:00 PM 0
Share

interesting !, i never thought of using asset bundles. this WILL work :) really great. thanks for that!

Show more comments

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

32 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

Related Questions

Declaring/modifying lists at runtime 1 Answer

Is it possible to change blend mode in shader at runtime? 1 Answer

A way to move Texture's offset in runtime? 2 Answers

Triangulate a polygon 1 Answer

How to make trees in a terrain transparent in runtime? 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