working on inventory
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
using System;
|
||||
using R3;
|
||||
using RebootKit.Engine.Foundation;
|
||||
using RebootKit.Engine.Main;
|
||||
using RebootReality.jelycho.Player.HUD;
|
||||
using Unity.Mathematics;
|
||||
using Unity.Netcode;
|
||||
using UnityEngine;
|
||||
@@ -15,6 +17,10 @@ namespace RebootReality.jelycho.Player {
|
||||
[SerializeField] Config m_Config;
|
||||
|
||||
PlayerActor m_Actor;
|
||||
PlayerHUD m_HUD;
|
||||
|
||||
DisposableBag m_OwnerActorDisposableBag = new DisposableBag();
|
||||
IDisposable m_TargetInteractableLabelDisposable;
|
||||
|
||||
public override void OnNetworkSpawn() {
|
||||
base.OnNetworkSpawn();
|
||||
@@ -22,6 +28,8 @@ namespace RebootReality.jelycho.Player {
|
||||
if (IsOwner) {
|
||||
RR.Input.LockCursor();
|
||||
RR.Input.EnableControls();
|
||||
|
||||
m_HUD = Instantiate(m_Config.playerHUDPrefab);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +39,13 @@ namespace RebootReality.jelycho.Player {
|
||||
if (IsOwner) {
|
||||
RR.Input.UnlockCursor();
|
||||
RR.Input.DisableControls();
|
||||
|
||||
if (m_HUD != null) {
|
||||
Destroy(m_HUD.gameObject);
|
||||
m_HUD = null;
|
||||
}
|
||||
|
||||
m_OwnerActorDisposableBag.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,10 +69,31 @@ namespace RebootReality.jelycho.Player {
|
||||
m_Actor.WarpToServerRpc(worldContext.PlayerSpawnPoint.position);
|
||||
}
|
||||
}
|
||||
|
||||
if (IsOwner) {
|
||||
m_OwnerActorDisposableBag.Dispose();
|
||||
m_OwnerActorDisposableBag = new DisposableBag();
|
||||
m_Actor.TargetInteractable.Subscribe(interactable => {
|
||||
if (m_TargetInteractableLabelDisposable != null) {
|
||||
m_TargetInteractableLabelDisposable.Dispose();
|
||||
m_TargetInteractableLabelDisposable = null;
|
||||
}
|
||||
|
||||
if (interactable is MonoBehaviour mb) {
|
||||
m_TargetInteractableLabelDisposable =
|
||||
m_HUD.ObjectsLabels.CreateLabel(mb.transform, mb.name);
|
||||
}
|
||||
})
|
||||
.AddTo(ref m_OwnerActorDisposableBag);
|
||||
|
||||
m_HUD.SetPlayerActor(m_Actor);
|
||||
}
|
||||
}
|
||||
|
||||
[ClientRpc]
|
||||
public void SetNullActorClientRpc() {
|
||||
m_OwnerActorDisposableBag.Dispose();
|
||||
m_OwnerActorDisposableBag = new DisposableBag();
|
||||
m_Actor = null;
|
||||
}
|
||||
|
||||
@@ -97,14 +133,31 @@ namespace RebootReality.jelycho.Player {
|
||||
if (m_Config.secondaryActionReference.action.WasReleasedThisFrame()) {
|
||||
m_Actor.SecondaryAction();
|
||||
}
|
||||
|
||||
|
||||
if (m_Config.interactActionReference.action.WasReleasedThisFrame()) {
|
||||
m_Actor.Interact();
|
||||
}
|
||||
|
||||
for (int i = 0; i < m_Config.inventorySlotSelectActionReferences.Length; i++) {
|
||||
if (m_Config.inventorySlotSelectActionReferences[i].action.WasReleasedThisFrame()) {
|
||||
m_Actor.SelectItemSlot(i);
|
||||
}
|
||||
}
|
||||
|
||||
float slotChangeAxis = m_Config.inventorySlotChangeActionReference.action.ReadValue<float>();
|
||||
if (math.abs(slotChangeAxis) > 0.5f) {
|
||||
if (slotChangeAxis > 0) {
|
||||
m_Actor.SelectNextItemSlot();
|
||||
} else {
|
||||
m_Actor.SelectPreviousItemSlot();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class Config {
|
||||
public PlayerHUD playerHUDPrefab;
|
||||
|
||||
public InputActionReference moveActionReference;
|
||||
public InputActionReference lookActionReference;
|
||||
public InputActionReference jumpActionReference;
|
||||
@@ -113,6 +166,9 @@ namespace RebootReality.jelycho.Player {
|
||||
public InputActionReference primaryActionReference;
|
||||
public InputActionReference secondaryActionReference;
|
||||
public InputActionReference interactActionReference;
|
||||
|
||||
public InputActionReference[] inventorySlotSelectActionReferences;
|
||||
public InputActionReference inventorySlotChangeActionReference;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user