Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Multiplayer-arena-game
/
Multiplayer-arena-game-GameObjects
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
ac0e80cf
authored
Jan 21, 2025
by
alsunj
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove updating righthanditemvalue for clients
parent
2d41ea35
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
87 additions
and
35 deletions
Assets/_Game/Code/Explosives/Explosive.cs
Assets/_Game/Code/Pickupable/IPickupable.cs
Assets/_Game/Code/Pickupable/Key/Key.cs
Assets/_Game/Code/Pickupable/Pickupable.cs
Assets/_Game/Code/Player/PlayerController.cs
Assets/_Game/Code/Player/PlayerPlacements.cs
Assets/_Game/Code/Explosives/Explosive.cs
View file @
ac0e80cf
...
...
@@ -17,12 +17,12 @@ public class Explosive : Pickupable, IExplosive
throw
new
System
.
NotImplementedException
();
}
public
override
void
Pickup
(
GameObject
pickupingTarget
)
public
override
void
Pickup
()
{
_boxCollider
.
isTrigger
=
true
;
}
public
override
void
PutDown
(
Vector3
position
)
public
override
void
PutDown
()
{
_boxCollider
.
isTrigger
=
false
;
// transform.position = position;
...
...
Assets/_Game/Code/Pickupable/IPickupable.cs
View file @
ac0e80cf
...
...
@@ -2,6 +2,6 @@ using UnityEngine;
public
interface
IPickupable
{
public
void
Pickup
(
GameObject
targetobject
);
public
void
PutDown
(
Vector3
position
);
public
void
Pickup
();
public
void
PutDown
();
}
\ No newline at end of file
Assets/_Game/Code/Pickupable/Key/Key.cs
View file @
ac0e80cf
...
...
@@ -13,16 +13,14 @@ public class Key : Pickupable, IPickupable
}
public
override
void
Pickup
(
GameObject
pickupingTarget
)
public
override
void
Pickup
()
{
_boxCollider
.
isTrigger
=
true
;
}
public
override
void
PutDown
(
Vector3
position
)
public
override
void
PutDown
()
{
_boxCollider
.
isTrigger
=
false
;
// transform.position = position;
// transform.rotation = _startingRotation;
}
}
\ No newline at end of file
Assets/_Game/Code/Pickupable/Pickupable.cs
View file @
ac0e80cf
...
...
@@ -2,7 +2,7 @@ using System;
using
Unity.Netcode
;
using
UnityEngine
;
public
abstract
class
Pickupable
:
NetworkBehaviour
,
IEquatable
<
Pickupable
>
public
abstract
class
Pickupable
:
NetworkBehaviour
,
IEquatable
<
Pickupable
>
,
IPickupable
{
private
NetworkVariable
<
bool
>
isObjectPickedup
=
new
NetworkVariable
<
bool
>();
private
FollowTransform
_followTransform
;
...
...
@@ -15,28 +15,45 @@ public abstract class Pickupable : NetworkBehaviour, IEquatable<Pickupable>
{
Debug
.
LogError
(
"FollowTransform component not found on the GameObject."
);
}
_startingRotation
=
transform
.
rotation
;
}
public
void
RequestPutDownObject
(
Vector3
position
)
public
void
RequestPutDownObject
(
NetworkObjectReference
pickupingTarget
)
{
RequestPutDownObjectServerRpc
(
p
osition
);
RequestPutDownObjectServerRpc
(
p
ickupingTarget
);
}
[
ServerRpc
(
RequireOwnership
=
false
)]
private
void
RequestPutDownObjectServerRpc
(
Vector3
position
)
private
void
RequestPutDownObjectServerRpc
(
NetworkObjectReference
pickupingTarget
)
{
if
(
isObjectPickedup
.
Value
)
{
isObjectPickedup
.
Value
=
false
;
_followTransform
.
SetTargetTransform
(
null
);
PutDownObjectClientRpc
(
position
);
Vector3
newPosition
=
Vector3
.
zero
;
if
(
pickupingTarget
.
TryGet
(
out
NetworkObject
target
))
{
newPosition
=
target
.
transform
.
position
+
target
.
transform
.
forward
;
PlayerPlacements
playerPlacements
=
target
.
GetComponent
<
PlayerPlacements
>();
if
(
playerPlacements
!=
null
)
{
playerPlacements
.
ClearPlayerRightHandItem
();
}
}
// Notify all clients to update their visuals
PutDownObjectClientRpc
(
newPosition
);
}
}
[
ClientRpc
]
private
void
PutDownObjectClientRpc
(
Vector3
p
osition
)
private
void
PutDownObjectClientRpc
(
Vector3
newP
osition
)
{
PutDown
(
position
);
_followTransform
.
SetTargetTransform
(
null
);
transform
.
position
=
newPosition
;
transform
.
rotation
=
_startingRotation
;
// Update the visuals on the client
PutDown
();
}
public
void
RequestPickupObject
(
NetworkObjectReference
pickupingTarget
)
...
...
@@ -56,11 +73,12 @@ public abstract class Pickupable : NetworkBehaviour, IEquatable<Pickupable>
PlayerPlacements
playerPlacements
=
target
.
GetComponent
<
PlayerPlacements
>();
if
(
playerPlacements
!=
null
)
{
playerPlacements
.
SetPlayerRightHandItem
ServerRpc
(
new
NetworkObjectReference
(
this
.
NetworkObject
));
playerPlacements
.
SetPlayerRightHandItem
(
new
NetworkObjectReference
(
this
.
NetworkObject
));
_followTransform
.
SetTargetTransform
(
playerPlacements
.
playerRightHand
.
transform
);
}
}
// Notify all clients to update their visuals
PickupObjectClientRpc
(
pickupingTarget
);
}
}
...
...
@@ -70,13 +88,19 @@ public abstract class Pickupable : NetworkBehaviour, IEquatable<Pickupable>
{
if
(
pickupingTarget
.
TryGet
(
out
NetworkObject
target
))
{
Pickup
(
target
.
gameObject
);
PlayerPlacements
playerPlacements
=
target
.
GetComponent
<
PlayerPlacements
>();
if
(
playerPlacements
!=
null
)
{
_followTransform
.
SetTargetTransform
(
playerPlacements
.
playerRightHand
.
transform
);
}
}
Pickup
();
}
public
abstract
void
PutDown
(
Vector3
position
);
public
abstract
void
PutDown
();
public
abstract
void
Pickup
(
GameObject
pickupingTarget
);
public
abstract
void
Pickup
();
public
bool
Equals
(
Pickupable
other
)
{
...
...
Assets/_Game/Code/Player/PlayerController.cs
View file @
ac0e80cf
...
...
@@ -146,6 +146,12 @@ public class PlayerController : NetworkBehaviour
{
_rb
.
isKinematic
=
false
;
}
_playerPlacements
=
GetComponent
<
PlayerPlacements
>();
if
(
_playerPlacements
==
null
)
{
Debug
.
LogError
(
"PlayerPlacements is null"
);
}
}
private
void
OnSprint
(
bool
state
)
...
...
@@ -377,9 +383,17 @@ public class PlayerController : NetworkBehaviour
private
void
PickupObject
(
Pickupable
pickupable
)
{
// if (!isRightHandFull)
// {
pickupable
.
RequestPickupObject
(
new
NetworkObjectReference
(
gameObject
.
GetComponent
<
NetworkObject
>()));
if
(!
_playerPlacements
.
IsRightHandFull
())
{
pickupable
.
RequestPickupObject
(
new
NetworkObjectReference
(
gameObject
.
GetComponent
<
NetworkObject
>()));
}
else
{
pickupable
.
RequestPutDownObject
(
new
NetworkObjectReference
(
gameObject
.
GetComponent
<
NetworkObject
>()));
}
//TODO: boolean should be set to true only if the object was picked up
// isRightHandFull = !isRightHandFull;
...
...
Assets/_Game/Code/Player/PlayerPlacements.cs
View file @
ac0e80cf
...
...
@@ -9,6 +9,7 @@ public class PlayerPlacements : NetworkBehaviour
private
NetworkVariable
<
NetworkObjectReference
>
playerRightHandItem
=
new
NetworkVariable
<
NetworkObjectReference
>();
private
NetworkVariable
<
NetworkObjectReference
>
playerLeftHandItem
=
new
NetworkVariable
<
NetworkObjectReference
>();
void
Start
()
{
playerRightHand
=
transform
.
Find
(
"PlayerVisual/Skeleton_Minion/Rig/root/handIK.r/EquippedItemR"
)?.
gameObject
;
...
...
@@ -24,8 +25,13 @@ public class PlayerPlacements : NetworkBehaviour
}
}
[
ServerRpc
]
public
void
SetPlayerRightHandItemServerRpc
(
NetworkObjectReference
newItem
)
public
void
SetPlayerRightHandItem
(
NetworkObjectReference
newItem
)
{
SetPlayerRightHandItemServerRpc
(
newItem
);
}
[
ServerRpc
(
RequireOwnership
=
false
)]
private
void
SetPlayerRightHandItemServerRpc
(
NetworkObjectReference
newItem
)
{
if
(
newItem
.
TryGet
(
out
NetworkObject
networkObject
))
{
...
...
@@ -33,21 +39,30 @@ public class PlayerPlacements : NetworkBehaviour
if
(
pickupable
!=
null
)
{
playerRightHandItem
.
Value
=
newItem
;
UpdatePlayerRightHandItemClientRpc
(
newItem
);
//
UpdatePlayerRightHandItemClientRpc(newItem);
}
}
}
[
ClientRpc
]
private
void
UpdatePlayerRightHandItemClientRpc
(
NetworkObjectReference
newItem
)
public
void
ClearPlayerRightHandItem
()
{
if
(
newItem
.
TryGet
(
out
NetworkObject
networkObject
))
ClearPlayerRightHandItemServerRpc
();
}
[
ServerRpc
(
RequireOwnership
=
false
)]
private
void
ClearPlayerRightHandItemServerRpc
()
{
playerRightHandItem
.
Value
=
new
NetworkObjectReference
();
// UpdatePlayerRightHandItemClientRpc(playerRightHandItem.Value);
}
public
bool
IsRightHandFull
()
{
if
(
playerRightHandItem
.
Value
.
TryGet
(
out
NetworkObject
networkObject
))
{
Pickupable
pickupable
=
networkObject
.
GetComponent
<
Pickupable
>();
if
(
pickupable
!=
null
)
{
playerRightHandItem
.
Value
=
newItem
;
}
return
networkObject
.
GetComponent
<
Pickupable
>()
!=
null
;
}
return
false
;
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment