Bläddra i källkod

修复-Bestfit的Bug

LiuQilin 8 år sedan
förälder
incheckning
37cf20ba7e
2 ändrade filer med 18 tillägg och 6 borttagningar
  1. 18 6
      Assets/Script/Tool/UI/BestfitText.cs
  2. BIN
      ProjectSettings/GraphicsSettings.asset

+ 18 - 6
Assets/Script/Tool/UI/BestfitText.cs

@@ -9,6 +9,9 @@ public class BestfitText : Text
 {
     #region
 
+    private int VerticalMinSize;
+    private int VerticalMaxSize;
+
     protected string FormerText;
     
     #endregion
@@ -26,7 +29,7 @@ public class BestfitText : Text
         {
             FormerText = text;
             
-            StartCoroutine(DelayCall(Bestfit, 2));
+            StartCoroutine(DelayCall(Bestfit, 1));
         }
     }
 
@@ -43,7 +46,7 @@ public class BestfitText : Text
         {
             antiCrush++;
 
-            if (antiCrush > 100)
+            if (antiCrush > 1000)
             {
                 Debug.LogError("Crush");
 
@@ -52,7 +55,7 @@ public class BestfitText : Text
 
             float bestHeight = cachedTextGenerator.GetPreferredHeight(text, textGenerationSettings);
             
-            if (bestHeight > rectTransform.rect.size.y)
+            if (bestHeight > rectTransform.rect.size.y*canvas.scaleFactor)
             {
                 textGenerationSettings.fontSize--;
 
@@ -63,7 +66,7 @@ public class BestfitText : Text
 
                 shrink = true;
             }
-            else if (bestHeight < rectTransform.rect.size.y)
+            else if (bestHeight < rectTransform.rect.size.y * canvas.scaleFactor)
             {
                 if (shrink)
                 {
@@ -74,12 +77,21 @@ public class BestfitText : Text
 
                 expand = true;
             }
-            else if (bestHeight.Equal(rectTransform.rect.size.y))
+            else if (bestHeight.Equal(rectTransform.rect.size.y * canvas.scaleFactor))
             {
                 break;
             }
         }
-        
+
+        //if (textGenerationSettings.fontSize < VerticalMinSize)
+        //{
+        //    textGenerationSettings.fontSize = VerticalMinSize;
+        //}
+        //else if (textGenerationSettings.fontSize > VerticalMaxSize)
+        //{
+        //    textGenerationSettings.fontSize = VerticalMaxSize;
+        //}
+
         fontSize = textGenerationSettings.fontSize;
     }
 

BIN
ProjectSettings/GraphicsSettings.asset