From 38e3e1fa64334f9cfd2f35e21439b93f525bf1b4 Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Sat, 31 Jan 2026 17:36:25 +0800 Subject: 完成问题生成 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Scripts/CameraFOVWithDistance.cs | 8 +-- Assets/Scripts/PlayerDrag.cs | 55 ++++++++++--------- Assets/Scripts/Tag/QuestionSystem.cs | 88 +++++++++++++++++++++++++++++++ Assets/Scripts/Tag/QuestionSystem.cs.meta | 2 + Assets/Scripts/Tag/TagItem.cs | 9 ++++ Assets/Scripts/Tag/TagItem.cs.meta | 2 + Assets/Scripts/Tag/TagPool.cs | 10 ++++ Assets/Scripts/Tag/TagPool.cs.meta | 2 + Assets/Scripts/Tag/TaggedItem.cs | 29 ---------- Assets/Scripts/Tag/TaggedItem.cs.meta | 2 - Assets/Scripts/Tag/TaggedItemInfo.cs | 29 ++++++++++ Assets/Scripts/Tag/TaggedItemInfo.cs.meta | 2 + 12 files changed, 179 insertions(+), 59 deletions(-) create mode 100644 Assets/Scripts/Tag/QuestionSystem.cs create mode 100644 Assets/Scripts/Tag/QuestionSystem.cs.meta create mode 100644 Assets/Scripts/Tag/TagItem.cs create mode 100644 Assets/Scripts/Tag/TagItem.cs.meta create mode 100644 Assets/Scripts/Tag/TagPool.cs create mode 100644 Assets/Scripts/Tag/TagPool.cs.meta delete mode 100644 Assets/Scripts/Tag/TaggedItem.cs delete mode 100644 Assets/Scripts/Tag/TaggedItem.cs.meta create mode 100644 Assets/Scripts/Tag/TaggedItemInfo.cs create mode 100644 Assets/Scripts/Tag/TaggedItemInfo.cs.meta (limited to 'Assets/Scripts') diff --git a/Assets/Scripts/CameraFOVWithDistance.cs b/Assets/Scripts/CameraFOVWithDistance.cs index 56c3562..c62cd83 100644 --- a/Assets/Scripts/CameraFOVWithDistance.cs +++ b/Assets/Scripts/CameraFOVWithDistance.cs @@ -10,11 +10,11 @@ public class CameraFOVWithDistance : MonoBehaviour private float _targetFOV; - private float _minDistance = 7.5f; - private float _maxDistance = 16.5f; + private float _minDistance = 6.4f; + private float _maxDistance = 14.4f; - private float _minFOV = 25f; - private float _maxFOV = 45f; + private float _minFOV = 35f; + private float _maxFOV = 73f; private void Update() { diff --git a/Assets/Scripts/PlayerDrag.cs b/Assets/Scripts/PlayerDrag.cs index 10300af..8e7a69d 100644 --- a/Assets/Scripts/PlayerDrag.cs +++ b/Assets/Scripts/PlayerDrag.cs @@ -1,56 +1,63 @@ +using System; using UnityEngine; /// /// 简化版玩家拖拽脚本(Trigger触发判定,仅保留核心拖拽逻辑) /// +[RequireComponent(typeof(PlayerControl))] public class PlayerDrag : MonoBehaviour { - // 拖拽核心配置 - [SerializeField] private KeyCode grabKey = KeyCode.G; // 抓取按键 + private DragItem _currentDragItem; - // 临时缓存:当前触发接触的可拖拽物品 - private DragItem currentDragItem; - // 标记是否处于拖拽状态 - private bool isDragging; + private bool _isDragging; - private void Update() + private bool _lastFrameGrabbing; + + private PlayerControl _control; + + private void Awake() { - // 仅检测G键输入,控制抓取/松开(核心逻辑不变) - CheckGrabInput(); + _control = GetComponent(); } - - private void CheckGrabInput() + private void Update() { + var grabbing = _control.grabbing; + var keyDown = !_lastFrameGrabbing && grabbing; + var keyUp = _lastFrameGrabbing && !grabbing; + // 按下G键:抓取物品(仅当触发接触且未拖拽时生效) - if (Input.GetKeyDown(grabKey) && !isDragging && currentDragItem != null) + if (keyDown && !_isDragging && _currentDragItem != null) { - isDragging = true; - currentDragItem.dragger = this.transform; // 给物品赋值拖拽锚点(玩家) + _isDragging = true; + _currentDragItem.dragger = transform; // 给物品赋值拖拽锚点(玩家) } // 松开G键:放下物品(解除关联) - if (Input.GetKeyUp(grabKey) && isDragging) + if (keyUp && _isDragging) { - isDragging = false; - if (currentDragItem != null) + _isDragging = false; + if (_currentDragItem != null) { - currentDragItem.dragger = null; // 清空物品的拖拽锚点 + _currentDragItem.dragger = null; // 清空物品的拖拽锚点 } - currentDragItem = null; + _currentDragItem = null; } + + // 更新抓取 + _lastFrameGrabbing = grabbing; } private void OnTriggerStay(Collider other) { // 如果已在拖拽状态,直接返回,不处理新物品 - if (isDragging) return; + if (_isDragging) return; // 尝试获取对方的DragItem组件,缓存为当前可抓取物品 DragItem dragItem = other.GetComponent(); if (dragItem != null) { - currentDragItem = dragItem; + _currentDragItem = dragItem; } } @@ -58,13 +65,13 @@ public class PlayerDrag : MonoBehaviour private void OnTriggerExit(Collider other) { // 如果已在拖拽状态,直接返回(避免拖拽中丢失目标) - if (isDragging) return; + if (_isDragging) return; // 确认离开的是当前缓存的物品,清空缓存 DragItem dragItem = other.GetComponent(); - if (dragItem != null && dragItem == currentDragItem) + if (dragItem != null && dragItem == _currentDragItem) { - currentDragItem = null; + _currentDragItem = null; } } } \ No newline at end of file diff --git a/Assets/Scripts/Tag/QuestionSystem.cs b/Assets/Scripts/Tag/QuestionSystem.cs new file mode 100644 index 0000000..0bc1580 --- /dev/null +++ b/Assets/Scripts/Tag/QuestionSystem.cs @@ -0,0 +1,88 @@ +using System.Collections.Generic; + +namespace Tag +{ + public class QuestionFactory + { + public Question RandomQuestion() + { + var random = new System.Random().Next(0, 5); + if (random == 0) + return new Question("我想要一张开心的脸", + new[] { "开心", "开心" }, + new string[] { }); + if (random == 1) + return new Question("我想要一张愤怒的脸", + new[] { "愤怒", "愤怒" }, + new string[] { }); + if (random == 2) + return new Question("我很愤怒,我得带上眼镜遮掩一下", + new[] { "愤怒", "愤怒", "眼镜" }, + new string[] { }); + if (random == 3) + return new Question("无所谓,只是想带个眼镜", + new[] { "眼镜" }, + new string[] { }); + return new Question("我想要一张开心的脸,而且我讨厌愤怒", + new[] { "开心", "开心" }, + new[] { "愤怒" }); + } + } + + public static class QuestionVerifier + { + public static int Verify(Question question, Answer answer) + { + var needs = new List(question.Need); + var has = new List(answer.Has); + int score = 0; + + for (int i = 0; i < has.Count; i++) + { + if (needs.Count > 0) + { + int index = needs.IndexOf(has[i]); + if (index >= 0) + { + needs.RemoveAt(index); + score++; + } + } + } + + foreach (var item in has) + { + if (question.NoNeed.Contains(item)) + { + score--; + } + } + + return score; + } + } + + public class Question + { + public string QuestionText; + public List Need; + public List NoNeed; + + public Question(string questionText, string[] need, string[] noNeed) + { + QuestionText = questionText; + Need = new List(need); + NoNeed = new List(noNeed); + } + } + + public class Answer + { + public List Has; + + public Answer(string[] has) + { + Has = new List(has); + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/Tag/QuestionSystem.cs.meta b/Assets/Scripts/Tag/QuestionSystem.cs.meta new file mode 100644 index 0000000..f4b5440 --- /dev/null +++ b/Assets/Scripts/Tag/QuestionSystem.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 15bba2010edb8b0dea1d6720a35e73f7 \ No newline at end of file diff --git a/Assets/Scripts/Tag/TagItem.cs b/Assets/Scripts/Tag/TagItem.cs new file mode 100644 index 0000000..837eb3f --- /dev/null +++ b/Assets/Scripts/Tag/TagItem.cs @@ -0,0 +1,9 @@ +using UnityEngine; + +namespace Tag +{ + public class TagItem : MonoBehaviour + { + public TaggedItemInfo info; + } +} diff --git a/Assets/Scripts/Tag/TagItem.cs.meta b/Assets/Scripts/Tag/TagItem.cs.meta new file mode 100644 index 0000000..09b3823 --- /dev/null +++ b/Assets/Scripts/Tag/TagItem.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 663eeaf5f927f973cb00d1a828312f29 \ No newline at end of file diff --git a/Assets/Scripts/Tag/TagPool.cs b/Assets/Scripts/Tag/TagPool.cs new file mode 100644 index 0000000..75bd0fc --- /dev/null +++ b/Assets/Scripts/Tag/TagPool.cs @@ -0,0 +1,10 @@ +using System.Collections.Generic; +using UnityEngine; + +namespace Tag +{ + public class TagPool : MonoBehaviour + { + public List items = new(); + } +} diff --git a/Assets/Scripts/Tag/TagPool.cs.meta b/Assets/Scripts/Tag/TagPool.cs.meta new file mode 100644 index 0000000..327e6cc --- /dev/null +++ b/Assets/Scripts/Tag/TagPool.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 9f8d4c046ebfb4068a47e9b95ba00cf2 \ No newline at end of file diff --git a/Assets/Scripts/Tag/TaggedItem.cs b/Assets/Scripts/Tag/TaggedItem.cs deleted file mode 100644 index 12e05f5..0000000 --- a/Assets/Scripts/Tag/TaggedItem.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System; -using System.Collections.Generic; -using UnityEngine; - -namespace Tag -{ - [CreateAssetMenu(fileName = "TaggedItem", menuName = "Scriptable Objects/TaggedItem")] - public class TaggedItem : ScriptableObject - { - public ItemType itemType; - public Sprite image; - public List tags; - } - - [Serializable] - public enum ItemType - { - [InspectorName("眼睛")] - Eye, - [InspectorName("鼻子")] - Norse, - [InspectorName("眉毛")] - Elbow, - [InspectorName("嘴巴")] - Mouse, - [InspectorName("配饰")] - Accessories - } -} diff --git a/Assets/Scripts/Tag/TaggedItem.cs.meta b/Assets/Scripts/Tag/TaggedItem.cs.meta deleted file mode 100644 index 8d62664..0000000 --- a/Assets/Scripts/Tag/TaggedItem.cs.meta +++ /dev/null @@ -1,2 +0,0 @@ -fileFormatVersion: 2 -guid: edcb65f129a9b03b0af0009c24d499bd \ No newline at end of file diff --git a/Assets/Scripts/Tag/TaggedItemInfo.cs b/Assets/Scripts/Tag/TaggedItemInfo.cs new file mode 100644 index 0000000..89cb238 --- /dev/null +++ b/Assets/Scripts/Tag/TaggedItemInfo.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using UnityEngine; + +namespace Tag +{ + [CreateAssetMenu(fileName = "TaggedItem", menuName = "Scriptable Objects/TaggedItem")] + public class TaggedItemInfo : ScriptableObject + { + public ItemType itemType; + public Sprite image; + public List tags; + } + + [Serializable] + public enum ItemType + { + [InspectorName("眼睛")] + Eye, + [InspectorName("鼻子")] + Norse, + [InspectorName("眉毛")] + Elbow, + [InspectorName("嘴巴")] + Mouse, + [InspectorName("配饰")] + Accessories + } +} diff --git a/Assets/Scripts/Tag/TaggedItemInfo.cs.meta b/Assets/Scripts/Tag/TaggedItemInfo.cs.meta new file mode 100644 index 0000000..8d62664 --- /dev/null +++ b/Assets/Scripts/Tag/TaggedItemInfo.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: edcb65f129a9b03b0af0009c24d499bd \ No newline at end of file -- cgit