Added leveler
This commit is contained in:
@@ -9,6 +9,8 @@ public sealed class PlayerInteractionController : NetworkBehaviour, IPlayerSyste
|
||||
|
||||
private Camera playerCamera;
|
||||
private IInteractable focusedInteractable;
|
||||
private IPlayerInteractionSession activeSession;
|
||||
private bool activeSessionReleaseRequested;
|
||||
private bool isInitialized;
|
||||
|
||||
public void Initialize(PlayerFacade facade)
|
||||
@@ -22,6 +24,23 @@ public sealed class PlayerInteractionController : NetworkBehaviour, IPlayerSyste
|
||||
if (!isInitialized || !IsOwner || Keyboard.current == null)
|
||||
return;
|
||||
|
||||
if (PlayerInteractionSessionRegistry.TryGetControlledSession(
|
||||
OwnerClientId,
|
||||
out activeSession))
|
||||
{
|
||||
focusedInteractable = null;
|
||||
|
||||
if (!Keyboard.current.eKey.isPressed && !activeSessionReleaseRequested)
|
||||
{
|
||||
activeSessionReleaseRequested = true;
|
||||
activeSession.RequestRelease();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
activeSession = null;
|
||||
activeSessionReleaseRequested = false;
|
||||
focusedInteractable = FindFocusedInteractable();
|
||||
|
||||
if (Keyboard.current.eKey.wasPressedThisFrame &&
|
||||
@@ -49,9 +68,26 @@ public sealed class PlayerInteractionController : NetworkBehaviour, IPlayerSyste
|
||||
|
||||
private void OnGUI()
|
||||
{
|
||||
if (!IsOwner || focusedInteractable == null)
|
||||
if (!IsOwner)
|
||||
return;
|
||||
|
||||
if (activeSession != null)
|
||||
{
|
||||
DrawPrompt(activeSession.ReleasePrompt);
|
||||
return;
|
||||
}
|
||||
|
||||
if (focusedInteractable == null)
|
||||
return;
|
||||
|
||||
string prompt = focusedInteractable.IsInteractionAvailable
|
||||
? "[E] " + focusedInteractable.InteractionPrompt
|
||||
: "In use";
|
||||
DrawPrompt(prompt);
|
||||
}
|
||||
|
||||
private static void DrawPrompt(string prompt)
|
||||
{
|
||||
GUIStyle style = new(GUI.skin.label)
|
||||
{
|
||||
alignment = TextAnchor.MiddleCenter,
|
||||
@@ -59,12 +95,7 @@ public sealed class PlayerInteractionController : NetworkBehaviour, IPlayerSyste
|
||||
normal = { textColor = Color.white }
|
||||
};
|
||||
|
||||
string prompt = focusedInteractable.IsInteractionAvailable
|
||||
? "[E] " + focusedInteractable.InteractionPrompt
|
||||
: "In use";
|
||||
|
||||
Rect area = new(0f, Screen.height * 0.62f, Screen.width, 28f);
|
||||
GUI.Label(area, prompt, style);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user