Advertisement
Guest User

Untitled

a guest
Jan 12th, 2017
442
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using UnityEngine;
  2. using UnityEditor;
  3. using System.Collections;
  4.  
  5. [CustomEditor(typeof(DigitTotal))]
  6. public class DigitTotalEditor : Editor {
  7.  
  8.     private DigitTotal _dTarget;
  9.  
  10.     private const int _maxDigit = 335;
  11.     private string _placeHolder = string.Empty;
  12.  
  13.     public override void OnInspectorGUI() {
  14.         _dTarget = (DigitTotal)target;
  15.        
  16.         _placeHolder = _dTarget.mazeNumData;
  17.         if(_placeHolder.Length > 335){
  18.             // remember to reassign the value back to the place
  19.             _dTarget.mazeNumData = _placeHolder.Substring(0, _maxDigit - 1);
  20.         }
  21.  
  22.         DrawDefaultInspector();
  23.         DrawCustomInspector();
  24.     }
  25.  
  26.     void DrawCustomInspector() {
  27.         GUIStyle guiStyle = EditorStyles.textArea;
  28.         guiStyle.wordWrap = true;
  29.  
  30.         EditorGUI.BeginChangeCheck();
  31.  
  32.         _dTarget.mazeNumData = EditorGUILayout.TextArea(_dTarget.mazeNumData, guiStyle, new GUILayoutOption[]
  33.         {
  34.             GUILayout.Height(100f),
  35.             GUILayout.Width(250f),
  36.         });
  37.  
  38.         if(EditorGUI.EndChangeCheck()){
  39.             if(_dTarget.mazeNumData.Length >= 338){
  40.                 _dTarget.mazeNumData.Remove((_dTarget.mazeNumData.Length - 1) - 3, 3);
  41.             }
  42.         }
  43.  
  44.         GUILayout.Space(5f);
  45.         GUILayout.Label("Digits : " + _dTarget.mazeNumData.Length, EditorStyles.boldLabel);
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement