83 lines
2.2 KiB
C#
83 lines
2.2 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using DG.Tweening;
|
|
public class WaterDrop : MonoBehaviour
|
|
{
|
|
|
|
public Button DropBtn;
|
|
public Transform targetPosition; // 目标位置
|
|
public float flyDuration = 1f; // 飞行持续时间
|
|
public int id;
|
|
string trans_id;
|
|
|
|
void Start()
|
|
{
|
|
DropBtn = GetComponent<Button>();
|
|
|
|
DropBtn.onClick.AddListener(DropClick);
|
|
}
|
|
|
|
async void DropClick()
|
|
{
|
|
|
|
|
|
trans_id = GenerateRandomString(6);
|
|
bool succefful = await Scene_main_jiekou.instance.TreeGetWaters(id, trans_id);
|
|
|
|
if (succefful)
|
|
{
|
|
|
|
|
|
TreeInfo info = await Scene_main_jiekou.instance.TreeInfoS();
|
|
// 先进行缩放动画
|
|
transform.DOScale(new Vector3(0.5f, 0.5f, 0.5f), 0.5f) // 缩小到0.5倍大小
|
|
.OnComplete(() =>
|
|
{
|
|
// 然后执行移动动画
|
|
transform.DOScale(Vector3.one, 0.5f);
|
|
transform.DOMove(targetPosition.position, flyDuration)
|
|
.OnComplete(async () =>
|
|
{
|
|
// 移动完成后更新水面信息并销毁物体
|
|
transform.DOScale(new Vector3(0.5f, 0.5f, 0.5f), 0.5f).OnComplete(() =>
|
|
{
|
|
transform.DOScale(Vector3.one, 0.5f);
|
|
WaterPanel.instance.Updated_water(info);
|
|
Destroy(this.gameObject);
|
|
});
|
|
});
|
|
});
|
|
|
|
|
|
}
|
|
else
|
|
{
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
public string GenerateRandomString(int length)
|
|
{
|
|
System.Random random = new System.Random(); // 创建一个新的随机数生成器
|
|
const string chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; // 可用字符
|
|
char[] stringChars = new char[length]; // 用来存储生成的字符
|
|
|
|
for (int i = 0; i < length; i++)
|
|
{
|
|
stringChars[i] = chars[random.Next(chars.Length)]; // 随机选择一个字符
|
|
}
|
|
|
|
return new string(stringChars); // 将字符数组转换为字符串
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
|
|
}
|
|
}
|