Cute_demon_attacks/meng_yao/Assets/script/scene_jinshakuang/roomcontroller.cs

290 lines
7.7 KiB
C#
Raw Normal View History

2024-11-15 22:44:04 +08:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using DG.Tweening;
using TMPro;
using System.Threading.Tasks;
public class roomcontroller : MonoBehaviour
{
[Range(0f, 1f)]
public float probabilityOfStand = 0.2f;//վ<><D5BE>״̬
[Header("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD>ĸ<EFBFBD><C4B8><EFBFBD>")]
[Range(0f, 1f)]
public float probabilityOfWalk = 0.3f;//<2F><>·״̬
[Header("<22><><EFBFBD><EFBFBD><EFBFBD>ڿ<EFBFBD><DABF>ĸ<EFBFBD><C4B8><EFBFBD>")]
[Range(0f, 1f)]
public float probabilityOfDig = 0.5f;//<2F>ڿ<EFBFBD>״̬
[Header("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ԥ<EFBFBD><D4A4><EFBFBD><EFBFBD>")]
public GameObject fishManPrefab;
[Header("<22><><EFBFBD><EFBFBD><EFBFBD>ľ<EFBFBD><C4BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>")]
public List<VoucherItem> listItem = new List<VoucherItem>();
private GameObject fishMan;//<2F><><EFBFBD>ɵ<EFBFBD><C9B5>
private SpriteAniationpro fishManShipContorl;//<2F><EFBFBD>Ŀ<EFBFBD><C4BF><EFBFBD><EFBFBD><EFBFBD>
[Header("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɵ<EFBFBD>")]
public Transform startPos;
[Header("<22><><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD>")]
public Transform endPos;
[Header("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͱ<EFBFBD><CDB1><EFBFBD>")]
public int type;
public float ActivateValue = 0;
public int Num = 0;
public int Type = 0;
[Header("<22><><EFBFBD><EFBFBD>·<EFBFBD><C2B7><EFBFBD><EFBFBD><E3BCAF>")]
public List<Path> paths;
//<2F><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
[Header("<22><>·ʱ<C2B7><CAB1>")]
public float pathsNeedTimer = 30f;
//<2F><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
[Header("<22>ڿ<EFBFBD>ʱ<EFBFBD><CAB1>")]
public float fishingNeedTimer = 30f;
//<2F><>Ϣʱ<CFA2><CAB1>
[Header("<22><>Ϣʱ<CFA2><CAB1>")]
public float restTimer = 5f;
[Header("<22><>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>")]
public Text shipNumberTextPro;
[Header("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч")]
public GameObject effectPrefab;//<2F><>Ч
[Header("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ť<EFBFBD><C5A5><EFBFBD>ֵĶ<D6B5><C4B6><EFBFBD>")]
public Transform OnBtnAni;
public float FishPrice;
public GameObject map;
public static bool canClick = true;
public List<string> ids = new List<string>();
2024-11-16 01:20:28 +08:00
public int number;
public GameObject musk;
2024-11-15 22:44:04 +08:00
// Start is called before the first frame update
private void Awake()
{
listItem = new List<VoucherItem>();
UpdateShipNumberTextPro(listItem.Count.ToString());
}
private void Start()
{
FishPrice = 10;
2024-11-15 23:57:06 +08:00
2024-11-15 22:44:04 +08:00
}
2024-11-15 23:57:06 +08:00
2024-11-15 22:44:04 +08:00
async void addman(int type, int number)
{
if (type == this.type)
{
GenerateForFisherElf generateForFisherElf = new GenerateForFisherElf(); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
generateForFisherElf.Num = Num;
generateForFisherElf.Count = 1;
string userponse = await web.SendRequest(web.URL + "/Voucher/GenerateForFisherElf", "POST", JsonUtility.ToJson(generateForFisherElf));
ids itemList = JsonUtility.FromJson<ids>(userponse);
Debug.Log(itemList.Ids[0]);
if (itemList.ErrorCode == 0) // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD>
{
Promptmgr.Instance.PromptBubble("<22><><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD>", Color.black, Color.blue);
/* foreach (string item in itemList.Ids)
{
Use use = new Use(); // ʹ<><CAB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
use.Id = item;
string rect = await web.SendRequest(web.URL + "/Voucher/Use", "POST", JsonUtility.ToJson(use));
Res res = JsonUtility.FromJson<ids>(userponse);
if (res.ErrorCode == 0)
{
Promptmgr.Instance.PromptBubble("<22><><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD>", Color.black, Color.blue);
//<2F><><EFBFBD>Ӵ<EFBFBD>ֻ<EFBFBD><D6BB><EFBFBD><EFBFBD>
//ChangeShipNumber(1);
}
else
{
Promptmgr.Instance.PromptBubble(res.ErrorMessage, Color.black, Color.red);
}
}*/
}
else// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>
{
Res res = JsonUtility.FromJson<ids>(userponse);
Promptmgr.Instance.PromptBubble(res.ErrorMessage, Color.black, Color.red);
}
}
}
public void OnClick()
{
if (!canClick)
{
return;
}
if (fishMan == null)
{
Promptmgr.Instance.PromptBubble("<22><>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>飡", Color.black, Color.red);
return;
}
add_fish();
}
public void add_fish(string timerStr = null)//<2F><><EFBFBD>ɴ<EFBFBD>ֻ
{
if (timerStr != null)
{
fishMan = GameObject.Instantiate(fishManPrefab, this.transform);
fishMan.transform.position = endPos.position;
fishManShipContorl = fishMan.GetComponent<SpriteAniationpro>();
Debug.Log("<22><><EFBFBD>´<EFBFBD>ʱ<EFBFBD><CAB1>");
//dig();
return;
}
2024-11-16 01:20:28 +08:00
musk.gameObject.SetActive(false);
number++;
UpdateShipNumberTextPro(number+"/10");
2024-11-15 22:44:04 +08:00
fishMan = GameObject.Instantiate(fishManPrefab, this.transform);
fishMan.transform.position = startPos.position;
fishManShipContorl = fishMan.GetComponent<SpriteAniationpro>();
MoveToFishingPos();
}
void MoveToFishingPos()
{
// <20><><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1>һ<EFBFBD><D2BB>·<EFBFBD><C2B7>
Path selectedPath = paths[Random.Range(0, paths.Count)];
// <20>ƶ<EFBFBD><C6B6><EFBFBD><EFBFBD>ڿ<EFBFBD><DABF><EFBFBD>
StartCoroutine(MoveToFishingPoint(selectedPath.pathPoints));
}
IEnumerator MoveToFishingPoint(List<Transform> path)
{
// <20><>·<EFBFBD><C2B7><EFBFBD><EFBFBD>ת<EFBFBD><D7AA>Ϊ Vector3 <20><><EFBFBD><EFBFBD>
Vector3[] pathPoints = new Vector3[path.Count];
for (int i = 0; i < path.Count; i++)
{
pathPoints[i] = path[i].position;
}
//<2F>ı<C4B1><E4B3AF>
ChangeShipLook(pathPoints[0], pathPoints[path.Count - 1]);
//<2F><><EFBFBD><EFBFBD><EFBFBD>仯,<2C>ƶ<EFBFBD>
fishManShipContorl.SetAni(1);
// ʹ<><CAB9> DOPath <20><><EFBFBD><EFBFBD>·<EFBFBD><C2B7><EFBFBD>ƶ<EFBFBD><C6B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E3A3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD>
yield return fishMan.transform.DOPath(pathPoints, pathsNeedTimer, PathType.CatmullRom)
.SetOptions(false) // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת
.SetEase(Ease.InOutSine)
.WaitForCompletion();
//<2F>ڿ<EFBFBD>
dig();
}
2024-11-15 23:57:06 +08:00
void dig()
2024-11-15 22:44:04 +08:00
{
//<2F><><EFBFBD><EFBFBD><EFBFBD>仯,<2C><><EFBFBD><EFBFBD>
fishManShipContorl.SetAni(2);
2024-11-15 23:57:06 +08:00
StartCoroutine(movetoStatrPos());
}
IEnumerator movetoStatrPos()
{
yield return new WaitForSeconds(3);
Debug.Log("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
fishMan.transform.rotation = Quaternion.Euler(0, 180, 0);
fishManShipContorl.SetAni(1);
Vector3[] ve = { endPos.position, startPos.position };
// ʹ<><CAB9> DOPath <20><><EFBFBD><EFBFBD>·<EFBFBD><C2B7><EFBFBD>ƶ<EFBFBD><C6B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E3A3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD>
yield return fishMan.transform.DOPath(ve, pathsNeedTimer, PathType.CatmullRom)
.SetOptions(false) // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת
.SetEase(Ease.InOutSine)
.WaitForCompletion();
fishManShipContorl.SetAni(0);
yield return new WaitForSeconds(3);
MoveToFishingPos();
2024-11-15 22:44:04 +08:00
}
//<2F><><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0>λ<EFBFBD>øı<C4B1><E4B3AF>
void ChangeShipLook(Vector3 _startpos, Vector3 _endpos)
{
if (_startpos.x > _endpos.x)
{
Debug.Log("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
fishMan.transform.rotation = Quaternion.Euler(0,180,0);
}
else
{
Debug.Log("<22><><EFBFBD><EFBFBD><EFBFBD>ұ<EFBFBD>");
fishMan.transform.rotation = Quaternion.Euler(0, 0, 0);
}
}
//<2F><><EFBFBD>¾<EFBFBD><C2BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ
public void UpdateShipNumberTextPro(string str)
{
if (shipNumberTextPro.text == str)
{
return;
}
shipNumberTextPro.text = str;
}
//ʹ<>ô<EFBFBD><C3B4><EFBFBD><EFBFBD><EFBFBD>
async void UseShip()
{
Use use = new Use(); // ʹ<><CAB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
use.Id = listItem[0].Id;
string rect = await web.SendRequest(web.URL + "/Voucher/Use", "POST", JsonUtility.ToJson(use));
Res res = JsonUtility.FromJson<ids>(rect);
if (res.ErrorCode == 0)
{
Promptmgr.Instance.PromptBubble("ʹ<>óɹ<C3B3>", Color.black, Color.blue);
}
else
{
Promptmgr.Instance.PromptBubble(res.ErrorMessage, Color.black, Color.red);
}
}
}