Skip to content

Commit f60c92a

Browse files
separation of pickup and hold actions, can visualize drop on action bar
1 parent 6042602 commit f60c92a

File tree

17 files changed

+141
-141
lines changed

17 files changed

+141
-141
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:233623c213dbc645c5c3a93da5963445fbb7028c9b8abaa24b684d5f90e3ee8b
3+
size 979

Assets/GameData/Action/General/Drop.asset.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:d66a4c5142547c017fb54aa3d881abc43eca7d5f4b74bc800d4439b31b4081d5
3-
size 997
2+
oid sha256:912155f31fbc6d9317b07ef92e5c7affee747fba3c8bd711179339fec38ab44b
3+
size 1023

Assets/Prefabs/Character/PlayerAvatar.prefab

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -220,17 +220,6 @@ MonoBehaviour:
220220
m_Script: {fileID: 11500000, guid: 4a3a07abfb44d50469112a0db6a202b2, type: 3}
221221
m_Name:
222222
m_EditorClassIdentifier:
223-
--- !u!114 &6009713983291384752 stripped
224-
MonoBehaviour:
225-
m_CorrespondingSourceObject: {fileID: 4600110157238723777, guid: 0d2d836e2e83b754fa1a1c4022d6d65d, type: 3}
226-
m_PrefabInstance: {fileID: 7831782662127126385}
227-
m_PrefabAsset: {fileID: 0}
228-
m_GameObject: {fileID: 6009713983291384756}
229-
m_Enabled: 1
230-
m_EditorHideFlags: 0
231-
m_Script: {fileID: 11500000, guid: edb78c1621dad5149bb47b96120d3fbf, type: 3}
232-
m_Name:
233-
m_EditorClassIdentifier:
234223
--- !u!1 &6009713983291384756 stripped
235224
GameObject:
236225
m_CorrespondingSourceObject: {fileID: 4600110157238723781, guid: 0d2d836e2e83b754fa1a1c4022d6d65d, type: 3}
@@ -350,20 +339,6 @@ MonoBehaviour:
350339
m_Name:
351340
m_EditorClassIdentifier:
352341
m_PlayerAvatars: {fileID: 11400000, guid: 13c227b8a2f5f5f4a8c252835aaf648f, type: 2}
353-
--- !u!114 &6387032110594377642
354-
MonoBehaviour:
355-
m_ObjectHideFlags: 0
356-
m_CorrespondingSourceObject: {fileID: 0}
357-
m_PrefabInstance: {fileID: 0}
358-
m_PrefabAsset: {fileID: 0}
359-
m_GameObject: {fileID: 6009713983291384756}
360-
m_Enabled: 1
361-
m_EditorHideFlags: 0
362-
m_Script: {fileID: 11500000, guid: 0e59f6113deae61408ad63553733ed77, type: 3}
363-
m_Name:
364-
m_EditorClassIdentifier:
365-
m_NetworkLifeState: {fileID: 6173771494986166194}
366-
m_NetworkCharacterState: {fileID: 6009713983291384752}
367342
--- !u!114 &6940323159316181846
368343
MonoBehaviour:
369344
m_ObjectHideFlags: 0

Assets/Prefabs/GameDataSource.prefab

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,4 @@ MonoBehaviour:
7878
- {fileID: 11400000, guid: f129c86376940384fb96b3512705c6e2, type: 2}
7979
- {fileID: 11400000, guid: 723a546f69cc50543b7b04f8277d26b5, type: 2}
8080
- {fileID: 11400000, guid: fc0a156ae5548e949a1b3dd3b5f27ad6, type: 2}
81+
- {fileID: 11400000, guid: ab3f9292f9b310a4795d26885e92a5d1, type: 2}

Assets/Scripts/Gameplay/Action/Action.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ public static Action MakeAction(ServerCharacter parent, ref ActionRequestData da
176176
case ActionLogic.DashAttack: return new DashAttackAction(parent, ref data);
177177
case ActionLogic.ImpToss: return new TossAction(parent, ref data);
178178
case ActionLogic.PickUp: return new PickUpAction(parent, ref data);
179+
case ActionLogic.Drop: return new DropAction(parent, ref data);
179180
default: throw new System.NotImplementedException();
180181
}
181182
}

