-
Notifications
You must be signed in to change notification settings - Fork 1
/
PredictedRigidBodyHelper.cs
39 lines (32 loc) · 1.1 KB
/
PredictedRigidBodyHelper.cs
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
namespace SavageCodes.Networking.ClientSidePrediction
{
public class PredictedRigidBodyHelper : NetworkBehaviour
{
private Rigidbody _rigidbody;
private PredictedNetworkMovement _predictedMovement;
void Start()
{
_predictedMovement = GetComponent<PredictedNetworkMovement>();
_rigidbody = GetComponent<Rigidbody>();
if (!isServer && !isLocalPlayer)
{
_rigidbody.isKinematic = true;
return;
}
PhysicsNetworkUpdater.Instance.CreatePhysicsSceneForGO(this.gameObject);
_predictedMovement.InputProcessorComponent.OnInputExecuted += OnInputProcessedAndExecuted;
}
public void OnInputProcessedAndExecuted()
{
PhysicsNetworkUpdater.Instance.UpdatePhysics(_predictedMovement);
}
void OnDestroy()
{
PhysicsNetworkUpdater.Instance.DestroyPhysicsSceneOfGO(this.gameObject);
}
}
}