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 theodox · Mar 05, 2013 at 07:05 AM · guieditortextarea

TextEditor in editor gui?

I've been trying to get access to the TextEditor for a TextArea object in an Editor window. I've used the same patterns I see in other examples and I think they work only in game gui, not editor gui. For example this works:

 Rect bounds = new Rect(10, 20, Screen.width - 10, Screen.height - 20);
 stringToEdit = GUI.TextArea(bounds, stringToEdit);
 int controlID = GUIUtility.GetControlID(bounds.GetHashCode(), FocusType.Keyboard);  
 TextEditor editor = (TextEditor)GUIUtility.GetStateObject(typeof(TextEditor), controlID -1);

but this does not:

 the_text= EditorGUILayout.TextArea(the_text, GUILayout.ExpandHeight(true));
 int controlID = EditorGUIUtility.GetControlID(b.GetHashCode(), FocusType.Keyboard);          
 TextEditor editor = (TextEditor)EditorGUIUtility.GetStateObject(typeof(TextEditor), controlID -1);

Am I right in thinking TextEditor can't be accessed in the editor? Or am I missing something obvious?

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

2 Replies

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

Answer by theodox · Mar 07, 2013 at 09:34 PM

For future reference: I've verified that the TextEditor is available when using GUI.Textarea but not when using EditorGUI.TextArea.

Comment
Add comment · Show 3 · 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 Jean-Fabre · Oct 10, 2013 at 12:12 PM 0
Share

how odd. Thanks, I could not think of checking that...

avatar image Demigiant · May 27, 2017 at 05:37 PM 0
Share

Did you find a solution to get the TextEditor for an EditorGUI TextField by any chance? Using regular GUI TextField in the editor prevents nice things like cut/copy/paste :(

avatar image Demigiant · May 27, 2017 at 06:10 PM 0
Share

Solved! :) See the answer I added

avatar image
8

Answer by Demigiant · May 27, 2017 at 06:10 PM

Found a way to grab the TextEditor for an EditorGUI.TextArea/Field (requires Reflection):

 TextEditor tEditor = typeof(EditorGUI)
      .GetField("activeEditor", BindingFlags.Static | BindingFlags.NonPublic)
      .GetValue(null) as TextEditor;
Comment
Add comment · Show 8 · 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 chen3286822 · Sep 12, 2017 at 02:19 AM 0
Share

$$anonymous$$any Thanks! You helped me a lot!

avatar image flashframe · Mar 19, 2019 at 12:16 AM 0
Share

Thank you thank you thank you!!

avatar image tcz8 · Apr 03, 2019 at 05:02 PM 0
Share

How do you actually use this? I got my TextArea in OnGui that draws properly but I'm not sure I get how to apply this.

avatar image Demigiant tcz8 · Apr 03, 2019 at 05:06 PM 0
Share

The TextEditor is what lies under the TextArea, and allows you to do more advanced text manipulation. You don't need it at all if you just want to use a normal TextArea (unless I misunderstood your comment :P)

avatar image tcz8 Demigiant · Apr 06, 2019 at 03:06 PM 0
Share

I think you're spot on. If I understand correctly, it allows grabbing the TextEditor instance of a text area which in turn provides access to a series of events and values needed to build a more complex text editor than a simple text box.

ie.: Is text selected, the content of the selection, etc...

Show more comments
avatar image MennoB · May 21, 2019 at 12:22 AM 0
Share

Thanks so much! I got this to work on an EditorGUILayout.PropertyField as well. Don't forget to perform a null check since this texteditor will refer to any textfield/propertyfield currently edited. If none is being edited this 'tEditor' is null.

avatar image Zuccinin · May 14, 2020 at 06:15 AM 0
Share

Could any of you guys answer my question as well? I just don't understand how this all works. I'm not that deep into editor scripting.

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

17 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

Related Questions

Create Multiple Foldouts. 1 Answer

How to know if something is selected in Hierarchy or in project. 5 Answers

Handling Undo/REdo in EditorWindow when editing DB record. 0 Answers

Add EditorUI elements when a button is pressed 0 Answers

EditorGUI like light explorer window 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