forked from Unity-Technologies/UnityCsReference
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFakeCursor.cs
More file actions
78 lines (68 loc) · 2.15 KB
/
FakeCursor.cs
File metadata and controls
78 lines (68 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Unity C# reference source
// Copyright (c) Unity Technologies. For terms of use, see
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEditor.IMGUI.Controls;
using UnityEngine;
namespace UnityEditor.UIAutomation
{
class FakeCursor
{
public enum CursorType
{
Normal
}
public Vector2 position { get; set; }
public CursorType currentCursorType = CursorType.Normal;
struct CursorData
{
public Texture2D cursor;
public Vector2 hotspotOffset;
}
static CursorData[] s_MouseCursors;
static Vector2 s_CursorSize = new Vector2(32, 32);
bool shouldDrawFakeMouseCursor
{
get { return position.x > 0f; }
}
public virtual void Draw()
{
if (shouldDrawFakeMouseCursor)
{
var cursor = GetCursor(currentCursorType);
if (cursor != null)
GUI.DrawTexture(GetCursorDrawRect(currentCursorType), cursor);
else
EditorGUI.DrawRect(new Rect(position.x, position.y, 5, 5), Color.white); // fallback rendering
}
}
Texture2D GetCursor(CursorType cursorType)
{
InitIfNeeded();
return s_MouseCursors[(int)cursorType].cursor;
}
Rect GetCursorDrawRect(CursorType cursorType)
{
InitIfNeeded();
Vector2 offset = s_MouseCursors[(int)cursorType].hotspotOffset;
return new Rect(position.x + offset.x, position.y + offset.y, s_CursorSize.x, s_CursorSize.y);
}
void InitIfNeeded()
{
if (s_MouseCursors == null)
{
s_MouseCursors = new[]
{
new CursorData()
{
cursor = EditorGUIUtility.Load("Cursors/CursorAI.psd") as Texture2D,
hotspotOffset = new Vector2(-13, -10)
}
};
}
}
}
}