98 lines
2.6 KiB
C#
98 lines
2.6 KiB
C#
using DG.Tweening;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using Unity.VisualScripting;
|
|
using Unity.VisualScripting.Antlr3.Runtime;
|
|
using UnityEngine;
|
|
|
|
public class Device_SIM : Device_Base
|
|
{
|
|
public bool isInstalled;
|
|
public Vector3 installedLocalPos;
|
|
public Vector3 uninstalledLocalPos;
|
|
|
|
/// <summary>
|
|
/// 点击事件
|
|
/// </summary>
|
|
public Action<bool> clickAction;
|
|
public Func<bool> checkAction;
|
|
|
|
protected override void OnMDown()
|
|
{
|
|
base.OnMDown();
|
|
Remove();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 安装
|
|
/// </summary>
|
|
public void Add()
|
|
{
|
|
if (checkAction == null || checkAction.Invoke())
|
|
{
|
|
if(!isInstalled && !isMoving)
|
|
{
|
|
if (triggerAction?.Invoke("sim卡碰撞区域", false) == 0)
|
|
{
|
|
isMoving = true;
|
|
gameObject.SetActive(true);
|
|
//安装
|
|
transform.DOLocalMove(installedLocalPos, 0.5f).OnComplete(() =>
|
|
{
|
|
isInstalled = true;
|
|
isMoving = false;
|
|
gameObject.name = "sim卡";
|
|
clickAction?.Invoke(isInstalled);
|
|
triggerAction?.Invoke("sim卡碰撞区域", true);
|
|
CallScoreAction(true);
|
|
});
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 拆除
|
|
/// </summary>
|
|
private void Remove()
|
|
{
|
|
if (checkAction == null || checkAction.Invoke())
|
|
{
|
|
if (isInstalled && !isMoving)
|
|
{
|
|
if (triggerAction==null || triggerAction?.Invoke(triggerName, false) == 0)
|
|
{
|
|
isMoving = true;
|
|
//拆除
|
|
transform.DOLocalMove(uninstalledLocalPos, 0.5f).OnComplete(() =>
|
|
{
|
|
isInstalled = false;
|
|
isMoving = false;
|
|
clickAction?.Invoke(isInstalled);
|
|
triggerAction?.Invoke(triggerName, true);
|
|
CallScoreAction(false);
|
|
gameObject.SetActive(false);
|
|
});
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public void SetState(bool isInstall)
|
|
{
|
|
if(isInstall)
|
|
{
|
|
gameObject.SetActive(true);
|
|
isInstalled = true;
|
|
transform.localPosition = installedLocalPos;
|
|
}
|
|
else
|
|
{
|
|
transform.localPosition = uninstalledLocalPos;
|
|
isInstalled = false;
|
|
gameObject.SetActive(false);
|
|
}
|
|
}
|
|
}
|