Skip to content

Commit

Permalink
1.0.57 1.#18 本地化模块不再依赖资产,可使用id索引资产。如添加多张图片,改为只需要一个id,2.修复资产模块展开资源时类型错…
Browse files Browse the repository at this point in the history
…误的问题
  • Loading branch information
TippingGame committed Nov 5, 2024
1 parent 8138139 commit 31b7b67
Show file tree
Hide file tree
Showing 21 changed files with 458 additions and 87 deletions.
2 changes: 1 addition & 1 deletion AssetMap/Resources/AssetBundleMap.json

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## [1.0.57] - 2024-11-06
1.#18 本地化模块不再依赖资产,可使用id索引资产。如添加多张图片,改为只需要一个id
2.修复资产模块展开资源时类型错误的问题

## [1.0.56] - 2024-11-04
1.优化资产模块,编辑器模式下增加缓存,加快搜索速度

Expand Down
84 changes: 79 additions & 5 deletions Editor/Localization/AudioLocalizerInspector.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using UnityEditor;
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using UnityEngine;

namespace F8Framework.Core.Editor
Expand All @@ -7,12 +9,14 @@ namespace F8Framework.Core.Editor
public class AudioLocalizerInspector : UnityEditor.Editor
{
AudioLocalizer localizer;
SerializedProperty localizedTextID;
SerializedProperty playFromSamePositionWhenInject;

void OnEnable()
{
localizer = (AudioLocalizer)target;
playFromSamePositionWhenInject = serializedObject.FindProperty("playFromSamePositionWhenInject");
localizedTextID = serializedObject.FindProperty("localizedTextID");
}

public override void OnInspectorGUI()
Expand All @@ -22,10 +26,82 @@ public override void OnInspectorGUI()
Localization.Instance.LoadInEditor();
serializedObject.Update();

EditorGUILayout.PropertyField(playFromSamePositionWhenInject, new GUIContent("从同一位置播放"));

var langCount = Localization.Instance.LanguageList.Count;

UpdateAudioClipInspector(langCount);

serializedObject.ApplyModifiedProperties();

GUI.skin.GetStyle("HelpBox").richText = true;
Localization.Instance.LoadInEditor();
var keys = Localization.Instance.GetAllIds();

if (keys.Count == 0)
{
EditorGUILayout.HelpBox("没有可用的数据。\n请将本地化表放在Excel存放文件夹中。", MessageType.Info);
return;
}

if (string.IsNullOrEmpty(localizer.localizedTextID))
{
EditorGUILayout.HelpBox($"输入 Text ID 或 拖拽音频 到上方", MessageType.Info);

var postfix = keys.Count > 5 ? $"\n\n<i>还有更多(共 {keys.Count.ToString()} 个ID)</i>" : "";
ShowSuggestion(keys.ToList(), postfix);
return;
}

var dict = Localization.Instance.GetDictionaryFromId(localizer.localizedTextID);
if (dict != null)
{
var helpText = dict.Aggregate("", (current, item) => current + $"{item.Key}: {item.Value}\n");
helpText = helpText.TrimEnd('\n');
EditorGUILayout.HelpBox($"{helpText}", MessageType.Info);
}
else
{
EditorGUILayout.HelpBox($"Text ID:{localizer.localizedTextID} 不可用。", MessageType.Error);
}

var suggestions = keys.Where(key => key.StartsWith(localizer.localizedTextID)).ToList();
ShowSuggestion(suggestions);
}

void ShowSuggestion(IReadOnlyCollection<string> suggestions, string postfix = "")
{
var noSuggestion = suggestions.Count == 0;
var exactMatch = suggestions.Count == 1 && suggestions.First() == localizer.localizedTextID;
if (noSuggestion || exactMatch) return;

var limit = LocalizationEditorSettings.current.maxSuggestion;
var text = suggestions.Take(limit)
.Aggregate("\n<b>ID 索引</b>\n", (current, item) => $"{current}\n- {GetMarkedIdRepresentation(item)}");
text += string.IsNullOrEmpty(postfix) ? "" : postfix;
EditorGUILayout.HelpBox($"{text}\n", MessageType.Info);

string GetMarkedIdRepresentation(string id)
{
if (string.IsNullOrEmpty(localizer.localizedTextID))
{
return id;
}
else
{
return $"<color=green>{id.Insert(localizer.localizedTextID.Length, "</color>")}";
}
}
}

void UpdateAudioClipInspector(int langCount)
{
EditorGUILayout.PropertyField(localizedTextID);
EditorGUILayout.PropertyField(playFromSamePositionWhenInject, new GUIContent("从同一位置播放"));

if (!localizedTextID.stringValue.IsNullOrEmpty())
{
return;
}

if (localizer.clips == null)
{
localizer.clips = new AudioClip[langCount];
Expand All @@ -49,8 +125,6 @@ public override void OnInspectorGUI()
EditorUtility.SetDirty(localizer);
}
}

serializedObject.ApplyModifiedProperties();
}
}
}
87 changes: 85 additions & 2 deletions Editor/Localization/ImageLocalizerInspector.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using UnityEditor;
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using UnityEngine;
using UnityEngine.UI;

