//- 挑战赛-公路- UI using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using asap.core; using game; using TMPro; using UniRx; using UnityEngine; namespace GampPlay.ChallengeMatch.Road { public class ChallengeMatchSceneRoadUI : MonoBehaviour { private Transform icon_reward; private Transform text_title; private Transform _textNumCash; private EventChallengeLevelTips _levelTipController; private FishingChallengeManager _fishingChallengeManager; public GameObject[] tipPlaceHolder; //- 启动的点 public ChallengeMatchSceneUIRegion[] uiRegion; // private EventChallengeHead _myHead; // private int _residualHeadCount; private CompositeDisposable _disposables = new(); private void Awake() { _fishingChallengeManager = GContext.container.Resolve(); GetComponent().worldCamera = Camera.main; _levelTipController = transform.Find("EventChallengeLevelTips").GetComponent(); GContext.OnEvent().Subscribe(OnShowLevelTips).AddTo(_disposables); _levelTipController.gameObject.SetActive(false); icon_reward = transform.Find("taizi_reward/icon_reward/icon_reward"); text_title = transform.Find("taizi_reward/total_reward/text_title"); _textNumCash = transform.Find("taizi_reward/total_reward/text_num_cash"); } private void Start() { var listItemData = _fishingChallengeManager.GetFinalReward(); var totalCount = listItemData.Sum(itemData => itemData.count); _textNumCash.GetComponent().text = "x" + ConvertTools.GetNumberString(totalCount); InitLevelTip(_fishingChallengeManager.fishingChallengeData.ProcessedScore); } #if UNITY_EDITOR bool isShow; string oldStepStr, newStepStr; private string _scoreStr; // 添加到渔获的价值 private int _level; string oldScoreStr, newScoreStr; private void Update() { if (Input.GetKeyDown(KeyCode.K)) { isShow = !isShow; } } private async void OnGUI() { GUI.color = Color.magenta; GUILayout.Label($"当前段位: {_fishingChallengeManager?.eventChallengeMain?.ID}"); if (!isShow) { return; } // Set the button width and height float buttonWidth = 300; // Replace with your desired width float buttonHeight = 70; // Replace with your desired height int fontSize = 40; // Replace with your desired font size // Set the font size for text fields, buttons, and labels GUI.skin.textField.fontSize = fontSize; GUI.skin.button.fontSize = fontSize; GUI.skin.label.fontSize = fontSize; // // 触发ChallengeShowPlayAniEvent 事件并能输入oldStep和newStep GUILayout.Label("oldStep:"); oldStepStr = GUILayout.TextField(oldStepStr, GUILayout.Width(buttonWidth), GUILayout.Height(buttonHeight)); int.TryParse(oldStepStr, out int oldStep); if (GUILayout.Button("ShowPlayerEvent", GUILayout.Width(buttonWidth), GUILayout.Height(buttonHeight))) { GContext.Publish(new ChallengeShowPlayerEvent { oldStep = oldStep }); // await Awaiters.Seconds(0.5f); // var challengePlayAniEvent = new ChallengePlayAniEvent(); // challengePlayAniEvent.oldStep = oldStep; // challengePlayAniEvent.newStep = newStep; // GContext.Publish(challengePlayAniEvent); } if (GUILayout.Button("Fail",GUILayout.Width(buttonWidth), GUILayout.Height(buttonHeight))) { // GContext.Publish(new ChallengeMatchPlayGMEvent() { step = oldStep }); OnGMFail(oldStep); // ChallengeFailEvent challengeFailEvent = new ChallengeFailEvent(); // challengeFailEvent.oldStep = oldStep; // OnFail(challengeFailEvent); } if (GUILayout.Button("测试放弃用户", GUILayout.Width(buttonWidth), GUILayout.Height(buttonHeight))) { GContext.Publish(new ChallengeMoveToNextStageEvent { newStep = oldStep + 1, residual = 10, }); } // GUILayout.Label("newStep:"); // newStepStr = GUILayout.TextField(newStepStr, GUILayout.Width(buttonWidth), GUILayout.Height(buttonHeight)); // int.TryParse(newStepStr, out var newStep); GUILayout.Label("QualityScore:"); _scoreStr = GUILayout.TextField(_scoreStr, GUILayout.Width(buttonWidth), GUILayout.Height(buttonHeight)); int.TryParse(_scoreStr, out var score); _fishingChallengeManager.SetQualityScore(score); GUILayout.Label("oldScore:"); oldScoreStr = GUILayout.TextField(oldScoreStr, GUILayout.Width(buttonWidth), GUILayout.Height(buttonHeight)); int.TryParse(oldScoreStr, out var oldScore); // GUILayout.Label("newScore:"); newScoreStr = GUILayout.TextField(newScoreStr, GUILayout.Width(buttonWidth), GUILayout.Height(buttonHeight)); int.TryParse(newScoreStr, out var newScore); // if (GUILayout.Button("RunNewPlay", GUILayout.Width(buttonWidth), GUILayout.Height(buttonHeight))) { var nStep = _fishingChallengeManager.GetStepByScore(oldScore, true); var evt = new ChallengeInitStepEvent() { step = nStep }; GContext.Publish(evt); await Awaiters.Seconds(0.5f); // 全部重置 var tipsEvent = new ChallengeLevelTipsEvent() { IsGm = true, oldScore = oldScore, newScore = newScore, }; GContext.Publish(tipsEvent); } } private async void OnGMFail (int oldStep) { ELog("OnGMFail"); GContext.Publish(new ChallengeShowPlayerEvent { oldStep = oldStep }); await Awaiters.Seconds(0.5f); var challengeFailEvent = new ChallengeFailEvent { oldStep = oldStep }; GContext.Publish(challengeFailEvent); } #endif private void OnDestroy() { _disposables?.Dispose(); _disposables = null; } #region Game Logic //- 阶段的启动, private async void OnShowLevelTips(ChallengeLevelTipsEvent tipsEvent) { var oldScore = tipsEvent.oldScore; var newScore = tipsEvent.newScore; var isGm = tipsEvent.IsGm; Log($"Start: OnShowLevelTips -> {oldScore}=> {newScore} isGm: {isGm}"); if (oldScore == newScore) { InitLevelTip(oldScore); tipsEvent.tcs.SetResult(true); return; } var step = _fishingChallengeManager.GetStepByScore(oldScore, true); var maxScore = _fishingChallengeManager.GetMaxScoreByStep(step); if (_levelTipController && step >= 0 && step < tipPlaceHolder.Length) { LocationLevelTips(step); var curScore = await _levelTipController.ShowTips(oldScore, newScore); // 播放显示动画 if (maxScore == curScore) { await _levelTipController.PlayInVisibleAni(); ReceiveStageReward(step); await JumpStage(step, curScore, newScore, isGm); } } tipsEvent.tcs.SetResult(true); } private async void ReceiveStageReward(int step) { ELog($"ReceiveStageReward {step}"); _fishingChallengeManager.AddStageReward(step); } private static async Task JumpStage(int step, int curScore, int newScore, bool isGm) { ELog($"JumpStage-> {step} {curScore} {newScore} {isGm}"); // 清理下一个台子 await CleanNextStage(step); // 播放动画 await RunPlayerAni(step); //- 进入下一阶段 await RunNextStageEvent(curScore, newScore, isGm); } private static async Task RunNextStageEvent(int curScore, int newScore, bool isGm) { var nextStageEvent = new ChallengeLevelTipsEvent { oldScore = curScore, newScore = newScore, IsGm = isGm, }; GContext.Publish(nextStageEvent); await nextStageEvent.tcs.Task; } private static async Task CleanNextStage(int step) { ELog($"CleanNextStage -> {step}"); var cleanEvent = new ChallengeCleanStageEvent { stage = step + 1, }; GContext.Publish(cleanEvent); await cleanEvent.Tcs.Task; ELog($"CleanNextStage -> {step} Finished"); } private static async Task RunPlayerAni(int step) { ELog($"RunPlayerAni -> {step}"); // 播放动画 var challengePlayAniEvent = new ChallengePlayAniEvent { oldStep = step, newStep = step + 1 }; GContext.Publish(challengePlayAniEvent); await challengePlayAniEvent.tcs.Task; ELog($"RunPlayerAni -> {step} Finished"); } private void LocationLevelTips(int step) { ELog($"LocationLevelTips -> {step}"); _levelTipController.transform.localPosition = tipPlaceHolder[step].transform.localPosition; _levelTipController.SetCurStep(step); _levelTipController.gameObject.SetActive(true); } // public void InitLevelTip(int score) { var step = _fishingChallengeManager.GetStepByScore(score, true); if (step > tipPlaceHolder.Length - 1) { return; } _levelTipController.transform.localPosition = tipPlaceHolder[step].transform.localPosition; _levelTipController.gameObject.SetActive(true); _levelTipController.Init(score); } #endregion #region Log private static void Log(string message) { Debug.Log($"ChallengeMatchSceneRoadUI => {message} "); } private static void ELog(string message) { #if UNITY_EDITOR Debug.Log($" {nameof(ChallengeMatchSceneRoadUI)} => {message} "); #endif } #endregion } }