285 lines
7.9 KiB
C#
285 lines
7.9 KiB
C#
|
using System;
|
|||
|
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
using Unity.VisualScripting.Antlr3.Runtime;
|
|||
|
using UnityEngine;
|
|||
|
using UnityEngine.U2D;
|
|||
|
using UnityEngine.UI;
|
|||
|
using Random = UnityEngine.Random;
|
|||
|
|
|||
|
public class OnlinePanel : BasePanel
|
|||
|
{
|
|||
|
//ʱ<><CAB1><EFBFBD><EFBFBD>
|
|||
|
public RectTransform imgBK;
|
|||
|
//ʱ<><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
public float maxWidth = 310f;
|
|||
|
//<2F>ر<EFBFBD>
|
|||
|
public Button btnClose;
|
|||
|
//<2F><><EFBFBD><EFBFBD>
|
|||
|
public Button btnHelp;
|
|||
|
//<2F><><EFBFBD>ﰴť
|
|||
|
public Button btnGift1;
|
|||
|
private bool isOpen1=false;
|
|||
|
public Button btnGift5;
|
|||
|
private bool isOpen5 = false;
|
|||
|
public Button btnGift10;
|
|||
|
private bool isOpen10 = false;
|
|||
|
public Button btnGift20;
|
|||
|
private bool isOpen20 = false;
|
|||
|
public Button btnGift30;
|
|||
|
private bool isOpen30 = false;
|
|||
|
public Button btnGift60;
|
|||
|
private bool isOpen60 = false;
|
|||
|
|
|||
|
//ʱ<><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
public Text txtTime;
|
|||
|
//<2F><>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>
|
|||
|
private float timeUp=0;
|
|||
|
|
|||
|
private PlayerData player;
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
private bool isRunning = true;
|
|||
|
private SpriteAtlas sa;
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD>Ľ<EFBFBD><C4BD><EFBFBD>
|
|||
|
private int gold;
|
|||
|
|
|||
|
public override void Init()
|
|||
|
{
|
|||
|
sa = Resources.Load<SpriteAtlas>("Atlas/OnlinePanel");
|
|||
|
//<2F><>ȡһ<C8A1>η<EFBFBD><CEB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
player = GameDataMgr.Instance.player;
|
|||
|
|
|||
|
StartCoroutine(UpdateTime(1f));
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>壬<EFBFBD><E5A3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵ<EFBFBD><CFB5><EFBFBD>ͼ<EFBFBD><CDBC>
|
|||
|
UpdateGift();
|
|||
|
|
|||
|
btnClose.onClick.AddListener(() =>
|
|||
|
{
|
|||
|
UIManager.Instance.HidePanel<OnlinePanel>(false);
|
|||
|
StopCorotine();
|
|||
|
});
|
|||
|
btnGift1.onClick.AddListener(() =>
|
|||
|
{
|
|||
|
if (isOpen1)
|
|||
|
{
|
|||
|
//<2F>رհ<D8B1>ť
|
|||
|
OpenGift(btnGift1);
|
|||
|
player.onlineGiftOpen[0] = true;
|
|||
|
GetGold();
|
|||
|
}
|
|||
|
});
|
|||
|
btnGift5.onClick.AddListener(() =>
|
|||
|
{
|
|||
|
if (isOpen5)
|
|||
|
{
|
|||
|
//<2F>رհ<D8B1>ť
|
|||
|
OpenGift(btnGift5);
|
|||
|
player.onlineGiftOpen[1] = true;
|
|||
|
GetGold();
|
|||
|
}
|
|||
|
});
|
|||
|
btnGift10.onClick.AddListener(() =>
|
|||
|
{
|
|||
|
if (isOpen10)
|
|||
|
{
|
|||
|
//<2F>رհ<D8B1>ť
|
|||
|
OpenGift(btnGift10);
|
|||
|
player.onlineGiftOpen[2] = true;
|
|||
|
GetGold();
|
|||
|
}
|
|||
|
});
|
|||
|
btnGift20.onClick.AddListener(() =>
|
|||
|
{
|
|||
|
if (isOpen20)
|
|||
|
{
|
|||
|
//<2F>رհ<D8B1>ť
|
|||
|
OpenGift(btnGift20);
|
|||
|
player.onlineGiftOpen[3] = true;
|
|||
|
GetGold();
|
|||
|
}
|
|||
|
});
|
|||
|
btnGift30.onClick.AddListener(() =>
|
|||
|
{
|
|||
|
if (isOpen30)
|
|||
|
{
|
|||
|
//<2F>رհ<D8B1>ť
|
|||
|
OpenGift(btnGift30);
|
|||
|
player.onlineGiftOpen[4] = true;
|
|||
|
GetGold();
|
|||
|
}
|
|||
|
});
|
|||
|
btnGift60.onClick.AddListener(() =>
|
|||
|
{
|
|||
|
if (isOpen60)
|
|||
|
{
|
|||
|
//<2F>رհ<D8B1>ť
|
|||
|
OpenGift(btnGift60);
|
|||
|
player.onlineGiftOpen[5] = true;
|
|||
|
GetGold();
|
|||
|
}
|
|||
|
});
|
|||
|
}
|
|||
|
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
private void GetGold()
|
|||
|
{
|
|||
|
int gold = 0;
|
|||
|
int valueRan = Random.Range(0, 10); // <20><><EFBFBD><EFBFBD>0<EFBFBD><30>1֮<31><D6AE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
if (valueRan < 6)
|
|||
|
{
|
|||
|
// 60% <20><><EFBFBD>ʻ<EFBFBD><CABB><EFBFBD> 1-100 <20><><EFBFBD><EFBFBD>
|
|||
|
gold = Random.Range(1, 101);
|
|||
|
}
|
|||
|
else if (valueRan>=6&&valueRan < 9f)
|
|||
|
{
|
|||
|
// 30% <20><><EFBFBD>ʻ<EFBFBD><CABB><EFBFBD> 101-500 <20><><EFBFBD><EFBFBD>
|
|||
|
gold = Random.Range(101, 501);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
// 10% <20><><EFBFBD>ʻ<EFBFBD><CABB><EFBFBD> 501-1000 <20><><EFBFBD><EFBFBD>
|
|||
|
gold = Random.Range(501, 1001);
|
|||
|
}
|
|||
|
//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϸ<EFBFBD><CFB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD>֪ͨ<CDA8><D6AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ؿ<EFBFBD><D8BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ
|
|||
|
player.gold += gold;
|
|||
|
StartCoroutine(NetMgr.Instance.ChangeDataPost(player));
|
|||
|
}
|
|||
|
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>Э<EFBFBD><D0AD>
|
|||
|
private IEnumerator UpdateTime(float delayTime)
|
|||
|
{
|
|||
|
while (isRunning)
|
|||
|
{
|
|||
|
// ִ<><D6B4><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD>IJ<EFBFBD><C4B2><EFBFBD>
|
|||
|
int minutes = Mathf.FloorToInt(GameMgr.Instance.timeAll / 60); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
int seconds = Mathf.FloorToInt(GameMgr.Instance.timeAll % 60); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
// <20><>ʽ<EFBFBD><CABD>ʱ<EFBFBD><CAB1>Ϊ "00:00" <20><>ʽ
|
|||
|
txtTime.text = string.Format("{0:00}:{1:00}", minutes, seconds);
|
|||
|
//<2F><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
UpdateImg();
|
|||
|
// <20><>ʱָ<CAB1><D6B8><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
|||
|
yield return new WaitForSeconds(delayTime);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
// ֹͣ<CDA3><D6B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD>IJ<EFBFBD><C4B2><EFBFBD>
|
|||
|
public void StopCorotine()
|
|||
|
{
|
|||
|
isRunning = false;
|
|||
|
}
|
|||
|
|
|||
|
private void UpdateImg()
|
|||
|
{
|
|||
|
// <20><><EFBFBD><EFBFBD> Image <20>Ŀ<EFBFBD><C4BF><EFBFBD>
|
|||
|
float newWidth = maxWidth * (GameMgr.Instance.timeAll /3600f);
|
|||
|
imgBK.sizeDelta = new Vector2(newWidth, imgBK.sizeDelta.y);
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// <20>ж<EFBFBD><D0B6>Ƿ<EFBFBD><C7B7>ﵽ<EFBFBD><EFB5BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
/// </summary>
|
|||
|
private void UpdateGift()
|
|||
|
{
|
|||
|
|
|||
|
if (GameMgr.Instance.timeAll >= 60 && !isOpen1)
|
|||
|
{
|
|||
|
if (!player.onlineGiftOpen[0])
|
|||
|
{
|
|||
|
btnGift1.image.sprite = sa.GetSprite("icn_giftrand");
|
|||
|
isOpen1 = true;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
OpenGift(btnGift1);
|
|||
|
}
|
|||
|
}
|
|||
|
if (GameMgr.Instance.timeAll >= 300 && !isOpen5)
|
|||
|
{
|
|||
|
if (!player.onlineGiftOpen[1])
|
|||
|
{
|
|||
|
btnGift5.image.sprite = sa.GetSprite("icn_giftrand");
|
|||
|
isOpen5 = true;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
OpenGift(btnGift5);
|
|||
|
}
|
|||
|
}
|
|||
|
if (GameMgr.Instance.timeAll >= 600 && !isOpen10)
|
|||
|
{
|
|||
|
if (!player.onlineGiftOpen[2])
|
|||
|
{
|
|||
|
btnGift10.image.sprite = sa.GetSprite("icn_giftrand");
|
|||
|
isOpen10 = true;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
OpenGift(btnGift10);
|
|||
|
}
|
|||
|
}
|
|||
|
if (GameMgr.Instance.timeAll >= 1200 && !isOpen20)
|
|||
|
{
|
|||
|
if (!player.onlineGiftOpen[3])
|
|||
|
{
|
|||
|
btnGift20.image.sprite = sa.GetSprite("icn_giftrand");
|
|||
|
isOpen20 = true;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
OpenGift(btnGift20);
|
|||
|
}
|
|||
|
}
|
|||
|
if (GameMgr.Instance.timeAll >= 1800 && !isOpen30)
|
|||
|
{
|
|||
|
if (!player.onlineGiftOpen[4])
|
|||
|
{
|
|||
|
btnGift30.image.sprite = sa.GetSprite("icn_giftrand");
|
|||
|
isOpen30 = true;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
OpenGift(btnGift30);
|
|||
|
}
|
|||
|
}
|
|||
|
if (GameMgr.Instance.timeAll >= 3600 && !isOpen60)
|
|||
|
{
|
|||
|
if (!player.onlineGiftOpen[5])
|
|||
|
{
|
|||
|
btnGift60.image.sprite = sa.GetSprite("icn_giftrand");
|
|||
|
isOpen60 = true;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
OpenGift(btnGift60);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
if (GameMgr.Instance.timeAll<60)
|
|||
|
{
|
|||
|
btnGift1.image.sprite = sa.GetSprite("icn_giftrandgray");
|
|||
|
btnGift1.GetComponent<RectTransform>().sizeDelta = new Vector2(108f, 112f);
|
|||
|
btnGift5.image.sprite = sa.GetSprite("icn_giftrandgray");
|
|||
|
btnGift5.GetComponent<RectTransform>().sizeDelta = new Vector2(108f, 112f);
|
|||
|
btnGift10.image.sprite = sa.GetSprite("icn_giftrandgray");
|
|||
|
btnGift10.GetComponent<RectTransform>().sizeDelta = new Vector2(108f, 112f);
|
|||
|
btnGift20.image.sprite = sa.GetSprite("icn_giftrandgray");
|
|||
|
btnGift20.GetComponent<RectTransform>().sizeDelta = new Vector2(108f, 112f);
|
|||
|
btnGift30.image.sprite = sa.GetSprite("icn_giftrandgray");
|
|||
|
btnGift30.GetComponent<RectTransform>().sizeDelta = new Vector2(108f, 112f);
|
|||
|
btnGift60.image.sprite = sa.GetSprite("icn_giftrandgray");
|
|||
|
btnGift60.GetComponent<RectTransform>().sizeDelta = new Vector2(108f, 112f);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֮<EFBFBD><D6AE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾͼƬ
|
|||
|
/// </summary>
|
|||
|
/// <param name="btn"></param>
|
|||
|
private void OpenGift( Button btn)
|
|||
|
{
|
|||
|
btn.image.sprite = sa.GetSprite("icn_giftrandopen");
|
|||
|
btn.GetComponent<RectTransform>().sizeDelta = new Vector2(134f, 112f);
|
|||
|
}
|
|||
|
}
|