当前位置:网站首页>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("选择题");
}
}边栏推荐
- West digital decided to raise the price of flash memory products immediately after the factory was polluted by materials
- ASP. Net MVC default configuration, if any, jumps to the corresponding program in the specified area
- Jerry's watch time synchronization [chapter]
- Typora+docsify quick start
- Interval DP acwing 282 Stone merging
- Redis introduction, scenario and data type
- 完全自主可控三维云CAD:CrownCAD便捷的命令搜索,快速定位所需命令具体位置。
- 接口测试面试题目,你都会了吗?
- MySQL: Invalid GIS data provided to function st_ geometryfromtext
- Unforgettable Ali, 4 skills, 5 hr additional written tests, it's really difficult and sad to walk
猜你喜欢

PR usage skills, how to use PR to watermark?

Hash table acwing 840 Simulated hash table

Modular commonjs es module

Ali on three sides, it's really difficult to successfully get the offer rated P7
![[opencv learning] [moving object detection]](/img/2e/9b437b7fe22f1d57334529eda68e37.jpg)
[opencv learning] [moving object detection]

js5day(事件监听,函数赋值给变量,回调函数,环境对象this,全选反选案例,tab栏案例)

Apply lnk306gn-tl converter, non isolated power supply

通过反射执行任意类的任意方法
![[opencv learning] [image histogram and equalization]](/img/e7/b8dc55a9febf2b2949fce3a7ac21f9.jpg)
[opencv learning] [image histogram and equalization]

堆 AcWing 838. 堆排序
随机推荐
Mongodb redis differences
C operator
Oracle from entry to mastery (4th Edition)
(7) Web security | penetration testing | how does network security determine whether CND exists, and how to bypass CND to find the real IP
面渣逆袭:MySQL六十六问,两万字+五十图详解!有点六
Everyone wants to eat a broken buffet. It's almost cold
Fully autonomous and controllable 3D cloud CAD: crowncad's convenient command search can quickly locate the specific location of the required command.
[error record] cannot open "XXX" because Apple cannot check whether it contains malware
Window10 upgrade encountered a big hole error code: 0xc000000e perfect solution
ASP. Net MVC default configuration, if any, jumps to the corresponding program in the specified area
JS iterator generator asynchronous code processing promise+ generator - > await/async
Jerry's watch ringtone audition [article]
js5day(事件监听,函数赋值给变量,回调函数,环境对象this,全选反选案例,tab栏案例)
Domestic free data warehouse ETL dispatching automation operation and maintenance expert taskctl
[opencv learning] [contour detection]
Unity SKFramework框架(十九)、POI 兴趣点/信息点
嵌入式软件开发
3 a VTT terminal regulator ncp51200mntxg data
ADB basic commands
js4day(DOM开始:获取DOM元素内容,修改元素样式,修改表单元素属性,setInterval定时器,轮播图案例)