aboutsummaryrefslogtreecommitdiff
path: root/Assets/Packages/Lean/Localization/Scripts/Behaviours/LeanLocalizedSpriteRenderer.cs
diff options
context:
space:
mode:
authorAndrew Lee <alee14498@gmail.com>2019-08-24 15:24:57 -0400
committerAndrew Lee <alee14498@gmail.com>2019-08-24 15:24:57 -0400
commit85553832ead1a96f88726cd2b35cb6ff1d8b8cc8 (patch)
tree7a2615034462d4296ed09d24038bb4c68107979d /Assets/Packages/Lean/Localization/Scripts/Behaviours/LeanLocalizedSpriteRenderer.cs
parente06acf066171670248b0b644c0eb8f6d895e051e (diff)
downloadUnicity-85553832ead1a96f88726cd2b35cb6ff1d8b8cc8.tar.gz
Unicity-85553832ead1a96f88726cd2b35cb6ff1d8b8cc8.tar.bz2
Unicity-85553832ead1a96f88726cd2b35cb6ff1d8b8cc8.zip
Attempt number 2 on localization
Diffstat (limited to 'Assets/Packages/Lean/Localization/Scripts/Behaviours/LeanLocalizedSpriteRenderer.cs')
-rw-r--r--Assets/Packages/Lean/Localization/Scripts/Behaviours/LeanLocalizedSpriteRenderer.cs47
1 files changed, 47 insertions, 0 deletions
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