Expand All @@ -8,12 +10,14 @@ namespace F8Framework.Core.Editor
public class ImageLocalizerInspector : UnityEditor.Editor
{
ImageLocalizer localizer;
SerializedProperty localizedTextID;
SerializedProperty propertyName;

void OnEnable()
{
localizer = (ImageLocalizer)target;
propertyName = serializedObject.FindProperty("propertyName");
localizedTextID = serializedObject.FindProperty("localizedTextID");
}

public override void OnInspectorGUI()
Expand Down Expand Up @@ -45,12 +49,77 @@ public override void OnInspectorGUI()
}

serializedObject.ApplyModifiedProperties();

GUI.skin.GetStyle("HelpBox").richText = true;
Localization.Instance.LoadInEditor();
var keys = Localization.Instance.GetAllIds();

if (keys.Count == 0)
{
EditorGUILayout.HelpBox("没有可用的数据。\n请将本地化表放在Excel存放文件夹中。", MessageType.Info);
return;
}

if (string.IsNullOrEmpty(localizer.localizedTextID))
{
EditorGUILayout.HelpBox($"输入 Text ID 或 拖拽图片 到上方", MessageType.Info);

var postfix = keys.Count > 5 ? $"\n\n<i>还有更多(共 {keys.Count.ToString()} 个ID)</i>" : "";
ShowSuggestion(keys.ToList(), postfix);
return;
}

var dict = Localization.Instance.GetDictionaryFromId(localizer.localizedTextID);
if (dict != null)
{
var helpText = dict.Aggregate("", (current, item) => current + $"{item.Key}: {item.Value}\n");
helpText = helpText.TrimEnd('\n');
EditorGUILayout.HelpBox($"{helpText}", MessageType.Info);
}
else
{
EditorGUILayout.HelpBox($"Text ID:{localizer.localizedTextID} 不可用。", MessageType.Error);
}

var suggestions = keys.Where(key => key.StartsWith(localizer.localizedTextID)).ToList();
ShowSuggestion(suggestions);
}

void ShowSuggestion(IReadOnlyCollection<string> suggestions, string postfix = "")
{
var noSuggestion = suggestions.Count == 0;
var exactMatch = suggestions.Count == 1 && suggestions.First() == localizer.localizedTextID;
if (noSuggestion || exactMatch) return;

var limit = LocalizationEditorSettings.current.maxSuggestion;
var text = suggestions.Take(limit)
.Aggregate("\n<b>ID 索引</b>\n", (current, item) => $"{current}\n- {GetMarkedIdRepresentation(item)}");
text += string.IsNullOrEmpty(postfix) ? "" : postfix;
EditorGUILayout.HelpBox($"{text}\n", MessageType.Info);

string GetMarkedIdRepresentation(string id)
{
if (string.IsNullOrEmpty(localizer.localizedTextID))
{
return id;
}
else
{
return $"<color=green>{id.Insert(localizer.localizedTextID.Length, "</color>")}";
}
}
}

void UpdateTexture2DInspector(int langCount)
{
EditorGUILayout.PropertyField(localizedTextID);
EditorGUILayout.PropertyField(propertyName);


if (!localizedTextID.stringValue.IsNullOrEmpty())
{
return;
}

if (localizer.texture2Ds == null)
{
localizer.texture2Ds = new Texture2D[langCount];
Expand Down Expand Up @@ -78,6 +147,13 @@ void UpdateTexture2DInspector(int langCount)

void UpdateTextureInspector(int langCount)
{
EditorGUILayout.PropertyField(localizedTextID);

if (!localizedTextID.stringValue.IsNullOrEmpty())
{
return;
}

if (localizer.textures == null)
{
localizer.textures = new Texture[langCount];
Expand Down Expand Up @@ -105,6 +181,13 @@ void UpdateTextureInspector(int langCount)

void UpdateSpriteInspector(int langCount)
{
EditorGUILayout.PropertyField(localizedTextID);

if (!localizedTextID.stringValue.IsNullOrEmpty())
{
return;
}

if (localizer.sprites == null)
{
localizer.sprites = new Sprite[langCount];
Expand Down
2 changes: 1 addition & 1 deletion Editor/Localization/TextLocalizerInspector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public override void OnInspectorGUI()

if (keys.Count == 0)
{
EditorGUILayout.HelpBox("没有可用的数据。\n请将LocalizedStrings.tsv放在StreamingAssets/localization文件夹中。", MessageType.Info);
EditorGUILayout.HelpBox("没有可用的数据。\n请将本地化表放在Excel存放文件夹中。", MessageType.Info);
return;
}

Expand Down
2 changes: 1 addition & 1 deletion Editor/Localization/TextLocalizerPlayableAssetInspector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public override void OnInspectorGUI()

if (keys.Count == 0)
{
EditorGUILayout.HelpBox("没有可用的数据。\n请将LocalizedStrings.tsv放在StreamingAssets/localization文件夹中。", MessageType.Info);
EditorGUILayout.HelpBox("没有可用的数据。\n请将本地化表放在Excel存放文件夹中。", MessageType.Info);
return;
}

Expand Down
Loading

0 comments on commit 31b7b67

Please sign in to comment.