Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ------- MyStringScriptableObject .cs
- using System.Collections.Generic;
- using UnityEngine;
- [CreateAssetMenu ( fileName = "MyStringScriptableObject", menuName = "New Scriptable Object/MyStringScriptableObject", order = 1 )]
- public class MyStringScriptableObject : ScriptableObject
- {
- public List<string> myStrings;
- public MyStringScriptableObject ( )
- {
- myStrings = new List<string> ( );
- }
- }
- // ------- ListEditor .cs
- using System.Collections.Generic;
- using UnityEditor;
- using UnityEngine;
- [CustomEditor ( typeof ( MyStringScriptableObject ) )]
- public class ListEditor : Editor
- {
- int currentIndex = 0;
- int lastIndex = 0;
- int pageSize = 3;
- bool updateList = true;
- public override void OnInspectorGUI ( )
- {
- MyStringScriptableObject myStrings = ( MyStringScriptableObject ) target;
- if ( myStrings == null ) return;
- // --------------------------------------------------------------------------------- Default Map
- if ( currentIndex == 0 )
- {
- if ( myStrings.myStrings == null ) myStrings.myStrings = new List<string> ( 10 );
- if ( myStrings.myStrings.Count == 0 )
- {
- lastIndex = 10;
- for ( int i = 0; i < lastIndex; i++ )
- myStrings.myStrings.Add ( $"New String at Index [{i}]..." );
- }
- lastIndex = Mathf.Clamp ( currentIndex + pageSize, 0, myStrings.myStrings.Count );
- }
- // --------------------------------------------------------------------------------- Previous And Next Buttons
- GUILayout.BeginHorizontal ( );
- if ( GUILayout.Button ( "< Prev", GUILayout.ExpandWidth ( false ) ) )
- {
- if ( currentIndex > 0 )
- {
- currentIndex = Mathf.Clamp ( currentIndex - pageSize, 0, myStrings.myStrings.Count );
- lastIndex = Mathf.Clamp ( currentIndex + pageSize, 0, myStrings.myStrings.Count );
- }
- updateList = true;
- }
- GUILayout.Space ( 5 );
- if ( GUILayout.Button ( "Next >", GUILayout.ExpandWidth ( false ) ) )
- {
- if ( currentIndex < ( myStrings.myStrings.Count - pageSize ) )
- {
- currentIndex = Mathf.Clamp ( currentIndex + pageSize, 0, myStrings.myStrings.Count );
- lastIndex = Mathf.Clamp ( currentIndex + pageSize, 0, myStrings.myStrings.Count );
- updateList = true;
- }
- updateList = true;
- }
- GUILayout.EndHorizontal ( );
- EditorGUIUtility.labelWidth = 200;
- currentIndex = EditorGUILayout.IntField ( "Current Index", currentIndex, GUILayout.ExpandWidth ( false ) );
- for ( int i = currentIndex; i < lastIndex; i++ )
- {
- EditorGUI.BeginChangeCheck ( );
- myStrings.myStrings [ i ] = EditorGUILayout.TextField ( $"Text[{i}]", myStrings.myStrings [ i ] );
- if ( EditorGUI.EndChangeCheck ( ) )
- EditorUtility.SetDirty( target );
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment