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 Heukhyeon · Jan 09, 2018 at 01:25 AM · inspectorcustom editorcustom-inspector

Can not you change the default GUI style of EditorGUI in OnInspectorGUI?

Information about the GUI skins on the Internet usually tells you to open a separate editor window and work there. However, I would like to use only some of the fonts, etc. in the basic editor component window.

 GUISkin skin;
 public override void OnInspectorGUI()
 {
     StyleInit(); //Edit the internal GUI styles of the GUI skin.
     GUI.skin = skin;
     base.OnInspectorGUI();
     script.test = GUILayout.TextField(script.test);
 }
 void StyleInit()
 {
     skin = EditorGUIUtility.GetBuiltinSkin(EditorSkin.Inspector);
     skin.font = font;
     labelStyle = new GUIStyle(EditorStyles.label);
     labelStyle.font = font;
     labelStyle.fontSize = defaultFontSize;
     skin.label = labelStyle;

     popupStyle = new GUIStyle(EditorStyles.popup);
     popupStyle.font = font;
     popupStyle.fontSize = defaultFontSize;
     popupStyle.fixedHeight = defaultFontSize;

     textFieldStyle = new GUIStyle(EditorStyles.textField);
     textFieldStyle.font = font;
     textFieldStyle.fontSize = defaultFontSize;
     textFieldStyle.fixedHeight = defaultFontSize + 5;
     skin.textField = textFieldStyle;

     buttonStyle = new GUIStyle(EditorStyles.miniButton);
     buttonStyle.font = font;
     buttonStyle.fontSize = defaultFontSize;
     buttonStyle.fixedHeight = defaultFontSize + 10;
     skin.button = buttonStyle;

     checkStyle = new GUIStyle(EditorStyles.toggle);
     checkStyle.font = font;
     checkStyle.fontSize = defaultFontSize;
     checkStyle.fixedHeight = defaultFontSize + 10;
     skin.toggle = checkStyle;

     boxStyle = new GUIStyle(GUI.skin.box);
     boxStyle.font = font;
     boxStyle.alignment = TextAnchor.UpperLeft;
     boxStyle.fontSize = defaultFontSize;
     skin.box = boxStyle;

     submitStyle = new GUIStyle(EditorStyles.miniButton);
     submitStyle.font = font;
     submitStyle.fontSize = (int)(defaultFontSize * 1.5f);
     submitStyle.fixedHeight = defaultFontSize * 2;

     objectStyle = new GUIStyle(EditorStyles.objectField);
     objectStyle.font = font;
     objectStyle.fontSize = defaultFontSize;
     objectStyle.fixedHeight = defaultFontSize + 5;
     //boxStyle.fixedHeight = defaultFontSize + 10;

 }

Here is the Edtior script for the component that wants to change the GUI skin. I created a GUI skin file in the Editor Default Resource folder as shown in this link, loaded it into EditorGUIUtility, and applied the GUI.skin attribute to my GUI skin before running the base function in OnInspectorGUI. alt text

However, no matter what method you use, you can not control the style of the inspector that is drawn in Unity by default. (The above function called base's OnInspectorGUI, but it did not call DrawDefaultInspector)

As you can see from the last TextField, when I manually set the TextField through the GUILayout call in the editor script, my intention was to come up without adding a separate GUIStyle. However, it is very troublesome to specify a field in the editor whenever you want to express more variables. Because of this, I want to follow the basic inspecting method of basic expression and change only some GUI style such as font.

Is this impossible? If you want to output TextFields and so on in modified fonts, is there only a way to make TextFields correspond to each other in the editor script?

1.png (5.2 kB)
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
1

Answer by Heukhyeon · Jan 09, 2018 at 02:36 AM

good. This was a much simpler problem than I thought. The reason I did not change the existing EditorStyle directly was that the output properties of existing components such as Transform changed when the property was directly changed.

But after these steps, I could only change the EditorStyle of my intended component.

 GUIStyle label;
 GUIStyle textField;
 Font font;
 public override void OnInspectorGUI()
 {
     BackUP();
     base.OnInspectorGUI();
     Revert();
 }
 void BackUP()
 {
     label = new GUIStyle(EditorStyles.label);
     textField = new GUIStyle(EditorStyles.textField);
     EditorStyles.label.font = font;
     EditorStyles.textField.font = font;
 }
 void Revert()
 {
     RevertStyle(EditorStyles.label, label);
     RevertStyle(EditorStyles.textField, textField);
 }
 void RevertStyle(GUIStyle target,GUIStyle backup)
 {
     target.font = backup.font;
     target.fixedHeight = backup.fixedHeight;
 }

alt text

However, at this time, when FixedHeight is modified, TextField or Label may appear to invade another property area. (That is, the height of the current property is not calculated properly.) This is true even if wrapped in BeginVertical ~ EndVertical of EditorGUILayout.


2.png (35.0 kB)
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

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

75 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

Related Questions

How to assign a rigidbody in custom inspector? 1 Answer

How can i get SerializedProperty from UnityEvent which in List. Sorry for my Eng. 2 Answers

Questions Regarding Images in Custom Inspector/Editor 1 Answer

Make a custom inspector that shows a group of variables in form of list 2 Answers

How to Hide/Show List or Array in the inspector based on a variable? 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