//Draw a scroll bar section at relative location private Vector2 ScrollBarSection(Vector2 scrollPosition, Rect relativeRect, System.Action toDraw, Texture2D tex = null) { //get the correct dimensions based off the current window size relativeRect = EditorEX.AdjustRect(relativeRect, window.position); GUIStyle s = new GUIStyle(); //have bars slightly away from edge s.padding = new RectOffset(10, 5, 10, 5); //place texture in backgroud if texture given if (tex != null) { GUI.DrawTexture(new Rect(relativeRect), tex, ScaleMode.ScaleAndCrop); } GUIContent content = new GUIContent("This is a content", tex, "This is a tooltip"); GUILayout.BeginArea(relativeRect, content, s); scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition); EditorGUILayout.BeginVertical("box"); //what to draw inside here toDraw(); EditorGUILayout.EndVertical(); EditorGUILayout.EndScrollView(); GUILayout.EndArea(); return(scrollPosition); }
//DEPRECIATED??? GUILayout.SelectionGrid does this already... Though wrapping in scroll view is nice... //create relative section that lists a number of buttons and returns the value of the button most recently pressed private ButtonMenuInfo ButtonMenu(ButtonMenuInfo info, Rect relativeRect, string[] buttonLabels, Texture2D tex = null) { //get the correct dimensions based off the current window size relativeRect = EditorEX.AdjustRect(relativeRect, window.position); GUIStyle s = new GUIStyle(); //have bars slightly away from edge s.padding = new RectOffset(5, 5, 5, 5); //place texture in backgroud if texture given if (tex != null) { GUI.DrawTexture(new Rect(relativeRect.x, relativeRect.y, relativeRect.width, relativeRect.height), tex, ScaleMode.ScaleAndCrop); } GUILayout.BeginArea(relativeRect, s); EditorGUILayout.BeginVertical("box", GUILayout.MinWidth(100), GUILayout.MaxWidth(100), GUILayout.ExpandWidth(false)); info.scrollPosition = EditorGUILayout.BeginScrollView(info.scrollPosition); for (int i = 0; i < buttonLabels.Length; i++) { if (GUILayout.Button(buttonLabels[i])) { //set selected value to this info.selectedElement = i; } } //close EditorGUILayout.EndScrollView(); EditorGUILayout.EndVertical(); GUILayout.EndArea(); return(info); }
//******Start building Library of easy to use designs***** //Draw a texture at relative location private void DrawTextureSection(Rect relativeRect, Texture2D tex) { //get the correct dimensions based off the current window size relativeRect = EditorEX.AdjustRect(relativeRect, window.position); GUI.DrawTexture(new Rect(relativeRect), tex, ScaleMode.ScaleAndCrop); }