Question by
floralDenis · Feb 27, 2017 at 07:05 AM ·
listcustom editorscrollbar
How to create scrollbar in customized window?
Hello! I want to create a scrollbar with handle in this customized unity window. Help me please. Thanks in advance!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.IO;
public class LocalizedTextEditor : EditorWindow
{
public LocalizationData localizationData;
[MenuItem("Window/Localized Text Editor")]
static void Init()
{
EditorWindow.GetWindow(typeof(LocalizedTextEditor)).Show();
}
private void OnGUI()
{
if (localizationData != null)
{
SerializedObject serializedObject = new SerializedObject(this);
SerializedProperty serializedProperty = serializedObject.FindProperty("localizationData");
EditorGUILayout.PropertyField(serializedProperty, true);
serializedObject.ApplyModifiedProperties();
if (GUILayout.Button("Save data"))
{
SaveGameData();
}
}
if (GUILayout.Button("Load data"))
{
LoadGameData();
}
if (GUILayout.Button("Create new data"))
{
CreateNewData();
}
}
private void LoadGameData()
{
string filePath = EditorUtility.OpenFilePanel("Select localization data file", Application.streamingAssetsPath, "json");
if (!string.IsNullOrEmpty(filePath))
{
string dataAsJson = File.ReadAllText(filePath);
localizationData = JsonUtility.FromJson<LocalizationData>(dataAsJson);
}
}
private void SaveGameData()
{
string filePath = EditorUtility.SaveFilePanel("Save localization data file", Application.streamingAssetsPath, "", "json");
if (!string.IsNullOrEmpty(filePath))
{
string dataAsJson = JsonUtility.ToJson(localizationData);
File.WriteAllText(filePath, dataAsJson);
}
}
private void CreateNewData()
{
localizationData = new LocalizationData();
}
}
customizedwindow.png
(20.1 kB)
Comment
use EditorGUILayout.BeginScrollView and EditorGUILayout.EndScrollView
wrap all UI code you want scrollable, inside this two method calls.
private void OnGUI()
{
if (localizationData != null)
{
EditorGUILayout.BeginScrollView();
//..........
EditorGUILayout.EndScrollView();
}
}
Your answer
Follow this Question
Related Questions
Error with list of lists in custom editor 0 Answers
How to cast SerializedProperty back to custom class? 0 Answers
Custom Inspector List Reset 0 Answers
Custom inspector ReorderableList gives an error when adding item to list 0 Answers
Inheritance, List and PropertyDrawer,CustomPropertyDrawer and Inheritance 0 Answers