QFramework-类幸存者笔记 -5:时间显示-

特别感谢:

本文是凉鞋的QFramework-类幸存者 教程的学习笔记

https://qframework.cn/qf​编辑https://qframework.cn/qficon-default.png?t=N7T8https://qframework.cn/qf QF官网:有详细免费入门教程


升级 Simpleability 的攻击力&时间显示

Global脚本中新建CurrentSeconds,SimpleAbilityDamage全局变量

using QFramework;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace ProjectSurvivor
{
    public class Global
    {
        /// <summary>
        /// 经验值
        /// </summary>
        public static BindableProperty<int> Exp =new BindableProperty<int>();

        public static BindableProperty<int> Level =new BindableProperty<int>(1);

        public static BindableProperty<float> CurrentSeconds=new BindableProperty<float>(0);

        public static BindableProperty<float> SimpleAbilityDamage=new BindableProperty<float>(1);
    }
}

UIGamePanel界面中复制一份TimeText, 再改一下信息,因为复制的有Bind脚本就不用生成了,直接生成代码即可(alt+C)

SimpleAbility脚本中修改一下HP减少代码

更新UIGamePanel代码

using UnityEngine;
using UnityEngine.UI;
using QFramework;
using System;

namespace ProjectSurvivor
{
	public class UIGamePanelData : UIPanelData
	{
	}
	public partial class UIGamePanel : UIPanel
	{
		protected override void OnInit(IUIData uiData = null)
		{
			mData = uiData as UIGamePanelData ?? new UIGamePanelData();
			// please add init code here

			Global.CurrentSeconds.RegisterWithInitValue(currentSeconds=>
			{
				if (Time.frameCount % 30 == 0)
				{



					var currentSecondsInt = Mathf.FloorToInt(currentSeconds);
					var seconds = currentSecondsInt % 60;
					var minutes = seconds / 60; ;
					TimeText.text = "时间:" + $"{minutes:00}:{seconds:00}";
				}

            }).UnRegisterWhenGameObjectDestroyed(gameObject);


            Global.Exp.RegisterWithInitValue(exp =>
			{
				EXPText.text = "经验值:" + exp;
			}).UnRegisterWhenGameObjectDestroyed(gameObject);

			Global.Level.RegisterWithInitValue(lv =>
			{
				LevelText.text="等级:"+lv;
            }).UnRegisterWhenGameObjectDestroyed(gameObject);

			Global.Level.Register(lv=>{
				Time.timeScale = 0;
				BtnUpgrade.Show();

			}).UnRegisterWhenGameObjectDestroyed(gameObject);

			Global.Exp.RegisterWithInitValue(exp =>
			{
				if (exp>=5)
				{
					Global.Exp.Value -= 5;
					Global.Level.Value++;
				}
			}).UnRegisterWhenGameObjectDestroyed(gameObject);
			BtnUpgrade.Hide();

			BtnUpgrade.onClick.AddListener(() =>
			{
				Time.timeScale=1;
				Global.SimpleAbilityDamage.Value *= 1.5f;
                BtnUpgrade.Hide();

            });

			ActionKit.OnUpdate.Register(
				() =>{
					Global.CurrentSeconds.Value += Time.deltaTime;

			}).UnRegisterWhenGameObjectDestroyed(gameObject);	
		}
		
		protected override void OnOpen(IUIData uiData = null)
		{
		}
		
		protected override void OnShow()
		{
		}
		
		protected override void OnHide()
		{
		}
		
		protected override void OnClose()
		{
		}
	}
}

完毕

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值