亲宝软件园·资讯

展开

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

learner-顶 人气:0
想了解Unity实现单机游戏每日签到系统的相关内容吗,learner-顶在本文为您仔细讲解Unity每日签到系统的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:Unity单机游戏签到系统,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();
    }
}

加载全部内容

相关教程
猜你喜欢
用户评论