Ejemplo n.º 1
0
        /// <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)));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Performs text localization (UI Text).
        /// </summary>
        /// <param name="text">Localized text.</param>
        public void Localize(string text)
        {
            if (!_allowNullOrEmpty && string.IsNullOrEmpty(text))
            {
                LogErrorMessage($"Localization of the item {gameObject.name} failed! Input localization is NULL or empty!");
                OnLocalizationFailed?.Invoke(this, new LocalizationItemEventArgs(typeof(string)));
                return;
            }

            var gameObjText = GetComponent <Text>();

            if (!gameObjText)
            {
                LogErrorMessage($"Localization of the item {gameObject.name} failed! Couldn't find UnityEngine.UI.Text component!");
                OnLocalizationFailed?.Invoke(this, new LocalizationItemEventArgs(typeof(string)));
            }
            else
            {
                gameObjText.text = text;
            }
        }
Ejemplo n.º 3
0
        /// <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)));
        }