Skip to content

Commit 74f5815

Browse files
committed
Allocation-free cursor spawning.
1 parent 6229054 commit 74f5815

5 files changed

Lines changed: 60 additions & 3 deletions

File tree

Source/Assets/TouchScript/Prefabs/Cursors/Mouse Cursor.prefab

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ GameObject:
4747
- component: {fileID: 22499528}
4848
- component: {fileID: 11416202}
4949
- component: {fileID: 223878911915740246}
50+
- component: {fileID: 225715774982127120}
5051
m_Layer: 0
5152
m_Name: Mouse Cursor
5253
m_TagString: Untagged
@@ -419,3 +420,14 @@ Canvas:
419420
m_SortingLayerID: 0
420421
m_SortingOrder: 0
421422
m_TargetDisplay: 0
423+
--- !u!225 &225715774982127120
424+
CanvasGroup:
425+
m_ObjectHideFlags: 1
426+
m_PrefabParentObject: {fileID: 0}
427+
m_PrefabInternal: {fileID: 100100000}
428+
m_GameObject: {fileID: 185820}
429+
m_Enabled: 1
430+
m_Alpha: 1
431+
m_Interactable: 0
432+
m_BlocksRaycasts: 0
433+
m_IgnoreParentGroups: 0

Source/Assets/TouchScript/Prefabs/Cursors/Pen Cursor.prefab

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ GameObject:
2828
- component: {fileID: 22480400}
2929
- component: {fileID: 11486812}
3030
- component: {fileID: 223912096970254378}
31+
- component: {fileID: 225894359780410702}
3132
m_Layer: 0
3233
m_Name: Pen Cursor
3334
m_TagString: Untagged
@@ -421,3 +422,14 @@ Canvas:
421422
m_SortingLayerID: 0
422423
m_SortingOrder: 0
423424
m_TargetDisplay: 0
425+
--- !u!225 &225894359780410702
426+
CanvasGroup:
427+
m_ObjectHideFlags: 1
428+
m_PrefabParentObject: {fileID: 0}
429+
m_PrefabInternal: {fileID: 100100000}
430+
m_GameObject: {fileID: 118164}
431+
m_Enabled: 1
432+
m_Alpha: 1
433+
m_Interactable: 0
434+
m_BlocksRaycasts: 0
435+
m_IgnoreParentGroups: 0

Source/Assets/TouchScript/Prefabs/Cursors/Pointer.prefab

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ GameObject:
2828
- component: {fileID: 22471328}
2929
- component: {fileID: 11468960}
3030
- component: {fileID: 223813922742015622}
31+
- component: {fileID: 225429637618999960}
3132
m_Layer: 0
3233
m_Name: Pointer
3334
m_TagString: Untagged
@@ -188,3 +189,14 @@ Canvas:
188189
m_SortingLayerID: 0
189190
m_SortingOrder: 0
190191
m_TargetDisplay: 0
192+
--- !u!225 &225429637618999960
193+
CanvasGroup:
194+
m_ObjectHideFlags: 1
195+
m_PrefabParentObject: {fileID: 0}
196+
m_PrefabInternal: {fileID: 100100000}
197+
m_GameObject: {fileID: 183852}
198+
m_Enabled: 1
199+
m_Alpha: 1
200+
m_Interactable: 0
201+
m_BlocksRaycasts: 0
202+
m_IgnoreParentGroups: 0

Source/Assets/TouchScript/Prefabs/Cursors/Touch Cursor.prefab

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ GameObject:
4646
- component: {fileID: 22499528}
4747
- component: {fileID: 11435582}
4848
- component: {fileID: 223147991810450650}
49+
- component: {fileID: 225477107791102178}
4950
m_Layer: 0
5051
m_Name: Touch Cursor
5152
m_TagString: Untagged
@@ -283,3 +284,14 @@ Canvas:
283284
m_SortingLayerID: 0
284285
m_SortingOrder: 0
285286
m_TargetDisplay: 0
287+
--- !u!225 &225477107791102178
288+
CanvasGroup:
289+
m_ObjectHideFlags: 1
290+
m_PrefabParentObject: {fileID: 0}
291+
m_PrefabInternal: {fileID: 100100000}
292+
m_GameObject: {fileID: 185820}
293+
m_Enabled: 1
294+
m_Alpha: 1
295+
m_Interactable: 0
296+
m_BlocksRaycasts: 0
297+
m_IgnoreParentGroups: 0

Source/Assets/TouchScript/Scripts/Behaviors/Cursors/PointerCursor.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,8 @@ public float Size
206206
/// </summary>
207207
protected uint hash = uint.MaxValue;
208208

209+
private CanvasGroup group;
210+
209211
#endregion
210212

211213
#region Public methods
@@ -218,11 +220,13 @@ public float Size
218220
public void Init(RectTransform parent, IPointer pointer)
219221
{
220222
hash = uint.MaxValue;
223+
group = GetComponent<CanvasGroup>();
221224

222225
show();
223226
rect.SetParent(parent);
224227
rect.SetAsLastSibling();
225228
state = CursorState.Released;
229+
226230
UpdatePointer(pointer);
227231
}
228232

@@ -290,16 +294,21 @@ private void Awake()
290294
/// </summary>
291295
protected virtual void hide()
292296
{
293-
gameObject.SetActive(false);
294-
gameObject.name = "inactive pointer";
297+
group.alpha = 0;
298+
#if UNITY_EDITOR
299+
gameObject.name = "Inactive Pointer";
300+
#endif
295301
}
296302

297303
/// <summary>
298304
/// Shows this instance.
299305
/// </summary>
300306
protected virtual void show()
301307
{
302-
gameObject.SetActive(true);
308+
group.alpha = 1;
309+
#if UNITY_EDITOR
310+
gameObject.name = "Pointer";
311+
#endif
303312
}
304313

305314
/// <summary>

0 commit comments

Comments
 (0)