0
私のカスタムインスペクタの文字領域の文字列の最大長を制限したい。私は以下のようにコードを作成しようとしました:テキスト領域の文字列長を制限する方法は? [Editor Scripting]
if(EditorGUI.EndChangeCheck()){
if(_dTarget.mazeNumData.Length >= 338){
_dTarget.mazeNumData.Remove((_dTarget.mazeNumData.Length - 1) - 3, 3);
}
}
しかし、それは動作しませんでした。私のコードに問題はありませんか?
私の完全なコード:
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);
}
}
答えに感謝します。私はあなたが提案したように私のコードを変更しましたが、それでも動作しませんでした。コードは次のとおりです:http://pastebin.com/n54XNKwQ –
@AliAkbarはあなたのペーストビンを編集しました:[http://pastebin.com/Uu8C9bTQ](http://pastebin.com/Uu8C9bTQ) –
ありがとうございました!しかし、問題は、テキスト領域の外のどこかをクリックすると、最後の3文字だけが削除されることです。 –