Cute_demon_attacks/meng_yao/Assets/script/scene_Main/WaterDrop.cs

83 lines
2.2 KiB
C#
Raw Normal View History

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; // Ŀ<><C4BF>λ<EFBFBD><CEBB>
public float flyDuration = 1f; // <20><><EFBFBD>г<EFBFBD><D0B3><EFBFBD>ʱ<EFBFBD><CAB1>
public int id;
2024-12-20 21:03:36 +08:00
string trans_id;
void Start()
{
2024-12-20 21:03:36 +08:00
DropBtn = GetComponent<Button>();
DropBtn.onClick.AddListener(DropClick);
}
async void DropClick()
{
2024-12-20 21:33:49 +08:00
2024-12-20 21:03:36 +08:00
trans_id = GenerateRandomString(6);
bool succefful = await Scene_main_jiekou.instance.TreeGetWaters(id, trans_id);
if (succefful)
{
2024-12-20 21:03:36 +08:00
2024-12-20 21:33:49 +08:00
TreeInfo info = await Scene_main_jiekou.instance.TreeInfoS();
// <20>Ƚ<EFBFBD><C8BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŷ<EFBFBD><C5B6><EFBFBD>
transform.DOScale(new Vector3(0.5f, 0.5f, 0.5f), 0.5f) // <20><>С<EFBFBD><D0A1>0.5<EFBFBD><EFBFBD><EFBFBD><EFBFBD>С
.OnComplete(() =>
{
// Ȼ<><C8BB>ִ<EFBFBD><D6B4><EFBFBD>ƶ<EFBFBD><C6B6><EFBFBD><EFBFBD><EFBFBD>
transform.DOScale(Vector3.one, 0.5f);
transform.DOMove(targetPosition.position, flyDuration)
.OnComplete(async () =>
{
// <20>ƶ<EFBFBD><C6B6><EFBFBD><EFBFBD>ɺ<EFBFBD><C9BA><EFBFBD><EFBFBD><EFBFBD>ˮ<EFBFBD><CBAE><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
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);
});
});
2024-12-20 21:03:36 +08:00
});
}
else
{
}
}
public string GenerateRandomString(int length)
{
System.Random random = new System.Random(); // <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>µ<EFBFBD><C2B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
const string chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; // <20><><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD>
char[] stringChars = new char[length]; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E6B4A2><EFBFBD>ɵ<EFBFBD><C9B5>ַ<EFBFBD>
for (int i = 0; i < length; i++)
{
stringChars[i] = chars[random.Next(chars.Length)]; // <20><><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1>һ<EFBFBD><D2BB><EFBFBD>ַ<EFBFBD>
}
2024-12-20 21:03:36 +08:00
return new string(stringChars); // <20><><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><D7AA>Ϊ<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
}
2024-12-20 21:03:36 +08:00
// Update is called once per frame
void Update()
{
2024-12-20 21:03:36 +08:00
}
}