From 48b8c50ce937977700b48d62890bed2ed5bdadf5 Mon Sep 17 00:00:00 2001 From: chiyulin0314 Date: Wed, 19 Nov 2025 00:52:59 +0800 Subject: [PATCH] fix Q11 --- Assets/Scenes/Server/ServerWorkScene.unity | 86 ++++- .../Scripts/Server/ServerGameTalkingPanel.cs | 16 + .../Scripts/Server/ServerGameTypingPanel.cs | 15 + Assets/Scripts/Utils/CustomerReportSystem.cs | 329 ++++++++++++++++++ .../Utils/CustomerReportSystem.cs.meta | 2 + 5 files changed, 445 insertions(+), 3 deletions(-) create mode 100644 Assets/Scripts/Utils/CustomerReportSystem.cs create mode 100644 Assets/Scripts/Utils/CustomerReportSystem.cs.meta diff --git a/Assets/Scenes/Server/ServerWorkScene.unity b/Assets/Scenes/Server/ServerWorkScene.unity index d2dc6e7..8c54823 100644 --- a/Assets/Scenes/Server/ServerWorkScene.unity +++ b/Assets/Scenes/Server/ServerWorkScene.unity @@ -11628,7 +11628,7 @@ MonoBehaviour: m_TargetGraphic: {fileID: 1027134027} m_HandleRect: {fileID: 1027134026} m_Direction: 2 - m_Value: 1 + m_Value: 0 m_Size: 1 m_NumberOfSteps: 0 m_OnValueChanged: @@ -13458,7 +13458,7 @@ MonoBehaviour: m_HandleRect: {fileID: 1558618295} m_Direction: 2 m_Value: 1.0000002 - m_Size: 0.45958003 + m_Size: 0.45957997 m_NumberOfSteps: 0 m_OnValueChanged: m_PersistentCalls: @@ -14559,6 +14559,7 @@ GameObject: - component: {fileID: 1176599491} - component: {fileID: 1176599493} - component: {fileID: 1176599492} + - component: {fileID: 1176599494} m_Layer: 5 m_Name: ScoreMeterPanel m_TagString: Untagged @@ -14634,6 +14635,45 @@ CanvasRenderer: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1176599490} m_CullTransparentMesh: 1 +--- !u!114 &1176599494 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1176599490} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 189ee448adf15a2479d8cd66d37e814f, type: 3} + m_Name: + m_EditorClassIdentifier: Assembly-CSharp::CustomerReportSystem + customerValueTexts: + - {fileID: 51071077} + - {fileID: 921151188} + - {fileID: 822703751} + increaseButtons: + - {fileID: 1519415806} + - {fileID: 1627850927} + - {fileID: 958256476} + decreaseButtons: + - {fileID: 1285575639} + - {fileID: 1859063090} + - {fileID: 1476069277} + confirmButton: {fileID: 138081378} + valueNames: + - "\u9670\u5FB7\u503C" + - "\u696D\u529B\u503C" + - "\u8AA0\u610F\u5EA6" + initialValues: 3c0000003c0000003c000000 + minValue: 0 + maxValue: 100 + changeAmount: 1 + numberColor: {r: 1, g: 0.92156863, b: 0.015686275, a: 1} + fontSize: 36 + useBold: 1 + audioSource: {fileID: 0} + buttonClickSound: {fileID: 0} + confirmSound: {fileID: 0} --- !u!1 &1182399752 GameObject: m_ObjectHideFlags: 0 @@ -20675,6 +20715,7 @@ GameObject: - component: {fileID: 1640656670} - component: {fileID: 1640656672} - component: {fileID: 1640656671} + - component: {fileID: 1640656673} m_Layer: 5 m_Name: ScoreMeterPanel m_TagString: Untagged @@ -20750,6 +20791,45 @@ CanvasRenderer: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1640656669} m_CullTransparentMesh: 1 +--- !u!114 &1640656673 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1640656669} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 189ee448adf15a2479d8cd66d37e814f, type: 3} + m_Name: + m_EditorClassIdentifier: Assembly-CSharp::CustomerReportSystem + customerValueTexts: + - {fileID: 1416923173} + - {fileID: 1870117283} + - {fileID: 640231342} + increaseButtons: + - {fileID: 699560995} + - {fileID: 439149288} + - {fileID: 522012262} + decreaseButtons: + - {fileID: 9238438} + - {fileID: 825431170} + - {fileID: 143942662} + confirmButton: {fileID: 1780462149} + valueNames: + - "\u9670\u5FB7\u503C" + - "\u696D\u529B\u503C" + - "\u8AA0\u610F\u5EA6" + initialValues: 3c0000003c0000003c000000 + minValue: 0 + maxValue: 100 + changeAmount: 1 + numberColor: {r: 1, g: 0.92156863, b: 0.015686275, a: 1} + fontSize: 36 + useBold: 1 + audioSource: {fileID: 0} + buttonClickSound: {fileID: 0} + confirmSound: {fileID: 0} --- !u!1 &1658875712 GameObject: m_ObjectHideFlags: 0 @@ -21976,7 +22056,7 @@ MonoBehaviour: m_HandleRect: {fileID: 810756926} m_Direction: 0 m_Value: 0 - m_Size: 1 + m_Size: 0.9999999 m_NumberOfSteps: 0 m_OnValueChanged: m_PersistentCalls: diff --git a/Assets/Scripts/Server/ServerGameTalkingPanel.cs b/Assets/Scripts/Server/ServerGameTalkingPanel.cs index 83fed1e..aea8077 100644 --- a/Assets/Scripts/Server/ServerGameTalkingPanel.cs +++ b/Assets/Scripts/Server/ServerGameTalkingPanel.cs @@ -1,6 +1,7 @@ using System; using System.Collections; using TMPro; +using Unity.VisualScripting; using UnityEngine; using UnityEngine.UI; using UnityEngine.Video; @@ -26,6 +27,8 @@ public class ServerGameTalkingPanel : MonoBehaviour public Button sample4Button; public Button sample5Button; + private CustomerReportSystem customReportScript; + private int gameTimeCountdownSecVal = GlobalData.GAME_TALK_COUNTDOWN_TIME; private string[] sampleTexts = { @@ -40,6 +43,7 @@ public class ServerGameTalkingPanel : MonoBehaviour private void Awake() { Instance = this; + customReportScript = gameObject.GetComponentInChildren(); } // Start is called once before the first execution of Update after the MonoBehaviour is created @@ -73,6 +77,18 @@ public class ServerGameTalkingPanel : MonoBehaviour sample5Button.onClick.AddListener(sample5Button_onClick); } + customReportScript.OnCustomerReportConfirmed = OnCustomerReportConfirmed; + } + + private void OnCustomerReportConfirmed(int[] values) + { + if (values.Length < 3) { return; } + if (ServerWorkTopRightScore.Instance == null) { return; } + + ServerWorkTopRightScore.ScoreVal1 = values[0]; + ServerWorkTopRightScore.ScoreVal2 = values[1]; + ServerWorkTopRightScore.ScoreVal3 = values[2]; + ServerWorkTopRightScore.Instance.UpdateScoreVals(); } private void sample5Button_onClick() diff --git a/Assets/Scripts/Server/ServerGameTypingPanel.cs b/Assets/Scripts/Server/ServerGameTypingPanel.cs index 128bbb5..bf8a3e7 100644 --- a/Assets/Scripts/Server/ServerGameTypingPanel.cs +++ b/Assets/Scripts/Server/ServerGameTypingPanel.cs @@ -24,11 +24,14 @@ public class ServerGameTypingPanel : MonoBehaviour public TMP_Text checkText; public Button checkOkButton; + private CustomerReportSystem customReportScript; + private int gameTimeCountdownSecVal = 10; private void Awake() { Instance = this; + customReportScript = gameObject.GetComponentInChildren(); } public void processStep(int step) @@ -159,6 +162,18 @@ public class ServerGameTypingPanel : MonoBehaviour SetupIntroVideoPlayer(); SetupPlayVideoPlayer(); + customReportScript.OnCustomerReportConfirmed = OnCustomerReportConfirmed; + } + + private void OnCustomerReportConfirmed(int[] values) + { + if (values.Length < 3) { return; } + if (ServerWorkTopRightScore.Instance == null) { return; } + + ServerWorkTopRightScore.ScoreVal1 = values[0]; + ServerWorkTopRightScore.ScoreVal2 = values[1]; + ServerWorkTopRightScore.ScoreVal3 = values[2]; + ServerWorkTopRightScore.Instance.UpdateScoreVals(); } private void checkOkButton_onClicked() diff --git a/Assets/Scripts/Utils/CustomerReportSystem.cs b/Assets/Scripts/Utils/CustomerReportSystem.cs new file mode 100644 index 0000000..8e35aea --- /dev/null +++ b/Assets/Scripts/Utils/CustomerReportSystem.cs @@ -0,0 +1,329 @@ +using System.Collections; +using UnityEngine; +using UnityEngine.UI; +using TMPro; + +public class CustomerReportSystem : MonoBehaviour +{ + [Header("Customer Report UI References")] + [Tooltip("三個數值顯示的TextMeshPro組件")] + public TextMeshProUGUI[] customerValueTexts = new TextMeshProUGUI[3]; + + [Tooltip("三個增加按鈕(+)")] + public Button[] increaseButtons = new Button[3]; + + [Tooltip("三個減少按鈕(-)")] + public Button[] decreaseButtons = new Button[3]; + + [Tooltip("確認儲存按鈕")] + public Button confirmButton; + + [Header("Customer Report Settings")] + [Tooltip("三個數值的名稱,可以自訂")] + public string[] valueNames = { "陰德值", "業力值", "誠意度" }; + + [Tooltip("初始數值,預設都是60")] + public int[] initialValues = { 60, 60, 60 }; + + [Tooltip("數值的最小值")] + public int minValue = 0; + + [Tooltip("數值的最大值")] + public int maxValue = 100; + + [Tooltip("每次點擊按鈕改變的數值")] + public int changeAmount = 1; + + [Header("Display Settings")] + [Tooltip("數字的顏色")] + public Color numberColor = Color.yellow; + + [Tooltip("數字的字體大小")] + public int fontSize = 36; + + [Tooltip("是否使用粗體")] + public bool useBold = true; + + [Header("Audio Settings")] + [Tooltip("音效播放器")] + public AudioSource audioSource; + + [Tooltip("按鈕點擊音效")] + public AudioClip buttonClickSound; + + [Tooltip("確認音效")] + public AudioClip confirmSound; + + // 私有變數 + private int[] customerValues = new int[3]; + + private void Start() + { + InitializeCustomerReport(); + SetupEventListeners(); + UpdateCustomerValueDisplays(); + } + + /// + /// 初始化客戶報表數值 + /// + private void InitializeCustomerReport() + { + // 複製初始數值到當前數值陣列 + for (int i = 0; i < customerValues.Length; i++) + { + if (i < initialValues.Length) + { + customerValues[i] = initialValues[i]; + } + else + { + customerValues[i] = 60; // 預設值 + } + } + } + + /// + /// 設置按鈕事件監聽器 + /// + private void SetupEventListeners() + { + // 設置增加和減少按鈕 + for (int i = 0; i < 3; i++) + { + int index = i; // 避免閉包問題 + + if (increaseButtons[i] != null) + { + increaseButtons[i].onClick.AddListener(() => ModifyCustomerValue(index, changeAmount)); + } + + if (decreaseButtons[i] != null) + { + decreaseButtons[i].onClick.AddListener(() => ModifyCustomerValue(index, -changeAmount)); + } + } + + // 設置確認按鈕 + if (confirmButton != null) + { + confirmButton.onClick.AddListener(ConfirmCustomerValues); + } + } + + /// + /// 修改指定數值 + /// + /// 數值索引 (0-2) + /// 改變量 + public void ModifyCustomerValue(int index, int change) + { + if (index < 0 || index >= customerValues.Length) return; + + // 計算新數值並限制範圍 + customerValues[index] = Mathf.Clamp(customerValues[index] + change, minValue, maxValue); + + // 更新顯示 + UpdateCustomerValueDisplays(); + + // 播放音效 + PlayButtonSound(); + + // 可以在這裡添加其他邏輯,如振動效果等 + Debug.Log($"{valueNames[index]} 變更為: {customerValues[index]}"); + } + + /// + /// 更新數值顯示 + /// + private void UpdateCustomerValueDisplays() + { + for (int i = 0; i < customerValues.Length && i < customerValueTexts.Length; i++) + { + if (customerValueTexts[i] != null) + { + // 使用Rich Text格式化數字顯示 + string colorHex = ColorUtility.ToHtmlStringRGBA(numberColor); + string boldTag = useBold ? "b" : ""; + + if (useBold) + { + customerValueTexts[i].text = $"<{boldTag}>{customerValues[i]}"; + } + else + { + customerValueTexts[i].text = $"{customerValues[i]}"; + } + + // 直接設置組件屬性(備用方案) + customerValueTexts[i].fontSize = fontSize; + customerValueTexts[i].color = numberColor; + customerValueTexts[i].fontStyle = useBold ? FontStyles.Bold : FontStyles.Normal; + customerValueTexts[i].alignment = TextAlignmentOptions.Center; + } + } + } + + /// + /// 確認並儲存數值 + /// + public void ConfirmCustomerValues() + { + // 播放確認音效 + PlayConfirmSound(); + + // 生成確認訊息 + string confirmMessage = "客戶報表已儲存 - "; + for (int i = 0; i < customerValues.Length && i < valueNames.Length; i++) + { + confirmMessage += $"{valueNames[i]}:{customerValues[i]}"; + if (i < customerValues.Length - 1) confirmMessage += " "; + } + + Debug.Log(confirmMessage); + + // 可以在這裡添加儲存到PlayerPrefs或其他持久化邏輯 + SaveToPlayerPrefs(); + + // 觸發確認事件(可以讓其他系統監聽) + OnCustomerReportConfirmed?.Invoke(customerValues); + } + + /// + /// 儲存數值到PlayerPrefs + /// + private void SaveToPlayerPrefs() + { + for (int i = 0; i < customerValues.Length; i++) + { + PlayerPrefs.SetInt($"CustomerValue_{i}", customerValues[i]); + } + PlayerPrefs.Save(); + } + + /// + /// 從PlayerPrefs載入數值 + /// + public void LoadFromPlayerPrefs() + { + for (int i = 0; i < customerValues.Length; i++) + { + customerValues[i] = PlayerPrefs.GetInt($"CustomerValue_{i}", initialValues[i]); + } + UpdateCustomerValueDisplays(); + } + + /// + /// 重置所有數值到初始值 + /// + public void ResetToDefault() + { + InitializeCustomerReport(); + UpdateCustomerValueDisplays(); + Debug.Log("客戶報表已重置到預設值"); + } + + /// + /// 播放按鈕音效 + /// + private void PlayButtonSound() + { + if (audioSource != null && buttonClickSound != null) + { + audioSource.PlayOneShot(buttonClickSound); + } + } + + /// + /// 播放確認音效 + /// + private void PlayConfirmSound() + { + if (audioSource != null && confirmSound != null) + { + audioSource.PlayOneShot(confirmSound); + } + } + + // 公開方法供其他腳本調用 + + /// + /// 獲取指定數值 + /// + /// 數值索引 + /// 數值 + public int GetCustomerValue(int index) + { + if (index >= 0 && index < customerValues.Length) + return customerValues[index]; + return -1; + } + + /// + /// 設置指定數值 + /// + /// 數值索引 + /// 新數值 + public void SetCustomerValue(int index, int value) + { + if (index >= 0 && index < customerValues.Length) + { + customerValues[index] = Mathf.Clamp(value, minValue, maxValue); + UpdateCustomerValueDisplays(); + } + } + + /// + /// 獲取所有數值的副本 + /// + /// 數值陣列 + public int[] GetAllCustomerValues() + { + int[] valuesCopy = new int[customerValues.Length]; + customerValues.CopyTo(valuesCopy, 0); + return valuesCopy; + } + + /// + /// 設置所有數值 + /// + /// 新的數值陣列 + public void SetAllCustomerValues(int[] newValues) + { + for (int i = 0; i < customerValues.Length && i < newValues.Length; i++) + { + customerValues[i] = Mathf.Clamp(newValues[i], minValue, maxValue); + } + UpdateCustomerValueDisplays(); + } + + // 事件系統 + public System.Action OnCustomerReportConfirmed; + public System.Action OnValueChanged; // index, newValue + + /// + /// 觸發數值改變事件 + /// + private void TriggerValueChangedEvent(int index, int newValue) + { + OnValueChanged?.Invoke(index, newValue); + } + + // 編輯器用的測試方法 +#if UNITY_EDITOR + [ContextMenu("Test - Add 10 to All Values")] + private void TestAddToAllValues() + { + for (int i = 0; i < 3; i++) + { + ModifyCustomerValue(i, 10); + } + } + + [ContextMenu("Test - Reset Values")] + private void TestResetValues() + { + ResetToDefault(); + } +#endif +} \ No newline at end of file diff --git a/Assets/Scripts/Utils/CustomerReportSystem.cs.meta b/Assets/Scripts/Utils/CustomerReportSystem.cs.meta new file mode 100644 index 0000000..3af4641 --- /dev/null +++ b/Assets/Scripts/Utils/CustomerReportSystem.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 189ee448adf15a2479d8cd66d37e814f \ No newline at end of file