Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Assets/_Project/Resources/LLMConfig.asset
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ MonoBehaviour:
_endpoint: https://api.deepseek.com/v1/chat/completions
_apiKey: sk-2c23ffc2bce6490f8a85678da3dd950d
_model: deepseek-v4-pro
_fallbackModels:
- deepseek-v4-flash
_angelSystemTemplate: "\u4F60\u662F\u4E00\u4F4D\u5929\u4F7F (Angel) \u2014\u2014
\u6E29\u67D4\u3001\u5305\u5BB9\u3001\u613F\u610F\u6307\u51FA\u5E0C\u671B\u3002\n\u5F53\u524D\u7684\u4F60\uFF1A{personality}\n\u7528\u4E2D\u6587\u7ED9\u51FA\u5854\u7F57\u89E3\u8BFB\uFF0C\u4E0D\u8D85\u8FC7
100 \u4E2A\u6C49\u5B57\u3002"
Expand Down
88 changes: 5 additions & 83 deletions Assets/_Project/Scenes/WorldMap/WorldMap_Main.unity
Original file line number Diff line number Diff line change
Expand Up @@ -14976,7 +14976,7 @@ Transform:
m_GameObject: {fileID: 138913199}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 27.760061, y: -2.942834, z: -0.25}
m_LocalPosition: {x: -44.75, y: -2.942834, z: -0.25}
m_LocalScale: {x: 0.22, y: 0.22, z: 0.22}
m_ConstrainProportionsScale: 0
m_Children: []
Expand Down Expand Up @@ -74945,81 +74945,6 @@ RectTransform:
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 20, y: 5}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!1 &625096670
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 625096673}
- component: {fileID: 625096672}
- component: {fileID: 625096671}
m_Layer: 5
m_Name: Page_Intro
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 0
--- !u!114 &625096671
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 625096670}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 0
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_Sprite: {fileID: 21300000, guid: 41bf3937f73ed3c4a8bda649666e7e6f, type: 3}
m_Type: 0
m_PreserveAspect: 1
m_FillCenter: 1
m_FillMethod: 4
m_FillAmount: 1
m_FillClockwise: 1
m_FillOrigin: 0
m_UseSpriteMesh: 0
m_PixelsPerUnitMultiplier: 1
--- !u!222 &625096672
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 625096670}
m_CullTransparentMesh: 1
--- !u!224 &625096673
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 625096670}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 916898188}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 1720, y: 970}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!1 &625495091
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -111539,11 +111464,9 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
_previewImage: {fileID: 0}
_previewTarget: {fileID: 625096670}
_previewKey: outdoor-intro
_previewTarget: {fileID: 886367749}
_previewKey: outdoor-1
_variants:
- Key: outdoor-1
Target: {fileID: 886367749}
- Key: outdoor-2
Target: {fileID: 896074888}
- Key: outdoor-3
Expand Down Expand Up @@ -111572,7 +111495,6 @@ RectTransform:
- {fileID: 1436077564}
- {fileID: 896074891}
- {fileID: 886367752}
- {fileID: 625096673}
- {fileID: 1823067439}
- {fileID: 1482816828}
- {fileID: 1259785875}
Expand Down Expand Up @@ -115614,7 +115536,7 @@ Transform:
m_GameObject: {fileID: 955552920}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 25.06006, y: -2.942834, z: -0.25}
m_LocalPosition: {x: -47.45, y: -2.942834, z: -0.25}
m_LocalScale: {x: 0.22, y: 0.22, z: 0.22}
m_ConstrainProportionsScale: 0
m_Children: []
Expand Down Expand Up @@ -203121,7 +203043,7 @@ Transform:
m_GameObject: {fileID: 1732304706}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 26.41006, y: -2.942834, z: -0.25}
m_LocalPosition: {x: -46.1, y: -2.942834, z: -0.25}
m_LocalScale: {x: 0.22, y: 0.22, z: 0.22}
m_ConstrainProportionsScale: 0
m_Children: []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static void Patch()
ConfigureFullscreen(panel);

