You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Just like Blender, allow the user to type numbers while scaling, rotating or translating as a multiplier.
I already wrote the code for a simple keyboard recorder. The problem has been finding an elegant way to add this to tools without having to copy and paste the logic everywhere. Something almost as simple as a C# property for the tools that support this feature (or an input focus related thing).
#if UNITY_EDITORusingSystem;usingUnityEditor;usingUnityEngine;namespaceAeternumGames.ShapeEditor{/// <summary>Processes keyboard numbers for typing multipliers during active tools and widgets.</summary>[Serializable]publicclassNumericKeyboardRecorder{/// <summary>The accumulated string of characters.</summary>privatestringaccumulator="";privatefloatlastValidFloat=0.0f;/// <summary>Gets or sets (clears) whether the user has typed a value using the keyboard.</summary>publicboolhasValue{get{if(accumulator.Length==0)returnfalse;returntrue;}set{if(!value)Reset();}}/// <summary>The last valid value typed assuming <see cref="hasValue"/> is true.</summary>publicfloatvalue=>lastValidFloat;/// <summary>The text typed assuming <see cref="hasValue"/> is true.</summary>publicstringtext=>accumulator;/// <summary>Must be called on key down events.</summary>publicboolOnKeyDown(KeyCodekeyCode){varcharacter=(char)keyCode;// add floating point related characters to the accumulator.if(ValidateCharacter(character)){accumulator+=character;UpdateValue();returntrue;}if(hasValue){// backspace can be used to remove the last character.if(keyCode==KeyCode.Backspace){OnBackspace();UpdateValue();returntrue;}// minus can be used to negate the number.if(keyCode==KeyCode.Minus){OnMinus();UpdateValue();returntrue;}}returnfalse;}// whitelist the input characters related to floating point numbers.privateboolValidateCharacter(charcharacter){switch(character){case'0':case'1':case'2':case'3':case'4':case'5':case'6':case'7':case'8':case'9':case'.':returntrue;}returnfalse;}privatevoidOnBackspace(){if(accumulator.Length==0)return;accumulator=accumulator.Remove(accumulator.Length-1,1);}privatevoidOnMinus(){if(accumulator.ContainsInvarianCulture("-"))accumulator=accumulator.Replace("-","");elseaccumulator="-"+accumulator;}privatevoidUpdateValue(){if(ExpressionEvaluator.Evaluate(accumulator,outfloatnumber))lastValidFloat=number;}/// <summary>Resets the current input.</summary>publicvoidReset(){accumulator="";lastValidFloat=0.0f;}}}
#endif
The text was updated successfully, but these errors were encountered:
Just like Blender, allow the user to type numbers while scaling, rotating or translating as a multiplier.
I already wrote the code for a simple keyboard recorder. The problem has been finding an elegant way to add this to tools without having to copy and paste the logic everywhere. Something almost as simple as a C# property for the tools that support this feature (or an input focus related thing).
The text was updated successfully, but these errors were encountered: