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
1
Question by Rs · Dec 13, 2016 at 11:08 PM · editorinspectorscrollviewguilayout

Editor GUILayout.ScrollView not scrolling when typing

I am having a rather frustrating time with ScrollViews. Here's a snippet from my custom editor that should be enough to reproduce the problem.

  EditorGUILayout.BeginVertical();
 scrollPosition = GUILayout.BeginScrollView (scrollPosition);
 _target.text = EditorGUILayout.TextArea(_target.text, style);
 GUILayout.EndScrollView ();
 EditorGUILayout.EndVertical ();

The problem is that when I give a few carriages so that the scroll bars appear, the scrolling does not follow the typing and I cannot see what I type.

Any ideas?

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 Adam-Mechtley · Dec 14, 2016 at 08:02 PM

Hi @Rs. That's super annoying! Would you mind filing a bug report please? In the meantime you can do something like this (though it's a little naive):

 EditorGUILayout.BeginVertical();
 scrollPosition = EditorGUILayout.BeginScrollView (scrollPosition);
 EditorGUI.BeginChangeCheck ();
 string newText = EditorGUILayout.TextArea(_target.text);
 if (EditorGUI.EndChangeCheck ())
 {
     if (newText.StartsWith (_target.text))
         scrollPosition.y = Mathf.Infinity;
     _target.text = newText;
 }
 EditorGUILayout.EndScrollView ();
 EditorGUILayout.LabelField (scrollPosition.ToString ());
 EditorGUILayout.EndVertical ();


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 Rs · Dec 15, 2016 at 04:46 PM 0
Share

Setting the y to $$anonymous$$athf.Infinity? :D I LI$$anonymous$$E THAT!

It's also quite clever to check if the text has changed in the end that way. The thing is that StartsWith does a full string comparison, I can't really do that in an asset I'm selling. Isn't there a way to know where the text cursor is? $$anonymous$$aybe I'm wrong but I kind of remember some API of that kind.

avatar image Rs · Dec 15, 2016 at 05:21 PM 0
Share

I'm trying this: http://answers.unity3d.com/questions/275973/find-cursor-position-in-a-textarea.html

avatar image Adam-Mechtley Rs · Dec 15, 2016 at 07:01 PM 1
Share

I posted on your other question. You could try manually walking like this (I've put both methods in so you can profile and compare performance):

 scrollPosition = EditorGUILayout.BeginScrollView (scrollPosition);
 EditorGUI.BeginChangeCheck ();
 string newText = EditorGUILayout.TextArea (targetText);
 if (EditorGUI.EndChangeCheck ())
 {
     string shorter, longer;
     if (newText.Length > targetText.Length)
     {
         shorter = targetText;
         longer = newText;
     }
     else
     {
         shorter = newText;
         longer = targetText;
     }
 
     UnityEngine.Profiling.Profiler.BeginSample ("STARTSWITH", this);
     bool changedAtEnd = longer.StartsWith (shorter);
     UnityEngine.Profiling.Profiler.EndSample ();
 
     UnityEngine.Profiling.Profiler.BeginSample ("$$anonymous$$ANUALLY WAL$$anonymous$$", this);
     changedAtEnd = true;
     for (int i = shorter.Length - 1; i >= 0; --i)
     {
         if (shorter[i] != longer[i])
         {
             changedAtEnd = false;
             break;
         }
     }
     UnityEngine.Profiling.Profiler.EndSample ();
 
     if (changedAtEnd)
         scrollPosition.y = $$anonymous$$athf.Infinity;
     targetText = newText;
 }
 EditorGUILayout.EndScrollView ();

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

72 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

Related Questions

How to allocate layout region inside the inspector? 1 Answer

Get mouse position in Editor based on screen coordinates 1 Answer

Inspector turns black on refresh 4 Answers

What should be handled in the custom inspector version of a script? 1 Answer

How to specify the rotation angle in degrees, in the inspector? 2 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