遊戲3的角度
This commit is contained in:
chiyulin0314 2025-11-20 07:30:00 +08:00
parent 40ce37edff
commit 7e8fa7732a
8 changed files with 95 additions and 7 deletions

View File

@ -43,6 +43,8 @@ public class IncenseController : MonoBehaviour
private float fallTimer = 0f; private float fallTimer = 0f;
private bool hasLanded = false; private bool hasLanded = false;
private float finalSincerity = 0f; private float finalSincerity = 0f;
public System.Action<int> OnCountdownFinished;
void Start() void Start()
{ {
@ -81,6 +83,13 @@ public class IncenseController : MonoBehaviour
CalculateStability(); CalculateStability();
UpdateVisuals(); UpdateVisuals();
UpdateUI(); UpdateUI();
// 觸發時間到事件
if (hasLanded)
{
int angle = Mathf.RoundToInt(currentAngle);
OnCountdownFinished?.Invoke(angle);
}
} }
else else
{ {

View File

@ -32,7 +32,7 @@ public class IncenseGameManager : MonoBehaviour
public int gameOverCountdownSec = 10; // ✅ 新增GameOver倒計時秒數 public int gameOverCountdownSec = 10; // ✅ 新增GameOver倒計時秒數
[Header("Result Settings")] [Header("Result Settings")]
public float receivedAngle = 87.5f; // 假的接收角度,之後會從另一台電腦接收 public float receivedAngle = 90f; // 假的接收角度,之後會從另一台電腦接收
[Header("Incense Settings")] [Header("Incense Settings")]
public GameObject incensePrefab; public GameObject incensePrefab;
@ -46,6 +46,9 @@ public class IncenseGameManager : MonoBehaviour
private int totalIncenseCount = 20; private int totalIncenseCount = 20;
private bool gameActive = true; private bool gameActive = true;
private int gameOverCountdownVal; // ✅ 新增:當前倒計時數值 private int gameOverCountdownVal; // ✅ 新增:當前倒計時數值
private bool isReceivedAngle = false;
public System.Action OnCountdownFinished;
void OnEnable() void OnEnable()
{ {
@ -57,6 +60,8 @@ public class IncenseGameManager : MonoBehaviour
currentTime = gameTime; currentTime = gameTime;
currentPowerValue = initialPowerValue; currentPowerValue = initialPowerValue;
gameActive = true; gameActive = true;
receivedAngle = 90f;
isReceivedAngle = false;
// 顯示遊戲UI隱藏結果UI // 顯示遊戲UI隱藏結果UI
if (gamePlayUI) gamePlayUI.SetActive(true); if (gamePlayUI) gamePlayUI.SetActive(true);
@ -344,6 +349,9 @@ public class IncenseGameManager : MonoBehaviour
// SceneManager.LoadScene("NextScene"); // SceneManager.LoadScene("NextScene");
// 或者呼叫其他控制器的方法 // 或者呼叫其他控制器的方法
Debug.Log("GameOver倒計時結束"); Debug.Log("GameOver倒計時結束");
// 觸發時間到事件
OnCountdownFinished?.Invoke();
} }
void ClearAllIncense() void ClearAllIncense()
@ -361,6 +369,12 @@ public class IncenseGameManager : MonoBehaviour
void SetupResultIncense() void SetupResultIncense()
{ {
if (isReceivedAngle == false)
{
angleDisplayText.text = "";
return;
}
if (resultIncense != null) if (resultIncense != null)
{ {
// 設置結果香的角度 // 設置結果香的角度
@ -383,6 +397,7 @@ public class IncenseGameManager : MonoBehaviour
public void SetReceivedAngle(float angle) public void SetReceivedAngle(float angle)
{ {
receivedAngle = angle; receivedAngle = angle;
isReceivedAngle = true;
if (!gameActive) // 如果已在結果畫面,立即更新 if (!gameActive) // 如果已在結果畫面,立即更新
{ {
SetupResultIncense(); SetupResultIncense();

View File

@ -950,6 +950,7 @@ MonoBehaviour:
playCountdownText: {fileID: 981401567} playCountdownText: {fileID: 981401567}
incenseTransform: {fileID: 1100068051} incenseTransform: {fileID: 1100068051}
incenseHolderTransform: {fileID: 0} incenseHolderTransform: {fileID: 0}
incenseController: {fileID: 1726446969}
finishGoToNextButton: {fileID: 535960335} finishGoToNextButton: {fileID: 535960335}
finishBackToMenuButton: {fileID: 443005029} finishBackToMenuButton: {fileID: 443005029}
--- !u!114 &981401567 stripped --- !u!114 &981401567 stripped
@ -1669,6 +1670,17 @@ PrefabInstance:
m_AddedGameObjects: [] m_AddedGameObjects: []
m_AddedComponents: [] m_AddedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: cefaaa3e8d6afa74d9be9cc1341b1a09, type: 3} m_SourcePrefab: {fileID: 100100000, guid: cefaaa3e8d6afa74d9be9cc1341b1a09, type: 3}
--- !u!114 &1726446969 stripped
MonoBehaviour:
m_CorrespondingSourceObject: {fileID: 6134439403010925337, guid: cefaaa3e8d6afa74d9be9cc1341b1a09, type: 3}
m_PrefabInstance: {fileID: 1726446968}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 571e1448f855fad41b25c97b16854985, type: 3}
m_Name:
m_EditorClassIdentifier: Assembly-CSharp::IncenseController
--- !u!1 &1780727869 --- !u!1 &1780727869
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

View File

@ -2109,7 +2109,7 @@ GameObject:
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
m_NavMeshLayer: 0 m_NavMeshLayer: 0
m_StaticEditorFlags: 0 m_StaticEditorFlags: 0
m_IsActive: 1 m_IsActive: 0
--- !u!224 &85247803 --- !u!224 &85247803
RectTransform: RectTransform:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -9307,7 +9307,7 @@ PrefabInstance:
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 5304771535841513772, guid: 8c3e8d5430f6ce145b97407a9411b8a2, type: 3} - target: {fileID: 5304771535841513772, guid: 8c3e8d5430f6ce145b97407a9411b8a2, type: 3}
propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.size propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.size
value: 1 value: 0
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 5304771535841513772, guid: 8c3e8d5430f6ce145b97407a9411b8a2, type: 3} - target: {fileID: 5304771535841513772, guid: 8c3e8d5430f6ce145b97407a9411b8a2, type: 3}
propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.data[0].m_Mode propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.data[0].m_Mode
@ -9323,7 +9323,7 @@ PrefabInstance:
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 5304771535841513772, guid: 8c3e8d5430f6ce145b97407a9411b8a2, type: 3} - target: {fileID: 5304771535841513772, guid: 8c3e8d5430f6ce145b97407a9411b8a2, type: 3}
propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.data[0].m_MethodName propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.data[0].m_MethodName
value: GoToGameWaitingPanel value:
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 5304771535841513772, guid: 8c3e8d5430f6ce145b97407a9411b8a2, type: 3} - target: {fileID: 5304771535841513772, guid: 8c3e8d5430f6ce145b97407a9411b8a2, type: 3}
propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.data[0].m_TargetAssemblyTypeName propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.data[0].m_TargetAssemblyTypeName

View File

@ -17,6 +17,7 @@ public class ClientGameSticksSceneController : MonoBehaviour
public TMP_Text playCountdownText; public TMP_Text playCountdownText;
public Transform incenseTransform; public Transform incenseTransform;
public Transform incenseHolderTransform; public Transform incenseHolderTransform;
public IncenseController incenseController;
private Image sincerityMeterFill; private Image sincerityMeterFill;
@ -106,7 +107,7 @@ public class ClientGameSticksSceneController : MonoBehaviour
{ {
ClientMessageHandler.Instance.SendMessageToServer("gameSticksFinish", ""); ClientMessageHandler.Instance.SendMessageToServer("gameSticksFinish", "");
} }
StartCoroutine(NextStep(4, 3)); StartCoroutine(NextStep(4, 6));
} }
} }
if (finishPanel) if (finishPanel)
@ -129,7 +130,22 @@ public class ClientGameSticksSceneController : MonoBehaviour
} }
init(); init();
incenseController.OnCountdownFinished = OnCountdownFinished;
} }
private void OnCountdownFinished(int angle)
{
if (ClientMessageHandler.Instance)
{
GameSticksResult msgObj = new GameSticksResult {
angle = angle,
};
string payload = JsonUtility.ToJson(msgObj);
ClientMessageHandler.Instance.SendMessageToServer("gameSticksFinish", payload);
}
}
private void finishGoToNextButton_onClicked() private void finishGoToNextButton_onClicked()
{ {

View File

@ -37,3 +37,7 @@ public class GameMessageSurvey
public string text1; public string text1;
} }
public class GameSticksResult
{
public int angle;
}