Assets/Scripts/Gameplay/Action/ActionFX.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ public static ActionFX MakeActionFX(ref ActionRequestData data, ClientCharacterV
7979
case ActionLogic.DashAttack: return new DashAttackActionFX(ref data, parent);
8080

8181
case ActionLogic.PickUp:
82+
case ActionLogic.Drop:
8283
case ActionLogic.Stunned:
8384
case ActionLogic.LaunchProjectile:
8485
case ActionLogic.Revive:

Assets/Scripts/Gameplay/Action/ActionPlayer.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ public ActionPlayer(ServerCharacter parent)
4343
/// </summary>
4444
public void PlayAction(ref ActionRequestData action)
4545
{
46-
if (!action.ShouldQueue && m_Queue.Count > 0 && m_Queue[0].Description.ActionInterruptible)
46+
if (!action.ShouldQueue && m_Queue.Count > 0 &&
47+
(m_Queue[0].Description.ActionInterruptible ||
48+
m_Queue[0].Description.IsInterruptableBy.Contains(action.ActionTypeEnum)));
4749
{
4850
ClearActions(false);
4951
}

Assets/Scripts/Gameplay/Action/ActionRequestData.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ public enum ActionType
3535
ArcherVolley,
3636
RogueDashAttack,
3737
ImpToss,
38-
PickUp
38+
PickUp,
39+
Drop
3940
}
4041

4142

@@ -60,7 +61,8 @@ public enum ActionLogic
6061
StealthMode,
6162
DashAttack,
6263
ImpToss,
63-
PickUp
64+
PickUp,
65+
Drop
6466
//O__O adding a new ActionLogic branch? Update Action.MakeAction!
6567
}
6668

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using System;
2+
using Unity.Netcode;
3+
using UnityEngine;
4+
5+
namespace Unity.Multiplayer.Samples.BossRoom.Server
6+
{
7+
/// <summary>
8+
/// Action for dropping "Heavy" items.
9+
/// </summary>
10+
public class DropAction : Action
11+
{
12+
float m_ActionStartTime;
13+
14+
NetworkObject m_HeldNetworkObject;
15+
16+
public DropAction(ServerCharacter parent, ref ActionRequestData data) : base(parent, ref data)
17+
{
18+
}
19+
20+
public override bool Start()
21+
{
22+
m_ActionStartTime = Time.time;
23+
24+
// play animation of dropping a heavy object, if one is already held
25+
if (NetworkManager.Singleton.SpawnManager.SpawnedObjects.TryGetValue(
26+
m_Parent.NetState.heldNetworkObject.Value, out var heldObject))
27+
{
28+
m_HeldNetworkObject = heldObject;
29+
30+
Data.TargetIds = null;
31+
32+
if (!string.IsNullOrEmpty(Description.Anim))
33+
{
34+
m_Parent.serverAnimationHandler.NetworkAnimator.SetTrigger(Description.Anim);
35+
}
36+
}
37+
38+
return true;
39+
}
40+
41+
public override bool Update()
42+
{
43+
if (Time.time > m_ActionStartTime + Description.ExecTimeSeconds)
44+
{
45+
// drop the pot in space
46+
m_HeldNetworkObject.transform.SetParent(null);
47+
m_Parent.NetState.heldNetworkObject.Value = 0;
48+
49+
return ActionConclusion.Stop;
50+
}
51+
52+
return ActionConclusion.Continue;
53+
}
54+
}
55+
}

Assets/Scripts/Gameplay/GameplayObjects/ServerDropItemOnFaint.cs.meta renamed to Assets/Scripts/Gameplay/Action/DropAction.cs.meta

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Scripts/Gameplay/Action/PickUpAction.cs

Lines changed: 40 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -18,66 +18,42 @@ public class PickUpAction : Action
1818

