当前位置:网站首页>Unity mouse cursor usage learning
Unity mouse cursor usage learning
2022-08-08 05:24:00 【live elsewhere】
UnityThe mouse cursor program below is related to one class2、3个方法.
首先,The settings for the cursor to import pictures need to be set to typeCursor.
There is only one way to set the mouse cursor,SetCursor.第一个参数是图片,The second parameter is the offset of the click point,The third parameter is the type.
public Texture2D texture;
void Start()
{
Cursor.SetCursor(texture, new Vector2(40, 4), CursorMode.Auto);
}
当使用CursorMode.Auto的时候,Will use hardware for cursor processing.性能好,兼容好.但是,在windows系统下,will force the cursor to shrink to 32*32.

当使用CursorMode.ForceSoftware的时候,Software will be used to handle the cursor.在windowsThis is the only way to make the mouse cursor bigger under the system,But occasionally there are small onesbug.在使用中发现unity2022.1+HDRP环境下,Image will darken.

If you want to achieve icon animation,Only one picture can be replaced in turn.CodeMonkeyThe big guy has the code to provide cursor animation,我就直接抄过来了.
[CreateAssetMenu]
public class CursorAnimation : ScriptableObject
{
public CursorType cursorType;
public Texture2D[] textureArray;
public float frameRate;
public Vector2 offset;
}
public class CursorMananger : MonoBehaviour
{
public CursorAnimation[] cursorAnimations;
private CursorAnimation currentAnimation;
private float frameRate;
private int frameCount;
private int currentFrame;
private float frameTimer;
private void Start()
{
SetActiveCursorAnimation(cursorAnimations[0]);
}
private void Update()
{
frameTimer -= Time.deltaTime;
if (frameTimer <= 0f)
{
frameTimer += frameRate;
currentFrame = (currentFrame + 1) % frameCount;
Cursor.SetCursor(currentAnimation.textureArray[currentFrame], currentAnimation.offset, CursorMode.Auto);
}
if (Input.GetKeyDown(KeyCode.A)) SetActiveCursorAnimation(cursorAnimations[(int)CursorType.Arrow]);
if (Input.GetKeyDown(KeyCode.S)) SetActiveCursorAnimation(cursorAnimations[(int)CursorType.Star]);
}
private void SetActiveCursorAnimation(CursorAnimation value)
{
currentAnimation = value;
currentFrame = 0;
frameTimer = value.frameRate;
frameCount = value.textureArray.Length;
}
}
BStation cursor effect demonstration video:https://www.bilibili.com/video/BV1EN4y1j7Ne/
边栏推荐
- 查询时间内用户分布的sql语句
- 【leetcode】剑指 Offer(专项突击版)汇总
- 《动机与人格》笔记(二)——认识和理解的欲望
- 多维度数组拉平到一维
- cs软件ui构建办法
- The fledgling Xiao Li's 115th blog project notes on the creation of the domestic GD32F103RCT6 basic project
- 二维码生成工具
- 11-golang流程控制
- 报错:[Intervention] Unable to preventDefault inside passive event listener due to target ...
- 关于如何做选择
猜你喜欢

Leetcode78. Subset

由联合体union引出的大小端问题

C语言日记 11 switch语句(分支结构程序设计)

邮件钓鱼上线cobalstrike

【OAuth2】十八、OIDC的认识应用

温故知新—Activity的五种启动模式

The difference between classification, object detection, semantic segmentation, and instance segmentation
![报错:[Intervention] Unable to preventDefault inside passive event listener due to target ...](/img/57/44e6bc7a330f075f79eb428475d89c.png)
报错:[Intervention] Unable to preventDefault inside passive event listener due to target ...

基本工具-NETCAT(telnet-banner、传输文本信息)

研发医疗器械产品需要做的测试
随机推荐
《动机与人格》笔记(一)——人类似乎从来就没有长久地感到过心满意足
How to play knowledge graph in recommender system
硬盘基础知识
OLTP和OLAP问题的个人总结
ES6对象字面量的新功能
Personal Summary of OLTP and OLAP Issues
Assertion failure in -[UITableView _configureCellForDisplay:forIndexPath:]
TSF Microservice Governance Combat Series (2) - Service Routing
Week 9 10 Neural Networks
Go-Excelize API source code reading (10) - SetActiveSheet(index int)
【多任务模型】《Multi-Faceted Hierarchical Multi-Task Learning for a Large Number of Tasks with Multi-dimens
千亿级、大规模:腾讯超大 Apache Pulsar 集群性能调优实践
Personalized use of Qt log module
Distributed Transactions: A Reliable Message Eventual Consistency Scheme
nonebot插件:说话的艺术
C语言力扣第58题之最后一个单词的长度。从后往前遍历
二维码生成工具
10 must-have free tools for self-media people to operate quickly and efficiently
Connect two tables to update the third table (updata) in postgresql
MySQL4(多表查询)