forked from Unity-Technologies/ECS-Network-Racing-Sample
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUpdateEndRaceCameraSystem.cs
More file actions
82 lines (72 loc) · 2.41 KB
/
Copy pathUpdateEndRaceCameraSystem.cs
File metadata and controls
82 lines (72 loc) · 2.41 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
using Unity.Entities.Racing.Common;
using Unity.NetCode;
using Unity.Transforms;
using UnityEngine;
using static Unity.Entities.SystemAPI;
namespace Unity.Entities.Racing.Gameplay
{
/// <summary>
/// Plays the camera transition ending
/// when the player has finished the race.
/// </summary>
[UpdateAfter(typeof(TransformSystemGroup))]
[WorldSystemFilter(WorldSystemFilterFlags.ClientSimulation)]
public partial class UpdateEndRaceCameraSystem : SystemBase
{
private Entity m_CurrentTarget;
private Transform m_TargetTransform;
protected override void OnCreate()
{
RequireForUpdate<Race>();
RequireForUpdate<LocalUser>();
}
protected override void OnStartRunning()
{
var cinematicTarget = GameObject.FindWithTag("FinalCinematicTarget");
if (cinematicTarget == null)
{
Enabled = false;
return;
}
m_TargetTransform = cinematicTarget.transform;
base.OnStartRunning();
}
protected override void OnUpdate()
{
var race = SystemAPI.GetSingleton<Race>();
if (!race.IsFinishing)
{
return;
}
var playerHasFinished = false;
foreach (var player in Query<RefRO<Player>>().WithAll<LocalUser>())
{
if (player.ValueRO.HasFinished)
{
playerHasFinished = true;
}
}
if (playerHasFinished)
{
// Search the next car in the Rank
foreach (var (rank, entity) in Query<RefRO<Rank>>()
.WithAll<GhostOwner>()
.WithAll<Player>().WithEntityAccess())
{
if (rank.ValueRO.Value == race.PlayersFinished + 1)
{
m_CurrentTarget = entity;
break;
}
}
TimelineManager.Instance.SwitchToNearestCamera();
}
if (!EntityManager.Exists(m_CurrentTarget))
{
return;
}
var targetPosition = EntityManager.GetComponentData<LocalTransform>(m_CurrentTarget);
m_TargetTransform.position = targetPosition.Position;
}
}
}