working on actors
This commit is contained in:
@@ -1,12 +1,9 @@
|
||||
using RebootKit.Engine.Extensions;
|
||||
using System;
|
||||
using RebootKit.Engine.Extensions;
|
||||
using RebootKit.Engine.Foundation;
|
||||
using RebootKit.Engine.Main;
|
||||
using RebootKit.Engine.Services.Simulation;
|
||||
using RebootKit.Engine.Services.Simulation.Sensors;
|
||||
using RebootKit.Engine.Simulation;
|
||||
using RebootKit.Engine.Simulation.Sensors;
|
||||
using RebootReality.jelycho.Main;
|
||||
using Unity.Collections;
|
||||
using Unity.Mathematics;
|
||||
using Unity.Netcode;
|
||||
using UnityEngine;
|
||||
@@ -29,6 +26,42 @@ namespace RebootReality.jelycho.Player {
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public struct GenericSensor : ISensor {
|
||||
[SerializeField] Transform m_Origin;
|
||||
[SerializeField] LayerMask m_LayerMask;
|
||||
[SerializeField] float m_MaxDistance;
|
||||
|
||||
public GameObject Sense() {
|
||||
Ray ray = new Ray(m_Origin.position, m_Origin.forward);
|
||||
|
||||
if (Physics.Raycast(ray, out RaycastHit hit, m_MaxDistance, m_LayerMask)) {
|
||||
return hit.collider.gameObject;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public struct GenericSensor<T> : ISensor<T> where T : class {
|
||||
[SerializeField] Transform m_Origin;
|
||||
[SerializeField] LayerMask m_LayerMask;
|
||||
[SerializeField] float m_MaxDistance;
|
||||
|
||||
public T Sense() {
|
||||
Ray ray = new Ray(m_Origin.position, m_Origin.forward);
|
||||
|
||||
if (Physics.Raycast(ray, out RaycastHit hit, m_MaxDistance, m_LayerMask)) {
|
||||
if (hit.collider.TryGetComponent(out T component)) {
|
||||
return component;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public class PlayerActor : NetworkBehaviour {
|
||||
static readonly Logger s_Logger = new Logger(nameof(PlayerActor));
|
||||
|
||||
@@ -75,6 +108,9 @@ namespace RebootReality.jelycho.Player {
|
||||
[SerializeField] LayerMask m_BeaconPlacementLayerMask = 0;
|
||||
[SerializeField] float m_BeaconPlacementMaxDistance = 15.0f;
|
||||
[SerializeField] float m_NormalDotUpThreshold = 0.5f;
|
||||
|
||||
[Header("Sensors")]
|
||||
[SerializeField] GenericSensor<IInteractable> m_InteractablesSensor;
|
||||
|
||||
[Header("Network")]
|
||||
[SerializeField] float m_MinTeleportDistance = 0.5f;
|
||||
@@ -318,7 +354,9 @@ namespace RebootReality.jelycho.Player {
|
||||
if (TryGetBeaconPosition(out Vector3 beaconPosition)) {
|
||||
SetAnimatorTriggerRpc(AnimatorParamHashes.Throw);
|
||||
|
||||
GameWorldController.Instance.RequestBeaconSpawnRpc(beaconPosition);
|
||||
if (RR.World.Context is WorldContext worldContext) {
|
||||
worldContext.BaseManager.TrySpawnBeacon(beaconPosition);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -331,10 +369,33 @@ namespace RebootReality.jelycho.Player {
|
||||
m_Animator.SetTrigger(AnimatorParamHashes.Block);
|
||||
}
|
||||
|
||||
public void Interact() {
|
||||
if (!IsOwner) {
|
||||
s_Logger.Error("Only the owner can perform interactions.");
|
||||
return;
|
||||
}
|
||||
|
||||
IInteractable interactable = m_InteractablesSensor.Sense();
|
||||
if (interactable is not null) {
|
||||
interactable.Interact();
|
||||
SetAnimatorTriggerRpc(AnimatorParamHashes.Throw);
|
||||
}
|
||||
}
|
||||
|
||||
[Rpc(SendTo.Everyone)]
|
||||
void SetAnimatorTriggerRpc(int hash) {
|
||||
m_Animator.SetTrigger(hash);
|
||||
}
|
||||
|
||||
bool TryGetInteractable(out IInteractable interactable) {
|
||||
GameObject pickedGameObject = m_Camera.Sensor.Sense();
|
||||
if (pickedGameObject != null && pickedGameObject.TryGetComponent(out interactable)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
interactable = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool TryGetBeaconPosition(out Vector3 position) {
|
||||
Ray ray = new Ray(m_Camera.Camera.transform.position, m_Camera.Camera.transform.forward);
|
||||
|
||||
@@ -97,6 +97,10 @@ namespace RebootReality.jelycho.Player {
|
||||
if (m_Config.secondaryActionReference.action.WasReleasedThisFrame()) {
|
||||
m_Actor.SecondaryAction();
|
||||
}
|
||||
|
||||
if (m_Config.interactActionReference.action.WasReleasedThisFrame()) {
|
||||
m_Actor.Interact();
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
@@ -108,6 +112,7 @@ namespace RebootReality.jelycho.Player {
|
||||
public InputActionReference dragObjectActionReference;
|
||||
public InputActionReference primaryActionReference;
|
||||
public InputActionReference secondaryActionReference;
|
||||
public InputActionReference interactActionReference;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user