基础内容
必要插件安装 缓动曲线和动画基础 ElementFolder,Track与其次级模块,PathNode重构
This commit is contained in:
36
Assets/I2/Localization/Scripts/Targets/ILocalizeTarget.cs
Normal file
36
Assets/I2/Localization/Scripts/Targets/ILocalizeTarget.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace I2.Loc
|
||||
{
|
||||
public abstract class ILocalizeTarget : ScriptableObject
|
||||
{
|
||||
public abstract bool IsValid(Localize cmp);
|
||||
public abstract void GetFinalTerms( Localize cmp, string Main, string Secondary, out string primaryTerm, out string secondaryTerm);
|
||||
public abstract void DoLocalize(Localize cmp, string mainTranslation, string secondaryTranslation);
|
||||
|
||||
public abstract bool CanUseSecondaryTerm();
|
||||
public abstract bool AllowMainTermToBeRTL();
|
||||
public abstract bool AllowSecondTermToBeRTL();
|
||||
public abstract eTermType GetPrimaryTermType(Localize cmp);
|
||||
public abstract eTermType GetSecondaryTermType(Localize cmp);
|
||||
}
|
||||
|
||||
public abstract class LocalizeTarget<T> : ILocalizeTarget where T : Object
|
||||
{
|
||||
public T mTarget;
|
||||
|
||||
public override bool IsValid(Localize cmp)
|
||||
{
|
||||
if (mTarget!=null)
|
||||
{
|
||||
var mTargetCmp = mTarget as Component;
|
||||
if (mTargetCmp != null && mTargetCmp.gameObject != cmp.gameObject)
|
||||
mTarget = null;
|
||||
}
|
||||
if (mTarget==null)
|
||||
mTarget = cmp.GetComponent<T>();
|
||||
return mTarget!=null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bc110e805ac87134bb23eb4f9d6989e8
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,41 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
namespace I2.Loc
|
||||
{
|
||||
public abstract class ILocalizeTargetDescriptor
|
||||
{
|
||||
public string Name;
|
||||
public int Priority;
|
||||
public abstract bool CanLocalize(Localize cmp);
|
||||
public abstract ILocalizeTarget CreateTarget(Localize cmp);
|
||||
public abstract Type GetTargetType();
|
||||
}
|
||||
|
||||
public abstract class LocalizeTargetDesc<T> : ILocalizeTargetDescriptor where T : ILocalizeTarget
|
||||
{
|
||||
public override ILocalizeTarget CreateTarget(Localize cmp) { return ScriptableObject.CreateInstance<T>(); }
|
||||
public override Type GetTargetType() { return typeof(T); }
|
||||
}
|
||||
|
||||
|
||||
|
||||
public class LocalizeTargetDesc_Type<T,G> : LocalizeTargetDesc<G> where T: Object
|
||||
where G: LocalizeTarget<T>
|
||||
{
|
||||
public override bool CanLocalize(Localize cmp) { return cmp.GetComponent<T>() != null; }
|
||||
public override ILocalizeTarget CreateTarget(Localize cmp)
|
||||
{
|
||||
var target = cmp.GetComponent<T>();
|
||||
if (target == null)
|
||||
return null;
|
||||
|
||||
var locTarget = ScriptableObject.CreateInstance<G>();
|
||||
locTarget.mTarget = target;
|
||||
return locTarget;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 65c3e6b4b14772c4e9fb35235497819b
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,66 @@
|
||||
#if TK2D
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
namespace I2.Loc
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
[UnityEditor.InitializeOnLoad]
|
||||
#endif
|
||||
|
||||
public class LocalizeTarget_2DToolKit_Label : LocalizeTarget<tk2dTextMesh>
|
||||
{
|
||||
static LocalizeTarget_2DToolKit_Label() { AutoRegister(); }
|
||||
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)] static void AutoRegister() { LocalizationManager.RegisterTarget(new LocalizeTargetDesc_Type<tk2dTextMesh, LocalizeTarget_2DToolKit_Label>() { Name = "2DToolKit Label", Priority = 100 }); }
|
||||
|
||||
TextAnchor mOriginalAlignment = TextAnchor.MiddleCenter;
|
||||
bool mInitializeAlignment = true;
|
||||
|
||||
public override eTermType GetPrimaryTermType(Localize cmp) { return eTermType.Text; }
|
||||
public override eTermType GetSecondaryTermType(Localize cmp) { return eTermType.TK2dFont; }
|
||||
|
||||
public override bool CanUseSecondaryTerm() { return true; }
|
||||
public override bool AllowMainTermToBeRTL() { return true; }
|
||||
public override bool AllowSecondTermToBeRTL() { return false; }
|
||||
|
||||
public override void GetFinalTerms(Localize cmp, string Main, string Secondary, out string primaryTerm, out string secondaryTerm)
|
||||
{
|
||||
primaryTerm = mTarget ? mTarget.text : null;
|
||||
secondaryTerm = (mTarget.font != null ? mTarget.font.name : string.Empty);
|
||||
}
|
||||
|
||||
|
||||
public override void DoLocalize(Localize cmp, string mainTranslation, string secondaryTranslation)
|
||||
{
|
||||
//--[ Localize Font Object ]----------
|
||||
tk2dFont newFont = cmp.GetSecondaryTranslatedObj<tk2dFont>(ref mainTranslation, ref secondaryTranslation);
|
||||
if (newFont != null && mTarget.font != newFont)
|
||||
{
|
||||
mTarget.font = newFont.data;
|
||||
}
|
||||
|
||||
if (mInitializeAlignment)
|
||||
{
|
||||
mInitializeAlignment = false;
|
||||
mOriginalAlignment = mTarget.anchor;
|
||||
}
|
||||
|
||||
if (mainTranslation != null && mTarget.text != mainTranslation)
|
||||
{
|
||||
if (Localize.CurrentLocalizeComponent.CorrectAlignmentForRTL)
|
||||
{
|
||||
int align = (int)mTarget.anchor;
|
||||
|
||||
if (align % 3 == 0)
|
||||
mTarget.anchor = LocalizationManager.IsRight2Left ? mTarget.anchor + 2 : mOriginalAlignment;
|
||||
else
|
||||
if (align % 3 == 2)
|
||||
mTarget.anchor = LocalizationManager.IsRight2Left ? mTarget.anchor - 2 : mOriginalAlignment;
|
||||
}
|
||||
mTarget.text = mainTranslation;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f7658f1522689aa4b93bc276acf537b1
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,53 @@
|
||||
#if TK2D
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
namespace I2.Loc
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
[UnityEditor.InitializeOnLoad]
|
||||
#endif
|
||||
|
||||
public class LocalizeTarget_2DToolKit_Sprite : LocalizeTarget<tk2dBaseSprite>
|
||||
{
|
||||
static LocalizeTarget_2DToolKit_Sprite() { AutoRegister(); }
|
||||
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)] static void AutoRegister() { LocalizationManager.RegisterTarget(new LocalizeTargetDesc_Type<tk2dBaseSprite, LocalizeTarget_2DToolKit_Sprite>() { Name = "2DToolKit Sprite", Priority = 100 }); }
|
||||
|
||||
|
||||
public override eTermType GetPrimaryTermType(Localize cmp) { return eTermType.TK2dCollection; }
|
||||
public override eTermType GetSecondaryTermType(Localize cmp) { return eTermType.TK2dCollection; }
|
||||
|
||||
public override bool CanUseSecondaryTerm() { return true; }
|
||||
public override bool AllowMainTermToBeRTL() { return false; }
|
||||
public override bool AllowSecondTermToBeRTL() { return false; }
|
||||
|
||||
public override void GetFinalTerms(Localize cmp, string Main, string Secondary, out string primaryTerm, out string secondaryTerm)
|
||||
{
|
||||
primaryTerm = (mTarget.CurrentSprite != null ? mTarget.CurrentSprite.name : string.Empty);
|
||||
secondaryTerm = (mTarget.Collection != null ? mTarget.Collection.spriteCollectionName : null);
|
||||
}
|
||||
|
||||
|
||||
public override void DoLocalize(Localize cmp, string mainTranslation, string secondaryTranslation)
|
||||
{
|
||||
if (string.IsNullOrEmpty(mainTranslation))
|
||||
return;
|
||||
|
||||
//--[ Localize Atlas ]----------
|
||||
tk2dSpriteCollection newCollection = cmp.GetSecondaryTranslatedObj<tk2dSpriteCollection>(ref mainTranslation, ref secondaryTranslation);
|
||||
|
||||
if (newCollection != null)
|
||||
{
|
||||
if (mTarget.CurrentSprite.name != mainTranslation || mTarget.Collection.name != secondaryTranslation)
|
||||
mTarget.SetSprite(newCollection.spriteCollection, mainTranslation);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (mTarget.CurrentSprite.name != mainTranslation)
|
||||
mTarget.SetSprite(mainTranslation);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 53d5ed87a66514e439dddd19568adedd
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,94 @@
|
||||
#if NGUI
|
||||
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace I2.Loc
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
[InitializeOnLoad]
|
||||
#endif
|
||||
|
||||
public class LocalizeTarget_NGUI_Label : LocalizeTarget<UILabel>
|
||||
{
|
||||
static LocalizeTarget_NGUI_Label() { AutoRegister(); }
|
||||
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)] static void AutoRegister() { LocalizationManager.RegisterTarget(new LocalizeTargetDesc_Type<UILabel, LocalizeTarget_NGUI_Label> { Name = "NGUI Label", Priority = 100 }); }
|
||||
|
||||
NGUIText.Alignment mAlignment_RTL = NGUIText.Alignment.Right;
|
||||
NGUIText.Alignment mAlignment_LTR = NGUIText.Alignment.Left;
|
||||
bool mAlignmentWasRTL;
|
||||
bool mInitializeAlignment = true;
|
||||
|
||||
public override eTermType GetPrimaryTermType(Localize cmp) { return eTermType.Text; }
|
||||
public override eTermType GetSecondaryTermType(Localize cmp) { return eTermType.UIFont; }
|
||||
public override bool CanUseSecondaryTerm() { return true; }
|
||||
public override bool AllowMainTermToBeRTL() { return true; }
|
||||
public override bool AllowSecondTermToBeRTL() { return false; }
|
||||
|
||||
public override void GetFinalTerms(Localize cmp, string Main, string Secondary, out string primaryTerm, out string secondaryTerm)
|
||||
{
|
||||
primaryTerm = mTarget ? mTarget.text : null;
|
||||
secondaryTerm = mTarget.ambigiousFont != null ? mTarget.ambigiousFont.name : string.Empty;
|
||||
}
|
||||
|
||||
|
||||
public override void DoLocalize(Localize cmp, string mainTranslation, string secondaryTranslation)
|
||||
{
|
||||
//--[ Localize Font Object ]----------
|
||||
Font newFont = cmp.GetSecondaryTranslatedObj<Font>(ref mainTranslation, ref secondaryTranslation);
|
||||
if (newFont != null)
|
||||
{
|
||||
if (newFont != mTarget.ambigiousFont)
|
||||
mTarget.ambigiousFont = newFont;
|
||||
}
|
||||
if (newFont==null)
|
||||
{
|
||||
UIFont newUIFont = cmp.GetSecondaryTranslatedObj<UIFont>(ref mainTranslation, ref secondaryTranslation);
|
||||
if (newUIFont != null && mTarget.ambigiousFont != newUIFont)
|
||||
mTarget.ambigiousFont = newUIFont;
|
||||
}
|
||||
if (newFont == null)
|
||||
{
|
||||
NGUIFont newUIFont = cmp.GetSecondaryTranslatedObj<NGUIFont>(ref mainTranslation, ref secondaryTranslation);
|
||||
if (newUIFont != null && mTarget.ambigiousFont != newUIFont)
|
||||
mTarget.ambigiousFont = newUIFont;
|
||||
}
|
||||
|
||||
|
||||
if (mInitializeAlignment)
|
||||
{
|
||||
mInitializeAlignment = false;
|
||||
mAlignment_LTR = mAlignment_RTL = mTarget.alignment;
|
||||
|
||||
if (LocalizationManager.IsRight2Left && mAlignment_RTL == NGUIText.Alignment.Right)
|
||||
mAlignment_LTR = NGUIText.Alignment.Left;
|
||||
if (!LocalizationManager.IsRight2Left && mAlignment_LTR == NGUIText.Alignment.Left)
|
||||
mAlignment_RTL = NGUIText.Alignment.Right;
|
||||
}
|
||||
|
||||
UIInput input = NGUITools.FindInParents<UIInput>(mTarget.gameObject);
|
||||
if (input != null && input.label == mTarget)
|
||||
{
|
||||
if (mainTranslation != null && input.defaultText != mainTranslation)
|
||||
{
|
||||
if (cmp.CorrectAlignmentForRTL && (input.label.alignment == NGUIText.Alignment.Left || input.label.alignment == NGUIText.Alignment.Right))
|
||||
input.label.alignment = LocalizationManager.IsRight2Left ? mAlignment_RTL : mAlignment_LTR;
|
||||
|
||||
input.defaultText = mainTranslation;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (mainTranslation != null && mTarget.text != mainTranslation)
|
||||
{
|
||||
if (cmp.CorrectAlignmentForRTL && (mTarget.alignment == NGUIText.Alignment.Left || mTarget.alignment == NGUIText.Alignment.Right))
|
||||
mTarget.alignment = LocalizationManager.IsRight2Left ? mAlignment_RTL : mAlignment_LTR;
|
||||
|
||||
mTarget.text = mainTranslation;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3bd97513069766847851e1041f64e378
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,65 @@
|
||||
#if NGUI
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
namespace I2.Loc
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
[UnityEditor.InitializeOnLoad]
|
||||
#endif
|
||||
|
||||
public class LocalizeTarget_NGUI_Sprite : LocalizeTarget<UISprite>
|
||||
{
|
||||
static LocalizeTarget_NGUI_Sprite() { AutoRegister(); }
|
||||
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)] static void AutoRegister() { LocalizationManager.RegisterTarget(new LocalizeTargetDesc_Type<UISprite, LocalizeTarget_NGUI_Sprite>() { Name = "NGUI UISprite", Priority = 100 }); }
|
||||
|
||||
public override eTermType GetPrimaryTermType(Localize cmp) { return eTermType.Sprite; }
|
||||
public override eTermType GetSecondaryTermType(Localize cmp) { return eTermType.UIAtlas; }
|
||||
public override bool CanUseSecondaryTerm () { return true; }
|
||||
public override bool AllowMainTermToBeRTL () { return false; }
|
||||
public override bool AllowSecondTermToBeRTL () { return false; }
|
||||
|
||||
public override void GetFinalTerms ( Localize cmp, string Main, string Secondary, out string primaryTerm, out string secondaryTerm )
|
||||
{
|
||||
primaryTerm = mTarget ? mTarget.spriteName : null;
|
||||
secondaryTerm = (mTarget.atlas is UIAtlas atlas ? atlas.name : string.Empty);
|
||||
}
|
||||
|
||||
|
||||
public override void DoLocalize ( Localize cmp, string mainTranslation, string secondaryTranslation )
|
||||
{
|
||||
if (mTarget.spriteName == mainTranslation)
|
||||
return;
|
||||
|
||||
//--[ Localize Atlas ]----------
|
||||
UIAtlas newAtlas = cmp.GetSecondaryTranslatedObj<UIAtlas>(ref mainTranslation, ref secondaryTranslation);
|
||||
bool bChanged = false;
|
||||
if (newAtlas != null && ((mTarget.atlas as UIAtlas) != newAtlas))
|
||||
{
|
||||
mTarget.atlas = newAtlas;
|
||||
bChanged = true;
|
||||
}
|
||||
|
||||
if (newAtlas==null)
|
||||
{
|
||||
NGUIAtlas newNGUIAtlas = cmp.GetSecondaryTranslatedObj<NGUIAtlas>(ref mainTranslation, ref secondaryTranslation);
|
||||
if (newAtlas != null && ((mTarget.atlas as NGUIAtlas) != newNGUIAtlas))
|
||||
{
|
||||
mTarget.atlas = newAtlas;
|
||||
bChanged = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (mTarget.spriteName != mainTranslation && mTarget.atlas.GetSprite(mainTranslation) != null)
|
||||
{
|
||||
mTarget.spriteName = mainTranslation;
|
||||
bChanged = true;
|
||||
}
|
||||
if (bChanged)
|
||||
mTarget.MakePixelPerfect();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 545ef381b929ce44cad2bf111b096f2c
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,41 @@
|
||||
#if NGUI
|
||||
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace I2.Loc
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
[InitializeOnLoad]
|
||||
#endif
|
||||
|
||||
public class LocalizeTarget_NGUI_Texture : LocalizeTarget<UITexture>
|
||||
{
|
||||
static LocalizeTarget_NGUI_Texture() { AutoRegister(); }
|
||||
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)] static void AutoRegister() { LocalizationManager.RegisterTarget(new LocalizeTargetDesc_Type<UITexture, LocalizeTarget_NGUI_Texture> { Name = "NGUI UITexture", Priority = 100 }); }
|
||||
|
||||
public override eTermType GetPrimaryTermType(Localize cmp) { return eTermType.Texture; }
|
||||
public override eTermType GetSecondaryTermType(Localize cmp) { return eTermType.Text; }
|
||||
public override bool CanUseSecondaryTerm() { return false; }
|
||||
public override bool AllowMainTermToBeRTL() { return false; }
|
||||
public override bool AllowSecondTermToBeRTL() { return false; }
|
||||
|
||||
public override void GetFinalTerms(Localize cmp, string Main, string Secondary, out string primaryTerm, out string secondaryTerm)
|
||||
{
|
||||
primaryTerm = mTarget!=null && mTarget.mainTexture!=null ? mTarget.mainTexture.name : null;
|
||||
secondaryTerm = null;
|
||||
}
|
||||
|
||||
public override void DoLocalize(Localize cmp, string mainTranslation, string secondaryTranslation)
|
||||
{
|
||||
Texture Old = mTarget.mainTexture;
|
||||
if (Old == null || Old.name != mainTranslation)
|
||||
{
|
||||
mTarget.mainTexture = cmp.FindTranslatedObject<Texture>(mainTranslation);
|
||||
mTarget.MakePixelPerfect();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8488ebda4a4bc5343b6fcd2158af0360
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,42 @@
|
||||
#if SVG
|
||||
using UnityEngine;
|
||||
|
||||
namespace I2.Loc
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
[UnityEditor.InitializeOnLoad]
|
||||
#endif
|
||||
|
||||
public class LocalizeTarget_SVGImporter_Image : LocalizeTarget<SVGImporter.SVGImage>
|
||||
{
|
||||
static LocalizeTarget_SVGImporter_Image() { AutoRegister(); }
|
||||
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)] static void AutoRegister() { LocalizationManager.RegisterTarget(new LocalizeTargetDesc_Type<SVGImporter.SVGImage, LocalizeTarget_SVGImporter_Image>() { Name = "SVG Image", Priority = 100 }); }
|
||||
|
||||
public override eTermType GetPrimaryTermType(Localize cmp) { return eTermType.SVGAsset; }
|
||||
public override eTermType GetSecondaryTermType(Localize cmp) { return eTermType.Material; }
|
||||
public override bool CanUseSecondaryTerm() { return true; }
|
||||
public override bool AllowMainTermToBeRTL() { return false; }
|
||||
public override bool AllowSecondTermToBeRTL() { return false; }
|
||||
|
||||
public override void GetFinalTerms(Localize cmp, string Main, string Secondary, out string primaryTerm, out string secondaryTerm)
|
||||
{
|
||||
primaryTerm = (mTarget.vectorGraphics != null ? mTarget.vectorGraphics.name : string.Empty);
|
||||
secondaryTerm = (mTarget.material != null ? mTarget.material.name : null);
|
||||
}
|
||||
|
||||
|
||||
public override void DoLocalize(Localize cmp, string mainTranslation, string secondaryTranslation)
|
||||
{
|
||||
var OldVectorG = mTarget.vectorGraphics;
|
||||
if (OldVectorG == null || OldVectorG.name != mainTranslation)
|
||||
mTarget.vectorGraphics = cmp.FindTranslatedObject<SVGImporter.SVGAsset>(mainTranslation);
|
||||
|
||||
var OldMaterial = mTarget.material;
|
||||
if (OldMaterial == null || OldMaterial.name != secondaryTranslation)
|
||||
mTarget.material = cmp.FindTranslatedObject<Material>(secondaryTranslation);
|
||||
|
||||
mTarget.SetAllDirty();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bbf97c698c733ea4bbf7bc2996984484
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,42 @@
|
||||
#if SVG
|
||||
using UnityEngine;
|
||||
|
||||
namespace I2.Loc
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
[UnityEditor.InitializeOnLoad]
|
||||
#endif
|
||||
|
||||
public class LocalizeTarget_SVGImporter_Renderer : LocalizeTarget<SVGImporter.SVGRenderer>
|
||||
{
|
||||
static LocalizeTarget_SVGImporter_Renderer() { AutoRegister(); }
|
||||
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)] static void AutoRegister() { LocalizationManager.RegisterTarget(new LocalizeTargetDesc_Type<SVGImporter.SVGRenderer, LocalizeTarget_SVGImporter_Renderer>() { Name = "SVG Renderer", Priority = 100 }); }
|
||||
|
||||
public override eTermType GetPrimaryTermType(Localize cmp) { return eTermType.SVGAsset; }
|
||||
public override eTermType GetSecondaryTermType(Localize cmp) { return eTermType.Material; }
|
||||
public override bool CanUseSecondaryTerm() { return true; }
|
||||
public override bool AllowMainTermToBeRTL() { return false; }
|
||||
public override bool AllowSecondTermToBeRTL() { return false; }
|
||||
|
||||
public override void GetFinalTerms(Localize cmp, string Main, string Secondary, out string primaryTerm, out string secondaryTerm)
|
||||
{
|
||||
primaryTerm = (mTarget.vectorGraphics != null ? mTarget.vectorGraphics.name : string.Empty);
|
||||
secondaryTerm = (mTarget.opaqueMaterial != null ? mTarget.opaqueMaterial.name : string.Empty);
|
||||
}
|
||||
|
||||
|
||||
public override void DoLocalize(Localize cmp, string mainTranslation, string secondaryTranslation)
|
||||
{
|
||||
var OldVectorG = mTarget.vectorGraphics;
|
||||
if (OldVectorG == null || OldVectorG.name != mainTranslation)
|
||||
mTarget.vectorGraphics = cmp.FindTranslatedObject<SVGImporter.SVGAsset>(mainTranslation);
|
||||
|
||||
var OldMaterial = mTarget.opaqueMaterial;
|
||||
if (OldMaterial == null || OldMaterial.name != secondaryTranslation)
|
||||
mTarget.opaqueMaterial = cmp.FindTranslatedObject<Material>(secondaryTranslation);
|
||||
|
||||
mTarget.SetAllDirty();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c78c473b19acc3844ba488904981d75c
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,191 @@
|
||||
using System;
|
||||
using TMPro;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
#if TextMeshPro
|
||||
namespace I2.Loc
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
[InitializeOnLoad]
|
||||
#endif
|
||||
|
||||
public class LocalizeTarget_TextMeshPro_Label : LocalizeTarget<TextMeshPro>
|
||||
{
|
||||
static LocalizeTarget_TextMeshPro_Label() { AutoRegister(); }
|
||||
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)] static void AutoRegister() { LocalizationManager.RegisterTarget(new LocalizeTargetDesc_Type<TextMeshPro, LocalizeTarget_TextMeshPro_Label> { Name = "TextMeshPro Label", Priority = 100 }); }
|
||||
|
||||
TextAlignmentOptions mAlignment_RTL = TextAlignmentOptions.Right;
|
||||
TextAlignmentOptions mAlignment_LTR = TextAlignmentOptions.Left;
|
||||
bool mAlignmentWasRTL;
|
||||
bool mInitializeAlignment = true;
|
||||
|
||||
public override eTermType GetPrimaryTermType(Localize cmp) { return eTermType.Text; }
|
||||
public override eTermType GetSecondaryTermType(Localize cmp) { return eTermType.Font; }
|
||||
public override bool CanUseSecondaryTerm() { return true; }
|
||||
public override bool AllowMainTermToBeRTL() { return true; }
|
||||
public override bool AllowSecondTermToBeRTL() { return false; }
|
||||
|
||||
public override void GetFinalTerms ( Localize cmp, string Main, string Secondary, out string primaryTerm, out string secondaryTerm)
|
||||
{
|
||||
primaryTerm = mTarget ? mTarget.text : null;
|
||||
secondaryTerm = mTarget.font != null ? mTarget.font.name : string.Empty;
|
||||
}
|
||||
|
||||
public override void DoLocalize(Localize cmp, string mainTranslation, string secondaryTranslation)
|
||||
{
|
||||
//--[ Localize Font Object ]----------
|
||||
{
|
||||
TMP_FontAsset newFont = cmp.GetSecondaryTranslatedObj<TMP_FontAsset>(ref mainTranslation, ref secondaryTranslation);
|
||||
|
||||
if (newFont != null)
|
||||
{
|
||||
SetFont(mTarget, newFont);
|
||||
}
|
||||
else
|
||||
{
|
||||
//--[ Localize Font Material ]----------
|
||||
Material newMat = cmp.GetSecondaryTranslatedObj<Material>(ref mainTranslation, ref secondaryTranslation);
|
||||
if (newMat != null && mTarget.fontMaterial != newMat)
|
||||
{
|
||||
if (!newMat.name.StartsWith(mTarget.font.name, StringComparison.Ordinal))
|
||||
{
|
||||
newFont = GetTMPFontFromMaterial(cmp, secondaryTranslation.EndsWith(newMat.name, StringComparison.Ordinal) ? secondaryTranslation : newMat.name);
|
||||
if (newFont != null)
|
||||
SetFont(mTarget, newFont);
|
||||
}
|
||||
SetMaterial(mTarget, newMat);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
if (mInitializeAlignment)
|
||||
{
|
||||
mInitializeAlignment = false;
|
||||
mAlignmentWasRTL = LocalizationManager.IsRight2Left;
|
||||
InitAlignment_TMPro(mAlignmentWasRTL, mTarget.alignment, out mAlignment_LTR, out mAlignment_RTL);
|
||||
}
|
||||
else
|
||||
{
|
||||
TextAlignmentOptions alignRTL, alignLTR;
|
||||
InitAlignment_TMPro(mAlignmentWasRTL, mTarget.alignment, out alignLTR, out alignRTL);
|
||||
|
||||
if (mAlignmentWasRTL && mAlignment_RTL != alignRTL ||
|
||||
!mAlignmentWasRTL && mAlignment_LTR != alignLTR)
|
||||
{
|
||||
mAlignment_LTR = alignLTR;
|
||||
mAlignment_RTL = alignRTL;
|
||||
}
|
||||
mAlignmentWasRTL = LocalizationManager.IsRight2Left;
|
||||
}
|
||||
|
||||
if (mainTranslation != null && mTarget.text != mainTranslation)
|
||||
{
|
||||
if (cmp.CorrectAlignmentForRTL)
|
||||
{
|
||||
mTarget.alignment = LocalizationManager.IsRight2Left ? mAlignment_RTL : mAlignment_LTR;
|
||||
}
|
||||
|
||||
mTarget.isRightToLeftText = LocalizationManager.IsRight2Left;
|
||||
if (LocalizationManager.IsRight2Left) mainTranslation = I2Utils.ReverseText(mainTranslation);
|
||||
|
||||
mTarget.text = mainTranslation;
|
||||
}
|
||||
}
|
||||
|
||||
#region Tools
|
||||
internal static TMP_FontAsset GetTMPFontFromMaterial(Localize cmp, string matName)
|
||||
{
|
||||
string splitChars = " .\\/-[]()";
|
||||
for (int i = matName.Length - 1; i > 0;)
|
||||
{
|
||||
// Find first valid character
|
||||
while (i > 0 && splitChars.IndexOf(matName[i]) >= 0)
|
||||
i--;
|
||||
|
||||
if (i <= 0) break;
|
||||
|
||||
var fontName = matName.Substring(0, i + 1);
|
||||
var obj = cmp.GetObject<TMP_FontAsset>(fontName);
|
||||
if (obj != null)
|
||||
return obj;
|
||||
|
||||
// skip this word
|
||||
while (i > 0 && splitChars.IndexOf(matName[i]) < 0)
|
||||
i--;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
internal static void InitAlignment_TMPro(bool isRTL, TextAlignmentOptions alignment, out TextAlignmentOptions alignLTR, out TextAlignmentOptions alignRTL)
|
||||
{
|
||||
alignLTR = alignRTL = alignment;
|
||||
|
||||
if (isRTL)
|
||||
{
|
||||
switch (alignment)
|
||||
{
|
||||
case TextAlignmentOptions.TopRight: alignLTR = TextAlignmentOptions.TopLeft; break;
|
||||
case TextAlignmentOptions.Right: alignLTR = TextAlignmentOptions.Left; break;
|
||||
case TextAlignmentOptions.BottomRight: alignLTR = TextAlignmentOptions.BottomLeft; break;
|
||||
case TextAlignmentOptions.BaselineRight: alignLTR = TextAlignmentOptions.BaselineLeft; break;
|
||||
case TextAlignmentOptions.MidlineRight: alignLTR = TextAlignmentOptions.MidlineLeft; break;
|
||||
case TextAlignmentOptions.CaplineRight: alignLTR = TextAlignmentOptions.CaplineLeft; break;
|
||||
|
||||
case TextAlignmentOptions.TopLeft: alignLTR = TextAlignmentOptions.TopRight; break;
|
||||
case TextAlignmentOptions.Left: alignLTR = TextAlignmentOptions.Right; break;
|
||||
case TextAlignmentOptions.BottomLeft: alignLTR = TextAlignmentOptions.BottomRight; break;
|
||||
case TextAlignmentOptions.BaselineLeft: alignLTR = TextAlignmentOptions.BaselineRight; break;
|
||||
case TextAlignmentOptions.MidlineLeft: alignLTR = TextAlignmentOptions.MidlineRight; break;
|
||||
case TextAlignmentOptions.CaplineLeft: alignLTR = TextAlignmentOptions.CaplineRight; break;
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (alignment)
|
||||
{
|
||||
case TextAlignmentOptions.TopRight: alignRTL = TextAlignmentOptions.TopLeft; break;
|
||||
case TextAlignmentOptions.Right: alignRTL = TextAlignmentOptions.Left; break;
|
||||
case TextAlignmentOptions.BottomRight: alignRTL = TextAlignmentOptions.BottomLeft; break;
|
||||
case TextAlignmentOptions.BaselineRight: alignRTL = TextAlignmentOptions.BaselineLeft; break;
|
||||
case TextAlignmentOptions.MidlineRight: alignRTL = TextAlignmentOptions.MidlineLeft; break;
|
||||
case TextAlignmentOptions.CaplineRight: alignRTL = TextAlignmentOptions.CaplineLeft; break;
|
||||
|
||||
case TextAlignmentOptions.TopLeft: alignRTL = TextAlignmentOptions.TopRight; break;
|
||||
case TextAlignmentOptions.Left: alignRTL = TextAlignmentOptions.Right; break;
|
||||
case TextAlignmentOptions.BottomLeft: alignRTL = TextAlignmentOptions.BottomRight; break;
|
||||
case TextAlignmentOptions.BaselineLeft: alignRTL = TextAlignmentOptions.BaselineRight; break;
|
||||
case TextAlignmentOptions.MidlineLeft: alignRTL = TextAlignmentOptions.MidlineRight; break;
|
||||
case TextAlignmentOptions.CaplineLeft: alignRTL = TextAlignmentOptions.CaplineRight; break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal static void SetFont(TMP_Text label, TMP_FontAsset newFont)
|
||||
{
|
||||
if (label.font != newFont)
|
||||
{
|
||||
label.font = newFont;
|
||||
}
|
||||
if (label.linkedTextComponent != null)
|
||||
{
|
||||
SetFont(label.linkedTextComponent, newFont);
|
||||
}
|
||||
}
|
||||
internal static void SetMaterial(TMP_Text label, Material newMat)
|
||||
{
|
||||
if (label.fontSharedMaterial != newMat)
|
||||
{
|
||||
label.fontSharedMaterial = newMat;
|
||||
}
|
||||
if (label.linkedTextComponent != null)
|
||||
{
|
||||
SetMaterial(label.linkedTextComponent, newMat);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d96a6c3ea7d28744aacc367115a71af5
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,98 @@
|
||||
using System;
|
||||
using TMPro;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
#if TextMeshPro
|
||||
namespace I2.Loc
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
[InitializeOnLoad]
|
||||
#endif
|
||||
|
||||
public class LocalizeTarget_TextMeshPro_UGUI : LocalizeTarget<TextMeshProUGUI>
|
||||
{
|
||||
static LocalizeTarget_TextMeshPro_UGUI() { AutoRegister(); }
|
||||
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)] static void AutoRegister() { LocalizationManager.RegisterTarget(new LocalizeTargetDesc_Type<TextMeshProUGUI, LocalizeTarget_TextMeshPro_UGUI> { Name = "TextMeshPro UGUI", Priority = 100 }); }
|
||||
|
||||
public TextAlignmentOptions mAlignment_RTL = TextAlignmentOptions.Right;
|
||||
public TextAlignmentOptions mAlignment_LTR = TextAlignmentOptions.Left;
|
||||
public bool mAlignmentWasRTL;
|
||||
public bool mInitializeAlignment = true;
|
||||
|
||||
public override eTermType GetPrimaryTermType(Localize cmp) { return eTermType.Text; }
|
||||
public override eTermType GetSecondaryTermType(Localize cmp) { return eTermType.TextMeshPFont; }
|
||||
public override bool CanUseSecondaryTerm() { return true; }
|
||||
public override bool AllowMainTermToBeRTL() { return true; }
|
||||
public override bool AllowSecondTermToBeRTL() { return false; }
|
||||
|
||||
public override void GetFinalTerms ( Localize cmp, string Main, string Secondary, out string primaryTerm, out string secondaryTerm)
|
||||
{
|
||||
primaryTerm = mTarget ? mTarget.text : null;
|
||||
secondaryTerm = mTarget.font != null ? mTarget.font.name : string.Empty;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public override void DoLocalize(Localize cmp, string mainTranslation, string secondaryTranslation)
|
||||
{
|
||||
{
|
||||
//--[ Localize Font Object ]----------
|
||||
TMP_FontAsset newFont = cmp.GetSecondaryTranslatedObj<TMP_FontAsset>(ref mainTranslation, ref secondaryTranslation);
|
||||
|
||||
if (newFont != null)
|
||||
{
|
||||
LocalizeTarget_TextMeshPro_Label.SetFont(mTarget, newFont);
|
||||
}
|
||||
else
|
||||
{
|
||||
//--[ Localize Font Material ]----------
|
||||
Material newMat = cmp.GetSecondaryTranslatedObj<Material>(ref mainTranslation, ref secondaryTranslation);
|
||||
if (newMat != null && mTarget.fontMaterial != newMat)
|
||||
{
|
||||
if (!newMat.name.StartsWith(mTarget.font.name, StringComparison.Ordinal))
|
||||
{
|
||||
newFont = LocalizeTarget_TextMeshPro_Label.GetTMPFontFromMaterial(cmp, secondaryTranslation.EndsWith(newMat.name, StringComparison.Ordinal) ? secondaryTranslation : newMat.name);
|
||||
if (newFont != null)
|
||||
LocalizeTarget_TextMeshPro_Label.SetFont(mTarget, newFont);
|
||||
}
|
||||
LocalizeTarget_TextMeshPro_Label.SetMaterial( mTarget, newMat );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (mInitializeAlignment)
|
||||
{
|
||||
mInitializeAlignment = false;
|
||||
mAlignmentWasRTL = LocalizationManager.IsRight2Left;
|
||||
LocalizeTarget_TextMeshPro_Label.InitAlignment_TMPro(mAlignmentWasRTL, mTarget.alignment, out mAlignment_LTR, out mAlignment_RTL);
|
||||
}
|
||||
else
|
||||
{
|
||||
TextAlignmentOptions alignRTL, alignLTR;
|
||||
LocalizeTarget_TextMeshPro_Label.InitAlignment_TMPro(mAlignmentWasRTL, mTarget.alignment, out alignLTR, out alignRTL);
|
||||
|
||||
if (mAlignmentWasRTL && mAlignment_RTL != alignRTL ||
|
||||
!mAlignmentWasRTL && mAlignment_LTR != alignLTR)
|
||||
{
|
||||
mAlignment_LTR = alignLTR;
|
||||
mAlignment_RTL = alignRTL;
|
||||
}
|
||||
mAlignmentWasRTL = LocalizationManager.IsRight2Left;
|
||||
}
|
||||
|
||||
if (mainTranslation != null && mTarget.text != mainTranslation)
|
||||
{
|
||||
if (cmp.CorrectAlignmentForRTL)
|
||||
{
|
||||
mTarget.alignment = LocalizationManager.IsRight2Left ? mAlignment_RTL : mAlignment_LTR;
|
||||
}
|
||||
if (LocalizationManager.IsRight2Left) mainTranslation = I2Utils.ReverseText(mainTranslation);
|
||||
|
||||
mTarget.isRightToLeftText = LocalizationManager.IsRight2Left;
|
||||
mTarget.text = mainTranslation;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 481ab606793a67349be805c13febeba0
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,45 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace I2.Loc
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
[InitializeOnLoad]
|
||||
#endif
|
||||
|
||||
public class LocalizeTarget_UnityStandard_AudioSource : LocalizeTarget<AudioSource>
|
||||
{
|
||||
static LocalizeTarget_UnityStandard_AudioSource() { AutoRegister(); }
|
||||
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)] static void AutoRegister() { LocalizationManager.RegisterTarget(new LocalizeTargetDesc_Type<AudioSource, LocalizeTarget_UnityStandard_AudioSource> { Name = "AudioSource", Priority = 100 }); }
|
||||
|
||||
public override eTermType GetPrimaryTermType(Localize cmp) { return eTermType.AudioClip; }
|
||||
public override eTermType GetSecondaryTermType(Localize cmp) { return eTermType.Text; }
|
||||
public override bool CanUseSecondaryTerm() { return false; }
|
||||
public override bool AllowMainTermToBeRTL() { return false; }
|
||||
public override bool AllowSecondTermToBeRTL() { return false; }
|
||||
|
||||
public override void GetFinalTerms ( Localize cmp, string Main, string Secondary, out string primaryTerm, out string secondaryTerm)
|
||||
{
|
||||
AudioClip clip = mTarget.clip;
|
||||
primaryTerm = clip ? clip.name : string.Empty;
|
||||
secondaryTerm = null;
|
||||
}
|
||||
|
||||
|
||||
public override void DoLocalize(Localize cmp, string mainTranslation, string secondaryTranslation)
|
||||
{
|
||||
bool bIsPlaying = (mTarget.isPlaying || mTarget.loop) && Application.isPlaying;
|
||||
AudioClip OldClip = mTarget.clip;
|
||||
AudioClip NewClip = cmp.FindTranslatedObject<AudioClip>(mainTranslation);
|
||||
if (OldClip != NewClip)
|
||||
mTarget.clip = NewClip;
|
||||
|
||||
if (bIsPlaying && mTarget.clip)
|
||||
mTarget.Play();
|
||||
|
||||
// If the old clip is not in the translatedObjects, then unload it as it most likely was loaded from Resources
|
||||
//if (!HasTranslatedObject(OldClip))
|
||||
// Resources.UnloadAsset(OldClip);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 007f2c3f7b0e4a048ae89d65dcd38729
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,51 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace I2.Loc
|
||||
{
|
||||
public class LocalizeTargetDesc_Child : LocalizeTargetDesc<LocalizeTarget_UnityStandard_Child>
|
||||
{
|
||||
public override bool CanLocalize(Localize cmp) { return cmp.transform.childCount > 1; }
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
[InitializeOnLoad]
|
||||
#endif
|
||||
|
||||
public class LocalizeTarget_UnityStandard_Child : LocalizeTarget<GameObject>
|
||||
{
|
||||
static LocalizeTarget_UnityStandard_Child() { AutoRegister(); }
|
||||
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)] static void AutoRegister() { LocalizationManager.RegisterTarget(new LocalizeTargetDesc_Child { Name = "Child", Priority = 200 }); }
|
||||
|
||||
public override bool IsValid(Localize cmp) { return cmp.transform.childCount>1; }
|
||||
public override eTermType GetPrimaryTermType(Localize cmp) { return eTermType.GameObject; }
|
||||
public override eTermType GetSecondaryTermType(Localize cmp) { return eTermType.Text; }
|
||||
public override bool CanUseSecondaryTerm() { return false; }
|
||||
public override bool AllowMainTermToBeRTL() { return false; }
|
||||
public override bool AllowSecondTermToBeRTL() { return false; }
|
||||
|
||||
public override void GetFinalTerms(Localize cmp, string Main, string Secondary, out string primaryTerm, out string secondaryTerm)
|
||||
{
|
||||
primaryTerm = cmp.name;
|
||||
secondaryTerm = null;
|
||||
}
|
||||
|
||||
public override void DoLocalize(Localize cmp, string mainTranslation, string secondaryTranslation)
|
||||
{
|
||||
if (string.IsNullOrEmpty(mainTranslation))
|
||||
return;
|
||||
Transform locTr = cmp.transform;
|
||||
|
||||
var objName = mainTranslation;
|
||||
var idx = mainTranslation.LastIndexOfAny(LanguageSourceData.CategorySeparators);
|
||||
if (idx >= 0)
|
||||
objName = objName.Substring(idx + 1);
|
||||
|
||||
for (int i = 0; i < locTr.childCount; ++i)
|
||||
{
|
||||
var child = locTr.GetChild(i);
|
||||
child.gameObject.SetActive(child.name == objName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 61a67a81d07fe85429a253a86ebac910
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,80 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
#pragma warning disable 618
|
||||
|
||||
namespace I2.Loc
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
[InitializeOnLoad]
|
||||
#endif
|
||||
|
||||
public class LocalizeTarget_UnityStandard_MeshRenderer : LocalizeTarget<MeshRenderer>
|
||||
{
|
||||
static LocalizeTarget_UnityStandard_MeshRenderer() { AutoRegister(); }
|
||||
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)] static void AutoRegister() { LocalizationManager.RegisterTarget(new LocalizeTargetDesc_Type<MeshRenderer, LocalizeTarget_UnityStandard_MeshRenderer> { Name = "MeshRenderer", Priority = 800 }); }
|
||||
|
||||
public override eTermType GetPrimaryTermType(Localize cmp) { return eTermType.Mesh; }
|
||||
public override eTermType GetSecondaryTermType(Localize cmp) { return eTermType.Material; }
|
||||
public override bool CanUseSecondaryTerm() { return true; }
|
||||
public override bool AllowMainTermToBeRTL() { return false; }
|
||||
public override bool AllowSecondTermToBeRTL() { return false; }
|
||||
|
||||
public override void GetFinalTerms ( Localize cmp, string Main, string Secondary, out string primaryTerm, out string secondaryTerm)
|
||||
{
|
||||
if (mTarget==null)
|
||||
{
|
||||
primaryTerm = secondaryTerm = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
MeshFilter filter = mTarget.GetComponent<MeshFilter>();
|
||||
if (filter==null || filter.sharedMesh==null)
|
||||
{
|
||||
primaryTerm = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
primaryTerm = AssetDatabase.GetAssetPath(filter.sharedMesh);
|
||||
I2Utils.RemoveResourcesPath(ref primaryTerm);
|
||||
#else
|
||||
primaryTerm = filter.sharedMesh.name;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
if (mTarget==null || mTarget.sharedMaterial==null)
|
||||
{
|
||||
secondaryTerm = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
secondaryTerm = AssetDatabase.GetAssetPath(mTarget.sharedMaterial);
|
||||
I2Utils.RemoveResourcesPath(ref secondaryTerm);
|
||||
#else
|
||||
secondaryTerm = mTarget.sharedMaterial.name;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
public override void DoLocalize(Localize cmp, string mainTranslation, string secondaryTranslation)
|
||||
{
|
||||
//--[ Localize Material]----------
|
||||
Material newMat = cmp.GetSecondaryTranslatedObj<Material>(ref mainTranslation, ref secondaryTranslation);
|
||||
if (newMat != null && mTarget.sharedMaterial != newMat)
|
||||
{
|
||||
mTarget.material = newMat;
|
||||
}
|
||||
|
||||
//--[ Localize Mesh ]----------
|
||||
Mesh newMesh = cmp.FindTranslatedObject<Mesh>( mainTranslation);
|
||||
MeshFilter filter = mTarget.GetComponent<MeshFilter>();
|
||||
if (newMesh != null && filter.sharedMesh != newMesh)
|
||||
{
|
||||
filter.mesh = newMesh;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b4679336707a2b54caa10d99561be751
|
||||
timeCreated: 1518408606
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,96 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
#pragma warning disable 618
|
||||
|
||||
namespace I2.Loc
|
||||
{
|
||||
public class LocalizeTargetDesc_Prefab : LocalizeTargetDesc<LocalizeTarget_UnityStandard_Prefab>
|
||||
{
|
||||
public override bool CanLocalize(Localize cmp) { return true; }
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
[InitializeOnLoad]
|
||||
#endif
|
||||
|
||||
public class LocalizeTarget_UnityStandard_Prefab : LocalizeTarget<GameObject>
|
||||
{
|
||||
static LocalizeTarget_UnityStandard_Prefab() { AutoRegister(); }
|
||||
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)] static void AutoRegister() { LocalizationManager.RegisterTarget(new LocalizeTargetDesc_Prefab { Name = "Prefab", Priority = 250 }); }
|
||||
|
||||
public override bool IsValid(Localize cmp) { return true; }
|
||||
public override eTermType GetPrimaryTermType(Localize cmp) { return eTermType.GameObject; }
|
||||
public override eTermType GetSecondaryTermType(Localize cmp) { return eTermType.Text; }
|
||||
public override bool CanUseSecondaryTerm() { return false; }
|
||||
public override bool AllowMainTermToBeRTL() { return false; }
|
||||
public override bool AllowSecondTermToBeRTL() { return false; }
|
||||
|
||||
public override void GetFinalTerms ( Localize cmp, string Main, string Secondary, out string primaryTerm, out string secondaryTerm)
|
||||
{
|
||||
primaryTerm = cmp.name;
|
||||
secondaryTerm = null;
|
||||
}
|
||||
|
||||
public override void DoLocalize(Localize cmp, string mainTranslation, string secondaryTranslation)
|
||||
{
|
||||
if (string.IsNullOrEmpty(mainTranslation))
|
||||
return;
|
||||
|
||||
if (mTarget && mTarget.name == mainTranslation)
|
||||
return;
|
||||
|
||||
Transform locTr = cmp.transform;
|
||||
|
||||
var objName = mainTranslation;
|
||||
var idx = mainTranslation.LastIndexOfAny(LanguageSourceData.CategorySeparators);
|
||||
if (idx >= 0)
|
||||
objName = objName.Substring(idx + 1);
|
||||
|
||||
Transform mNew = InstantiateNewPrefab(cmp, mainTranslation);
|
||||
if (mNew == null)
|
||||
return;
|
||||
mNew.name = objName;
|
||||
|
||||
for (int i = locTr.childCount - 1; i >= 0; --i)
|
||||
{
|
||||
var child = locTr.GetChild(i);
|
||||
if (child!=mNew)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (Application.isPlaying)
|
||||
Destroy(child.gameObject);
|
||||
else
|
||||
DestroyImmediate(child.gameObject);
|
||||
#else
|
||||
Object.Destroy (child.gameObject);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Transform InstantiateNewPrefab(Localize cmp, string mainTranslation)
|
||||
{
|
||||
GameObject NewPrefab = cmp.FindTranslatedObject<GameObject>(mainTranslation);
|
||||
if (NewPrefab == null)
|
||||
return null;
|
||||
|
||||
GameObject current = mTarget;
|
||||
|
||||
mTarget = Instantiate(NewPrefab);
|
||||
if (mTarget == null)
|
||||
return null;
|
||||
|
||||
Transform locTr = cmp.transform;
|
||||
Transform mNew = mTarget.transform;
|
||||
mNew.SetParent(locTr);
|
||||
|
||||
Transform bBase = current ? current.transform : locTr;
|
||||
//mNew.localScale = bBase.localScale;
|
||||
mNew.rotation = bBase.rotation;
|
||||
mNew.position = bBase.position;
|
||||
|
||||
return mNew;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bd8b481d182cbcd4293524eb92ee520c
|
||||
timeCreated: 1518408606
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,41 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
#pragma warning disable 618
|
||||
|
||||
namespace I2.Loc
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
[InitializeOnLoad]
|
||||
#endif
|
||||
|
||||
public class LocalizeTarget_UnityStandard_SpriteRenderer : LocalizeTarget<SpriteRenderer>
|
||||
{
|
||||
static LocalizeTarget_UnityStandard_SpriteRenderer() { AutoRegister(); }
|
||||
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)] static void AutoRegister() { LocalizationManager.RegisterTarget(new LocalizeTargetDesc_Type<SpriteRenderer, LocalizeTarget_UnityStandard_SpriteRenderer> { Name = "SpriteRenderer", Priority = 100 }); }
|
||||
|
||||
public override eTermType GetPrimaryTermType(Localize cmp) { return eTermType.Sprite; }
|
||||
public override eTermType GetSecondaryTermType(Localize cmp) { return eTermType.Text; }
|
||||
public override bool CanUseSecondaryTerm() { return false; }
|
||||
public override bool AllowMainTermToBeRTL() { return false; }
|
||||
public override bool AllowSecondTermToBeRTL() { return false; }
|
||||
|
||||
public override void GetFinalTerms ( Localize cmp, string Main, string Secondary, out string primaryTerm, out string secondaryTerm)
|
||||
{
|
||||
Sprite sprite = mTarget.sprite;
|
||||
primaryTerm = sprite != null ? sprite.name : string.Empty;
|
||||
secondaryTerm = null;
|
||||
}
|
||||
|
||||
public override void DoLocalize(Localize cmp, string mainTranslation, string secondaryTranslation)
|
||||
{
|
||||
Sprite Old = mTarget.sprite;
|
||||
if (Old == null || Old.name != mainTranslation)
|
||||
mTarget.sprite = cmp.FindTranslatedObject<Sprite>(mainTranslation);
|
||||
|
||||
// If the old value is not in the translatedObjects, then unload it as it most likely was loaded from Resources
|
||||
//if (!HasTranslatedObject(Old))
|
||||
// Resources.UnloadAsset(Old);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3b29d7ab09a96634a9f704e6a1f21193
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,68 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
#pragma warning disable 618
|
||||
|
||||
namespace I2.Loc
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
[InitializeOnLoad]
|
||||
#endif
|
||||
|
||||
public class LocalizeTarget_UnityStandard_TextMesh : LocalizeTarget<TextMesh>
|
||||
{
|
||||
static LocalizeTarget_UnityStandard_TextMesh() { AutoRegister(); }
|
||||
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)] static void AutoRegister() { LocalizationManager.RegisterTarget(new LocalizeTargetDesc_Type<TextMesh, LocalizeTarget_UnityStandard_TextMesh> { Name = "TextMesh", Priority = 100 }); }
|
||||
|
||||
TextAlignment mAlignment_RTL = TextAlignment.Right;
|
||||
TextAlignment mAlignment_LTR = TextAlignment.Left;
|
||||
bool mAlignmentWasRTL;
|
||||
bool mInitializeAlignment = true;
|
||||
|
||||
public override eTermType GetPrimaryTermType(Localize cmp) { return eTermType.Text; }
|
||||
public override eTermType GetSecondaryTermType(Localize cmp) { return eTermType.Font; }
|
||||
public override bool CanUseSecondaryTerm() { return true; }
|
||||
public override bool AllowMainTermToBeRTL() { return true; }
|
||||
public override bool AllowSecondTermToBeRTL() { return false; }
|
||||
|
||||
public override void GetFinalTerms ( Localize cmp, string Main, string Secondary, out string primaryTerm, out string secondaryTerm)
|
||||
{
|
||||
primaryTerm = mTarget ? mTarget.text : null;
|
||||
secondaryTerm = string.IsNullOrEmpty(Secondary) && mTarget.font != null ? mTarget.font.name : null;
|
||||
}
|
||||
|
||||
public override void DoLocalize(Localize cmp, string mainTranslation, string secondaryTranslation)
|
||||
{
|
||||
//--[ Localize Font Object ]----------
|
||||
Font newFont = cmp.GetSecondaryTranslatedObj<Font>(ref mainTranslation, ref secondaryTranslation);
|
||||
if (newFont != null && mTarget.font != newFont)
|
||||
{
|
||||
mTarget.font = newFont;
|
||||
MeshRenderer rend = mTarget.GetComponentInChildren<MeshRenderer>();
|
||||
rend.material = newFont.material;
|
||||
}
|
||||
|
||||
//--[ Localize Text ]----------
|
||||
if (mInitializeAlignment)
|
||||
{
|
||||
mInitializeAlignment = false;
|
||||
|
||||
mAlignment_LTR = mAlignment_RTL = mTarget.alignment;
|
||||
|
||||
if (LocalizationManager.IsRight2Left && mAlignment_RTL == TextAlignment.Right)
|
||||
mAlignment_LTR = TextAlignment.Left;
|
||||
if (!LocalizationManager.IsRight2Left && mAlignment_LTR == TextAlignment.Left)
|
||||
mAlignment_RTL = TextAlignment.Right;
|
||||
|
||||
}
|
||||
if (mainTranslation != null && mTarget.text != mainTranslation)
|
||||
{
|
||||
if (cmp.CorrectAlignmentForRTL && mTarget.alignment != TextAlignment.Center)
|
||||
mTarget.alignment = LocalizationManager.IsRight2Left ? mAlignment_RTL : mAlignment_LTR;
|
||||
|
||||
mTarget.font.RequestCharactersInTexture(mainTranslation);
|
||||
mTarget.text = mainTranslation;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 62e865dd37373234c9d966bdd78278e1
|
||||
timeCreated: 1518408606
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,33 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Video;
|
||||
|
||||
namespace I2.Loc
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
[InitializeOnLoad]
|
||||
#endif
|
||||
public class LocalizeTarget_UnityStandard_VideoPlayer : LocalizeTarget<VideoPlayer>
|
||||
{
|
||||
static LocalizeTarget_UnityStandard_VideoPlayer() { AutoRegister(); }
|
||||
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
|
||||
static void AutoRegister() { LocalizationManager.RegisterTarget(new LocalizeTargetDesc_Type<VideoPlayer, LocalizeTarget_UnityStandard_VideoPlayer> { Name = "VideoPlayer", Priority = 100 }); }
|
||||
public override eTermType GetPrimaryTermType(Localize cmp) { return eTermType.Video; }
|
||||
public override eTermType GetSecondaryTermType(Localize cmp) { return eTermType.Text; }
|
||||
public override bool CanUseSecondaryTerm() { return false; }
|
||||
public override bool AllowMainTermToBeRTL() { return false; }
|
||||
public override bool AllowSecondTermToBeRTL() { return false; }
|
||||
public override void GetFinalTerms ( Localize cmp, string Main, string Secondary, out string primaryTerm, out string secondaryTerm)
|
||||
{
|
||||
VideoClip clip = mTarget.clip;
|
||||
primaryTerm = clip != null ? clip.name: string.Empty;
|
||||
secondaryTerm = null;
|
||||
}
|
||||
public override void DoLocalize(Localize cmp, string mainTranslation, string secondaryTranslation)
|
||||
{
|
||||
VideoClip Old = mTarget.clip;
|
||||
if (Old == null || Old.name != mainTranslation)
|
||||
mTarget.clip = cmp.FindTranslatedObject<VideoClip>(mainTranslation);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5fcaa99c1874460eb953851cbf4bfad2
|
||||
timeCreated: 1601759602
|
||||
@@ -0,0 +1,53 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace I2.Loc
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
[InitializeOnLoad]
|
||||
#endif
|
||||
|
||||
public class LocalizeTarget_UnityUI_Image : LocalizeTarget<Image>
|
||||
{
|
||||
static LocalizeTarget_UnityUI_Image() { AutoRegister(); }
|
||||
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)] static void AutoRegister() { LocalizationManager.RegisterTarget(new LocalizeTargetDesc_Type<Image, LocalizeTarget_UnityUI_Image> { Name = "Image", Priority = 100 }); }
|
||||
|
||||
public override bool CanUseSecondaryTerm () { return false; }
|
||||
public override bool AllowMainTermToBeRTL () { return false; }
|
||||
public override bool AllowSecondTermToBeRTL () { return false; }
|
||||
public override eTermType GetPrimaryTermType(Localize cmp)
|
||||
{
|
||||
return mTarget.sprite == null ? eTermType.Texture : eTermType.Sprite;
|
||||
}
|
||||
public override eTermType GetSecondaryTermType(Localize cmp) { return eTermType.Text; }
|
||||
|
||||
|
||||
public override void GetFinalTerms ( Localize cmp, string Main, string Secondary, out string primaryTerm, out string secondaryTerm )
|
||||
{
|
||||
primaryTerm = mTarget.mainTexture ? mTarget.mainTexture.name : "";
|
||||
if (mTarget.sprite!=null && mTarget.sprite.name!=primaryTerm)
|
||||
primaryTerm += "." + mTarget.sprite.name;
|
||||
|
||||
secondaryTerm = null;
|
||||
}
|
||||
|
||||
|
||||
public override void DoLocalize ( Localize cmp, string mainTranslation, string secondaryTranslation )
|
||||
{
|
||||
Sprite Old = mTarget.sprite;
|
||||
if (Old==null || Old.name!=mainTranslation)
|
||||
mTarget.sprite = cmp.FindTranslatedObject<Sprite>( mainTranslation );
|
||||
|
||||
// If the old value is not in the translatedObjects, then unload it as it most likely was loaded from Resources
|
||||
//if (!HasTranslatedObject(Old))
|
||||
// Resources.UnloadAsset(Old);
|
||||
|
||||
// In the editor, sometimes unity "forgets" to show the changes
|
||||
#if UNITY_EDITOR
|
||||
if (!Application.isPlaying)
|
||||
EditorUtility.SetDirty( mTarget );
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bedef2aeaac8da04faa9a07b7241d0ad
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,47 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace I2.Loc
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
[InitializeOnLoad]
|
||||
#endif
|
||||
|
||||
public class LocalizeTarget_UnityUI_RawImage : LocalizeTarget<RawImage>
|
||||
{
|
||||
static LocalizeTarget_UnityUI_RawImage() { AutoRegister(); }
|
||||
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)] static void AutoRegister() { LocalizationManager.RegisterTarget(new LocalizeTargetDesc_Type<RawImage, LocalizeTarget_UnityUI_RawImage> { Name = "RawImage", Priority = 100 }); }
|
||||
|
||||
public override eTermType GetPrimaryTermType(Localize cmp) { return eTermType.Texture; }
|
||||
public override eTermType GetSecondaryTermType(Localize cmp) { return eTermType.Text; }
|
||||
public override bool CanUseSecondaryTerm() { return false; }
|
||||
public override bool AllowMainTermToBeRTL() { return false; }
|
||||
public override bool AllowSecondTermToBeRTL() { return false; }
|
||||
|
||||
|
||||
public override void GetFinalTerms(Localize cmp, string Main, string Secondary, out string primaryTerm, out string secondaryTerm)
|
||||
{
|
||||
primaryTerm = mTarget.mainTexture ? mTarget.mainTexture.name : "";
|
||||
secondaryTerm = null;
|
||||
}
|
||||
|
||||
|
||||
public override void DoLocalize(Localize cmp, string mainTranslation, string secondaryTranslation)
|
||||
{
|
||||
Texture Old = mTarget.texture;
|
||||
if (Old == null || Old.name != mainTranslation)
|
||||
mTarget.texture = cmp.FindTranslatedObject<Texture>(mainTranslation);
|
||||
|
||||
// If the old value is not in the translatedObjects, then unload it as it most likely was loaded from Resources
|
||||
//if (!HasTranslatedObject(Old))
|
||||
// Resources.UnloadAsset(Old);
|
||||
|
||||
// In the editor, sometimes unity "forgets" to show the changes
|
||||
#if UNITY_EDITOR
|
||||
if (!Application.isPlaying)
|
||||
EditorUtility.SetDirty(mTarget);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a58a0cb6f0764ca42b2877aa2c6fa0af
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,111 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace I2.Loc
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
[InitializeOnLoad]
|
||||
#endif
|
||||
|
||||
public class LocalizeTarget_UnityUI_Text : LocalizeTarget<Text>
|
||||
{
|
||||
static LocalizeTarget_UnityUI_Text() { AutoRegister(); }
|
||||
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)] static void AutoRegister() { LocalizationManager.RegisterTarget(new LocalizeTargetDesc_Type<Text, LocalizeTarget_UnityUI_Text> { Name = "Text", Priority = 100 }); }
|
||||
|
||||
TextAnchor mAlignment_RTL = TextAnchor.UpperRight;
|
||||
TextAnchor mAlignment_LTR = TextAnchor.UpperLeft;
|
||||
bool mAlignmentWasRTL;
|
||||
bool mInitializeAlignment = true;
|
||||
|
||||
public override eTermType GetPrimaryTermType(Localize cmp) { return eTermType.Text; }
|
||||
public override eTermType GetSecondaryTermType(Localize cmp) { return eTermType.Font; }
|
||||
public override bool CanUseSecondaryTerm () { return true; }
|
||||
public override bool AllowMainTermToBeRTL () { return true; }
|
||||
public override bool AllowSecondTermToBeRTL () { return false; }
|
||||
|
||||
public override void GetFinalTerms ( Localize cmp, string Main, string Secondary, out string primaryTerm, out string secondaryTerm )
|
||||
{
|
||||
primaryTerm = mTarget ? mTarget.text : null;
|
||||
secondaryTerm = mTarget.font!=null ? mTarget.font.name : string.Empty;
|
||||
}
|
||||
|
||||
|
||||
public override void DoLocalize ( Localize cmp, string mainTranslation, string secondaryTranslation )
|
||||
{
|
||||
//--[ Localize Font Object ]----------
|
||||
Font newFont = cmp.GetSecondaryTranslatedObj<Font>( ref mainTranslation, ref secondaryTranslation );
|
||||
if (newFont!=null && newFont!=mTarget.font)
|
||||
mTarget.font = newFont;
|
||||
|
||||
if (mInitializeAlignment)
|
||||
{
|
||||
mInitializeAlignment = false;
|
||||
mAlignmentWasRTL = LocalizationManager.IsRight2Left;
|
||||
InitAlignment( mAlignmentWasRTL, mTarget.alignment, out mAlignment_LTR, out mAlignment_RTL );
|
||||
}
|
||||
else
|
||||
{
|
||||
TextAnchor alignRTL, alignLTR;
|
||||
InitAlignment( mAlignmentWasRTL, mTarget.alignment, out alignLTR, out alignRTL );
|
||||
|
||||
if (mAlignmentWasRTL && mAlignment_RTL!=alignRTL ||
|
||||
!mAlignmentWasRTL && mAlignment_LTR != alignLTR)
|
||||
{
|
||||
mAlignment_LTR = alignLTR;
|
||||
mAlignment_RTL = alignRTL;
|
||||
}
|
||||
mAlignmentWasRTL = LocalizationManager.IsRight2Left;
|
||||
}
|
||||
|
||||
if (mainTranslation!=null && mTarget.text != mainTranslation)
|
||||
{
|
||||
if (cmp.CorrectAlignmentForRTL)
|
||||
{
|
||||
mTarget.alignment = LocalizationManager.IsRight2Left ? mAlignment_RTL : mAlignment_LTR;
|
||||
}
|
||||
|
||||
|
||||
mTarget.text = mainTranslation;
|
||||
mTarget.SetVerticesDirty();
|
||||
|
||||
// In the editor, sometimes unity "forgets" to show the changes
|
||||
#if UNITY_EDITOR
|
||||
if (!Application.isPlaying)
|
||||
EditorUtility.SetDirty( mTarget );
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void InitAlignment ( bool isRTL, TextAnchor alignment, out TextAnchor alignLTR, out TextAnchor alignRTL )
|
||||
{
|
||||
alignLTR = alignRTL = alignment;
|
||||
|
||||
if (isRTL)
|
||||
{
|
||||
switch (alignment)
|
||||
{
|
||||
case TextAnchor.UpperRight: alignLTR = TextAnchor.UpperLeft; break;
|
||||
case TextAnchor.MiddleRight: alignLTR = TextAnchor.MiddleLeft; break;
|
||||
case TextAnchor.LowerRight: alignLTR = TextAnchor.LowerLeft; break;
|
||||
case TextAnchor.UpperLeft: alignLTR = TextAnchor.UpperRight; break;
|
||||
case TextAnchor.MiddleLeft: alignLTR = TextAnchor.MiddleRight; break;
|
||||
case TextAnchor.LowerLeft: alignLTR = TextAnchor.LowerRight; break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (alignment)
|
||||
{
|
||||
case TextAnchor.UpperRight: alignRTL = TextAnchor.UpperLeft; break;
|
||||
case TextAnchor.MiddleRight: alignRTL = TextAnchor.MiddleLeft; break;
|
||||
case TextAnchor.LowerRight: alignRTL = TextAnchor.LowerLeft; break;
|
||||
case TextAnchor.UpperLeft: alignRTL = TextAnchor.UpperRight; break;
|
||||
case TextAnchor.MiddleLeft: alignRTL = TextAnchor.MiddleRight; break;
|
||||
case TextAnchor.LowerLeft: alignRTL = TextAnchor.LowerRight; break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 332e36893e7cf4a49b3c1f72f76cd5e1
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user