View File

@ -230,7 +230,15 @@ public class NetworkMessageHandler : MonoBehaviour
break; break;
case "gameSticksFinish": case "gameSticksFinish":
{ {
// 保持不變 GameSticksResult msgObj = JsonUtility.FromJson<GameSticksResult>(msg.payload);
if (msgObj != null)
{
if (ServerGameSticksPanel.Instance)
{
ServerGameSticksPanel.Instance.OnReceivedResult(msgObj.angle);
}
}
} }
break; break;
} }

View File

@ -8,20 +8,32 @@ public class ServerGameSticksPanel : MonoBehaviour
{ {
public static ServerGameSticksPanel Instance; public static ServerGameSticksPanel Instance;
private IncenseGameManager gameManager;
private CustomerReportSystem customReportScript; private CustomerReportSystem customReportScript;
private void Awake() private void Awake()
{ {
Instance = this; Instance = this;
gameManager = gameObject.GetComponentInChildren<IncenseGameManager>(includeInactive: true);
customReportScript = gameObject.GetComponentInChildren<CustomerReportSystem>(includeInactive: true); customReportScript = gameObject.GetComponentInChildren<CustomerReportSystem>(includeInactive: true);
} }
// Start is called once before the first execution of Update after the MonoBehaviour is created // Start is called once before the first execution of Update after the MonoBehaviour is created
void Start() void Start()
{ {
gameManager.OnCountdownFinished = OnCountdownFinished;
customReportScript.OnCustomerReportConfirmed = OnCustomerReportConfirmed; customReportScript.OnCustomerReportConfirmed = OnCustomerReportConfirmed;
} }
private void OnCountdownFinished()
{
//倒數時間到,直接跳轉頁面
if (ServerWorkSceneController.Instance)
{
ServerWorkSceneController.Instance.processStep(17);
}
}
private void OnCustomerReportConfirmed(int[] values) private void OnCustomerReportConfirmed(int[] values)
{ {
if (values.Length < 3) { return; } if (values.Length < 3) { return; }
@ -31,6 +43,18 @@ public class ServerGameSticksPanel : MonoBehaviour
GlobalData.KARMA_SCORE = values[1]; GlobalData.KARMA_SCORE = values[1];
GlobalData.SINCERITY_SCORE = values[2]; GlobalData.SINCERITY_SCORE = values[2];
ServerWorkTopRightScore.Instance.UpdateScoreVals(); ServerWorkTopRightScore.Instance.UpdateScoreVals();
//跳轉頁面
if (ServerWorkSceneController.Instance)
{
ServerWorkSceneController.Instance.processStep(17);
}
}
public void OnReceivedResult(int angle)
{
//更新角度
gameManager.SetReceivedAngle(angle);
} }
// Update is called once per frame // Update is called once per frame