当前位置:网站首页>Unity SKFramework框架(十二)、Score 计分模块
Unity SKFramework框架(十二)、Score 计分模块
2022-07-02 09:45:00 【CoderZ1010】
目录
一、配置文件
1.新建
通过右键/Create/Score Profile创建一个分数配置文件
2.编辑
首先在ScoreIDConstant脚本中编写代表分数项ID的int常量
填写配置文件
ID为分数项ID,Description为分数项描述信息,Value为分数项分值。
3.路径
模块内默认的配置文件加载路径为Resources/Score Profile,也可以在代码中进行更改
//加载配置文件
Resources.Load<ScoreProfile>("Score Profile");
二、创建分数
1.创建单项分数
使用Create方法创建单项分数,参数传入分数项ID
using UnityEngine;
using SK.Framework;
public class Example : MonoBehaviour
{
private void Start()
{
Score.Create(ScoreIDConstant.QUESTION_1);
}
}
2.创建分数组合
使用CreateGroup方法创建分数组合,第一个参数传入分数组合的命名;第二个参数传入计分的方式,有两种计分方式,Additive表示分数是累加的,Mutually Exclusive表示组合内分数项之间是互斥的;后面的参数均为分数项ID,为可选参数。
using UnityEngine;
using SK.Framework;
public class Example : MonoBehaviour
{
private void Start()
{
Score.CreateGroup("选择题", ValueMode.Additive,
ScoreIDConstant.QUESTION_1,
ScoreIDConstant.QUESTION_2,
ScoreIDConstant.QUESTION_3,
ScoreIDConstant.QUESTION_4);
}
}
三、获取分数
创建分数项时会返回对应数量的标识,通过这些标识可以获取、取消分数。
using UnityEngine;
using SK.Framework;
public class Example : MonoBehaviour
{
private void Start()
{
//创建分数组合 记录标识
string[] flags = Score.CreateGroup("选择题", ValueMode.Additive,
ScoreIDConstant.QUESTION_1,
ScoreIDConstant.QUESTION_2,
ScoreIDConstant.QUESTION_3,
ScoreIDConstant.QUESTION_4);
//通过标识获取分数
Score.Obtain("选择题", flags[0]);
}
}
上例中表示获取"选择题"分数组合第一个分数项的分值,也就是ID为QUESTION_1的分数项的分值。
四、取消分数
假如想取消一个已经获得的分数项分值,通过Cancle方法实现
using UnityEngine;
using SK.Framework;
public class Example : MonoBehaviour
{
private void Start()
{
//创建分数组合 记录标识
string[] flags = Score.CreateGroup("选择题", ValueMode.Additive,
ScoreIDConstant.QUESTION_1,
ScoreIDConstant.QUESTION_2,
ScoreIDConstant.QUESTION_3,
ScoreIDConstant.QUESTION_4);
//通过标识获取分数
Score.Obtain("选择题", flags[0]);
//取消分数
Score.Cancle("选择题", flags[0]);
}
}
如图所示,Obtain获取分数后再通过Cancle取消分数,获得的分值已经取消
五、计算总分
通过GetSum方法获取已经获得的总分值
using UnityEngine;
using SK.Framework;
public class Example : MonoBehaviour
{
private void Start()
{
//创建分数组合 记录标识
string[] flags = Score.CreateGroup("选择题", ValueMode.Additive,
ScoreIDConstant.QUESTION_1,
ScoreIDConstant.QUESTION_2,
ScoreIDConstant.QUESTION_3,
ScoreIDConstant.QUESTION_4);
//通过标识获取分数
Score.Obtain("选择题", flags[0]);
//获取总分
float sum = Score.GetSum();
}
}
另外可以通过GetGroupSum方法获取一个分数组合中已经获得的总分值
using UnityEngine;
using SK.Framework;
public class Example : MonoBehaviour
{
private void Start()
{
//创建分数组合 记录标识
string[] flags = Score.CreateGroup("选择题", ValueMode.Additive,
ScoreIDConstant.QUESTION_1,
ScoreIDConstant.QUESTION_2,
ScoreIDConstant.QUESTION_3,
ScoreIDConstant.QUESTION_4);
//通过标识获取分数
Score.Obtain("选择题", flags[0]);
//获取一个分数组合的总分
float sum = Score.GetGroupSum("选择题");
}
}
边栏推荐
- 绕过ObRegisterCallbacks需要驱动签名方法
- bellman-ford AcWing 853. Shortest path with side limit
- (7) Web security | penetration testing | how does network security determine whether CND exists, and how to bypass CND to find the real IP
- Jerry's watch modifies the alarm clock [chapter]
- [opencv learning] [Canny edge detection]
- [200 opencv routines] 100 Adaptive local noise reduction filter
- Mongodb redis differences
- Std:: vector batch import fast de duplication method
- West digital decided to raise the price of flash memory products immediately after the factory was polluted by materials
- C modifier
猜你喜欢
The coloring method determines the bipartite graph acwing 860 Chromatic judgement bipartite graph
NTMFS4C05NT1G N-CH 30V 11.9A MOS管,PDF
C operator
Js1day (input / output syntax, data type, data type conversion, VaR and let differences)
Domestic free data warehouse ETL dispatching automation operation and maintenance expert taskctl
Everyone wants to eat a broken buffet. It's almost cold
Js6day (search, add and delete DOM nodes. Instantiation time, timestamp, timestamp cases, redrawing and reflow)
JSON serialization and parsing
[opencv learning] [image histogram and equalization]
JS iterator generator asynchronous code processing promise+ generator - > await/async
随机推荐
JS7day(事件对象,事件流,事件捕获和冒泡,阻止事件流动,事件委托,学生信息表案例)
Hundreds of web page special effects can be used. Don't you come and have a look?
Linear DP acwing 899 Edit distance
Async/await asynchronous function
Interview questions for software testing - a collection of interview questions for large factories in 2022
Modular commonjs es module
ADB basic commands
Finally, someone explained the supervised learning clearly
[opencv learning] [contour detection]
spfa AcWing 851. SPFA finding the shortest path
Apply lnk306gn-tl converter, non isolated power supply
百款拿来就能用的网页特效,不来看看吗?
Jerry's watch reads the alarm clock [chapter]
. Net wechat message template push
[opencv learning] [Canny edge detection]
OLED screen driver based on stm32
Js1day (input / output syntax, data type, data type conversion, VaR and let differences)
Rust language document Lite (Part 1) - cargo, output, basic syntax, data type, ownership, structure, enumeration and pattern matching
嵌入式软件开发
JS6day(DOM结点的查找、增加、删除。实例化时间,时间戳,时间戳的案例,重绘和回流)