using DG.Tweening;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
///
/// 接线
///
public class Tool_Line: Tool_Base
{
///
/// 是否接上
///
public bool isConnected;
///
/// 标识
///
public string id;
///
/// 固定接线的螺丝
///
public List screws=new List();
///
/// 安装状态时Y的local值
///
public float InstallPosY;
///
/// 操作后回调
///
private Action actionBack;
///
/// 是否可移动判断
///
private Func checkCanMove;
public void AddCompleteAction(Action actionBack)
{
this.actionBack = actionBack;
}
public void AddCanMoveCheck(Func canMoveCheck)
{
this.checkCanMove = canMoveCheck;
}
///
/// 是否可以
///
///
public bool CanMove()
{
if (checkCanMove == null)
{
return true;
}
else
{
return checkCanMove.Invoke();
}
}
protected override void OnMDown()
{
if (CanMove())
{
if ((triggerAction == null ? 0 : triggerAction.Invoke(triggerName, false)) == 0)
{
base.OnMDown();
if (isConnected)
{
//取下接线
if (screws.TrueForAll(a => !a.isInstall))
{
transform.DOLocalMoveY(InstallPosY - 2, 1).OnComplete(() =>
{
isConnected = false;
actionBack?.Invoke(isConnected);
int state = (triggerAction == null ? 0 : triggerAction.Invoke(triggerName, true));
CallScoreAction(false);
});
}
}
else
{
//装上接线
if (screws.TrueForAll(a => !a.isInstall))
{
transform.DOLocalMoveY(InstallPosY, 1).OnComplete(() =>
{
isConnected = true;
actionBack?.Invoke(isConnected);
int state = (triggerAction == null ? 0 : triggerAction.Invoke(triggerName, true));
CallScoreAction(true);
});
}
}
}
}
}
}