Files
aibis-dream/Assets/Scripts/FixSystem/Tools/Module.cs
T

186 lines
4.8 KiB
C#

using UnityEngine;
using UnityEngine.EventSystems;
using DG.Tweening;
using System.Drawing; // 需要引入 DOTween 命名空间
using UnityEngine.UI;
using AibisDream;
public class Module : MonoBehaviour, IPointerClickHandler
{
public Transform faceCanvas; // 需要移动和缩放的面板
public Vector3 repairCanvasPosition; // 维修模式下的面板位置
public Vector3 originalCanvasPosition; // 原始面板位置
public float repairCanvasScale = 1.5f; // 维修模式下的面板缩放比例
public float animationDuration = 0.5f; // 动画持续时间
public bool isallowedRepair = false; // 动画持续时间
public bool isalloweInstall = false; // 动画持续时间
public GameObject screwsContainer; // 螺丝的父对象
public RectTransform targetArea; // 拖拽的目标区域,用于判定维修完成
[HideInInspector]
public bool isRepairMode = false;
private bool canDrag = false;
private Vector3 initialPosition;
private Plug plug;
public bool isRepiarFinished=false;
public GameObject ObejctToInstall;
public bool isInstall=false;
public Socket socketToEnable;
private void Start()
{
if(ObejctToInstall!=null)
{
if(isInstall)
{
ObejctToInstall.SetActive(true);
}
else
{
ObejctToInstall.SetActive(false);
}
}
if(isRepiarFinished)
{
Destroy(gameObject);
}
plug=FindObjectOfType<Plug>();
initialPosition = transform.position;
if(faceCanvas!=null)
{
originalCanvasPosition = faceCanvas.position;
}
else
{
originalCanvasPosition=Vector3.zero;
}
if(socketToEnable!=null)
{
socketToEnable.IsAvailable=false;
}
if(screwsContainer!=null)
{
foreach (Transform screw in screwsContainer.transform)
{
screw.GetComponent<Screw>().enabled = false;
}
}
}
public void SetReapirState(bool state)
{
isRepiarFinished=state;
if(isRepiarFinished)
{
Destroy(gameObject);
}
}
public void SetInstallState(bool state)
{
isInstall=state;
if(isInstall)
{
ObejctToInstall.SetActive(true);
isalloweInstall=false;
}
else
{
ObejctToInstall.SetActive(false);
}
}
public void RemoveAllPlugsFromSockets()
{
Socket[] sockets = FindObjectsOfType<Socket>(); // 找到场景中的所有Socket组件
foreach (Socket socket in sockets)
{
socket.RemovePlug(plug); // 移除Plug
}
plug.ReturnToInit();
plug.enabled=false;
}
public void Install()
{
Debug.Log(gameObject.name+"InStalled");
isInstall=true;
ObejctToInstall.SetActive(true);
DialogController.Instance.StartDialogNode("FinishInstall");
}
public void EnableScrewsInteraction(bool isEnabled)
{
foreach (Transform screw in screwsContainer.transform)
{
screw.GetComponent<Screw>().enabled = isEnabled;
}
plug.enabled=true;
}
private void ResetModulePosition()
{
transform.position = initialPosition;
canDrag = false; // 禁用拖拽,防止未拆完螺丝时拖动
}
public void EnableDragging()
{
canDrag = true;
}
public void CheckAllScrews()
{
bool allDropped = true;
foreach (Transform screw in screwsContainer.transform)
{
if (screw.gameObject.activeSelf)
{
allDropped = false;
break;
}
}
if (allDropped)
{
socketToEnable.IsAvailable=true;
foreach (Transform screw in screwsContainer.transform)
{
if(screw!=null)
{
screw.GetComponent<Screw>().enabled = false;
}
}
CompleteRepair();
Destroy(gameObject);
}
}
public void OnPointerClick(PointerEventData eventData)
{
// 只有在玩家已获得工具且当前工具是螺丝刀时,才尝试进入维修模式
if (ToolManager.Instance.HasTool)
{
ToolManager.Instance.TryStartRepairMode(this);
ToolManager.Instance.TryInstall(this);
}
else
{
Debug.Log("No tool");
}
}
private void CompleteRepair()
{
DialogController.Instance.StartDialogNode("FinishedReapir");
Debug.Log("维修完成!");
//ExitRepairMode();
}
}