C#教程

关注公众号 jb51net

关闭
首页 > 软件编程 > C#教程 > Unity每日签到系统

Unity实现单机游戏每日签到系统

作者:learner-顶

这篇文章主要为大家详细介绍了Unity实现单机游戏每日签到系统,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

本文实例为大家分享了Unity实现每日签到系统的具体代码,供大家参考,具体内容如下

代码:

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

public class HallManager : UnitySingleton<HallManager>
{
    public Text textSingInCoinDes, textSingInCoin;
    public Button btnSignInNormal, btnSignInAd;

    //------------------------------------------    签到模块    ------------------------------------------

    /// <summary>
    /// 设置签到数据
    /// </summary>
    public void SetSignInPanelData()
    {
        if (string.IsNullOrEmpty(PlayerPrefs.GetString("SignInDay7")))
        {
            for (int i = 0; i < 7; i++)
            {
                PlayerPrefs.SetString("SignInDay" + (i + 1), DateTime.Today.AddDays(i).ToShortDateString());
            }
        }
        for (int i = 0; i < 7; i++)
        {
            if (DateTime.Today.ToShortDateString().Equals(PlayerPrefs.GetString("SignInDay" + (i + 1))))
            {
                textSingInCoinDes.text = "今天领取";
                textSingInCoin.text = signInCoin[i].ToString();
                btnSignInNormal.gameObject.SetActive(true);
                btnSignInAd.gameObject.SetActive(true);
                signFinish.gameObject.SetActive(false);
            }
            else if ("已签到".Equals(PlayerPrefs.GetString("SignInDay" + (i + 1))) && i != 6)
            {
                textSingInCoinDes.text = "明天领取";
                textSingInCoin.text = signInCoin[i + 1].ToString();
                btnSignInNormal.gameObject.SetActive(false);
                btnSignInAd.gameObject.SetActive(false);
                signFinish.gameObject.SetActive(true);
            }
        }

        for (int i = 0; i < 7; i++)
        {
            if (DateTime.Today.ToShortDateString().Equals(PlayerPrefs.GetString("SignInDay" + (i + 1))) || "已签到".Equals(PlayerPrefs.GetString("SignInDay" + (i + 1))))
            {
                if ("已签到".Equals(PlayerPrefs.GetString("SignInDay" + (i + 1))))
                {
                    signInPanel.transform.Find("Items").GetChild(i).Find("YiQianDao").gameObject.SetActive(true);
                }
                else
                {
                    signInPanel.transform.Find("Items").GetChild(i).Find("YiQianDao").gameObject.SetActive(false);
                }
            }
        }
    }

    /// <summary>
    /// 点击普通签到
    /// </summary>
    void ClickBtnSignInNormal()
    {
        for (int i = 0; i < 7; i++)
        {
            if (DateTime.Today.ToShortDateString().Equals(PlayerPrefs.GetString("SignInDay" + (i + 1))))
            {
                CoinManager.Instance.AddCoin(signInCoin[i]);
                PlayerPrefs.SetString("SignInDay" + (i + 1), "已签到");
                ShowRewardPanel(signInCoin[i]);
            }
        }
        SetUserInfo();
        SetSignInPanelData();
        //全屏广告
        MobileController.Instance.CallFullScreenAd(FullScreenAdRewardType.None);
    }

    /// <summary>
    /// 点击视频双倍奖励签到
    /// </summary>
    void ClickSignInAd()
    {
        MobileController.Instance.CallVedioRewardAd("signIn");
    }

    /// <summary>
    /// 回调 - 视频双倍奖励签到
    /// </summary>
    public void CallBackSignInReward()
    {
        for (int i = 0; i < 7; i++)
        {
            if (DateTime.Today.ToShortDateString().Equals(PlayerPrefs.GetString("SignInDay" + (i + 1))))
            {
                CoinManager.Instance.AddCoin(signInCoin[i] * 2);
                PlayerPrefs.SetString("SignInDay" + (i + 1), "已签到");
                ShowRewardPanel(signInCoin[i] * 2);
            }
        }
        SetUserInfo();
        SetSignInPanelData();
    }
}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

您可能感兴趣的文章:
阅读全文