特别感谢:
本文是凉鞋的QFramework-类幸存者 教程的学习笔记
https://qframework.cn/qf编辑https://qframework.cn/qfhttps://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()
{
}
}
}
完毕