浏览代码

Reduce nesting

/main
Brett 4 年前
当前提交
0f0b8928
共有 2 个文件被更改,包括 55 次插入60 次删除
  1. 96
      UOP1_Project/Assets/Scripts/Quests/Editor/LocalizationUtils.cs
  2. 19
      UOP1_Project/Assets/Scripts/Quests/Editor/QuestEditorWindow.cs

96
UOP1_Project/Assets/Scripts/Quests/Editor/LocalizationUtils.cs


using UnityEngine.Localization;
using System;
using UnityEngine.Localization;
using UnityEngine.Localization.Tables;
#if UNITY_EDITOR

public static class LocalizationUtils
{
#if UNITY_EDITOR
#if UNITY_EDITOR
/// <summary>
/// (Editor only)
/// Gets a locale to use in edit mode in the editor.
/// </summary>
/// <param name="tableCollection">Optional table collection with which to filter the available locales.</param>
/// <returns>The locale, null if none usable found.</returns>
/// <summary>
/// (Editor only)
/// Gets a locale to use in edit mode in the editor.
/// </summary>
/// <param name="tableCollection">Optional table collection with which to filter the available locales.</param>
/// <returns>The locale, null if none usable found.</returns>
static Locale Editor_GetValidLocaleInEditMode(LocalizationTableCollection tableCollection)
{
foreach (var locale in LocalizationEditorSettings.GetLocales())
{
if (locale != null && (tableCollection == null || tableCollection.GetTable(locale.Identifier) != null))
return locale;
}
static Locale Editor_GetValidLocaleInEditMode(LocalizationTableCollection tableCollection)
{
foreach (var locale in LocalizationEditorSettings.GetLocales())
{
if (locale != null && (tableCollection == null || tableCollection.GetTable(locale.Identifier) != null))
return locale;
}
return null;
}
return null;
}
#endif
#endif
/// <summary>
/// Gets the localized string from an already loaded table, taking into account whether we are in edit mode, play mode, or a build.
/// </summary>
/// <param name="localizedStringReference">The <see cref="LocalizedString"/>.</param>
/// <returns>The localized string.</returns>
/// <summary>
/// Gets the localized string from an already loaded table, taking into account whether we are in edit mode, play mode, or a build.
/// </summary>
/// <param name="localizedStringReference">The <see cref="LocalizedString"/>.</param>
/// <returns>The localized string.</returns>
public static string GetLocalizedStringImmediateSafe(this LocalizedString localizedStringReference)
{
// If we are in the editor in edit mode, we need to find a valid locale and get the localized string from it:
#if UNITY_EDITOR
{
if (!EditorApplication.isPlaying)
{
string text = null;
if (!localizedStringReference.IsEmpty)
{
var tableCollection = LocalizationEditorSettings.GetStringTableCollection(localizedStringReference.TableReference);
Locale locale = Editor_GetValidLocaleInEditMode(tableCollection);
if (locale != null)
{
StringTable table = (StringTable)tableCollection.GetTable(locale.Identifier);
if (table != null)
text = table.GetEntryFromReference(localizedStringReference.TableEntryReference).LocalizedValue;
}
}
public static string GetLocalizedStringImmediateSafe(this LocalizedString localizedStringReference)
{
// If we are in the editor in edit mode, we need to find a valid locale and get the localized string from it:
#if UNITY_EDITOR
if (EditorApplication.isPlaying)
return String.Empty;
return text;
}
}
#endif
string text = null;
if (!localizedStringReference.IsEmpty)
{
var tableCollection = LocalizationEditorSettings.GetStringTableCollection(localizedStringReference.TableReference);
Locale locale = Editor_GetValidLocaleInEditMode(tableCollection);
if (locale != null)
{
StringTable table = (StringTable)tableCollection.GetTable(locale.Identifier);
if (table != null)
text = table.GetEntryFromReference(localizedStringReference.TableEntryReference).LocalizedValue;
}
}
return text;
#endif
// At runtime (build or editor in play mode), we just get the localized string normally:
return localizedStringReference.GetLocalizedString().Result;
}
// At runtime (build or editor in play mode), we just get the localized string normally:
return localizedStringReference.GetLocalizedString().Result;
}
}

19
UOP1_Project/Assets/Scripts/Quests/Editor/QuestEditorWindow.cs


private void SetUpQuestPreview(QuestSO quest)
{
if (quest != null)
{
LoadActorImage(quest.Steps[0].Actor.name);
if (quest == null)
return;
//Clear actor conversations area
VisualElement actorConversationsVE = rootVisualElement.Q<VisualElement>("actor-conversations");
actorConversationsVE.Clear();
LoadActorImage(quest.Steps[0].Actor.name);
//Clear actor conversations area
rootVisualElement.Q<VisualElement>("actor-conversations").Clear();
foreach (StepSO step in quest.Steps)
{
LoadAndInitStepUXML(step);
}
}
foreach (StepSO step in quest.Steps)
LoadAndInitStepUXML(step);
}
private void LoadAndInitStepUXML(StepSO step)

正在加载...
取消
保存