Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ServerOrClient attribute #1013

Merged
merged 4 commits into from
Feb 22, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Assets/Scripts/SS3D/Attributes/ServerOrClientAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;


/// <summary>
/// Informative only attribute, does not make any check.
/// Use it to let contributors know that method can be called client or server side.
/// </summary>
[AttributeUsage(AttributeTargets.Method, Inherited = true, AllowMultiple = false)]
public class ServerOrClientAttribute : Attribute
{

}
11 changes: 11 additions & 0 deletions Assets/Scripts/SS3D/Attributes/ServerOrClientAttribute.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions Assets/Scripts/SS3D/Systems/Interactions/InteractionController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public sealed class InteractionController : NetworkActor
private Camera _camera;
private RadialInteractionView _radialView;

[Client]
protected override void OnStart()
stilnat marked this conversation as resolved.
Show resolved Hide resolved
{
base.OnStart();
Expand All @@ -36,6 +37,7 @@ protected override void OnStart()
_camera = SystemLocator.Get<CameraSystem>().PlayerCamera.GetComponent<Camera>();
}

[Client]
protected override void HandleUpdate(in float deltaTime)
stilnat marked this conversation as resolved.
Show resolved Hide resolved
{
base.HandleUpdate(in deltaTime);
Expand All @@ -61,11 +63,13 @@ protected override void HandleUpdate(in float deltaTime)
}
}

[Client]
private void ProcessPrimaryClick()
{
RunPrimaryInteraction();
}

[Client]
private void ProcessSecondaryClick()
{
Ray ray = _camera.ScreenPointToRay(Input.mousePosition);
Expand All @@ -74,6 +78,7 @@ private void ProcessSecondaryClick()
ViewTargetInteractions(viableInteractions, interactionEvent, ray);
}

[Client]
private void ProcessUse()
{
// Activate item in selected hand
Expand All @@ -93,6 +98,7 @@ private void ProcessUse()
/// <summary>
/// Runs the most prioritised action
/// </summary>
[Client]
private void RunPrimaryInteraction()
{
Ray ray = _camera.ScreenPointToRay(Input.mousePosition);
Expand All @@ -116,6 +122,7 @@ private void RunPrimaryInteraction()
/// <param name="viableInteractions"></param>
/// <param name="interactionEvent"></param>
/// <param name="ray"></param>
[Client]
private void ViewTargetInteractions(List<InteractionEntry> viableInteractions, InteractionEvent interactionEvent, Ray ray)
{
List<IInteraction> interactions = viableInteractions.Select(entry => entry.Interaction).ToList();
Expand Down Expand Up @@ -238,6 +245,7 @@ private void RpcExecuteClientInteraction(Ray ray, string interactionName, int re
/// <param name="ray">The ray to use in ray casting</param>
/// <param name="interactionEvent">The produced interaction event</param>
/// <returns>A list of possible interactions</returns>
[ServerOrClient]
private List<InteractionEntry> GetViableInteractions(Ray ray, out InteractionEvent interactionEvent)
{
// Get source that's currently interacting (eg. hand, tool)
Expand Down Expand Up @@ -272,6 +280,7 @@ private List<InteractionEntry> GetViableInteractions(Ray ray, out InteractionEve
/// <param name="source">The source of the interaction</param>
/// <param name="targetGameObject">The game objects the interaction targets are on</param>
/// <returns>A list of all valid interaction targets</returns>
[ServerOrClient]
private List<IInteractionTarget> GetTargetsFromGameObject(IInteractionSource source, GameObject targetGameObject)
{
List<IInteractionTarget> targets = new();
Expand All @@ -293,6 +302,7 @@ private List<IInteractionTarget> GetTargetsFromGameObject(IInteractionSource sou
/// <param name="targets">The interaction targets</param>
/// <param name="interactionEvent">The interaction event data</param>
/// <returns>A list of all possible interaction entries</returns>
[ServerOrClient]
private List<InteractionEntry> GetInteractionsFromTargets(IInteractionSource source, List<IInteractionTarget> targets, InteractionEvent interactionEvent)
{
List<InteractionEntry> interactions = new();
Expand Down Expand Up @@ -329,6 +339,7 @@ private List<InteractionEntry> GetInteractionsFromTargets(IInteractionSource sou
return interactionsFromTargets;
}

[ServerOrClient]
private IInteractionSource GetActiveInteractionSource()
{
IToolHolder toolHolder = GetComponent<IToolHolder>();
Expand Down