diff options
| author | Andrew Lee <alee14498@gmail.com> | 2019-08-24 15:24:57 -0400 |
|---|---|---|
| committer | Andrew Lee <alee14498@gmail.com> | 2019-08-24 15:24:57 -0400 |
| commit | 85553832ead1a96f88726cd2b35cb6ff1d8b8cc8 (patch) | |
| tree | 7a2615034462d4296ed09d24038bb4c68107979d /Assets/Packages/Lean/Localization/Scripts/Behaviours | |
| parent | e06acf066171670248b0b644c0eb8f6d895e051e (diff) | |
| download | Unicity-85553832ead1a96f88726cd2b35cb6ff1d8b8cc8.tar.gz Unicity-85553832ead1a96f88726cd2b35cb6ff1d8b8cc8.tar.bz2 Unicity-85553832ead1a96f88726cd2b35cb6ff1d8b8cc8.zip | |
Attempt number 2 on localization
Diffstat (limited to 'Assets/Packages/Lean/Localization/Scripts/Behaviours')
16 files changed, 467 insertions, 0 deletions
diff --git a/Assets/Packages/Lean/Localization/Scripts/Behaviours/LeanLocalizedAudioSource.cs b/Assets/Packages/Lean/Localization/Scripts/Behaviours/LeanLocalizedAudioSource.cs new file mode 100644 index 0000000..7b45595 --- /dev/null +++ b/Assets/Packages/Lean/Localization/Scripts/Behaviours/LeanLocalizedAudioSource.cs @@ -0,0 +1,47 @@ +using UnityEngine; + +namespace Lean.Localization +{ + /// <summary>This component will update an AudioSource component with localized text, or use a fallback if none is found.</summary> + [ExecuteInEditMode] + [DisallowMultipleComponent] + [RequireComponent(typeof(AudioSource))] + [HelpURL(LeanLocalization.HelpUrlPrefix + "LeanLocalizedAudioSource")] + [AddComponentMenu(LeanLocalization.ComponentPathPrefix + "Localized AudioSource")] + public class LeanLocalizedAudioSource : LeanLocalizedBehaviour + { + [Tooltip("If PhraseName couldn't be found, this clip will be used")] + public AudioClip FallbackAudioClip; + + // This gets called every time the translation needs updating + public override void UpdateTranslation(LeanTranslation translation) + { + // Get the AudioSource component attached to this GameObject + var audioSource = GetComponent<AudioSource>(); + + // Use translation? + if (translation != null && translation.Data is AudioClip) + { + audioSource.clip = (AudioClip)translation.Data; + } + // Use fallback? + else + { + audioSource.clip = FallbackAudioClip; + } + } + + protected virtual void Awake() + { + // Should we set FallbackAudioClip? + if (FallbackAudioClip == null) + { + // Get the AudioSource component attached to this GameObject + var audioSource = GetComponent<AudioSource>(); + + // Copy current sprite to fallback + FallbackAudioClip = audioSource.clip; + } + } + } +}
\ No newline at end of file diff --git a/Assets/Packages/Lean/Localization/Scripts/Behaviours/LeanLocalizedAudioSource.cs.meta b/Assets/Packages/Lean/Localization/Scripts/Behaviours/LeanLocalizedAudioSource.cs.meta new file mode 100644 index 0000000..479d2ca --- /dev/null +++ b/Assets/Packages/Lean/Localization/Scripts/Behaviours/LeanLocalizedAudioSource.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 4bbcd1203ed53d54e9a127af382c0181 +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Assets/Packages/Lean/Localization/Scripts/Behaviours/LeanLocalizedImage.cs b/Assets/Packages/Lean/Localization/Scripts/Behaviours/LeanLocalizedImage.cs new file mode 100644 index 0000000..664ec95 --- /dev/null +++ b/Assets/Packages/Lean/Localization/Scripts/Behaviours/LeanLocalizedImage.cs @@ -0,0 +1,48 @@ +using UnityEngine; +using UnityEngine.UI; + +namespace Lean.Localization +{ + /// <summary>This component will update an Image component with a localized sprite, or use a fallback if none is found</summary> + [ExecuteInEditMode] + [DisallowMultipleComponent] + [RequireComponent(typeof(Image))] + [HelpURL(LeanLocalization.HelpUrlPrefix + "LeanLocalizedImage")] + [AddComponentMenu(LeanLocalization.ComponentPathPrefix + "Localized Image")] + public class LeanLocalizedImage : LeanLocalizedBehaviour + { + [Tooltip("If PhraseName couldn't be found, this sprite will be used")] + public Sprite FallbackSprite; + + // This gets called every time the translation needs updating + public override void UpdateTranslation(LeanTranslation translation) + { + // Get the Image component attached to this GameObject + var image = GetComponent<Image>(); + + // Use translation? + if (translation != null && translation.Data is Sprite) + { + image.sprite = (Sprite)translation.Data; + } + // Use fallback? + else + { + image.sprite = FallbackSprite; + } + } + + protected virtual void Awake() + { + // Should we set FallbackSprite? + if (FallbackSprite == null) + { + // Get the SpriteRenderer component attached to this GameObject + var spriteRenderer = GetComponent<Image>(); + + // Copy current sprite to fallback + FallbackSprite = spriteRenderer.sprite; + } + } + } +}
\ No newline at end of file diff --git a/Assets/Packages/Lean/Localization/Scripts/Behaviours/LeanLocalizedImage.cs.meta b/Assets/Packages/Lean/Localization/Scripts/Behaviours/LeanLocalizedImage.cs.meta new file mode 100644 index 0000000..b7be84d --- /dev/null +++ b/Assets/Packages/Lean/Localization/Scripts/Behaviours/LeanLocalizedImage.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 5b28f7e33d1e3e0408d7ff2c8a92a650 +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Assets/Packages/Lean/Localization/Scripts/Behaviours/LeanLocalizedRenderer.cs b/Assets/Packages/Lean/Localization/Scripts/Behaviours/LeanLocalizedRenderer.cs new file mode 100644 index 0000000..701e538 --- /dev/null +++ b/Assets/Packages/Lean/Localization/Scripts/Behaviours/LeanLocalizedRenderer.cs @@ -0,0 +1,55 @@ +using UnityEngine; + +namespace Lean.Localization +{ + /// <summary>This component will update a Renderer component's sharedMaterial with a localized material, or use a fallback if none is found.</summary> + [ExecuteInEditMode] + [DisallowMultipleComponent] + [RequireComponent(typeof(Renderer))] + [HelpURL(LeanLocalization.HelpUrlPrefix + "LeanLocalizedRenderer")] + [AddComponentMenu(LeanLocalization.ComponentPathPrefix + "Localized Renderer")] + public class LeanLocalizedRenderer : LeanLocalizedBehaviour + { + [Tooltip("If PhraseName couldn't be found, this material will be used")] + public Material FallbackMaterial; + + [Tooltip("The material index you want to replace.")] + public int Index; + + // This gets called every time the translation needs updating + public override void UpdateTranslation(LeanTranslation translation) + { + // Get the Renderer component attached to this GameObject + var renderer = GetComponent<Renderer>(); + + // Get the shared materials of this component + var sharedMaterials = renderer.sharedMaterials; + + // Use translation? + if (translation != null && translation.Data is Material) + { + sharedMaterials[Index] = (Material)translation.Data; + } + // Use fallback? + else + { + sharedMaterials[Index] = FallbackMaterial; + } + + renderer.sharedMaterials = sharedMaterials; + } + + protected virtual void Awake() + { + // Should we set FallbackFont? + if (FallbackMaterial == null) + { + // Get the Renderer component attached to this GameObject + var renderer = GetComponent<Renderer>(); + + // Copy current material to fallback + FallbackMaterial = renderer.sharedMaterials[Index]; + } + } + } +}
\ No newline at end of file diff --git a/Assets/Packages/Lean/Localization/Scripts/Behaviours/LeanLocalizedRenderer.cs.meta b/Assets/Packages/Lean/Localization/Scripts/Behaviours/LeanLocalizedRenderer.cs.meta new file mode 100644 index 0000000..4fcb5ed --- /dev/null +++ b/Assets/Packages/Lean/Localization/Scripts/Behaviours/LeanLocalizedRenderer.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: b42c83c3c333a7e4a8e498fec50ce1fb +timeCreated: 1478133615 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Packages/Lean/Localization/Scripts/Behaviours/LeanLocalizedSpriteRenderer.cs b/Assets/Packages/Lean/Localization/Scripts/Behaviours/LeanLocalizedSpriteRenderer.cs new file mode 100644 index 0000000..e1170b0 --- /dev/null +++ b/Assets/Packages/Lean/Localization/Scripts/Behaviours/LeanLocalizedSpriteRenderer.cs @@ -0,0 +1,47 @@ +using UnityEngine; + +namespace Lean.Localization +{ + /// <summary>This component will update a SpriteRenderer component with a localized sprite, or use a fallback if none is found</summary> + [ExecuteInEditMode] + [DisallowMultipleComponent] + [RequireComponent(typeof(SpriteRenderer))] + [HelpURL(LeanLocalization.HelpUrlPrefix + "LeanLocalizedSpriteRenderer")] + [AddComponentMenu(LeanLocalization.ComponentPathPrefix + "Localized SpriteRenderer")] + public class LeanLocalizedSpriteRenderer : LeanLocalizedBehaviour + { + [Tooltip("If PhraseName couldn't be found, this sprite will be used")] + public Sprite FallbackSprite; + + // This gets called every time the translation needs updating + public override void UpdateTranslation(LeanTranslation translation) + { + // Get the SpriteRenderer component attached to this GameObject + var spriteRenderer = GetComponent<SpriteRenderer>(); + + // Use translation? + if (translation != null && translation.Data is Sprite) + { + spriteRenderer.sprite = (Sprite)translation.Data; + } + // Use fallback? + else + { + spriteRenderer.sprite = FallbackSprite; + } + } + + protected virtual void Awake() + { + // Should we set FallbackSprite? + if (FallbackSprite == null) + { + // Get the SpriteRenderer component attached to this GameObject + var spriteRenderer = GetComponent<SpriteRenderer>(); + + // Copy current sprite to fallback + FallbackSprite = spriteRenderer.sprite; + } + } + } +}
\ No newline at end of file diff --git a/Assets/Packages/Lean/Localization/Scripts/Behaviours/LeanLocalizedSpriteRenderer.cs.meta b/Assets/Packages/Lean/Localization/Scripts/Behaviours/LeanLocalizedSpriteRenderer.cs.meta new file mode 100644 index 0000000..84485b2 --- /dev/null +++ b/Assets/Packages/Lean/Localization/Scripts/Behaviours/LeanLocalizedSpriteRenderer.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 84f599809c9879044b69f17af8c248c6 +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Assets/Packages/Lean/Localization/Scripts/Behaviours/LeanLocalizedText.cs b/Assets/Packages/Lean/Localization/Scripts/Behaviours/LeanLocalizedText.cs new file mode 100644 index 0000000..df63743 --- /dev/null +++ b/Assets/Packages/Lean/Localization/Scripts/Behaviours/LeanLocalizedText.cs @@ -0,0 +1,48 @@ +using UnityEngine; +using UnityEngine.UI; + +namespace Lean.Localization +{ + /// <summary>This component will update a UI.Text component with localized text, or use a fallback if none is found.</summary> + [ExecuteInEditMode] + [DisallowMultipleComponent] + [RequireComponent(typeof(Text))] + [HelpURL(LeanLocalization.HelpUrlPrefix + "LeanLocalizedText")] + [AddComponentMenu(LeanLocalization.ComponentPathPrefix + "Localized Text")] + public class LeanLocalizedText : LeanLocalizedBehaviour + { + [Tooltip("If PhraseName couldn't be found, this text will be used")] + public string FallbackText; + + // This gets called every time the translation needs updating + public override void UpdateTranslation(LeanTranslation translation) + { + // Get the Text component attached to this GameObject + var text = GetComponent<Text>(); + + // Use translation? + if (translation != null && translation.Data is string) + { + text.text = LeanTranslation.FormatText((string)translation.Data, text.text, this); + } + // Use fallback? + else + { + text.text = LeanTranslation.FormatText(FallbackText, text.text, this); + } + } + + protected virtual void Awake() + { + // Should we set FallbackText? + if (string.IsNullOrEmpty(FallbackText) == true) + { + // Get the Text component attached to this GameObject + var text = GetComponent<Text>(); + + // Copy current text to fallback + FallbackText = text.text; + } + } + } +}
\ No newline at end of file diff --git a/Assets/Packages/Lean/Localization/Scripts/Behaviours/LeanLocalizedText.cs.meta b/Assets/Packages/Lean/Localization/Scripts/Behaviours/LeanLocalizedText.cs.meta new file mode 100644 index 0000000..8b76311 --- /dev/null +++ b/Assets/Packages/Lean/Localization/Scripts/Behaviours/LeanLocalizedText.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 7ee4021ce59f313499a5cab041f02aba +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Assets/Packages/Lean/Localization/Scripts/Behaviours/LeanLocalizedTextFont.cs b/Assets/Packages/Lean/Localization/Scripts/Behaviours/LeanLocalizedTextFont.cs new file mode 100644 index 0000000..6730956 --- /dev/null +++ b/Assets/Packages/Lean/Localization/Scripts/Behaviours/LeanLocalizedTextFont.cs @@ -0,0 +1,48 @@ +using UnityEngine; +using UnityEngine.UI; + +namespace Lean.Localization +{ + /// <summary>This component will update a Text component's Font with a localized font, or use a fallback if none is found.</summary> + [ExecuteInEditMode] + [DisallowMultipleComponent] + [RequireComponent(typeof(Text))] + [HelpURL(LeanLocalization.HelpUrlPrefix + "LeanLocalizedTextFont")] + [AddComponentMenu(LeanLocalization.ComponentPathPrefix + "Localized TextFont")] + public class LeanLocalizedTextFont : LeanLocalizedBehaviour + { + [Tooltip("If PhraseName couldn't be found, this font will be used")] + public Font FallbackFont; + + // This gets called every time the translation needs updating + public override void UpdateTranslation(LeanTranslation translation) + { + // Get the Text component attached to this GameObject + var text = GetComponent<Text>(); + + // Use translation? + if (translation != null && translation.Data is Font) + { + text.font = (Font)translation.Data; + } + // Use fallback? + else + { + text.font = FallbackFont; + } + } + + protected virtual void Awake() + { + // Should we set FallbackFont? + if (FallbackFont == null) + { + // Get the Text component attached to this GameObject + var text = GetComponent<Text>(); + + // Copy current font to fallback + FallbackFont = text.font; + } + } + } +}
\ No newline at end of file diff --git a/Assets/Packages/Lean/Localization/Scripts/Behaviours/LeanLocalizedTextFont.cs.meta b/Assets/Packages/Lean/Localization/Scripts/Behaviours/LeanLocalizedTextFont.cs.meta new file mode 100644 index 0000000..5b0ceea --- /dev/null +++ b/Assets/Packages/Lean/Localization/Scripts/Behaviours/LeanLocalizedTextFont.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: fce53ba05f9c84246b062afd12f4619f +timeCreated: 1478133615 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Packages/Lean/Localization/Scripts/Behaviours/LeanLocalizedTextMesh.cs b/Assets/Packages/Lean/Localization/Scripts/Behaviours/LeanLocalizedTextMesh.cs new file mode 100644 index 0000000..c9fcbc6 --- /dev/null +++ b/Assets/Packages/Lean/Localization/Scripts/Behaviours/LeanLocalizedTextMesh.cs @@ -0,0 +1,46 @@ +using UnityEngine; + +namespace Lean.Localization +{ + /// <summary>This component will update a TMPro.TextMeshProUGUI component with localized text, or use a fallback if none is found.</summary> + [ExecuteInEditMode] + [DisallowMultipleComponent] + [RequireComponent(typeof(TextMesh))] + [AddComponentMenu(LeanLocalization.ComponentPathPrefix + "Localized TextMesh")] + public class LeanLocalizedTextMesh : LeanLocalizedBehaviour + { + [Tooltip("If PhraseName couldn't be found, this text will be used")] + public string FallbackText; + + // This gets called every time the translation needs updating + public override void UpdateTranslation(LeanTranslation translation) + { + // Get the TextMeshProUGUI component attached to this GameObject + var text = GetComponent<TextMesh>(); + + // Use translation? + if (translation != null && translation.Data is string) + { + text.text = LeanTranslation.FormatText((string)translation.Data, text.text, this); + } + // Use fallback? + else + { + text.text = LeanTranslation.FormatText(FallbackText, text.text, this); + } + } + + protected virtual void Awake() + { + // Should we set FallbackText? + if (string.IsNullOrEmpty(FallbackText) == true) + { + // Get the TextMeshProUGUI component attached to this GameObject + var text = GetComponent<TextMesh>(); + + // Copy current text to fallback + FallbackText = text.text; + } + } + } +}
\ No newline at end of file diff --git a/Assets/Packages/Lean/Localization/Scripts/Behaviours/LeanLocalizedTextMesh.cs.meta b/Assets/Packages/Lean/Localization/Scripts/Behaviours/LeanLocalizedTextMesh.cs.meta new file mode 100644 index 0000000..6af3498 --- /dev/null +++ b/Assets/Packages/Lean/Localization/Scripts/Behaviours/LeanLocalizedTextMesh.cs.meta @@ -0,0 +1,13 @@ +fileFormatVersion: 2 +guid: 365897690d9e7c54f9fd65401bffb0d3 +timeCreated: 1561293177 +licenseType: Store +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Packages/Lean/Localization/Scripts/Behaviours/LeanLocalizedTextMeshFont.cs b/Assets/Packages/Lean/Localization/Scripts/Behaviours/LeanLocalizedTextMeshFont.cs new file mode 100644 index 0000000..a0046a7 --- /dev/null +++ b/Assets/Packages/Lean/Localization/Scripts/Behaviours/LeanLocalizedTextMeshFont.cs @@ -0,0 +1,46 @@ +using UnityEngine; + +namespace Lean.Localization +{ + /// <summary>This component will update a TextMesh component's Font with a localized font, or use a fallback if none is found.</summary> + [ExecuteInEditMode] + [DisallowMultipleComponent] + [RequireComponent(typeof(TextMesh))] + [AddComponentMenu(LeanLocalization.ComponentPathPrefix + "Localized TextMesh Font")] + public class LeanLocalizedTextMeshFont : LeanLocalizedBehaviour + { + [Tooltip("If PhraseName couldn't be found, this font asset will be used")] + public Font FallbackFont; + + // This gets called every time the translation needs updating + public override void UpdateTranslation(LeanTranslation translation) + { + // Get the TextMesh component attached to this GameObject + var text = GetComponent<TextMesh>(); + + // Use translation? + if (translation != null && translation.Data is Font) + { + text.font = (Font)translation.Data; + } + // Use fallback? + else + { + text.font = FallbackFont; + } + } + + protected virtual void Awake() + { + // Should we set FallbackFont? + if (FallbackFont == null) + { + // Get the TextMesh component attached to this GameObject + var text = GetComponent<TextMesh>(); + + // Copy current text to fallback + FallbackFont = text.font; + } + } + } +}
\ No newline at end of file diff --git a/Assets/Packages/Lean/Localization/Scripts/Behaviours/LeanLocalizedTextMeshFont.cs.meta b/Assets/Packages/Lean/Localization/Scripts/Behaviours/LeanLocalizedTextMeshFont.cs.meta new file mode 100644 index 0000000..d8c179f --- /dev/null +++ b/Assets/Packages/Lean/Localization/Scripts/Behaviours/LeanLocalizedTextMeshFont.cs.meta @@ -0,0 +1,13 @@ +fileFormatVersion: 2 +guid: 3904cf0d2d9103140ab648dbbee38d3f +timeCreated: 1561293177 +licenseType: Store +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: |
