72 lines
2.0 KiB
C#
72 lines
2.0 KiB
C#
using Cysharp.Threading.Tasks;
|
|
using DG.Tweening;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class Outboundequipment : MonoBehaviour
|
|
{
|
|
/// <summary>
|
|
/// 提升机架子
|
|
/// </summary>
|
|
public GameObject frame;
|
|
/// <summary>
|
|
/// 箱子位移的速度
|
|
/// </summary>
|
|
private float speed = 5f;
|
|
/// <summary>
|
|
/// 提升机第一个点位
|
|
/// </summary>
|
|
public Transform point1;
|
|
/// <summary>
|
|
/// 提升机第二个点位
|
|
/// </summary>
|
|
public Transform point2;
|
|
/// <summary>
|
|
/// 提升机第三个点位
|
|
/// </summary>
|
|
public Transform point3;
|
|
void Start()
|
|
{
|
|
|
|
}
|
|
void Update()
|
|
{
|
|
|
|
}
|
|
private async void OnTriggerEnter(Collider other)
|
|
{
|
|
if (other.gameObject.CompareTag("Box"))
|
|
{
|
|
await Shipment(other.gameObject,frame);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 出货
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
private async UniTask Shipment(GameObject box,GameObject frame)
|
|
{
|
|
await MoveObjectToPosition(frame.transform, point1.transform.position, speed);
|
|
await MoveObjectToPosition(box.transform, point1.transform.position, speed);
|
|
box.transform.SetParent(null);
|
|
box.transform.SetParent(frame.transform);
|
|
await MoveObjectToPosition(frame.transform, point2.transform.position, speed);
|
|
box.transform.SetParent(null);
|
|
await MoveObjectToPosition(box.transform, point3.transform.position, speed);
|
|
|
|
}
|
|
/// <summary>
|
|
/// 出货动画
|
|
/// </summary>
|
|
/// <param name="target"></param>
|
|
/// <param name="destination"></param>
|
|
/// <param name="speed"></param>
|
|
/// <returns></returns>
|
|
private async UniTask MoveObjectToPosition(Transform target, Vector3 destination, float speed)
|
|
{
|
|
float duration = Vector3.Distance(target.position, destination) / speed;
|
|
await target.DOMove(destination, duration).SetEase(Ease.InOutQuad).AsyncWaitForCompletion();
|
|
}
|
|
}
|