/// <summary> /// Performs sprite localization (Image or SpriteRenderer). /// </summary> /// <param name="sprite">Localized sprite.</param> public void Localize(Sprite sprite) { if (!_allowNullOrEmpty && sprite == null) { LogErrorMessage($"Localization of the item {gameObject.name} failed! Input localization is NULL!"); OnLocalizationFailed?.Invoke(this, new LocalizationItemEventArgs(typeof(Sprite))); return; } switch (_itemType) { case ItemType.Image: var gameObjImage = GetComponent <Image>(); if (!gameObjImage) { LogErrorMessage($"Localization of the item {gameObject.name} failed! Couldn't find UnityEngine.UI.Image component!"); OnLocalizationFailed?.Invoke(this, new LocalizationItemEventArgs(typeof(Sprite))); return; } else { gameObjImage.sprite = sprite; } break; case ItemType.Sprite: var gameObjSpriteRenderer = GetComponent <SpriteRenderer>(); if (!gameObjSpriteRenderer) { Debug.LogError($"Localization of the item {gameObject.name} failed! Couldn't find UnityEngine.SpriteRenderer component!"); OnLocalizationFailed?.Invoke(this, new LocalizationItemEventArgs(typeof(Sprite))); return; } else { gameObjSpriteRenderer.sprite = sprite; } break; default: Debug.LogWarning($"Localization of the item {gameObject.name} failed! Item type doesn't match to localization input."); OnLocalizationFailed?.Invoke(this, new LocalizationItemEventArgs(typeof(Sprite))); return; } OnLocalizationSucceeded?.Invoke(this, new LocalizationItemEventArgs(typeof(Sprite))); }
/// <summary> /// Performs sound localization (AudioSource). /// </summary> /// <param name="clip">Localized audio clip.</param> public void Localize(AudioClip clip) { if (!_allowNullOrEmpty && clip == null) { LogErrorMessage($"Localization of the item {gameObject.name} failed! Input localization is NULL!"); OnLocalizationFailed?.Invoke(this, new LocalizationItemEventArgs(typeof(AudioClip))); return; } var gameObjAudioSource = GetComponent <AudioSource>(); if (!gameObjAudioSource) { LogErrorMessage($"Localization of the item {gameObject.name} failed! Couldn't find UnityEngine.SpriteRenderer component!"); OnLocalizationFailed?.Invoke(this, new LocalizationItemEventArgs(typeof(AudioClip))); return; } else { gameObjAudioSource.clip = clip; } OnLocalizationSucceeded?.Invoke(this, new LocalizationItemEventArgs(typeof(AudioClip))); }