Exemplo n.º 1
0
        protected virtual void DoAlertAction()
        {
            if (string.IsNullOrEmpty(alertMessage))
            {
                return;
            }
            string localizedAlertMessage;

            if ((textTable != null) && textTable.HasFieldTextForLanguage(alertMessage, Localization.GetCurrentLanguageID(textTable)))
            {
                localizedAlertMessage = textTable.GetFieldTextForLanguage(alertMessage, Localization.GetCurrentLanguageID(textTable));
            }
            else
            {
                localizedAlertMessage = DialogueManager.GetLocalizedText(alertMessage);
            }
            if (Mathf.Approximately(0, alertDuration))
            {
                DialogueManager.ShowAlert(localizedAlertMessage);
            }
            else
            {
                DialogueManager.ShowAlert(localizedAlertMessage, alertDuration);
            }
        }
 /// <summary>
 /// Gets the localized text for a field name.
 /// </summary>
 /// <returns>The localized text.</returns>
 /// <param name="fieldName">Field name.</param>
 public virtual string GetLocalizedText(string fieldName)
 {
     if ((textTable != null) && textTable.HasFieldTextForLanguage(fieldName, Localization.GetCurrentLanguageID(textTable)))
     {
         return(textTable.GetFieldTextForLanguage(fieldName, Localization.GetCurrentLanguageID(textTable)));
     }
     else
     {
         return(DialogueManager.GetLocalizedText(fieldName));
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Call this method to manually run the action.
        /// </summary>
        public void Fire()
        {
            // Quest:
            if (!string.IsNullOrEmpty(questName))
            {
                QuestLog.SetQuestState(questName, questState);
            }

            // Lua:
            if (!string.IsNullOrEmpty(luaCode))
            {
                Lua.Run(luaCode, DialogueDebug.logInfo);
                DialogueManager.CheckAlerts();
            }

            // Sequence:
            if (!string.IsNullOrEmpty(sequence))
            {
                DialogueManager.PlaySequence(sequence);
            }

            // Alert:
            if (!string.IsNullOrEmpty(alertMessage))
            {
                string localizedAlertMessage;
                if ((textTable != null) && textTable.HasFieldTextForLanguage(alertMessage, Localization.GetCurrentLanguageID(textTable)))
                {
                    localizedAlertMessage = textTable.GetFieldTextForLanguage(alertMessage, Localization.GetCurrentLanguageID(textTable));
                }
                else
                {
                    localizedAlertMessage = DialogueManager.GetLocalizedText(alertMessage);
                }
                DialogueManager.ShowAlert(localizedAlertMessage);
            }

            // Send Messages:
            foreach (var sma in sendMessages)
            {
                if (sma.gameObject != null && !string.IsNullOrEmpty(sma.message))
                {
                    sma.gameObject.SendMessage(sma.message, sma.parameter, SendMessageOptions.DontRequireReceiver);
                }
            }

            DialogueManager.SendUpdateTracker();

            if (once)
            {
                StopObserving();
                enabled = false;
            }
        }
Exemplo n.º 4
0
        public virtual void LocalizeText()
        {
            if (!started)
            {
                return;
            }

            // Skip if no language set:
            if (string.IsNullOrEmpty(PixelCrushers.DialogueSystem.Localization.language))
            {
                return;
            }
            if (textTable == null)
            {
                textTable = DialogueManager.displaySettings.localizationSettings.textTable;
                if (textTable == null)
                {
                    if (DialogueDebug.logWarnings)
                    {
                        Debug.LogWarning(DialogueDebug.Prefix + ": No localized text table is assigned to " + name + " or the Dialogue Manager.", this);
                    }
                    return;
                }
            }

            if (!HasCurrentLanguage())
            {
                if (DialogueDebug.logWarnings)
                {
                    Debug.LogWarning(DialogueDebug.Prefix + "Localized text table '" + textTable + "' does not have a language '" + PixelCrushers.DialogueSystem.Localization.language + "'", this);
                }
                return;
            }

            // Make sure we have a Text or Dropdown:
            if (text == null && dropdown == null)
            {
                text     = GetComponent <UnityEngine.UI.Text>();
                dropdown = GetComponent <UnityEngine.UI.Dropdown>();
                if (text == null && dropdown == null)
                {
                    if (DialogueDebug.logWarnings)
                    {
                        Debug.LogWarning(DialogueDebug.Prefix + ": LocalizeUIText didn't find a Text or Dropdown component on " + name + ".", this);
                    }
                    return;
                }
            }

            // Get the original values to use as field lookups:
            if (string.IsNullOrEmpty(fieldName))
            {
                fieldName = (text != null) ? text.text : string.Empty;
            }
            if ((fieldNames.Count == 0) && (dropdown != null))
            {
                dropdown.options.ForEach(opt => fieldNames.Add(opt.text));
            }
            // Localize Text:
            if (text != null)
            {
                if (!textTable.HasField(fieldName))
                {
                    if (DialogueDebug.logWarnings)
                    {
                        Debug.LogWarning(DialogueDebug.Prefix + ": Localized text table '" + textTable.name + "' does not have a field: " + fieldName, this);
                    }
                }
                else
                {
                    text.text = textTable.GetFieldTextForLanguage(fieldName, Localization.GetCurrentLanguageID(textTable));
                }
            }

            // Localize Dropdown:
            if (dropdown != null)
            {
                for (int i = 0; i < dropdown.options.Count; i++)
                {
                    if (i < fieldNames.Count)
                    {
                        dropdown.options[i].text = textTable.GetFieldTextForLanguage(fieldNames[i], Localization.GetCurrentLanguageID(textTable));
                    }
                }
                dropdown.captionText.text = textTable.GetFieldTextForLanguage(fieldNames[dropdown.value], Localization.GetCurrentLanguageID(textTable));
            }
        }