Эх сурвалжийг харах

disable UGUI resizing as it was broken #4

Scrublord1336 6 жил өмнө
parent
commit
f2eeaac70d

+ 11 - 42
src/XUnity.AutoTranslator.Plugin.Core/TranslationInfo.cs

@@ -33,55 +33,24 @@ namespace XUnity.AutoTranslator.Plugin.Core
       {
          if( graphic == null ) return;
 
-         if( graphic is Text )
-         {
-            var ui = (Text)graphic;
+         var type = graphic.GetType();
 
-            // text is likely to be longer than there is space for, simply expand out anyway then
-            var width = ( (RectTransform)ui.transform ).rect.width;
-            var quarterScreenSize = Screen.width / 5;
+         // special handling for NGUI to better handle textbox sizing
+         if( type.Name == UILabelClassName )
+         {
+            var originalMultiLine = type.GetProperty( MultiLinePropertyName )?.GetGetMethod()?.Invoke( graphic, null );
+            var originalOverflowMethod = type.GetProperty( OverflowMethodPropertyName )?.GetGetMethod()?.Invoke( graphic, null );
 
-            // width < quarterScreenSize is used to determine the likelihood of a text using multiple lines
-            // the idea is, if the UI element is larger than the width of half the screen, there is a larger
-            // likelihood that it will go into multiple lines too.
-            var originalHorizontalOverflow = ui.horizontalOverflow;
-            if( ui.verticalOverflow == VerticalWrapMode.Truncate && width < quarterScreenSize && !ui.resizeTextForBestFit )
-            {
-               // will prevent the text from going into multiple lines and from "dispearing" if there is not enough room on a single line
-               ui.horizontalOverflow = HorizontalWrapMode.Overflow;
-            }
-            else
-            {
-               ui.horizontalOverflow = HorizontalWrapMode.Wrap;
-            }
+            type.GetProperty( MultiLinePropertyName )?.GetSetMethod()?.Invoke( graphic, new object[] { true } );
+            type.GetProperty( OverflowMethodPropertyName )?.GetSetMethod()?.Invoke( graphic, new object[] { 0 } );
 
             _reset = g =>
             {
-               var gui = (Text)g;
-               gui.horizontalOverflow = originalHorizontalOverflow;
+               var gtype = g.GetType();
+               gtype.GetProperty( MultiLinePropertyName )?.GetSetMethod()?.Invoke( g, new object[] { originalMultiLine } );
+               gtype.GetProperty( OverflowMethodPropertyName )?.GetSetMethod()?.Invoke( g, new object[] { originalOverflowMethod } );
             };
          }
-         else
-         {
-            var type = graphic.GetType();
-
-            // special handling for NGUI to better handle textbox sizing
-            if( type.Name == UILabelClassName )
-            {
-               var originalMultiLine = type.GetProperty( MultiLinePropertyName )?.GetGetMethod()?.Invoke( graphic, null );
-               var originalOverflowMethod = type.GetProperty( OverflowMethodPropertyName )?.GetGetMethod()?.Invoke( graphic, null );
-
-               type.GetProperty( MultiLinePropertyName )?.GetSetMethod()?.Invoke( graphic, new object[] { true } );
-               type.GetProperty( OverflowMethodPropertyName )?.GetSetMethod()?.Invoke( graphic, new object[] { 0 } );
-
-               _reset = g =>
-               {
-                  var gtype = g.GetType();
-                  gtype.GetProperty( MultiLinePropertyName )?.GetSetMethod()?.Invoke( g, new object[] { originalMultiLine } );
-                  gtype.GetProperty( OverflowMethodPropertyName )?.GetSetMethod()?.Invoke( g, new object[] { originalOverflowMethod } );
-               };
-            }
-         }
       }
 
       public void UnresizeUI( object graphic )