I want to limit my string max length in text area in my custom inspector. I have tried to make code as below:
if(EditorGUI.EndChangeCheck()){
if(_dTarget.mazeNumData.Length >= 338){
_dTarget.mazeNumData.Remove((_dTarget.mazeNumData.Length - 1) - 3, 3);
}
}
But it didn't work.Is anything wrong with my code?
My full Code :
using UnityEngine;
using UnityEditor;
using System.Collections;
[CustomEditor(typeof(DigitTotal))]
public class DigitTotalEditor : Editor {
private DigitTotal _dTarget;
public override void OnInspectorGUI() {
_dTarget = (DigitTotal)target;
DrawDefaultInspector();
DrawCustomInspector();
}
void DrawCustomInspector() {
GUIStyle guiStyle = EditorStyles.textArea;
guiStyle.wordWrap = true;
EditorGUI.BeginChangeCheck();
_dTarget.mazeNumData = EditorGUILayout.TextArea(_dTarget.mazeNumData, guiStyle, new GUILayoutOption[]
{
GUILayout.Height(100f),
GUILayout.Width(250f),
});
if(EditorGUI.EndChangeCheck()){
if(_dTarget.mazeNumData.Length >= 338){
_dTarget.mazeNumData.Remove((_dTarget.mazeNumData.Length - 1) - 3, 3);
}
}
GUILayout.Space(5f);
GUILayout.Label("Digits : " + _dTarget.mazeNumData.Length, EditorStyles.boldLabel);
}
}