123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- using UnityEngine;
- namespace GFGGame
- {
- public class MailInfo
- {
- public long mailId;//邮件id
- public string title;//邮件标题
- public long timeSec;//邮件时间戳,单位秒
- public string content = "";//邮件内容
- public List<ItemData> rewards;
- public int state;//邮件状态 0未读, 1已读未领取,2已读已领取
- public bool hasItem;//是否有奖励
- }
- public class MailDataManager : SingletonBase<MailDataManager>
- {
- private int _totolCount = 0;
- public int TotolCount//邮件总数
- {
- get { return _totolCount; }
- set { _totolCount = value; }
- }
- private int _unreadCount = 0;
- public int UnreadCount////未读邮件数量
- {
- get { return _unreadCount; }
- set { _unreadCount = value; }
- }
- public const int Count = 20;//每次请求个数
- private int _startIndex = 0;
- public int StartIndex//起始索引,从0开始
- {
- get { return _startIndex; }
- set { _startIndex = value; }
- }
- public List<MailInfo> mailInfos = new List<MailInfo>();
- public void UpdateMailInfoList(List<MailInfo> list)
- {
- mailInfos.Clear();
- mailInfos = list;
- }
- public void UpdateMailContent(long mailId, int state, string content = "", List<ItemData> rewards = null)
- {
- for (int i = 0; i < mailInfos.Count; i++)
- {
- if (mailInfos[i].mailId == mailId)
- {
- mailInfos[i].state = state;
- if (content != "") mailInfos[i].content = content;
- if (rewards != null) mailInfos[i].rewards = rewards;
- break;
- }
- }
- }
- /// <summary>
- /// 根据邮件Id获取邮件信息
- /// </summary>
- /// <param name="mailId"></param>
- /// <returns></returns>
- public MailInfo GetMailInfoById(long mailId)
- {
- for (int i = 0; i < mailInfos.Count; i++)
- {
- if (mailInfos[i].mailId == mailId)
- {
- return mailInfos[i];
- }
- }
- return null;
- }
- //0未读,1无奖已读,2有奖未领,3有奖已领
- public int GetMailState(MailInfo data)
- {
- if (data.hasItem == false)
- {
- if ((ConstMailStatus)data.state == ConstMailStatus.Unread) return 0;
- if ((ConstMailStatus)data.state == ConstMailStatus.ReadedButNotGet) return 1;
- if ((ConstMailStatus)data.state == ConstMailStatus.ReadedAndGot) return 1;
- }
- else
- {
- if ((ConstMailStatus)data.state == ConstMailStatus.Unread) return 2;
- if ((ConstMailStatus)data.state == ConstMailStatus.ReadedButNotGet) return 2;
- if ((ConstMailStatus)data.state == ConstMailStatus.ReadedAndGot) return 3;
- }
- return 0;
- }
- }
- }
|