1919
const string k_NpcLayer = "NPCs";
2020

21-
const float k_PickUpWait = 0.6f;
22-
2321
const string k_FailedPickupTrigger = "PickUpFailed";
2422

25-
float m_AnimationTimer;
23+
float m_ActionStartTime;
2624

2725
static RaycastHitComparer s_RaycastHitComparer;
2826

27+
NetworkLifeState m_NetworkLifeState;
28+
29+
bool m_AttemptedPickup;
30+
2931
public PickUpAction(ServerCharacter parent, ref ActionRequestData data) : base(parent, ref data)
3032
{
3133
s_RaycastHitComparer ??= new RaycastHitComparer();
34+
35+
m_NetworkLifeState = m_Parent.NetState.NetworkLifeState;
3236
}
3337

3438
public override bool Start()
3539
{
36-
// play animation based on if a heavy object is already held and start timer
37-
if (NetworkManager.Singleton.SpawnManager.SpawnedObjects.TryGetValue(m_Parent.NetState.heldNetworkObject.Value, out var heldObject))
38-
{
39-
Data.TargetIds = null;
40+
m_ActionStartTime = Time.time;
4041

41-
if (!string.IsNullOrEmpty(Description.Anim))
42-
{
43-
m_Parent.serverAnimationHandler.NetworkAnimator.ResetTrigger(Description.Anim);
44-
}
45-
46-
// drop
47-
if (!string.IsNullOrEmpty(Description.Anim2))
48-
{
49-
m_Parent.serverAnimationHandler.NetworkAnimator.SetTrigger(Description.Anim2);
50-
}
51-
}
52-
else
42+
// play pickup animation based if a heavy object is not already held
43+
if (!NetworkManager.Singleton.SpawnManager.SpawnedObjects.TryGetValue(
44+
m_Parent.NetState.heldNetworkObject.Value, out var heldObject))
5345
{
54-
if (!string.IsNullOrEmpty(Description.Anim2))
55-
{
56-
m_Parent.serverAnimationHandler.NetworkAnimator.ResetTrigger(Description.Anim2);
57-
}
58-
59-
// pickup
6046
if (!string.IsNullOrEmpty(Description.Anim))
6147
{
6248
m_Parent.serverAnimationHandler.NetworkAnimator.SetTrigger(Description.Anim);
6349
}
6450
}
6551

66-
m_AnimationTimer = k_PickUpWait;
67-
6852
return true;
6953
}
7054

71-
void PickUpOrDrop()
55+
bool TryPickUp()
7256
{
73-
if (NetworkManager.Singleton.SpawnManager.SpawnedObjects.TryGetValue(m_Parent.NetState.heldNetworkObject.Value, out var heldObject))
74-
{
75-
// pickup object found inside of hierarchy; drop it
76-
m_Parent.NetState.heldNetworkObject.Value = 0;
77-
heldObject.transform.SetParent(null);
78-
return;
79-
}
80-
8157
var numResults = Physics.RaycastNonAlloc(m_Parent.physicsWrapper.Transform.position,
8258
m_Parent.physicsWrapper.Transform.forward,
8359
m_RaycastHits,
@@ -86,28 +62,16 @@ void PickUpOrDrop()
8662

8763
Array.Sort(m_RaycastHits, 0, numResults, s_RaycastHitComparer);
8864

89-
// collider must contain "Heavy" tag
65+
// collider must contain "Heavy" tag, the heavy object must not be parented to another NetworkObject, and
66+
// parenting attempt must be successful
9067
if (numResults == 0 || !m_RaycastHits[0].collider.TryGetComponent(out NetworkObject heavyNetworkObject) ||
91-
!m_RaycastHits[0].collider.gameObject.CompareTag(k_HeavyTag))
92-
{
93-
m_Parent.serverAnimationHandler.NetworkAnimator.SetTrigger(k_FailedPickupTrigger);
94-
return;
95-
}
96-
97-
// found a suitable collider; make sure it is not already held by another player
98-
if (heavyNetworkObject.transform.parent != null &&
99-
heavyNetworkObject.transform.parent.TryGetComponent(out NetworkObject parentNetworkObject))
68+
!m_RaycastHits[0].collider.gameObject.CompareTag(k_HeavyTag) ||
69+
(heavyNetworkObject.transform.parent != null &&
70+
heavyNetworkObject.transform.parent.TryGetComponent(out NetworkObject parentNetworkObject)) ||
71+
!heavyNetworkObject.TrySetParent(m_Parent.transform))
10072
{
101-
// pot already parented; return for now
10273
m_Parent.serverAnimationHandler.NetworkAnimator.SetTrigger(k_FailedPickupTrigger);
103-
return;
104-
}
105-
106-
// found a suitable collider; try to child this NetworkObject
107-
if (!heavyNetworkObject.TrySetParent(m_Parent.transform))
108-
{
109-
m_Parent.serverAnimationHandler.NetworkAnimator.SetTrigger(k_FailedPickupTrigger);
110-
return;
74+
return false;
11175
}
11276

11377
m_Parent.NetState.heldNetworkObject.Value = heavyNetworkObject.NetworkObjectId;
@@ -138,20 +102,35 @@ void PickUpOrDrop()
138102
positionConstraint.constraintActive = true;
139103
}
140104
}
105+
106+
return true;
141107
}
142108

