104 lines
2.6 KiB
C#
104 lines
2.6 KiB
C#
using DG.Tweening;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
/// <summary>
|
|
/// 螺丝
|
|
/// </summary>
|
|
public class Tool_Screw : Tool_Base
|
|
{
|
|
/// <summary>
|
|
/// 标识
|
|
/// </summary>
|
|
public string id;
|
|
|
|
/// <summary>
|
|
/// 是否已拧紧
|
|
/// </summary>
|
|
public bool isInstall;
|
|
/// <summary>
|
|
/// 上螺丝位置
|
|
/// </summary>
|
|
public Transform installPos;
|
|
/// <summary>
|
|
/// 是否带电
|
|
/// </summary>
|
|
public bool hasElectricity;
|
|
|
|
/// <summary>
|
|
/// 安装状态时Y的local值
|
|
/// </summary>
|
|
public float initPostionY;
|
|
|
|
/// <summary>
|
|
/// 螺丝拆装事件回调
|
|
/// </summary>
|
|
private Action<bool> installAction;
|
|
|
|
|
|
//protected override void OnAwake()
|
|
//{
|
|
// base.OnAwake();
|
|
// id = gameObject.name;
|
|
//}
|
|
|
|
public void AddAction(Action<bool> action)
|
|
{
|
|
this.installAction=action;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 被拧紧
|
|
/// </summary>
|
|
/// <param name="screwdriver"></param>
|
|
public void BeInstalled(Tool_Screwdriver screwdriver)
|
|
{
|
|
//动画
|
|
transform.DOLocalMoveY(initPostionY, 1)
|
|
.OnUpdate(() =>
|
|
{
|
|
transform.RotateAroundLocal(Vector3.up, 1);
|
|
screwdriver.transform.position = installPos.position;
|
|
screwdriver.transform.RotateAroundLocal(Vector3.right, 10);
|
|
})
|
|
.OnComplete(() =>
|
|
{
|
|
Debug.Log("螺丝已拧紧");
|
|
isInstall = true;
|
|
isMoving = false;
|
|
screwdriver.isMoving = false;
|
|
installAction?.Invoke(true);
|
|
screwdriver.ReBackHead();
|
|
CallScoreAction(true);
|
|
});
|
|
}
|
|
|
|
/// <summary>
|
|
/// 被拧松
|
|
/// </summary>
|
|
/// <param name="screwdriver"></param>
|
|
public void BeUnInstalled(Tool_Screwdriver screwdriver)
|
|
{
|
|
//动画
|
|
transform.DOLocalMoveY(initPostionY - 0.02f, 1)
|
|
.OnUpdate(() =>
|
|
{
|
|
transform.RotateAroundLocal(Vector3.up, 1);
|
|
screwdriver.transform.position = installPos.position;
|
|
screwdriver.transform.RotateAroundLocal(Vector3.right, 10);
|
|
})
|
|
.OnComplete(() =>
|
|
{
|
|
Debug.Log("螺丝已拧松");
|
|
isInstall = false;
|
|
isMoving = false;
|
|
screwdriver.isMoving = false;
|
|
installAction?.Invoke(false);
|
|
screwdriver.ReBackHead();
|
|
CallScoreAction(false);
|
|
});
|
|
}
|
|
}
|