209 lines
5.9 KiB
C#
209 lines
5.9 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using DG.Tweening;
|
|
public class BaoshiRoomcontroller : MonoBehaviour
|
|
{
|
|
[Header("房间id")]
|
|
public int RoomId;
|
|
|
|
[Header("精灵的预制体")]
|
|
public GameObject fishManPrefab;
|
|
[Header("购买的精灵数据")]
|
|
public List<VoucherItem> listItem = new List<VoucherItem>();
|
|
private GameObject fishMan;//生成的渔船
|
|
private minerControl fishManShipContorl;//渔船的控制器
|
|
|
|
[Header("精灵生成点")]
|
|
public Transform startPos;
|
|
[Header("精灵终点")]
|
|
public Transform endPos;
|
|
|
|
[Header("房间类型编号")]
|
|
public int type;
|
|
|
|
public float ActivateValue = 0;
|
|
public int Num = 0;
|
|
public int Type = 0;
|
|
|
|
[Header("精灵路径点集合")]
|
|
public List<Path> paths;
|
|
//航行时间
|
|
[Header("走路时间")]
|
|
public float pathsNeedTimer = 30f;
|
|
//捕鱼时间
|
|
[Header("挖矿时间")]
|
|
public float fishingNeedTimer = 30f;
|
|
//休息时间
|
|
[Header("休息时间")]
|
|
public float restTimer = 5f;
|
|
|
|
[Header("保存精灵对象")]
|
|
List<GameObject> fishManlist = new List<GameObject>();
|
|
|
|
[Header("显示精灵数量")]
|
|
public Text shipNumberTextPro;
|
|
public int shipNumber;
|
|
public int MaxShipNumber=10;
|
|
|
|
[Header("显示购买价格")] public Text price;
|
|
public int ShipNumber
|
|
{
|
|
get=> shipNumber;
|
|
set
|
|
{
|
|
shipNumber=value;
|
|
shipNumberTextPro.text = shipNumber.ToString()+"/"+MaxShipNumber.ToString();
|
|
}
|
|
}
|
|
|
|
[Header("点击的特效")]
|
|
public GameObject effectPrefab;//特效
|
|
|
|
[Header("点击按钮出现的动画")]
|
|
public Transform OnBtnAni;
|
|
|
|
public float FishPrice;
|
|
|
|
public GameObject map;
|
|
|
|
|
|
public static bool canClick = true;
|
|
|
|
public List<string> ids = new List<string>();
|
|
|
|
|
|
|
|
public GameObject musk;
|
|
// Start is called before the first frame update
|
|
private void Awake()
|
|
{
|
|
listItem = new List<VoucherItem>();
|
|
// UpdateShipNumberTextPro(listItem.Count.ToString());
|
|
}
|
|
private void Start()
|
|
{
|
|
FishPrice = 10;
|
|
}
|
|
|
|
|
|
async void addman(int type, int number)
|
|
{
|
|
if (type == this.type)
|
|
{
|
|
GenerateForFisherElf generateForFisherElf = new GenerateForFisherElf(); // 购买渔夫
|
|
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) // 如果购买成功
|
|
{
|
|
Promptmgr.Instance.PromptBubble("购买成功", Color.black, Color.blue);
|
|
|
|
/* foreach (string item in itemList.Ids)
|
|
{
|
|
Use use = new Use(); // 使用渔夫
|
|
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("购买成功", Color.black, Color.blue);
|
|
//增加船只数量
|
|
//ChangeShipNumber(1);
|
|
|
|
|
|
}
|
|
else
|
|
{
|
|
Promptmgr.Instance.PromptBubble(res.ErrorMessage, Color.black, Color.red);
|
|
}
|
|
}*/
|
|
|
|
}
|
|
else// 如果购买失败
|
|
{
|
|
Res res = JsonUtility.FromJson<ids>(userponse);
|
|
Promptmgr.Instance.PromptBubble(res.ErrorMessage, Color.black, Color.red);
|
|
}
|
|
}
|
|
}
|
|
|
|
public async void OnClick()
|
|
{
|
|
|
|
if (!canClick)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (await ActivationRoom())
|
|
{
|
|
add_fish();
|
|
}
|
|
}
|
|
|
|
public void add_fish(string timerStr = null)//生成船只
|
|
{
|
|
//ActivationRoom()
|
|
|
|
if (timerStr != null)
|
|
{
|
|
musk.gameObject.SetActive(false);
|
|
fishMan = GameObject.Instantiate(fishManPrefab, this.transform);
|
|
fishManlist.Add(fishMan);
|
|
fishMan.transform.position = endPos.position;
|
|
fishManShipContorl = fishMan.GetComponent<minerControl>();
|
|
fishManShipContorl.init(this.paths, this.pathsNeedTimer, this.fishingNeedTimer, this.restTimer, this.startPos, this.endPos);
|
|
|
|
Debug.Log("更新船时间");
|
|
|
|
//dig();
|
|
return;
|
|
}
|
|
musk.gameObject.SetActive(false);
|
|
//number++;
|
|
//UpdateShipNumberTextPro(number + "/10");
|
|
fishMan = GameObject.Instantiate(fishManPrefab, this.transform);
|
|
fishMan.transform.position = startPos.position;
|
|
fishManShipContorl = fishMan.GetComponent<minerControl>();
|
|
fishManShipContorl.init(this.paths, this.pathsNeedTimer, this.fishingNeedTimer, this.restTimer, this.startPos, this.endPos);
|
|
}
|
|
//使用代金卷
|
|
async void UseShip()
|
|
{
|
|
Use use = new Use(); // 使用渔夫
|
|
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("使用成功", Color.black, Color.blue);
|
|
}
|
|
else
|
|
{
|
|
Promptmgr.Instance.PromptBubble(res.ErrorMessage, Color.black, Color.red);
|
|
}
|
|
}
|
|
|
|
|
|
public async Task<bool> ActivationRoom()
|
|
{
|
|
return await miner_jiekou.instance.MiningActivate(this.RoomId);
|
|
}
|
|
|
|
|
|
private void OnDisable()
|
|
{
|
|
foreach (GameObject obj in fishManlist)
|
|
{
|
|
Destroy(obj);
|
|
}
|
|
fishManlist.Clear();
|
|
}
|
|
}
|