143109
public override bool Update()
144110
{
145-
m_AnimationTimer -= Time.deltaTime;
146-
147-
if (m_AnimationTimer <= 0f)
111+
if (!m_AttemptedPickup && Time.time > m_ActionStartTime + Description.ExecTimeSeconds)
148112
{
149-
PickUpOrDrop();
150-
151-
return ActionConclusion.Stop;
113+
m_AttemptedPickup = true;
114+
if (!TryPickUp())
115+
{
116+
// pickup attempt unsuccessful; action can be terminated
117+
return ActionConclusion.Stop;
118+
}
152119
}
153120

154121
return ActionConclusion.Continue;
155122
}
123+
124+
public override void Cancel()
125+
{
126+
if (m_NetworkLifeState.LifeState.Value == LifeState.Fainted)
127+
{
128+
if (NetworkManager.Singleton.SpawnManager.SpawnedObjects.TryGetValue(m_Parent.NetState.heldNetworkObject.Value, out var heavyNetworkObject))
129+
{
130+
heavyNetworkObject.transform.SetParent(null);
131+
}
132+
m_Parent.NetState.heldNetworkObject.Value = 0;
133+
}
134+
}
156135
}
157136
}

Assets/Scripts/Gameplay/Configuration/ActionDescription.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using UnityEngine;
34

45
namespace Unity.Multiplayer.Samples.BossRoom
@@ -73,6 +74,9 @@ public class ActionDescription : ScriptableObject
7374
[Tooltip("Is this Action interruptible by other action-plays or by movement? (Implicitly stops movement when action starts.) Generally, actions with short exec times should not be interruptible in this way.")]
7475
public bool ActionInterruptible;
7576

77+
[Tooltip("This action is interrupted if an action of any of the following types is requested")]
78+
public List<ActionType> IsInterruptableBy;
79+
7680
[System.Serializable]
7781
public enum BlockingModeType
7882
{

Assets/Scripts/Gameplay/GameplayObjects/Character/ServerCharacter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,6 @@ void ReceiveHP(ServerCharacter inflicter, int HP)
235235
//that's handled by a separate function.
236236
if (NetState.HitPoints <= 0)
237237
{
238-
m_ActionPlayer.ClearActions(false);
239-
240238
if (IsNpc)
241239
{
242240
if (m_KilledDestroyDelaySeconds >= 0.0f && NetState.LifeState != LifeState.Dead)
@@ -250,6 +248,8 @@ void ReceiveHP(ServerCharacter inflicter, int HP)
250248
{
251249
NetState.LifeState = LifeState.Fainted;
252250
}
251+
252+
m_ActionPlayer.ClearActions(false);
253253
}
254254
}
255255

0 commit comments

Comments
 (0)