这篇文章主要为大家详细介绍了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();
}
}
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持得得之家。
沃梦达教程
本文标题为:Unity实现单机游戏每日签到系统
基础教程推荐
猜你喜欢
- 一个读写csv文件的C#类 2022-11-06
- winform把Office转成PDF文件 2023-06-14
- C#类和结构详解 2023-05-30
- C# 调用WebService的方法 2023-03-09
- unity实现动态排行榜 2023-04-27
- C#控制台实现飞行棋小游戏 2023-04-22
- ZooKeeper的安装及部署教程 2023-01-22
- C# windows语音识别与朗读实例 2023-04-27
- linux – 如何在Debian Jessie中安装dotnet core sdk 2023-09-26
- C# List实现行转列的通用方案 2022-11-02