码迷,mamicode.com
首页 > 其他好文 > 详细

Unity3d之个性化鼠标

时间:2014-09-11 23:38:22      阅读:190      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   io   os   ar   for   art   div   

代码实例:

 1 using UnityEngine;
 2 using System.Collections;
 3 
 4 public class CursorController : MonoBehaviour
 5 {
 6     /// <summary>
 7     /// 一般鼠标样式
 8     /// </summary>
 9     public Texture2D cursorMouseNormol;
10     /// <summary>
11     /// 单击鼠标样式
12     /// </summary>
13     public Texture2D cursorMouseClick;
14 
15     public float cursorWidth;
16     public float cursorHeight;
17     /// <summary>
18     /// 是否按下鼠标
19     /// </summary>
20     private bool isMouseClick = false;
21     // Use this for initialization
22     void Start()
23     {
24         //关闭系统默认鼠标显示
25         Screen.showCursor = false;
26         cursorWidth = cursorMouseNormol.width;
27         cursorHeight = cursorMouseNormol.height;
28     }
29 
30     // Update is called once per frame
31     void Update()
32     {
33         //鼠标左键单击切换鼠标样式
34         if (Input.GetMouseButtonDown(0))
35         {
36             isMouseClick = true;
37         }
38         else if (Input.GetMouseButtonUp(0))
39         {
40             isMouseClick = false;
41         }
42     }
43 
44     void OnGUI()
45     {
46         if (isMouseClick)
47         {
48             GUI.DrawTexture(new Rect(Input.mousePosition.x - cursorWidth / 2f, Screen.height - Input.mousePosition.y - cursorHeight / 2f, cursorWidth, cursorHeight), cursorMouseClick);
49         }
50         else
51         {
52             GUI.DrawTexture(new Rect(Input.mousePosition.x - cursorWidth / 2f, Screen.height - Input.mousePosition.y - cursorHeight / 2f, cursorWidth, cursorHeight), cursorMouseNormol);
53         }
54     }
55 }

PS:屏幕坐标系:左上角为原点

       鼠标坐标系:左下角为原点

Unity3d之个性化鼠标

标签:style   blog   color   io   os   ar   for   art   div   

原文地址:http://www.cnblogs.com/Moranyouqing/p/3967412.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!