-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathInputCaretSystem.cs
More file actions
102 lines (91 loc) · 4.19 KB
/
Copy pathInputCaretSystem.cs
File metadata and controls
102 lines (91 loc) · 4.19 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
using DotsUI.Core;
using Unity.Collections;
using Unity.Entities;
using Unity.Jobs;
using Unity.Mathematics;
namespace DotsUI.Controls
{
[UpdateInGroup(typeof(UserInputSystemGroup))]
internal class InputCaretSystem : JobComponentSystem
{
private EntityQuery m_CaretGroup;
private float m_DeltaTime = 0.0f;
private bool m_Show = false;
protected override void OnCreate()
{
m_CaretGroup = GetEntityQuery(new EntityQueryDesc()
{
All = new ComponentType[]
{
ComponentType.ReadOnly<InputFieldCaret>(),
ComponentType.ReadWrite<ElementVertexData>(),
ComponentType.ReadWrite<ElementVertexIndex>(),
}
});
}
protected override JobHandle OnUpdate(JobHandle inputDeps)
{
m_DeltaTime += UnityEngine.Time.deltaTime;
if (m_DeltaTime > 0.5f)
{
m_DeltaTime = 0.0f;
m_Show = !m_Show;
using (var entityArray = m_CaretGroup.ToEntityArray(Allocator.TempJob))
{
for (int i = 0; i < entityArray.Length; i++)
{
var entity = entityArray[i];
var caret = EntityManager.GetComponentData<InputFieldCaret>(entity);
var inputFieldEntity = caret.InputFieldEntity;
var inputField = EntityManager.GetComponentData<InputField>(inputFieldEntity);
var caretState = EntityManager.GetComponentData<InputFieldCaretState>(inputFieldEntity);
var controlVertexData = EntityManager.GetBuffer<ElementVertexData>(entity);
var controlVertexIndex = EntityManager.GetBuffer<ElementVertexIndex>(entity);
var rect = TextUtils.GetCaretRect(inputField.Target, EntityManager, caretState.CaretPosition);
controlVertexData.Clear();
controlVertexIndex.Clear();
var color = m_Show
? new float4(0.0f, 0.0f, 0.0f, 1.0f)
: new float4(0.0f, 0.0f, 0.0f, 0.0f);
controlVertexData.Add(new ElementVertexData()
{
Color = color,
Normal = new float3(0.0f, 0.0f, -1.0f),
Position = new float3(rect.Min, 0.0f),
TexCoord0 = new float2(0.0f)
});
controlVertexData.Add(new ElementVertexData()
{
Color = color,
Normal = new float3(0.0f, 0.0f, -1.0f),
Position = new float3(rect.Max.x, rect.Min.y, 0.0f),
TexCoord0 = new float2(0.0f)
});
controlVertexData.Add(new ElementVertexData()
{
Color = color,
Normal = new float3(0.0f, 0.0f, -1.0f),
Position = new float3(rect.Max.x, rect.Max.y, 0.0f),
TexCoord0 = new float2(0.0f)
});
controlVertexData.Add(new ElementVertexData()
{
Color = color,
Normal = new float3(0.0f, 0.0f, -1.0f),
Position = new float3(rect.Min.x, rect.Max.y, 0.0f),
TexCoord0 = new float2(0.0f)
});
controlVertexIndex.Add(0);
controlVertexIndex.Add(3);
controlVertexIndex.Add(2);
controlVertexIndex.Add(2);
controlVertexIndex.Add(1);
controlVertexIndex.Add(0);
EntityManager.AddComponent(inputFieldEntity, typeof(DirtyElementFlag));
}
}
}
return inputDeps;
}
}
}