summaryrefslogtreecommitdiff
path: root/Assets/Scripts
diff options
context:
space:
mode:
Diffstat (limited to 'Assets/Scripts')
-rw-r--r--Assets/Scripts/CameraFOVWithDistance.cs8
-rw-r--r--Assets/Scripts/PlayerDrag.cs55
-rw-r--r--Assets/Scripts/Tag/QuestionSystem.cs88
-rw-r--r--Assets/Scripts/Tag/QuestionSystem.cs.meta2
-rw-r--r--Assets/Scripts/Tag/TagItem.cs9
-rw-r--r--Assets/Scripts/Tag/TagItem.cs.meta2
-rw-r--r--Assets/Scripts/Tag/TagPool.cs10
-rw-r--r--Assets/Scripts/Tag/TagPool.cs.meta2
-rw-r--r--Assets/Scripts/Tag/TaggedItemInfo.cs (renamed from Assets/Scripts/Tag/TaggedItem.cs)10
-rw-r--r--Assets/Scripts/Tag/TaggedItemInfo.cs.meta (renamed from Assets/Scripts/Tag/TaggedItem.cs.meta)0
10 files changed, 153 insertions, 33 deletions
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;
/// <summary>
/// 简化版玩家拖拽脚本(Trigger触发判定,仅保留核心拖拽逻辑)
/// </summary>
+[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<PlayerControl>();
}
-
- 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<DragItem>();
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<DragItem>();
- 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<string>(question.Need);
+ var has = new List<string>(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<string> Need;
+ public List<string> NoNeed;
+
+ public Question(string questionText, string[] need, string[] noNeed)
+ {
+ QuestionText = questionText;
+ Need = new List<string>(need);
+ NoNeed = new List<string>(noNeed);
+ }
+ }
+
+ public class Answer
+ {
+ public List<string> Has;
+
+ public Answer(string[] has)
+ {
+ Has = new List<string>(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<TaggedItemInfo> 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/TaggedItemInfo.cs
index 12e05f5..89cb238 100644
--- a/Assets/Scripts/Tag/TaggedItem.cs
+++ b/Assets/Scripts/Tag/TaggedItemInfo.cs
@@ -5,7 +5,7 @@ using UnityEngine;
namespace Tag
{
[CreateAssetMenu(fileName = "TaggedItem", menuName = "Scriptable Objects/TaggedItem")]
- public class TaggedItem : ScriptableObject
+ public class TaggedItemInfo : ScriptableObject
{
public ItemType itemType;
public Sprite image;
@@ -16,13 +16,13 @@ namespace Tag
public enum ItemType
{
[InspectorName("眼睛")]
- Eye,
+ Eye,
[InspectorName("鼻子")]
- Norse,
+ Norse,
[InspectorName("眉毛")]
- Elbow,
+ Elbow,
[InspectorName("嘴巴")]
- Mouse,
+ Mouse,
[InspectorName("配饰")]
Accessories
}
diff --git a/Assets/Scripts/Tag/TaggedItem.cs.meta b/Assets/Scripts/Tag/TaggedItemInfo.cs.meta
index 8d62664..8d62664 100644
--- a/Assets/Scripts/Tag/TaggedItem.cs.meta
+++ b/Assets/Scripts/Tag/TaggedItemInfo.cs.meta