新增维修工具基础逻辑,重构face的结构并替换美术

This commit is contained in:
2024-11-06 18:34:18 +08:00
parent a6cfc50470
commit 3ee9b040d2
21 changed files with 6795 additions and 4949 deletions
+48 -48
View File
@@ -187,41 +187,41 @@ private void ExitLineSegment()
}
currentLineSegment = null;
}
private void Update()
{
if (isScissorsMode)
{
// Get the position of the mouse in world coordinates
Vector3 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
// private void Update()
// {
// if (isScissorsMode)
// {
// // Get the position of the mouse in world coordinates
// Vector3 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
// Check if there is a line segment in the scissors' detection range
Collider2D hitCollider = Physics2D.OverlapCircle(mousePosition, detectionRadius);
InteractiveLineSegment hitLineSegment = hitCollider != null ? hitCollider.GetComponent<InteractiveLineSegment>() : null;
if (hitLineSegment != null)
{
EnterLineSegment(hitLineSegment);
// // Check if there is a line segment in the scissors' detection range
// Collider2D hitCollider = Physics2D.OverlapCircle(mousePosition, detectionRadius);
// InteractiveLineSegment hitLineSegment = hitCollider != null ? hitCollider.GetComponent<InteractiveLineSegment>() : null;
// if (hitLineSegment != null)
// {
// EnterLineSegment(hitLineSegment);
if (Input.GetMouseButtonDown(0))
{
longPressTime = 0.0f;
}
else if (Input.GetMouseButton(0))
{
LongPressLineSegment(hitLineSegment);
}
else if (Input.GetMouseButtonUp(0))
{
longPressTime = 0.0f;
//customCursor.ResetRotation(); // 假设你有一个方法来重置剪刀的旋转
//currentLineSegment.ResetColor(); // 假设你有一个方法来重置线段的颜色
}
}
else
{
ExitLineSegment();
}
}
}
// if (Input.GetMouseButtonDown(0))
// {
// longPressTime = 0.0f;
// }
// else if (Input.GetMouseButton(0))
// {
// LongPressLineSegment(hitLineSegment);
// }
// else if (Input.GetMouseButtonUp(0))
// {
// longPressTime = 0.0f;
// //customCursor.ResetRotation(); // 假设你有一个方法来重置剪刀的旋转
// //currentLineSegment.ResetColor(); // 假设你有一个方法来重置线段的颜色
// }
// }
// else
// {
// ExitLineSegment();
// }
// }
// }
private void SetScissorsCursor()
{
// 启用自定义光标
@@ -294,22 +294,22 @@ public void DeleteLine(string input)
}
}
private void Start()
{
foreach (LineSegmentInfo lineSegmentInfo in lineSegmentInfos)
{
if (IsLineCut(lineSegmentInfo.Name))
{
continue;
}
InteractiveLineSegment newSegment = Instantiate(interactiveLineSegmentPrefab, transform);
newSegment.StartTransform = lineSegmentInfo.StartTransform;
newSegment.EndTransform = lineSegmentInfo.EndTransform;
newSegment.Initialize();
lineSegmentDictionary.Add(lineSegmentInfo.Name, newSegment);
}
// private void Start()
// {
// foreach (LineSegmentInfo lineSegmentInfo in lineSegmentInfos)
// {
// if (IsLineCut(lineSegmentInfo.Name))
// {
// continue;
// }
// InteractiveLineSegment newSegment = Instantiate(interactiveLineSegmentPrefab, transform);
// newSegment.StartTransform = lineSegmentInfo.StartTransform;
// newSegment.EndTransform = lineSegmentInfo.EndTransform;
// newSegment.Initialize();
// lineSegmentDictionary.Add(lineSegmentInfo.Name, newSegment);
// }
}
// }
public InteractiveLineSegment GetLineSegmentByName(string lineSegmentName)
{
@@ -115,6 +115,7 @@ private void DeepInexecution()
phaseSlider.interactable=true;
//screenText.text="";
plug.Enable_plugInput();
DialogController.OnDialogueComplete-=DeepInexecution;
}
private void HandleDeepIn()
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: fc63edb8eeaae1143a9e1f96badddaa6
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,53 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;
public class Screwdriver : Tool
{
private int rotationCount = 0;
private int requiredRotations = 5;
private bool isFixing = false; // 是否在维修状态
public override void UseTool(Vector3 targetPosition)
{
// 检查是否在维修状态
if (isFixing && IsOverScrewSlot(targetPosition))
{
StartRemoveScrew();
}
}
public void StartFixMode()
{
isFixing = true; // 设置为维修模式
}
private bool IsOverScrewSlot(Vector3 position)
{
// 假设使用碰撞检测或其他方法确认是否靠近螺丝槽位
// 可以在此实现实际的检测逻辑
return true; // 简单返回true用于测试
}
private void StartRemoveScrew()
{
// 螺丝旋转动画
transform.DORotate(new Vector3(0, 0, -90), 0.5f, RotateMode.LocalAxisAdd).OnComplete(() =>
{
rotationCount++;
if (rotationCount >= requiredRotations)
{
RemoveScrew();
}
});
}
private void RemoveScrew()
{
Debug.Log("Screw removed");
rotationCount = 0;
// 可以加入螺丝掉落的逻辑,比如销毁对象或改变其状态
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e072592968a98434d9dbfe8277602f9b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+27
View File
@@ -0,0 +1,27 @@
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using UnityEngine;
public abstract class Tool : MonoBehaviour
{
//public string toolName;
protected bool isFollowingMouse = false;
public bool IsFollowingMouse => isFollowingMouse; // 只读属性
// 启动跟随鼠标
public virtual void StartFollowMouse()
{
isFollowingMouse = true;
}
// 停止跟随鼠标
public virtual void StopFollowMouse()
{
isFollowingMouse = false;
}
// 工具的使用行为,由子类实现
public abstract void UseTool(Vector3 targetPosition);
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f9d10c27818d3c1468305e265021d762
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,187 @@
using System.Collections.Generic;
using DG.Tweening;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class ToolManager : MonoBehaviour
{
public GameObject toolBox; // 工具盒的UI对象
private Tool currentTool;
public List<GameObject> toolPrefabs;
private Dictionary<string, GameObject> toolPrefabDictionary;
public Canvas toolCanvas;
private bool isBoxShow = false;
private void Start()
{
toolBox.SetActive(false); // 初始隐藏工具盒
toolPrefabDictionary = new Dictionary<string, GameObject>();
foreach (GameObject toolPrefab in toolPrefabs)
{
Tool tool = toolPrefab.GetComponent<Tool>();
if (tool != null)
{
toolPrefabDictionary[tool.gameObject.name] = toolPrefab;
}
}
}
public void EnterFixMode(string moduleName)
{
Debug.Log($"Entering fix mode for module: {moduleName}");
if (currentTool != null && currentTool is Screwdriver screwdriver)
{
screwdriver.StartFixMode(); // 调用螺丝刀进入维修状态
}
}
public void ShowTool(string toolName)
{
if (toolPrefabDictionary.TryGetValue(toolName, out GameObject toolPrefab))
{
// 实例化工具
GameObject toolInstance = Instantiate(toolPrefab, toolBox.transform);
currentTool = toolInstance.GetComponent<Tool>();
toolBox.SetActive(true);
isBoxShow = true;
// 工具盒上移动画
toolBox.transform.DOMoveY(-4f, 0.5f).SetEase(Ease.OutBounce);
// 添加点击事件以启动工具跟随鼠标
AddToolClickEvent(toolInstance);
currentTool.GetComponent<CanvasGroup>().blocksRaycasts=true;
}
else
{
Debug.LogWarning($"Tool '{toolName}' not found in tool manager.");
}
}
private void AddToolClickEvent(GameObject toolInstance)
{
EventTrigger eventTrigger = toolInstance.GetComponent<EventTrigger>();
if (eventTrigger == null)
{
eventTrigger = toolInstance.AddComponent<EventTrigger>();
}
// 清除之前可能存在的点击事件,避免重复添加
eventTrigger.triggers.Clear();
EventTrigger.Entry clickEntry = new EventTrigger.Entry
{
eventID = EventTriggerType.PointerClick
};
// 点击事件:当点击工具时,使其开始跟随鼠标
clickEntry.callback.AddListener((data) =>
{
currentTool.transform.SetParent(toolCanvas.transform);
currentTool.StartFollowMouse();
currentTool.GetComponent<CanvasGroup>().blocksRaycasts=false;
//RemoveToolClickEvent(eventTrigger); // 移除点击事件,防止再触发
HideTool();
});
eventTrigger.triggers.Add(clickEntry);
}
// 移除工具的点击事
// 显示工具盒并添加归还工具的点击事件
public void ShowToolBoxAfterTask()
{
toolBox.SetActive(true);
isBoxShow = true;
toolBox.transform.DOMoveY(-4f, 0.5f).SetEase(Ease.OutBounce);
// 为工具盒添加一次性点击事件
AddToolBoxReturnEvent();
}
private void AddToolBoxReturnEvent()
{
EventTrigger toolBoxTrigger = toolBox.GetComponent<EventTrigger>();
if (toolBoxTrigger == null)
{
toolBoxTrigger = toolBox.AddComponent<EventTrigger>();
}
// 清除之前的事件,确保归还工具的事件仅触发一次
toolBoxTrigger.triggers.Clear();
EventTrigger.Entry boxClickEntry = new EventTrigger.Entry
{
eventID = EventTriggerType.PointerClick
};
boxClickEntry.callback.AddListener((data) =>
{
ReturnTool(); // 点击工具盒时归还工具
});
toolBoxTrigger.triggers.Add(boxClickEntry);
}
public void HideTool()
{
toolBox.transform.DOMoveY(-6f, 0.5f).SetEase(Ease.InBack).OnComplete(() =>
{
toolBox.SetActive(false);
isBoxShow = false;
// 在工具盒的子物体中查找并删除工具对象
foreach (Transform child in toolBox.transform)
{
Tool tool = child.GetComponent<Tool>();
if (tool != null)
{
Destroy(child.gameObject); // 删除工具对象
currentTool = null; // 清空当前工具的引用
}
}
});
}
private void Update()
{
if (currentTool != null && currentTool.IsFollowingMouse)
{
Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
currentTool.transform.position = new Vector3(mousePos.x, mousePos.y, 0);
}
if(Input.GetKeyDown(KeyCode.O))
{
ShowTool("ScrewDriver");
}
if(Input.GetKeyDown(KeyCode.P))
{
ShowToolBoxAfterTask();
}
}
public void ReturnTool()
{
if (currentTool != null)
{
Debug.Log("Returning tool and stopping follow mouse.");
// 停止工具跟随鼠标
currentTool.StopFollowMouse();
// 将工具放回工具盒
currentTool.transform.SetParent(toolBox.transform);
currentTool.transform.localPosition = Vector3.zero;
// 重新添加点击事件,以便可以再次点击
//AddToolClickEvent(currentTool.gameObject);
currentTool = null;
HideTool();
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 89ebd69b82a440a4794beb4ef2717a3b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: