diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-02-01 10:13:56 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-02-01 10:13:56 +0800 |
| commit | 4c8534b7b36e77a7c7c47a10b163695686391739 (patch) | |
| tree | d5399ddb195252b63292bdf62eadc2a0a64f56f9 /Assets/Scripts | |
| parent | 7100bf815bd4458f5e40a2c992e915f15bd6efa9 (diff) | |
整合素材
Diffstat (limited to 'Assets/Scripts')
| -rw-r--r-- | Assets/Scripts/CameraFOVWithDistance.cs | 6 | ||||
| -rw-r--r-- | Assets/Scripts/GameProgressManager.cs | 42 | ||||
| -rw-r--r-- | Assets/Scripts/StartSceneGuide.cs | 13 | ||||
| -rw-r--r-- | Assets/Scripts/StartSceneGuide.cs.meta | 2 | ||||
| -rw-r--r-- | Assets/Scripts/Tag/QuestionPlayer.cs (renamed from Assets/Scripts/Tag/TaggedItemSelector.cs) | 38 | ||||
| -rw-r--r-- | Assets/Scripts/Tag/QuestionPlayer.cs.meta (renamed from Assets/Scripts/Tag/TaggedItemSelector.cs.meta) | 0 | ||||
| -rw-r--r-- | Assets/Scripts/Tag/QuestionSystem.cs | 40 | ||||
| -rw-r--r-- | Assets/Scripts/Tag/TagItem.cs | 14 | ||||
| -rw-r--r-- | Assets/Scripts/UI.meta | 8 | ||||
| -rw-r--r-- | Assets/Scripts/UI/UIBinding.cs | 34 | ||||
| -rw-r--r-- | Assets/Scripts/UI/UIBinding.cs.meta | 2 |
11 files changed, 167 insertions, 32 deletions
diff --git a/Assets/Scripts/CameraFOVWithDistance.cs b/Assets/Scripts/CameraFOVWithDistance.cs index c62cd83..2d564c3 100644 --- a/Assets/Scripts/CameraFOVWithDistance.cs +++ b/Assets/Scripts/CameraFOVWithDistance.cs @@ -5,6 +5,7 @@ public class CameraFOVWithDistance : MonoBehaviour { public PlayerTracker tracker; public Camera camera; + public RectTransform uiScale; public float lerpSpeed = 0.15f; @@ -18,8 +19,9 @@ public class CameraFOVWithDistance : MonoBehaviour private void Update() { - var distancePercent = Mathf.InverseLerp(_minDistance, _maxDistance, Math.Clamp(tracker.Distance, _minDistance, _maxDistance)); - _targetFOV = Mathf.Lerp(_minFOV, _maxFOV, distancePercent); + var percent = Mathf.InverseLerp(_minDistance, _maxDistance, Math.Clamp(tracker.Distance, _minDistance, _maxDistance)); + uiScale.localScale = Vector3.one * Mathf.Lerp(1.0f, 1.1f, percent); + _targetFOV = Mathf.Lerp(_minFOV, _maxFOV, percent); } private void FixedUpdate() diff --git a/Assets/Scripts/GameProgressManager.cs b/Assets/Scripts/GameProgressManager.cs index 463e2b3..f4d1645 100644 --- a/Assets/Scripts/GameProgressManager.cs +++ b/Assets/Scripts/GameProgressManager.cs @@ -1,12 +1,20 @@ +using System.Collections; using Tag; using UnityEngine; [RequireComponent(typeof(SceneStatus))] public class GameProgressManager : MonoBehaviour { + public int time = 60; + public MaskAnswers player1; public MaskAnswers player2; - + + public int questionMaxScore; + public int player1Score; + public int player2Score; + + public QuestionPlayer questionPlayer; public SceneStatus sceneStatus; private void Awake() @@ -31,5 +39,37 @@ public class GameProgressManager : MonoBehaviour Debug.Log("开始游戏!"); player1.bindPlayer.GetComponent<PlayerMovement>().enabled = true; player2.bindPlayer.GetComponent<PlayerMovement>().enabled = true; + + // 记录最大分数 + questionMaxScore = questionPlayer.currentQuestion.Need.Count; + + StartCoroutine(GameTime()); + } + + private void OnGameEnd() + { + Debug.Log("游戏结束!"); + } + + IEnumerator GameTime() + { + while (true) + { + yield return new WaitForSeconds(0.2f); + UpdateScore(); + yield return new WaitForSeconds(0.4f); + UpdateScore(); + yield return new WaitForSeconds(0.2f); + time--; + if (time <= 0) + break; + } + OnGameEnd(); + } + + private void UpdateScore() + { + player1Score = QuestionVerifier.Verify(questionPlayer.currentQuestion, player1.CollectToAnswer()); + player2Score = QuestionVerifier.Verify(questionPlayer.currentQuestion, player2.CollectToAnswer()); } } diff --git a/Assets/Scripts/StartSceneGuide.cs b/Assets/Scripts/StartSceneGuide.cs new file mode 100644 index 0000000..d1d9ebc --- /dev/null +++ b/Assets/Scripts/StartSceneGuide.cs @@ -0,0 +1,13 @@ +using Mountools.LoadingScreen; +using UnityEngine; + +public class StartSceneGuide : MonoBehaviour +{ + private void Update() + { + if (Input.GetKeyDown(KeyCode.Space)) + { + LoadingScreen.LoadScene("Assets/Scenes/PlayScene.unity"); + } + } +} diff --git a/Assets/Scripts/StartSceneGuide.cs.meta b/Assets/Scripts/StartSceneGuide.cs.meta new file mode 100644 index 0000000..d13ad28 --- /dev/null +++ b/Assets/Scripts/StartSceneGuide.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 7ab0d002871cbc0debca4f314510b00a
\ No newline at end of file diff --git a/Assets/Scripts/Tag/TaggedItemSelector.cs b/Assets/Scripts/Tag/QuestionPlayer.cs index 6ce7334..4929082 100644 --- a/Assets/Scripts/Tag/TaggedItemSelector.cs +++ b/Assets/Scripts/Tag/QuestionPlayer.cs @@ -2,11 +2,13 @@ using System; using System.Collections.Generic; using System.Linq; using UnityEngine; +using Random = System.Random; namespace Tag { - public class TaggedItemSelector : MonoBehaviour + public class QuestionPlayer : MonoBehaviour { + public Question currentQuestion; public List<TaggedItemInfo> infos; public TagPool pool; @@ -18,7 +20,39 @@ namespace Tag private void Start() { - var question = QuestionFactory + // 生成问题 + var question = QuestionFactory.RandomQuestion(); + + // 过滤出选项 + var items = FilterByQuestion(question); + + // 设置文本 + currentQuestion = question; + + var randomItem = GetRandomItems(pool.items, items.Count); + var v = 0; + foreach (var i in randomItem) + { + i.info = items[v]; + i.Refresh(); + v++; + } + + foreach (var item in pool.items) + { + if (item.info == null) + Destroy(item.gameObject); + } + } + + public static List<T> GetRandomItems<T>(List<T> source, int count) + { + if (source == null) throw new ArgumentNullException(nameof(source)); + if (count <= 0) throw new ArgumentException("数量必须大于0", nameof(count)); + if (count > source.Count) throw new ArgumentException("数量不能超过列表长度", nameof(count)); + + var random = new Random(); + return source.OrderBy(x => random.Next()).Take(count).ToList(); } public List<TaggedItemInfo> FilterByQuestion(Question question) diff --git a/Assets/Scripts/Tag/TaggedItemSelector.cs.meta b/Assets/Scripts/Tag/QuestionPlayer.cs.meta index bbe62e0..bbe62e0 100644 --- a/Assets/Scripts/Tag/TaggedItemSelector.cs.meta +++ b/Assets/Scripts/Tag/QuestionPlayer.cs.meta diff --git a/Assets/Scripts/Tag/QuestionSystem.cs b/Assets/Scripts/Tag/QuestionSystem.cs index a8e6e62..d5733f9 100644 --- a/Assets/Scripts/Tag/QuestionSystem.cs +++ b/Assets/Scripts/Tag/QuestionSystem.cs @@ -2,11 +2,11 @@ using System.Collections.Generic; namespace Tag { - public class QuestionFactory + public static class QuestionFactory { - public Question RandomQuestion() + public static Question RandomQuestion() { - var random = new System.Random().Next(0, 15); + var random = new System.Random().Next(0, 19); if (random == 0) return new Question("我想要一张高兴的脸,我不喜欢眼镜", new[] { "Happy", "Happy" }, @@ -31,58 +31,62 @@ namespace Tag return new Question("我想要一张有点伤心的脸", new[] { "Sad"}, new string[] {"Happy","Angry" }); - if (random == 5) + if (random == 6) return new Question("我想要一张又生气又委屈的脸", new[] { "Angry","Sad","Sad"}, new string[] {"Happy","Angry" }); - if (random == 6) + if (random == 7) return new Question("我想要一张戴眼镜得意的脸,我昨天已经剃了胡须", new[] { "Happy","Happy","Happy","Glass"}, new string[] {"Happy","Angry","Beard" }); - if (random == 7) + if (random == 8) return new Question("我想要一张又生气又委屈的脸,因为我的眼镜被偷了", new[] { "Angry","Sad","Sad",}, new string[] {"Happy","Angry","Glass" }); - if (random == 8) + if (random == 9) return new Question("我想要一张卡通风格的高兴脸", new[] { "Happy","Happy","Cartoon",}, new string[] {"Sad","Angry","Abstract","Hard" }); - if (random == 9) + if (random == 10) return new Question("我想要一张硬朗风格的气愤脸", new[] { "Hard","Angry","Angry","Hard",}, new string[] {"Sad","Happy","Abstract","Cartoon" }); - if (random == 10) + if (random == 11) return new Question("我想要一张抽象风格的伤心脸", new[] { "Abstract","Sad"}, new string[] {"Angry","Happy","Hard","Cartoon" }); - if (random == 11) + if (random == 12) return new Question("我想要一张有胡子的硬朗气愤脸,我喜欢眼镜,可是昨天剃了胡子把我的眼镜弄掉了 ", new[] { "Beard","Hard","Angry","Angry"}, new string[] {"Happy","Sad","Abstract","Cartoon","Glass","Beard" }); - if (random == 11) + if (random == 13) return new Question("我想要一张钉子配饰不要其他也都不要的委屈卡通脸,谁想的卡通角色有纹身,我不喜欢纹身 ", new[] { "Sad","Sad","Cartoon"}, new string[] {"Happy","Angry","Abstract","Hard","Tattoo","Necklace","Beard","Piercing","Glass" }); - if (random == 12) + if (random == 14) return new Question("我想要一张有眼镜和钉子的抽象开心脸,配饰我只纹了纹身但是长胡子了就洗了 ", new[] { "Glass","Happy","Abstract","Glass","Piercing","Beard"}, new string[] {"Sad","Angry","Cartoon","Hard","Tattoo","Necklace"}); - if (random == 13) + if (random == 15) return new Question("硬汉王脸,带胡带火不带镜,万配不沾 ", new[] { "Hard","Beard","Angry"}, new string[] {"Sad","Angry","Cartoon","Hard","Tattoo","Necklace","Piercing","Glass"}); - if (random == 14) + if (random == 16) return new Question("卡硬混搭,又喜又怒但只一点,原生态不带配 ", new[] { "Cartoon","Hard","Angry","Happy"}, new string[] {"Sad","Beard","Abstract","Tattoo","Necklace","Piercing","Glass"}); - if (random == 15) + if (random == 17) return new Question("火气直冲天灵盖,什么风格都不带 ", new[] { "Angry","Angry","Angry"}, new string[] {"Happy","Sad","Abstract","Cartoon","Hard"}); + if (random == 18) + return new Question("为了我,对他使用炎拳吧!", + new[] { "FirePunch","FirePunch","FirePunch","FirePunch", "Angry", "Sad"}, + new string[] { }); - return new Question("我很难蚌,来到这就说明程序错误了,纯纯地扣分", - new[] { "难蚌" }, - new[] { "Angry","Happy", "Sad","Tattoo","Necklace","Beard","Piercing","Glass"}); + return new Question("我想要一张有点伤心的脸", + new[] { "Sad"}, + new string[] {"Happy","Angry" }); } } diff --git a/Assets/Scripts/Tag/TagItem.cs b/Assets/Scripts/Tag/TagItem.cs index 27b5efe..6194a91 100644 --- a/Assets/Scripts/Tag/TagItem.cs +++ b/Assets/Scripts/Tag/TagItem.cs @@ -6,18 +6,14 @@ namespace Tag { public TaggedItemInfo info; public SpriteRenderer spriteRenderer; - - public static void CleanTagItem() - { - foreach (var i in FindObjectsByType<TagItem>(FindObjectsSortMode.None)) - { - if (i.info == null) - Destroy(i.gameObject); - } - } private void OnEnable() { + Refresh(); + } + + public void Refresh() + { if (info == null) return; spriteRenderer.sprite = info.image; } diff --git a/Assets/Scripts/UI.meta b/Assets/Scripts/UI.meta new file mode 100644 index 0000000..31219dc --- /dev/null +++ b/Assets/Scripts/UI.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 1cb35befe68c40516b4a5b3202c1e528 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/UI/UIBinding.cs b/Assets/Scripts/UI/UIBinding.cs new file mode 100644 index 0000000..b84f307 --- /dev/null +++ b/Assets/Scripts/UI/UIBinding.cs @@ -0,0 +1,34 @@ +using System; +using TMPro; +using UnityEngine; +using UnityEngine.UI; + +namespace UI +{ + public class UIBinding : MonoBehaviour + { + public GameProgressManager progress; + [Range(0, 1)] public float player1ScorePercent; + [Range(0, 1)] public float player2ScorePercent; + + public TMP_Text timeText; + public Image player1ScoreDisplay; + public Image player2ScoreDisplay; + + private void FixedUpdate() + { + // 更新时间文本 + timeText.text = progress.time.ToString(); + + // 更新百分比 + player1ScorePercent = Mathf.Clamp(progress.player1Score, 0, Single.MaxValue) * 1.0f / progress.questionMaxScore * 1.0f; + player2ScorePercent = Mathf.Clamp(progress.player2Score, 0, Single.MaxValue) * 1.0f / progress.questionMaxScore * 1.0f; + var targetPlayer1Amount = Mathf.Lerp(0.25f, 0.5f, player1ScorePercent); + var targetPlayer2Amount = Mathf.Lerp(0.25f, 0.5f, player2ScorePercent); + + // 更新进度条 + player1ScoreDisplay.fillAmount = targetPlayer1Amount; + player2ScoreDisplay.fillAmount = targetPlayer2Amount; + } + } +} diff --git a/Assets/Scripts/UI/UIBinding.cs.meta b/Assets/Scripts/UI/UIBinding.cs.meta new file mode 100644 index 0000000..6dded59 --- /dev/null +++ b/Assets/Scripts/UI/UIBinding.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 5aef56347fe7ee8d0b29a6bcacd72008
\ No newline at end of file |