SceneAuthoredImageVariantView pageView = GetOrAdd<SceneAuthoredImageVariantView>(panel);
GameObject introPage = EnsurePage(panel.transform, "Page_Intro", OutdoorArtRoot + "/intro.png", uiLayer);
RemoveChild(panel.transform, "Page_Intro");
GameObject[] pages = new GameObject[6];
for (int i = 0; i < pages.Length; i++)
{
Expand All @@ -56,7 +56,7 @@ public static void Patch()
uiLayer);
}

ConfigurePageView(pageView, introPage, pages);
ConfigurePageView(pageView, pages);

Button previousButton = EnsureImageButton(
panel.transform,
Expand Down Expand Up @@ -97,12 +97,11 @@ public static void Patch()
EditorUtility.SetDirty(pageView);
EditorSceneManager.MarkSceneDirty(scene);
EditorSceneManager.SaveScene(scene);
Debug.Log("[WorldMapOutdoorTutorialAuthoring] Outdoor tutorial authored with seven pages and placeholder entry.");
Debug.Log("[WorldMapOutdoorTutorialAuthoring] Outdoor tutorial authored with six pages and placeholder entry.");
}

private static void ConfigurePageView(
SceneAuthoredImageVariantView pageView,
GameObject introPage,
GameObject[] pages)
{
SerializedObject serialized = new SerializedObject(pageView);
Expand All @@ -111,22 +110,22 @@ private static void ConfigurePageView(
SerializedProperty? previewTarget = serialized.FindProperty("_previewTarget");
if (previewTarget != null)
{
previewTarget.objectReferenceValue = introPage;
previewTarget.objectReferenceValue = pages.Length > 0 ? pages[0] : null;
}

SerializedProperty? previewKey = serialized.FindProperty("_previewKey");
if (previewKey != null)
{
previewKey.stringValue = "outdoor-intro";
previewKey.stringValue = pages.Length > 0 ? "outdoor-1" : string.Empty;
}

SerializedProperty? variants = serialized.FindProperty("_variants");
if (variants != null)
{
variants.arraySize = pages.Length;
for (int i = 0; i < pages.Length; i++)
variants.arraySize = Mathf.Max(0, pages.Length - 1);
for (int i = 1; i < pages.Length; i++)
{
SerializedProperty element = variants.GetArrayElementAtIndex(i);
SerializedProperty element = variants.GetArrayElementAtIndex(i - 1);
element.FindPropertyRelative("Key").stringValue = $"outdoor-{i + 1}";
element.FindPropertyRelative("Target").objectReferenceValue = pages[i];
}
Expand Down Expand Up @@ -232,6 +231,15 @@ private static GameObject EnsureChild(Transform parent, string name, int layer)
return created;
}

private static void RemoveChild(Transform parent, string name)
{
Transform? existing = parent.Find(name);
if (existing != null)
{
Undo.DestroyObjectImmediate(existing.gameObject);
}
}

private static void ConfigureFullscreen(GameObject target)
{
SetRect(
Expand Down
101 changes: 63 additions & 38 deletions Assets/_Project/Scripts/Modules/AI/EmotionGardenAiProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@ public EmotionGardenAiProvider(LLMConfigSO config)
return null;
}

Debug.Log($"[AI] request-entry role={role} feature=Emotion inputEmpty={inputEmpty} service={GetType().Name} registered=true sent=false");
string[] modelCandidates = _config.ModelCandidates;
if (modelCandidates.Length == 0)
{
LogFallback(role, "NoModelCandidates");
return null;
}

string systemPrompt = BuildSystemPrompt(normalizedOwner);
string userPrompt = BuildUserPrompt(
Expand All @@ -55,46 +60,57 @@ public EmotionGardenAiProvider(LLMConfigSO config)
flowerName,
flowerDescription);

try
Debug.Log($"[AI] request-entry role={role} feature=Emotion inputEmpty={inputEmpty} service={GetType().Name} registered=true models={string.Join(",", modelCandidates)}");

string lastFailure = string.Empty;
for (int modelIndex = 0; modelIndex < modelCandidates.Length; modelIndex++)
{
using var timeoutCts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
float timeoutSeconds = _config.TimeoutSeconds > 0f ? _config.TimeoutSeconds : 10f;
timeoutCts.CancelAfter(TimeSpan.FromSeconds(timeoutSeconds));
string model = modelCandidates[modelIndex];
try
{
using var timeoutCts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
float timeoutSeconds = _config.TimeoutSeconds > 0f ? _config.TimeoutSeconds : 10f;
timeoutCts.CancelAfter(TimeSpan.FromSeconds(timeoutSeconds));

string responseContent = await SendRequestAsync(role, systemPrompt, userPrompt, timeoutCts.Token);
Debug.Log($"[AI] raw-response role={role} feature=Emotion content={SanitizeForLog(responseContent)}");
string responseContent = await SendRequestAsync(role, model, systemPrompt, userPrompt, timeoutCts.Token);
Debug.Log($"[AI] raw-response role={role} feature=Emotion model={model} content={SanitizeForLog(responseContent)}");

EmotionGardenAiResult result = ParseResponse(responseContent);
if (!EmotionGardenAiValidation.IsCompleteResult(result, out string validationReason))
EmotionGardenAiResult result = ParseResponse(responseContent);
if (!EmotionGardenAiValidation.IsCompleteResult(result, out string validationReason))
{
lastFailure = $"InvalidResult:{validationReason}";
LogModelFailure(role, model, modelIndex, modelCandidates.Length, lastFailure);
continue;
}

result.EmotionType = EmotionFlowerCatalog.NormalizeEmotionType(result.EmotionType);
result.EmotionKeywords = EmotionGardenAiValidation.NormalizeKeywords(result.EmotionKeywords);
result.FlowerDescription = EmotionGardenAiValidation.NormalizeText(result.FlowerDescription, 120);
result.FlowerLanguage = EmotionGardenAiValidation.NormalizeText(result.FlowerLanguage, 160);
result.Summary = EmotionGardenAiValidation.NormalizeText(result.Summary, 60);
result.AngelNote = EmotionGardenAiValidation.NormalizeText(result.AngelNote, 80);
result.DevilNote = EmotionGardenAiValidation.NormalizeText(result.DevilNote, 80);
result.ResultSource = EmotionGardenResultSources.Ai;
result.IsFallback = false;

Debug.Log($"{EmotionGardenResultSources.Ai} role={role} feature=Emotion model={model} result=Accepted emotion={result.EmotionType}");
return result;
}
catch (OperationCanceledException)
{
LogFallback(role, $"InvalidResult:{validationReason}");
return null;
if (cancellationToken.IsCancellationRequested) throw;
lastFailure = "Timeout";
LogModelFailure(role, model, modelIndex, modelCandidates.Length, lastFailure);
}
catch (Exception ex)
{
lastFailure = $"{ex.GetType().Name}:{SanitizeForLog(ex.Message, 240)}";
LogModelFailure(role, model, modelIndex, modelCandidates.Length, lastFailure);
}

result.EmotionType = EmotionFlowerCatalog.NormalizeEmotionType(result.EmotionType);
result.EmotionKeywords = EmotionGardenAiValidation.NormalizeKeywords(result.EmotionKeywords);
result.FlowerDescription = EmotionGardenAiValidation.NormalizeText(result.FlowerDescription, 120);
result.FlowerLanguage = EmotionGardenAiValidation.NormalizeText(result.FlowerLanguage, 160);
result.Summary = EmotionGardenAiValidation.NormalizeText(result.Summary, 60);
result.AngelNote = EmotionGardenAiValidation.NormalizeText(result.AngelNote, 80);
result.DevilNote = EmotionGardenAiValidation.NormalizeText(result.DevilNote, 80);
result.ResultSource = EmotionGardenResultSources.Ai;
result.IsFallback = false;

Debug.Log($"{EmotionGardenResultSources.Ai} role={role} feature=Emotion result=Accepted emotion={result.EmotionType}");
return result;
}
catch (OperationCanceledException)
{
if (cancellationToken.IsCancellationRequested) throw;
LogFallback(role, "Timeout");
return null;
}
catch (Exception ex)
{
LogFallback(role, $"{ex.GetType().Name}:{SanitizeForLog(ex.Message, 240)}");
return null;
}

LogFallback(role, $"AllModelsFailed:{lastFailure}");
return null;
}

private static string BuildSystemPrompt(string owner)
Expand All @@ -111,7 +127,9 @@ private static string BuildSystemPrompt(string owner)
"必须优先根据玩家输入判断,不能无理由返回平静;例如生气/愤怒优先选愤怒,开心/快乐优先选喜悦,悲伤/难过优先选悲伤,明确平静才选平静。" +
"EmotionKeywords 返回 2 到 5 个简短中文关键词。" +
"Summary 必须是 30 到 60 个中文字符;AngelNote 和 DevilNote 必须分别是 40 到 80 个中文字符。" +
"FlowerDescription 和 FlowerLanguage 使用具体、自然的中文。";
"FlowerDescription 必须紧扣玩家输入,至少使用其中一个具体事件、细节、情绪、人物关系或愿望,并把它映射到花朵的形态、气质或象征上。" +
"禁止只写花瓣、露珠、阳光等与输入无关的通用外观描写,禁止套用脱离玩家输入也成立的固定句式,也不要逐字复述整句输入。" +
"若玩家输入为空,只能使用不编造经历的泛化表达。FlowerLanguage 也要使用具体、自然的中文,并可适度承接玩家输入。";
}

private static string BuildUserPrompt(
Expand All @@ -135,13 +153,14 @@ private static string BuildUserPrompt(

private async Task<string> SendRequestAsync(
string role,
string model,
string systemPrompt,
string userPrompt,
CancellationToken cancellationToken)
{
var body = new LlmRequest
{
model = _config.Model,
model = model,
messages = new[]
{
new LlmMessage { role = "system", content = systemPrompt },
Expand All @@ -161,7 +180,7 @@ private async Task<string> SendRequestAsync(
request.SetRequestHeader("Authorization", $"Bearer {_config.ApiKey}");

var operation = request.SendWebRequest();
Debug.Log($"[AI] request-sent role={role} feature=Emotion method=POST endpoint={_config.Endpoint} model={_config.Model}");
Debug.Log($"[AI] request-sent role={role} feature=Emotion method=POST endpoint={_config.Endpoint} model={model}");
while (!operation.isDone)
{
if (cancellationToken.IsCancellationRequested)
Expand Down Expand Up @@ -292,6 +311,12 @@ private void LogFallback(string role, string reason)
Debug.LogWarning($"{EmotionGardenResultSources.Fallback} role={role} feature=Emotion reason={SanitizeForLog(reason, 240)}");
}

private void LogModelFailure(string role, string model, int modelIndex, int modelCount, string reason)
{
bool hasNextModel = modelIndex + 1 < modelCount;
Debug.LogWarning($"[AI] model-failed role={role} feature=Emotion model={model} attempt={modelIndex + 1}/{modelCount} hasNext={hasNextModel} reason={SanitizeForLog(reason, 240)}");
}

private static string ResolveLogRole(string owner)
{
return EmotionFlowerCatalog.NormalizeOwner(owner) == EmotionFlowerCatalog.OwnerDemon
Expand Down
Loading
Loading