Files
JJBB/Assets/Project/Script/GUI/ImperialExam/RankingPanelCtr.cs
2024-08-23 15:49:34 +08:00

168 lines
5.0 KiB
C#

using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System.Collections.Generic;
using SPacket.SocketInstance;
using GCGame.Table;
public class RankingPanelCtr : MonoBehaviour {
public static RankingPanelCtr Instance;
private void Awake()
{
Instance = this;
}
private void OnDestroy()
{
Instance = null;
}
public GameObject RoleInfoGameObject;
public Transform ContentParent;
public Text CountTimeText; //倒计时显示TEXT
public Slider CountTimeSlider; //倒计时ProgressBar
public int RemainTime = 0;
public bool isStartCountTime = false;
public float m_CountTime = 0;
private float perQuestionLimitTime = 0.0f;
public void SetMyQuestionRemainTime(int remainTime, ImpreialExamPanelCtr.Question_Type type)
{
//重置Slider 时间
CountTimeText.text = remainTime.ToString();
CountTimeSlider.value = 1;
RemainTime = remainTime;
isStartCountTime = true;
Tab_QuestionOther other = TableManager.GetQuestionOtherByID((int)type, 0);
if(other != null)
{
perQuestionLimitTime = other.LimitTimePer;
}
}
public void CreateMyRoleInfoItem(int count)
{
for(int index = 0; index < count; index++)
{
GameObject m_RoleItem = GameObject.Instantiate(RoleInfoGameObject);
//设置位置
m_RoleItem.transform.parent = ContentParent;
m_RoleItem.transform.localPosition = Vector3.zero;
m_RoleItem.transform.localRotation = Quaternion.Euler(Vector3.zero);
m_RoleItem.transform.localScale = Vector3.one;
}
}
private void OnEnable()
{
RankingListRoleInfoItem[] roleInfoItems = GetComponentsInChildren<RankingListRoleInfoItem>();
for(int index = 0; index < roleInfoItems.Length; index++)
{
GameObject.Destroy(roleInfoItems[index].gameObject);
}
}
//初始化排行榜显示Item
public void InitMyRoleInfoShowItem(List<QuestionRankInfoList> m_RoleInfoList)
{
if(m_RoleInfoList == null || m_RoleInfoList.Count == 0)
{
return;
}
//先排序
m_RoleInfoList.Sort((infoA, infoB)=>
{
if (infoA.score < infoB.score)
{
return 1;
}
else if (infoA.score == infoB.score)
{
if (infoA.Rankper > infoB.Rankper)
{
return 1;
}else if(infoA.Rankper == infoB.Rankper)
{
return 0;
}
else
{
return -1;
}
}
else
{
return -1;
}
});
//存起来
ImperialExamManager.GetInstance().SetMyQuestionRankList(m_RoleInfoList);
//判断已经存在的item
RankingListRoleInfoItem[] roleInfoItems = GetComponentsInChildren<RankingListRoleInfoItem>();
//人数不够10人 删除多余的
if (roleInfoItems.Length > m_RoleInfoList.Count && roleInfoItems != null)
{
for(int index = m_RoleInfoList.Count; index < roleInfoItems.Length; index++)
{
Destroy(roleInfoItems[index].gameObject); //删除多余的
}
}
else
{
//人数增加
CreateMyRoleInfoItem(m_RoleInfoList.Count - roleInfoItems.Length);
}
roleInfoItems = GetComponentsInChildren<RankingListRoleInfoItem>(); //增删之后再获取一次
//剩余的就是当前排行榜的人数 进行刷新
for (int role_Index = 0; role_Index < roleInfoItems.Length; role_Index++)
{
roleInfoItems[role_Index].SetRankingListItem(m_RoleInfoList[role_Index]); //存在的信息重置
}
roleInfoItems = null; //滞空
}
// Update is called once per frame
void Update () {
if(isStartCountTime)
{
if(RemainTime <= 0)
{
isStartCountTime = false;
m_CountTime = 0.0f;
return;
}
m_CountTime += Time.deltaTime;
if(m_CountTime >= 1.0f)
{
RemainTime--;
CountTimeSlider.value = (float)RemainTime / perQuestionLimitTime;
if (RemainTime <= 0)
{
//显示答案正确与否
ImpreialExamPanelCtr.Instance.ShowAnswerWrongOrRight();
//启用蒙版
if(!ImpreialExamPanelCtr.Instance.ClickMask.gameObject.activeInHierarchy)
ImpreialExamPanelCtr.Instance.ClickMask.gameObject.SetActive(true);
}
//显示
CountTimeText.text = RemainTime.ToString();
m_CountTime = 1.0f - m_CountTime;
}
}
}
}