فهرست منبع

some type checking

Scrublord1336 6 سال پیش
والد
کامیت
73e806f0d0

+ 6 - 0
src/XUnity.AutoTranslator.Plugin.Core/AutoTranslationPlugin.cs

@@ -423,6 +423,8 @@ namespace XUnity.AutoTranslator.Plugin.Core
 
       public string Hook_TextChanged_WithResult( object ui, string text )
       {
+         if( !ui.IsKnownType() ) return null;
+
          if( _hooksEnabled )
          {
             return TranslateOrQueueWebJob( ui, text, true );
@@ -432,6 +434,8 @@ namespace XUnity.AutoTranslator.Plugin.Core
 
       public void Hook_TextChanged( object ui )
       {
+         if( !ui.IsKnownType() ) return;
+
          if( _hooksEnabled )
          {
             TranslateOrQueueWebJob( ui, null, false );
@@ -440,6 +444,8 @@ namespace XUnity.AutoTranslator.Plugin.Core
 
       public void Hook_TextInitialized( object ui )
       {
+         if( !ui.IsKnownType() ) return;
+
          if( _hooksEnabled )
          {
             TranslateOrQueueWebJob( ui, null, true );

+ 14 - 1
src/XUnity.AutoTranslator.Plugin.Core/Extensions/ObjectExtensions.cs

@@ -14,7 +14,20 @@ namespace XUnity.AutoTranslator.Plugin.Core.Extensions
    {
       private static readonly object Sync = new object();
       private static readonly WeakDictionary<object, object> DynamicFields = new WeakDictionary<object, object>();
-      
+
+      public static bool IsKnownType( this object ui )
+      {
+         if( ui == null ) return false;
+
+         var type = ui.GetType();
+
+         return ui is Text
+            || ui is UnityEngine.GUIContent
+            || ( Types.UILabel != null && Types.UILabel.IsAssignableFrom( type ) )
+            || ( Types.TMP_Text != null && Types.TMP_Text.IsAssignableFrom( type ) )
+            || ( Types.AdvCommand != null && Types.AdvCommand.IsAssignableFrom( type ) );
+      }
+
       public static bool SupportsStabilization( this object ui )
       {
          if( ui == null ) return false;