forked from Unity-Technologies/ECS-Network-Racing-Sample
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayerProgress.cs
More file actions
92 lines (80 loc) · 2.7 KB
/
Copy pathPlayerProgress.cs
File metadata and controls
92 lines (80 loc) · 2.7 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
using System.Collections.Generic;
using Unity.Burst;
using Unity.Mathematics;
using Unity.NetCode;
namespace Unity.Entities.Racing.Common
{
/// <summary>
/// Stores player progress in the game
/// </summary>
public struct LapProgress : IComponentData
{
[GhostField] public int CurrentCheckPoint;
[GhostField] public int LapCount;
[GhostField] public int CurrentLap;
[GhostField] public float3 LastCheckPointPosition;
[GhostField] public bool AddedToLeaderboard;
[GhostField] public float CelebrationIdleDelay;
[GhostField] public double ArrivalTime;
public int NextPointId => CurrentCheckPoint + 1;
public bool HasArrived => ArrivalTime > 0;
public void Reset(int lapCount = 1)
{
CurrentCheckPoint = 0;
CurrentLap = 1;
AddedToLeaderboard = false;
LapCount = lapCount;
CelebrationIdleDelay = 0;
ArrivalTime = 0;
}
}
/// <summary>
/// Access the player's progress data to do a comparison process
/// </summary>
public struct SortableProgress
{
public float Distance;
public LapProgress Progress;
public Entity Entity;
public int Rank;
}
/// <summary>
/// Executes comparison between rank parameters
/// </summary>
[BurstCompile]
public struct SortableRankComparer : IComparer<SortableProgress>
{
public int Compare(SortableProgress x, SortableProgress y)
{
return y.Rank.CompareTo(x.Rank);
}
}
/// <summary>
/// Executes comparison between progress parameters
/// </summary>
[BurstCompile]
public struct SortableProgressComparer : IComparer<SortableProgress>
{
public int Compare(SortableProgress x, SortableProgress y)
{
if(x.Progress.HasArrived && y.Progress.HasArrived)
return x.Progress.ArrivalTime.CompareTo(y.Progress.ArrivalTime);
if (x.Progress.HasArrived || y.Progress.HasArrived)
return y.Progress.HasArrived.CompareTo(x.Progress.HasArrived);
if (x.Progress.CurrentLap != y.Progress.CurrentLap)
return y.Progress.CurrentLap.CompareTo(x.Progress.CurrentLap);
if (x.Progress.CurrentCheckPoint == y.Progress.CurrentCheckPoint)
{
return y.Distance.CompareTo(x.Distance);
}
return y.Progress.CurrentCheckPoint.CompareTo(x.Progress.CurrentCheckPoint);
}
}
/// <summary>
/// Stores the current rank in the leaderboard
/// </summary>
public struct Rank : IComponentData
{
[GhostField] public int Value;
}
}