先存一个版本....

This commit is contained in:
2024-11-13 03:19:55 +08:00
parent 256f6dbb12
commit 0237c32950
11 changed files with 733 additions and 493 deletions
+68 -31
View File
@@ -3,6 +3,7 @@ using UnityEngine.EventSystems;
using DG.Tweening;
using System.Drawing; // 需要引入 DOTween 命名空间
using UnityEngine.UI;
using AibisDream;
public class Module : MonoBehaviour, IPointerClickHandler
{
@@ -16,65 +17,92 @@ public class Module : MonoBehaviour, IPointerClickHandler
public GameObject screwsContainer; // 螺丝的父对象
public RectTransform targetArea; // 拖拽的目标区域,用于判定维修完成
private bool isRepairMode = false;
[HideInInspector]
public bool isRepairMode = false;
private bool canDrag = false;
private Vector3 initialPosition;
private Plug plug;
public Socket socketToEnable;
private void Start()
{
plug=FindObjectOfType<Plug>();
initialPosition = transform.position;
originalCanvasPosition = faceCanvas.position;
//socketToEnable.raycastTarget=false;
socketToEnable.IsAvailable=false;
EnableScrewsInteraction(false);
foreach (Transform screw in screwsContainer.transform)
{
screw.GetComponent<Screw>().enabled = false;
}
}
public void StartRepairIfToolIsScrewdriver(Tool tool)
// public void StartRepairIfToolIsScrewdriver(Tool tool)
// {
// EnterRepairMode();
// }
public void RemoveAllPlugsFromSockets()
{
EnterRepairMode();
Socket[] sockets = FindObjectsOfType<Socket>(); // 找到场景中的所有Socket组件
foreach (Socket socket in sockets)
{
socket.RemovePlug(plug); // 移除Plug
}
plug.ReturnToInit();
plug.enabled=false;
}
public void EnterRepairMode()
{
isRepairMode = true;
// public void EnterRepairMode()
// {
// 使用 DOTween 对 Canvas 的位置和缩放进行平滑过渡
faceCanvas.DOMove(repairCanvasPosition, animationDuration)
.SetEase(Ease.OutQuad) // 移动面板
.OnComplete(() => EnableScrewsInteraction(true)); // 动画完成后才启用交互
// DialogController.Instance.StartDialogNode("EnterRepairMode");
// isRepairMode = true;
// RemoveAllPlugsFromSockets();
// // 使用 DOTween 对 Canvas 的位置和缩放进行平滑过渡
// faceCanvas.DOMove(repairCanvasPosition, animationDuration)
// .SetEase(Ease.OutQuad) // 移动面板
// .OnComplete(() => EnableScrewsInteraction(true)); // 动画完成后才启用交互
faceCanvas.DOScale(repairCanvasScale, animationDuration)
.SetEase(Ease.OutQuad); // 缩放面板
}
// faceCanvas.DOScale(repairCanvasScale, animationDuration)
// .SetEase(Ease.OutQuad); // 缩放面板
// }
public void ExitRepairMode()
{
isRepairMode = false;
// public void ExitRepairMode()
// {
// isRepairMode = false;
// 使用 DOTween 对 Canvas 的位置和缩放进行平滑过渡
faceCanvas.DOMove(originalCanvasPosition, animationDuration)
.SetEase(Ease.InQuad)
.OnComplete(() => EnableScrewsInteraction(false)); // 动画完成后禁用交互
// // 使用 DOTween 对 Canvas 的位置和缩放进行平滑过渡
// faceCanvas.DOMove(originalCanvasPosition, animationDuration)
// .SetEase(Ease.InQuad)
// .OnComplete(() => EnableScrewsInteraction(false)); // 动画完成后禁用交互
faceCanvas.DOScale(1f, animationDuration)
.SetEase(Ease.InQuad); // 恢复面板缩放
ResetModulePosition();
ToolManager.Instance.ShowToolBoxAfterTask();
//socketToEnable.raycastTarget=true;
socketToEnable.IsAvailable=true;
}
// faceCanvas.DOScale(1f, animationDuration)
// .SetEase(Ease.InQuad); // 恢复面板缩放
// ResetModulePosition();
// ToolManager.Instance.ShowToolBoxAfterTask();
// //socketToEnable.raycastTarget=true;
// socketToEnable.IsAvailable=true;
private void EnableScrewsInteraction(bool isEnabled)
// foreach (Transform screw in screwsContainer.transform)
// {
// if(screw!=null)
// {
// screw.GetComponent<Screw>().enabled = false;
// }
// }
// }
public void EnableScrewsInteraction(bool isEnabled)
{
foreach (Transform screw in screwsContainer.transform)
{
screw.GetComponent<Screw>().enabled = isEnabled;
}
plug.enabled=true;
}
private void ResetModulePosition()
@@ -102,6 +130,14 @@ public class Module : MonoBehaviour, IPointerClickHandler
if (allDropped)
{
socketToEnable.IsAvailable=true;
foreach (Transform screw in screwsContainer.transform)
{
if(screw!=null)
{
screw.GetComponent<Screw>().enabled = false;
}
}
Destroy(gameObject);
CompleteRepair();
}
@@ -122,7 +158,8 @@ public class Module : MonoBehaviour, IPointerClickHandler
private void CompleteRepair()
{
DialogController.Instance.StartDialogNode("FinishedReapir");
Debug.Log("维修完成!");
ExitRepairMode();
//ExitRepairMode();
}
}