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 seaders · Nov 05, 2014 at 08:25 PM · editorbuttontext

Custom editor for Text / Button for externalising texts

We're externalising all texts in our game, and want an easy and efficient way to set it all via the GUI. Basically when anyone creates a button, or label, or anything with text in, we want them to be able to put in the text ID of that component, "TEXT_ID_OK" for instance, and the text associated with that ID show up on it.

I've tried the below script in "ButtonEditor.cs" in the Assets/Editor, but it's done nothing at all, same with a near identical "TextEditor.cs" file. The Inspector editor stays exactly the same with no change.

 using UnityEngine;
 using UnityEditor;
 using UnityEngine.UI; 
 
 [CustomEditor(typeof(Button))]
 public class ButtonEditor : Editor
 {
     public override void OnInspectorGUI()
     {
         Button button = (Button)target;
         Text text = button.GetComponentsInChildren<Text>()[0];
         text.text = GetTextFromId(EditorGUILayout.TextField("Button TextID", text.text));
         DrawDefaultInspector();
     }
 }
 

Can anyone point out what I'm doing wrong? Can you not set custom editors for default components? Am I referencing the incorrect components? When I reference "CustomButton" (which does nothing but inherit from Button) instead of just "Button" it works as expected, but but nothing happens when just "Button" or "Text".

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
2

Answer by Nik-Space · Jan 30, 2015 at 05:36 PM

I know this quastion is old but ...

I faced the same problem and i did some digging on the UnityEditor.UI and i find out that this is not possible to be done that easy.

At least not like that [CustomEditor(typeof(Button))] Because the new UI Inspectors are based form multiple classes.

What do i mean with that. Lets see Tranform for example. the Class "Tranform" has as Editor Inspector the Class "TransformInspector" and that has as base the Editor.

So the we can use that:

 [CustomEditor(typeof(Transform))]
 public class TransformCustomInspector: Editor

But on the new UI is more complex. The Class that is called as Inspector for the "Text" is named "TextEditor" and has as base the "GraphicEditor"

and at the OnInspectorGUI it calls the "PropertyField"s of a "Text" and a "FontData"

And in the FontDataDrawer i find all the Editor GUI is on the Default Inspector of a Text. Without the textarea that is on the top.

I try this then

 [CustomEditor(typeof(Text), true)]
 public class TextInspector : UnityEditor.UI.TextEditor 

But still i get nothing.

I realy can't find an anwser to that too.

So i think the best way is to make a "CustomButton" Class as you said.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Changing Text Based off of a Prefab 0 Answers

Edit Default Text Mesh Pro Component 0 Answers

gui text button dont work 1 Answer

GUI Button appears when Paused 1 Answer

Change text in text component from editor script 1 Answer


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