Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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
8
Question by robhuhn · Oct 01, 2013 at 12:48 PM · editorguilayoutscroll view

EditorGUILayout split view (resizable scroll view)

I did some search on the internet but didn't find any info how to create a split view or resizable scroll view within an EditorWindow.

When I say 'split view' I mean two views in one window with a variable width (split vertical) or height (split horizontal). E.g. the console in unity is having one where the log title is displayed in the upper view and log details in the lower view.

EditorGUILayout doesn't seem to have such an specific element, so I guess it must be possible using a scroll view somehow but I can't figure out how to get this resize mouse icon when hovering the bottom of the scroll view.

Is there an out-of-the-box solution for that?

Thanks in advance

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
17
Best Answer

Answer by Jamora · Oct 01, 2013 at 06:56 PM

To get the mouse cursor to change like in the Editor Console, you can use EditorGUIUtility.AddCursorRect. I so enjoyed your question that I wrote an EditorWindow with split-view functionality:

 using UnityEngine;
 using UnityEditor;
 
 public class SplitViewWindow : EditorWindow
 {
     private Vector2 scrollPos = Vector2.zero;
     float currentScrollViewHeight;
     bool resize = false;
     Rect cursorChangeRect;
     
     [MenuItem("MyWindows/SplitView")]
     public static void Init(){
          EditorWindow t = GetWindow<tesdteditro>();
     }
     
     void OnEnable(){
         this.position = new Rect(200,200,400,300);
         currentScrollViewHeight = this.position.height/2;
         cursorChangeRect = new Rect(0,currentScrollViewHeight,this.position.width,5f);
     }
     
     void OnGUI(){
         GUILayout.BeginVertical();
         scrollPos = GUILayout.BeginScrollView(scrollPos,GUILayout.Height(currentScrollViewHeight));
             for(int i=0;i<20;i++)
             GUILayout.Label("dfs");
         GUILayout.EndScrollView();
                 
         ResizeScrollView();

             GUILayout.FlexibleSpace();
             GUILayout.Label("Lower part");
             
         GUILayout.EndVertical();
         Repaint();
     }
     
     private void ResizeScrollView(){
         GUI.DrawTexture(cursorChangeRect,EditorGUIUtility.whiteTexture);
         EditorGUIUtility.AddCursorRect(cursorChangeRect,MouseCursor.ResizeVertical);
         
         if( Event.current.type == EventType.mouseDown && cursorChangeRect.Contains(Event.current.mousePosition)){
             resize = true;
         }
         if(resize){
             currentScrollViewHeight = Event.current.mousePosition.y;
             cursorChangeRect.Set(cursorChangeRect.x,currentScrollViewHeight,cursorChangeRect.width,cursorChangeRect.height);
         }
         if(Event.current.type == EventType.MouseUp)
             resize = false;        
     }
 }


[2]: http://docs.unity3d.com/Documentation/ScriptReference/MouseCursor.html

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 robhuhn · Oct 02, 2013 at 07:36 AM 0
Share

That's great! Thank you very much Jamora

avatar image Sky-Slider · Aug 30, 2017 at 02:57 PM 0
Share

This solution does not work correctly if $$anonymous$$ouseUp event occurs outside the window. You need to use RawType Event like this: Event.current.rawType == EventType.mouseUp.

avatar image pdinklag · Dec 24, 2018 at 08:55 AM 0
Share

If any control in either side of the split view also handles mouse events, make sure to use the events in mouseDown and mouseDrag by adding Event.current.Use(), otherwise things may get confused.

avatar image
0

Answer by mitchmunro · Jul 18, 2021 at 03:59 AM

Yo, I just found this and it is useful! Though there were a few errors in the script due to it being 8 years old. Here is an updated version I edited for 2021.

 using UnityEngine;
 using UnityEditor;
 
 public class SplitViewWindow : EditorWindow
 {
     private Vector2 scrollPos = Vector2.zero;
     float currentScrollViewHeight;
     bool resize = false;
     Rect cursorChangeRect;
 
     [MenuItem("Example/SplitView")]
     public static void Init()
     {
         EditorWindow t = GetWindow<SplitViewWindow>();
     }
 
     void OnEnable()
     {
         this.position = new Rect(200, 200, 400, 300);
         currentScrollViewHeight = this.position.height / 2;
         cursorChangeRect = new Rect(0, currentScrollViewHeight, this.position.width, 5f);
     }
 
     void OnGUI()
     {
         GUILayout.BeginVertical();
         scrollPos = GUILayout.BeginScrollView(scrollPos, GUILayout.Height(currentScrollViewHeight));
         for (int i = 0; i < 20; i++)
             GUILayout.Label("dfs");
         GUILayout.EndScrollView();
 
         ResizeScrollView();
         GUILayout.FlexibleSpace();
         GUILayout.Label("Lower part");
 
         GUILayout.EndVertical();
         Repaint();
     }
 
     private void ResizeScrollView()
     {
         GUI.DrawTexture(cursorChangeRect, EditorGUIUtility.whiteTexture);
         EditorGUIUtility.AddCursorRect(cursorChangeRect, MouseCursor.ResizeVertical);
 
         if (Event.current.type == EventType.MouseDown && cursorChangeRect.Contains(Event.current.mousePosition))
         {
             resize = true;
         }
         if (resize)
         {
             currentScrollViewHeight = Event.current.mousePosition.y;
             cursorChangeRect.Set(cursorChangeRect.x, currentScrollViewHeight, cursorChangeRect.width, cursorChangeRect.height);
         }
         if (Event.current.type == EventType.MouseUp)
             resize = false;
     }
 }

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

18 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

Related Questions

GUILayout.MinHeight and EditorGUILayout.BeginScrollView not respecting layout options. 1 Answer

Using EditorGUILayout controls in OnSceneGUI() 2 Answers

Issues with EditorGUILayout, and GUILayout, after installing Unity4 0 Answers

Is it possible to make EditorGuiLayout.ObjectField(Texture2D) look like ObjectField(String,Texture2D)? 2 Answers

Create a custom editor window with repeating subsection (mockup included) 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