新增拆除功能
This commit is contained in:
@@ -6,6 +6,7 @@ using UnityEngine.UI;
|
||||
|
||||
public class ToolManager : MonoBehaviour
|
||||
{
|
||||
public static ToolManager Instance { get; private set; }
|
||||
public GameObject toolBox; // 工具盒的UI对象
|
||||
private Tool currentTool;
|
||||
public List<GameObject> toolPrefabs;
|
||||
@@ -14,6 +15,22 @@ public class ToolManager : MonoBehaviour
|
||||
public Canvas toolCanvas;
|
||||
private bool isBoxShow = false;
|
||||
|
||||
public bool HasTool => currentTool != null; // 判断玩家是否已获得工具
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
// 确保 ToolManager 只有一个实例,并且这个实例是唯一的
|
||||
if (Instance != null && Instance != this)
|
||||
{
|
||||
Destroy(gameObject); // 如果实例已经存在,销毁当前实例
|
||||
}
|
||||
else
|
||||
{
|
||||
Instance = this; // 保持唯一实例
|
||||
//DontDestroyOnLoad(gameObject); // 不销毁这个工具管理器
|
||||
}
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
toolBox.SetActive(false); // 初始隐藏工具盒
|
||||
@@ -28,16 +45,14 @@ public class ToolManager : MonoBehaviour
|
||||
}
|
||||
}
|
||||
}
|
||||
public void EnterFixMode(string moduleName)
|
||||
public void TryStartRepairMode(Module module)
|
||||
{
|
||||
Debug.Log($"Entering fix mode for module: {moduleName}");
|
||||
|
||||
if (currentTool != null && currentTool is Screwdriver screwdriver)
|
||||
// 如果当前工具是螺丝刀,调用Module的EnterRepairMode方法
|
||||
if (currentTool is Screwdriver)
|
||||
{
|
||||
screwdriver.StartFixMode(); // 调用螺丝刀进入维修状态
|
||||
module.StartRepairIfToolIsScrewdriver(currentTool);
|
||||
}
|
||||
}
|
||||
|
||||
public void ShowTool(string toolName)
|
||||
{
|
||||
if (toolPrefabDictionary.TryGetValue(toolName, out GameObject toolPrefab))
|
||||
@@ -99,7 +114,7 @@ public class ToolManager : MonoBehaviour
|
||||
toolBox.SetActive(true);
|
||||
isBoxShow = true;
|
||||
|
||||
toolBox.transform.DOMoveY(-4f, 0.5f).SetEase(Ease.OutBounce);
|
||||
toolBox.transform.DOMoveY(-3.7f, 0.5f).SetEase(Ease.OutBounce);
|
||||
|
||||
// 为工具盒添加一次性点击事件
|
||||
AddToolBoxReturnEvent();
|
||||
@@ -129,7 +144,7 @@ public class ToolManager : MonoBehaviour
|
||||
|
||||
public void HideTool()
|
||||
{
|
||||
toolBox.transform.DOMoveY(-6f, 0.5f).SetEase(Ease.InBack).OnComplete(() =>
|
||||
toolBox.transform.DOMoveY(-6.3f, 0.5f).SetEase(Ease.InBack).OnComplete(() =>
|
||||
{
|
||||
toolBox.SetActive(false);
|
||||
isBoxShow = false;
|
||||
@@ -150,8 +165,11 @@ public class ToolManager : MonoBehaviour
|
||||
{
|
||||
if (currentTool != null && currentTool.IsFollowingMouse)
|
||||
{
|
||||
//Vector2 imageSize = toolImage.rect.size;
|
||||
//Cursor.visible = false;
|
||||
Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
|
||||
currentTool.transform.position = new Vector3(mousePos.x, mousePos.y, 0);
|
||||
//Vector3 toolOffset=currentTool.offset;
|
||||
currentTool.transform.position = new Vector3(mousePos.x+0.75f, mousePos.y+0.75f, 0);
|
||||
}
|
||||
if(Input.GetKeyDown(KeyCode.O))
|
||||
{
|
||||
@@ -181,6 +199,7 @@ public void ReturnTool()
|
||||
|
||||
currentTool = null;
|
||||
HideTool();
|
||||
//Cursor.visible = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user