Ejemplo n.º 1
0
        public static void SaveAccountMainData(ToolBagTestAccountMainData mainData)
        {
            if (mainData == null)
            {
                return;
            }

            string dataStr = "";

            if (mainData.accountDataList != null)
            {
                for (int i = 0; i < mainData.accountDataList.Count; i++)
                {
                    dataStr += JsonUtility.ToJson(mainData.accountDataList[i]);
                    if (i != mainData.accountDataList.Count - 1)
                    {
                        dataStr += "|";
                    }
                }
            }

            ToolBagTestAccountSaveData saveData = new ToolBagTestAccountSaveData(mainData.accountName, dataStr);

            PlayerPrefs.SetString(CTestAccountMainKey, JsonUtility.ToJson(saveData));
        }
Ejemplo n.º 2
0
        public static ToolBagTestAccountMainData LoadAccountMainData()
        {
            string str = PlayerPrefs.GetString(CTestAccountMainKey);

            if (string.IsNullOrEmpty(str))
            {
                return(new ToolBagTestAccountMainData("TestAccount"));
            }

            ToolBagTestAccountSaveData saveData = JsonUtility.FromJson <ToolBagTestAccountSaveData>(str);

            ToolBagTestAccountMainData mainData = new ToolBagTestAccountMainData(saveData.accountName);

            string[] dataStrList = saveData.accountDataStr.Split(new char[] { '|' });

            for (int i = 0; i < dataStrList.Length; i++)
            {
                ToolBagTestAccountData data = JsonUtility.FromJson <ToolBagTestAccountData>(dataStrList[i]);
                if (data != null)
                {
                    mainData.accountDataList.Add(data);
                }
            }

            return(mainData);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 清理废弃账号
        /// </summary>
        /// <param name="mainData"></param>
        public static void ClearOldAccount(ToolBagTestAccountMainData mainData)
        {
            if (mainData != null && mainData.accountDataList != null && mainData.accountDataList.Count != 0)
            {
                int currentStamp = GetCurrentTimeStamp();
                int checkTime    = 86400 * 14;

                mainData.accountDataList = mainData.accountDataList.FindAll(x => currentStamp - x.lastLoginTime < checkTime);
            }
        }
Ejemplo n.º 4
0
        public override void ShowWindow()
        {
            ToolBagTestAccountMainData mainData = ToolBagTestAccountUtil.LoadAccountMainData();

            bool   hasLoad = false;
            string oldName = mainData.accountName;

            GUILayout.BeginHorizontal();
            GUILayout.TextArea("用户名");
            mainData.accountName = GUILayout.TextField(mainData.accountName);
            GUILayout.EndHorizontal();

            GUILayout.Space(2);

            GUILayout.BeginHorizontal();
            GUILayout.TextArea("账号");
            GUILayout.TextArea("注册时间");
            GUILayout.TextArea("最后使用时间");
            GUILayout.TextArea("");
            GUILayout.EndHorizontal();

            scrollVec2 = GUILayout.BeginScrollView(scrollVec2);

            if (mainData.accountDataList != null)
            {
                mainData.accountDataList.Sort((a, b) => - a.lastLoginTime.CompareTo(b.lastLoginTime));

                for (int i = 0; i < mainData.accountDataList.Count; i++)
                {
                    GUILayout.BeginHorizontal();
                    GUILayout.TextArea(ToolBagTestAccountUtil.GetAccountStrByData(mainData.accountName, mainData.accountDataList[i]));
                    GUILayout.TextArea(ToolBagTestAccountUtil.GetSystemTimeFromStamp(mainData.accountDataList[i].registTime).ToString());
                    GUILayout.TextArea(ToolBagTestAccountUtil.GetSystemTimeFromStamp(mainData.accountDataList[i].lastLoginTime).ToString());
                    if (GUILayout.Button("使用账号"))
                    {
                        mainData.accountDataList[i].lastLoginTime = ToolBagTestAccountUtil.GetCurrentTimeStamp();
                        hasLoad = true;
                        ToolBagTestAccountUtil.CopyAccount(mainData.accountName, mainData.accountDataList[i]);
                    }

                    GUILayout.EndHorizontal();
                    GUILayout.Space(1);
                }
            }

            GUILayout.EndScrollView();

            if (oldName != mainData.accountName)
            {
                ToolBagTestAccountUtil.SaveAccountMainData(mainData);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 获取并复制最后使用账号
        /// </summary>
        public static void CopyLastLoginAccount()
        {
            ToolBagTestAccountMainData accountMainData = LoadAccountMainData();

            ToolBagTestAccountData accountData = GetLastLoginAccount(accountMainData);

            if (accountData != null)
            {
                accountData.lastLoginTime = GetCurrentTimeStamp();
                SaveAccountMainData(accountMainData);
            }

            CopyAccount(accountMainData.accountName, accountData);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 注册新账号
        /// </summary>
        public static void RegistNewAccount()
        {
            ToolBagTestAccountMainData accountmainData = LoadAccountMainData();

            ClearOldAccount(accountmainData);

            int currentStampTime = GetCurrentTimeStamp();

            ToolBagTestAccountData accountData = new ToolBagTestAccountData(GetNewAccountIndex(accountmainData), currentStampTime, currentStampTime);

            accountmainData.accountDataList.Add(accountData);

            SaveAccountMainData(accountmainData);

            CopyAccount(accountmainData.accountName, accountData);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 获取新账号index
        /// </summary>
        /// <param name="mainData"></param>
        /// <returns></returns>
        private static int GetNewAccountIndex(ToolBagTestAccountMainData mainData)
        {
            ToolBagTestAccountData lastAccount = GetLastLoginAccount(mainData);

            if (lastAccount == null)
            {
                return(1);
            }

            DateTime lastDateTime = GetSystemTimeFromStamp(lastAccount.registTime);

            if (lastDateTime.Year == DateTime.UtcNow.Year && lastDateTime.Month == DateTime.UtcNow.Month && lastDateTime.Day == DateTime.UtcNow.Day)
            {
                return(lastAccount.index + 1);
            }
            else
            {
                return(1);
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 获取最后使用账号
        /// </summary>
        /// <returns></returns>
        private static ToolBagTestAccountData GetLastLoginAccount(ToolBagTestAccountMainData accountMainData)
        {
            if (accountMainData == null)
            {
                return(null);
            }

            if (accountMainData.accountDataList == null || accountMainData.accountDataList.Count == 0)
            {
                return(null);
            }

            ToolBagTestAccountData accountData = accountMainData.accountDataList[0];

            accountMainData.accountDataList.ForEach(x =>
            {
                //不能改成大于 防止同一秒点击多次
                if (x.lastLoginTime >= accountData.lastLoginTime)
                {
                    accountData = x;
                }
            });
            return(accountData);
        }