This article shares the specific code for unity3d to implement the seven-day check-in function for your reference. The specific content is as follows
There is a check-in function in many games (the implementation of the 7-day continuous check-in function is recorded here)
1. Functional analysis
1. Judgment on whether to sign in on that day
2. Whether the number of sign-in days has been continuously and whether the sign-in for 7 days has been completed (discontinuous or 7 days has been completed for 7 consecutive days has been completed. The data needs to be clear and the sign-in is recalculated)
The most important thing is that these two functions need to be implemented. Other data storage includes: the number of consecutive check-in times and the date of last check-in.
The following code is to check in and get gold coins by default. However, when using it, you still need to delete or add your own code:
using ; using ; using UnityEngine; using System; using ; using ; public class Jungle_DailyCheck : MonoBehaviour { /// <summary> /// Get the number of check-in times /// </summary> /// <returns>The sign number.</returns> public int GetSignNum() { if (("signNum")) return ("signNum"); return 0; } /// <summary> /// Set the number of check-in times /// </summary> /// <param name="num">Number.</param> public void SetSignNum(int num) { ("signNum", num); } /// <summary> /// Get the last check-in date /// </summary> /// <returns>The sign data.</returns> public string GetSignData() { if (("signData")) return ("signData"); return (); } /// <summary> /// Set the last check-in date /// </summary> public void SetSignData(DateTime data) { ("signData", ()); } int signNum;//Number of check-in times DateTime today;//Today's date DateTime signData;//Last check-in date private bool isRewardTake = false; public Text text_Getcoin; private void Start() { today = ; signNum = GetSignNum(); signData = (GetSignData()); if (IsOneDay(signData, today)) { return; } // (("lastSign==={0},today===={1}", signData, today)); //For the new check-in cycle, the check-in archive needs to be cleared (clear the number of check-in times and the last check-in date) if (NeedClean()) { ("signNum"); ("signData"); } signNum = GetSignNum(); OnBtnGetRewordClick(); } //Click the check-in button public void OnBtnGetRewordClick() { signNum++; signData = today; //Update the archive SetSignData(signData); SetSignNum(signNum); //Add gold coins to the user (() + signNum * 3); text_Getcoin.(0).GetComponent<Text>().text = "Get" + " " + signNum * 3 + " coins"; text_Getcoin.(true); text_Getcoin.(0).(1.2f, 2.5f).onComplete = delegate { text_Getcoin.(0). = new Vector3(1, 1, 1); text_Getcoin.(false); }; } //Judge whether it is the same day bool IsOneDay(DateTime t1, DateTime t2) { return ( == && == && == ); } //The data needs to be cleared (when the number of check-in days is greater than or equal to 7 days or the check-in interval is about one day, the data will be reset) bool NeedClean() { TimeSpan tsNow = new TimeSpan(); TimeSpan tsSign = new TimeSpan(); TimeSpan tsDur = (tsSign).Duration(); // (("days====={0},hours======{1},minutes====={2}", , , )); signNum = GetSignNum(); if (signNum >= 7 || > 1) { return true; } else { return false; } } }
The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.