@@ -39,18 +39,14 @@ public class ClientCharacterVisualization : NetworkBehaviour
39
39
/// </summary>
40
40
public Material ReticuleFriendlyMat => m_VisualizationConfiguration . ReticuleFriendlyMat ;
41
41
42
- /// <summary>
43
- /// Returns our pseudo-Parent, the object that owns the visualization.
44
- /// (We don't have an actual transform parent because we're on a top-level GameObject.)
45
- /// </summary>
46
- public Transform Parent { get ; private set ; }
47
-
48
42
PhysicsWrapper m_PhysicsWrapper ;
49
43
50
44
public bool CanPerformActions => m_NetState . CanPerformActions ;
51
45
52
46
NetworkCharacterState m_NetState ;
53
47
48
+ public NetworkCharacterState NetState => m_NetState ;
49
+
54
50
ActionVisualization m_ActionViz ;
55
51
56
52
PositionLerper m_PositionLerper ;
@@ -64,20 +60,24 @@ public class ClientCharacterVisualization : NetworkBehaviour
64
60
65
61
Quaternion m_LerpedRotation ;
66
62
63
+ void Awake ( )
64
+ {
65
+ enabled = false ;
66
+ }
67
+
67
68
public override void OnNetworkSpawn ( )
68
69
{
69
70
if ( ! IsClient || transform . parent == null )
70
71
{
71
- enabled = false ;
72
72
return ;
73
73
}
74
74
75
+ enabled = true ;
76
+
75
77
m_ActionViz = new ActionVisualization ( this ) ;
76
78
77
79
m_NetState = GetComponentInParent < NetworkCharacterState > ( ) ;
78
80
79
- Parent = m_NetState . transform ;
80
-
81
81
m_PhysicsWrapper = m_NetState . GetComponent < PhysicsWrapper > ( ) ;
82
82
83
83
m_NetState . DoActionEventClient += PerformActionFX ;
@@ -99,7 +99,7 @@ public override void OnNetworkSpawn()
99
99
{
100
100
name = "AvatarGraphics" + m_NetState . OwnerClientId ;
101
101
102
- if ( Parent . TryGetComponent ( out ClientAvatarGuidHandler clientAvatarGuidHandler ) )
102
+ if ( m_NetState . TryGetComponent ( out ClientAvatarGuidHandler clientAvatarGuidHandler ) )
103
103
{
104
104
m_ClientVisualsAnimator = clientAvatarGuidHandler . graphicsAnimator ;
105
105
}
@@ -115,7 +115,7 @@ public override void OnNetworkSpawn()
115
115
m_ActionViz . PlayAction ( ref data ) ;
116
116
gameObject . AddComponent < CameraController > ( ) ;
117
117
118
- if ( Parent . TryGetComponent ( out ClientInputSender inputSender ) )
118
+ if ( m_NetState . TryGetComponent ( out ClientInputSender inputSender ) )
119
119
{
120
120
// TODO: revisit; anticipated actions would play twice on the host
121
121
if ( ! IsServer )
@@ -128,22 +128,8 @@ public override void OnNetworkSpawn()
128
128
}
129
129
}
130
130
131
- void OnActionInput ( ActionRequestData data )
132
- {
133
- m_ActionViz . AnticipateAction ( ref data ) ;
134
- }
135
-
136
- void OnMoveInput ( Vector3 position )
137
- {
138
- if ( ! IsAnimating ( ) )
139
- {
140
- OurAnimator . SetTrigger ( m_VisualizationConfiguration . AnticipateMoveTriggerID ) ;
141
- }
142
- }
143
-
144
- public override void OnDestroy ( )
131
+ public override void OnNetworkDespawn ( )
145
132
{
146
- base . OnDestroy ( ) ;
147
133
if ( m_NetState )
148
134
{
149
135
m_NetState . DoActionEventClient -= PerformActionFX ;
@@ -152,12 +138,27 @@ public override void OnDestroy()
152
138
m_NetState . OnStopChargingUpClient -= OnStoppedChargingUp ;
153
139
m_NetState . IsStealthy . OnValueChanged -= OnStealthyChanged ;
154
140
155
- if ( Parent != null && Parent . TryGetComponent ( out ClientInputSender sender ) )
141
+ if ( m_NetState . TryGetComponent ( out ClientInputSender sender ) )
156
142
{
157
143
sender . ActionInputEvent -= OnActionInput ;
158
144
sender . ClientMoveEvent -= OnMoveInput ;
159
145
}
160
146
}
147
+
148
+ enabled = false ;
149
+ }
150
+
151
+ void OnActionInput ( ActionRequestData data )
152
+ {
153
+ m_ActionViz . AnticipateAction ( ref data ) ;
154
+ }
155
+
156
+ void OnMoveInput ( Vector3 position )
157
+ {
158
+ if ( ! IsAnimating ( ) )
159
+ {
160
+ OurAnimator . SetTrigger ( m_VisualizationConfiguration . AnticipateMoveTriggerID ) ;
161
+ }
161
162
}
162
163
163
164
void PerformActionFX ( ActionRequestData data )
@@ -238,13 +239,6 @@ float GetVisualMovementSpeed()
238
239
239
240
void Update ( )
240
241
{
241
- if ( Parent == null )
242
- {
243
- // since we aren't in the transform hierarchy, we have to explicitly die when our parent dies.
244
- Destroy ( gameObject ) ;
245
- return ;
246
- }
247
-
248
242
// On the host, Characters are translated via ServerCharacterMovement's FixedUpdate method. To ensure that
249
243
// the game camera tracks a GameObject moving in the Update loop and therefore eliminate any camera jitter,
250
244
// this graphics GameObject's position is smoothed over time on the host. Clients do not need to perform any
0 commit comments