3
3
using Unity . BossRoom . Gameplay . UserInput ;
4
4
using Unity . BossRoom . Gameplay . GameplayObjects ;
5
5
using Unity . BossRoom . Gameplay . GameplayObjects . Character ;
6
- using Unity . Netcode ;
7
6
using UnityEngine ;
8
7
using Action = Unity . BossRoom . Gameplay . Actions . Action ;
9
8
using SkillTriggerStyle = Unity . BossRoom . Gameplay . UserInput . ClientInputSender . SkillTriggerStyle ;
@@ -41,22 +40,6 @@ public class HeroActionBar : MonoBehaviour
41
40
/// </summary>
42
41
ClientInputSender m_InputSender ;
43
42
44
- /// <summary>
45
- /// Cached reference to local player's net state.
46
- /// We find the Sprites to use by checking the Skill1, Skill2, and Skill3 members of our chosen CharacterClass
47
- /// </summary>
48
- ServerCharacter m_ServerCharacter ;
49
-
50
- /// <summary>
51
- /// If we have another player selected, this is a reference to their stats; if anything else is selected, this is null
52
- /// </summary>
53
- ServerCharacter m_SelectedPlayerServerCharacter ;
54
-
55
- /// <summary>
56
- /// If m_SelectedPlayerNetState is non-null, this indicates whether we think they're alive. (Updated every frame)
57
- /// </summary>
58
- bool m_WasSelectedPlayerAliveDuringLastUpdate ;
59
-
60
43
/// <summary>
61
44
/// Identifiers for the buttons on the action bar.
62
45
/// </summary>
@@ -139,26 +122,46 @@ void RegisterInputSender(ClientPlayerAvatar clientPlayerAvatar)
139
122
}
140
123
141
124
m_InputSender = inputSender ;
142
- m_ServerCharacter = m_InputSender . GetComponent < ServerCharacter > ( ) ;
143
- m_ServerCharacter . TargetId . OnValueChanged += OnSelectionChanged ;
144
- m_ServerCharacter . HeldNetworkObject . OnValueChanged += OnHeldNetworkObjectChanged ;
145
- UpdateAllActionButtons ( ) ;
125
+ m_InputSender . action1ModifiedCallback += Action1ModifiedCallback ;
126
+
127
+ Action action1 = null ;
128
+ if ( m_InputSender . actionState1 != null )
129
+ {
130
+ GameDataSource . Instance . TryGetActionPrototypeByID ( m_InputSender . actionState1 . actionID , out action1 ) ;
131
+ }
132
+ UpdateActionButton ( m_ButtonInfo [ ActionButtonType . BasicAction ] , action1 ) ;
133
+
134
+ Action action2 = null ;
135
+ if ( m_InputSender . actionState2 != null )
136
+ {
137
+ GameDataSource . Instance . TryGetActionPrototypeByID ( m_InputSender . actionState2 . actionID , out action2 ) ;
138
+ }
139
+ UpdateActionButton ( m_ButtonInfo [ ActionButtonType . Special1 ] , action2 ) ;
140
+
141
+ Action action3 = null ;
142
+ if ( m_InputSender . actionState3 != null )
143
+ {
144
+ GameDataSource . Instance . TryGetActionPrototypeByID ( m_InputSender . actionState3 . actionID , out action3 ) ;
145
+ }
146
+ UpdateActionButton ( m_ButtonInfo [ ActionButtonType . Special2 ] , action3 ) ;
146
147
}
147
148
148
- void OnHeldNetworkObjectChanged ( ulong previousValue , ulong newValue )
149
+ void Action1ModifiedCallback ( )
149
150
{
150
- UpdateAllActionButtons ( ) ;
151
+ var action = GameDataSource . Instance . GetActionPrototypeByID ( m_InputSender . actionState1 . actionID ) ;
152
+
153
+ UpdateActionButton ( m_ButtonInfo [ ActionButtonType . BasicAction ] ,
154
+ action ,
155
+ m_InputSender . actionState1 . selectable ) ;
151
156
}
152
157
153
158
void DeregisterInputSender ( )
154
159
{
155
- m_InputSender = null ;
156
- if ( m_ServerCharacter != null )
160
+ if ( m_InputSender )
157
161
{
158
- m_ServerCharacter . TargetId . OnValueChanged -= OnSelectionChanged ;
159
- m_ServerCharacter . HeldNetworkObject . OnValueChanged -= OnHeldNetworkObjectChanged ;
162
+ m_InputSender . action1ModifiedCallback -= Action1ModifiedCallback ;
160
163
}
161
- m_ServerCharacter = null ;
164
+ m_InputSender = null ;
162
165
}
163
166
164
167
void Awake ( )
@@ -201,29 +204,10 @@ void OnDestroy()
201
204
202
205
void Update ( )
203
206
{
204
- // If we have another player selected, see if their aliveness state has changed,
205
- // and if so, update the interactiveness of the basic-action button
206
-
207
- if ( UnityEngine . Input . GetKeyUp ( KeyCode . Alpha4 ) )
207
+ if ( Input . GetKeyUp ( KeyCode . Alpha4 ) )
208
208
{
209
209
m_ButtonInfo [ ActionButtonType . EmoteBar ] . Button . OnPointerUpEvent . Invoke ( ) ;
210
210
}
211
-
212
- if ( ! m_SelectedPlayerServerCharacter ) { return ; }
213
-
214
- bool isAliveNow = m_SelectedPlayerServerCharacter . NetLifeState . LifeState . Value == LifeState . Alive ;
215
- if ( isAliveNow != m_WasSelectedPlayerAliveDuringLastUpdate )
216
- {
217
- // this will update the icons so that the basic-action button's interactiveness is correct
218
- UpdateAllActionButtons ( ) ;
219
- }
220
-
221
- m_WasSelectedPlayerAliveDuringLastUpdate = isAliveNow ;
222
- }
223
-
224
- void OnSelectionChanged ( ulong oldSelectionNetworkId , ulong newSelectionNetworkId )
225
- {
226
- UpdateAllActionButtons ( ) ;
227
211
}
228
212
229
213
void OnButtonClickedDown ( ActionButtonType buttonType )
@@ -240,7 +224,7 @@ void OnButtonClickedDown(ActionButtonType buttonType)
240
224
}
241
225
242
226
// send input to begin the action associated with this button
243
- m_InputSender . RequestAction ( m_ButtonInfo [ buttonType ] . CurAction , SkillTriggerStyle . UI ) ;
227
+ m_InputSender . RequestAction ( m_ButtonInfo [ buttonType ] . CurAction . ActionID , SkillTriggerStyle . UI ) ;
244
228
}
245
229
246
230
void OnButtonClickedUp ( ActionButtonType buttonType )
@@ -258,61 +242,7 @@ void OnButtonClickedUp(ActionButtonType buttonType)
258
242
}
259
243
260
244
// send input to complete the action associated with this button
261
- m_InputSender . RequestAction ( m_ButtonInfo [ buttonType ] . CurAction , SkillTriggerStyle . UIRelease ) ;
262
- }
263
-
264
- /// <summary>
265
- /// Updates all the action buttons and caches info about the currently-selected entity (when appropriate):
266
- /// stores info in m_SelectedPlayerNetState and m_WasSelectedPlayerAliveDuringLastUpdate
267
- /// </summary>
268
- void UpdateAllActionButtons ( )
269
- {
270
- UpdateActionButton ( m_ButtonInfo [ ActionButtonType . BasicAction ] , m_ServerCharacter . CharacterClass . Skill1 ) ;
271
- UpdateActionButton ( m_ButtonInfo [ ActionButtonType . Special1 ] , m_ServerCharacter . CharacterClass . Skill2 ) ;
272
- UpdateActionButton ( m_ButtonInfo [ ActionButtonType . Special2 ] , m_ServerCharacter . CharacterClass . Skill3 ) ;
273
-
274
- var isHoldingNetworkObject =
275
- NetworkManager . Singleton . SpawnManager . SpawnedObjects . TryGetValue ( m_ServerCharacter . HeldNetworkObject . Value ,
276
- out var heldNetworkObject ) ;
277
-
278
- NetworkManager . Singleton . SpawnManager . SpawnedObjects . TryGetValue ( m_ServerCharacter . TargetId . Value ,
279
- out var selection ) ;
280
-
281
- if ( isHoldingNetworkObject )
282
- {
283
- // show drop!
284
- UpdateActionButton ( m_ButtonInfo [ ActionButtonType . BasicAction ] , GameDataSource . Instance . DropActionPrototype , true ) ;
285
- }
286
- if ( ( m_ServerCharacter . TargetId . Value != 0
287
- && selection != null
288
- && selection . TryGetComponent ( out PickUpState pickUpState ) )
289
- )
290
- {
291
- // special case: targeting a pickup-able item or holding a pickup object
292
- UpdateActionButton ( m_ButtonInfo [ ActionButtonType . BasicAction ] , GameDataSource . Instance . PickUpActionPrototype , true ) ;
293
- }
294
- else if ( m_ServerCharacter . TargetId . Value != 0
295
- && selection != null
296
- && selection . NetworkObjectId != m_ServerCharacter . NetworkObjectId
297
- && selection . TryGetComponent ( out ServerCharacter charState )
298
- && ! charState . IsNpc )
299
- {
300
- // special case: when we have a player selected, we change the meaning of the basic action
301
- // we have another player selected! In that case we want to reflect that our basic Action is a Revive, not an attack!
302
- // But we need to know if the player is alive... if so, the button should be disabled (for better player communication)
303
-
304
- bool isAlive = charState . NetLifeState . LifeState . Value == LifeState . Alive ;
305
- UpdateActionButton ( m_ButtonInfo [ ActionButtonType . BasicAction ] , GameDataSource . Instance . ReviveActionPrototype , ! isAlive ) ;
306
-
307
- // we'll continue to monitor our selected player every frame to see if their life-state changes.
308
- m_SelectedPlayerServerCharacter = charState ;
309
- m_WasSelectedPlayerAliveDuringLastUpdate = isAlive ;
310
- }
311
- else
312
- {
313
- m_SelectedPlayerServerCharacter = null ;
314
- m_WasSelectedPlayerAliveDuringLastUpdate = false ;
315
- }
245
+ m_InputSender . RequestAction ( m_ButtonInfo [ buttonType ] . CurAction . ActionID , SkillTriggerStyle . UIRelease ) ;
316
246
}
317
247
318
248
void UpdateActionButton ( ActionButtonInfo buttonInfo , Action action , bool isClickable = true )
0 commit comments