multiplayer stuff
This commit is contained in:
47
Assets/jelycho/Code/Beacons/BaseManager.cs
Normal file
47
Assets/jelycho/Code/Beacons/BaseManager.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using System.Collections.Generic;
|
||||
using RebootKit.Engine.Main;
|
||||
using Unity.Netcode;
|
||||
using UnityEngine;
|
||||
|
||||
namespace RebootReality.jelycho.Beacons {
|
||||
public class BaseManager : NetworkBehaviour {
|
||||
[SerializeField] Beacon m_BeaconPrefab;
|
||||
[SerializeField] float m_ConnectionRopeLength = 10.0f;
|
||||
[SerializeField] float m_BeaconSpawnRadius = 15.0f;
|
||||
|
||||
readonly List<Beacon> m_Beacons = new List<Beacon>();
|
||||
|
||||
public IReadOnlyList<Beacon> Beacons => m_Beacons;
|
||||
|
||||
[ServerRpc(RequireOwnership = false)]
|
||||
public void SpawnBeaconServerRpc(Vector3 position) {
|
||||
if (!IsServer) {
|
||||
Debug.LogWarning("Only the server can spawn beacons.");
|
||||
return;
|
||||
}
|
||||
|
||||
Beacon beacon = Instantiate(m_BeaconPrefab, position, Quaternion.identity);
|
||||
beacon.NetworkObject.Spawn();
|
||||
beacon.GrowClientRpc();
|
||||
|
||||
foreach (Beacon otherBeacon in m_Beacons) {
|
||||
if ((otherBeacon.transform.position - beacon.transform.position).sqrMagnitude <
|
||||
m_BeaconSpawnRadius * m_BeaconSpawnRadius) {
|
||||
|
||||
Vector3 startPosition = otherBeacon.RopeConnectionPoint.position;
|
||||
Vector3 endPosition = beacon.RopeConnectionPoint.position;
|
||||
SpawnRopeRpc(startPosition, endPosition);
|
||||
}
|
||||
}
|
||||
|
||||
m_Beacons.Add(beacon);
|
||||
}
|
||||
|
||||
[Rpc(SendTo.Everyone)]
|
||||
void SpawnRopeRpc(Vector3 startPosition, Vector3 endPosition) {
|
||||
if (RR.World.Context is WorldContext worldContext) {
|
||||
worldContext.RopesManager.SpawnLockedRope(m_ConnectionRopeLength, startPosition, endPosition);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/jelycho/Code/Beacons/BaseManager.cs.meta
Normal file
3
Assets/jelycho/Code/Beacons/BaseManager.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ac767dd7ed4c424ebad060b7149afac8
|
||||
timeCreated: 1751317007
|
||||
14
Assets/jelycho/Code/Beacons/Beacon.cs
Normal file
14
Assets/jelycho/Code/Beacons/Beacon.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using Unity.Netcode;
|
||||
using UnityEngine;
|
||||
|
||||
namespace RebootReality.jelycho.Beacons {
|
||||
public class Beacon : NetworkBehaviour {
|
||||
[SerializeField] BeaconGraphics m_Graphics;
|
||||
[field: SerializeField] public Transform RopeConnectionPoint { get; private set; }
|
||||
|
||||
[ClientRpc]
|
||||
public void GrowClientRpc() {
|
||||
m_Graphics.Grow();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
using RebootKit.Engine.Services.Simulation;
|
||||
using RebootKit.Engine.Simulation;
|
||||
|
||||
namespace RebootReality.jelycho.Beacons {
|
||||
public class BeaconActor : Actor {
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
123
Assets/jelycho/Code/Beacons/BeaconGraphics.cs
Normal file
123
Assets/jelycho/Code/Beacons/BeaconGraphics.cs
Normal file
@@ -0,0 +1,123 @@
|
||||
using System;
|
||||
using Unity.Mathematics;
|
||||
using UnityEngine;
|
||||
|
||||
namespace RebootReality.jelycho.Beacons {
|
||||
public class BeaconGraphics : MonoBehaviour {
|
||||
[SerializeField] BeaconElement[] m_BeaconElements;
|
||||
|
||||
[Range(0.0f, 1.0f)] public float growAmount = 0.5f;
|
||||
[SerializeField] public float growSpeed = 0.5f;
|
||||
|
||||
float m_CurrentGrowAmount = 0.0f;
|
||||
|
||||
void Update() {
|
||||
if (m_CurrentGrowAmount >= 1.0f) {
|
||||
foreach (BeaconElement beaconElement in m_BeaconElements) {
|
||||
if (!beaconElement.usePulsing) {
|
||||
continue;
|
||||
}
|
||||
|
||||
float t = (Mathf.Sin(Time.time * beaconElement.pulsingSpeed) + 1.0f) * 0.5f;
|
||||
float scale = Mathf.Lerp(beaconElement.pulsingMinScale,
|
||||
beaconElement.pulsingMaxScale,
|
||||
t);
|
||||
beaconElement.transform.localScale = Vector3.one * scale;
|
||||
}
|
||||
}
|
||||
|
||||
if (Mathf.Approximately(m_CurrentGrowAmount, growAmount)) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_CurrentGrowAmount = Mathf.MoveTowards(m_CurrentGrowAmount,
|
||||
growAmount,
|
||||
growSpeed * Time.deltaTime);
|
||||
UpdateElements(m_CurrentGrowAmount);
|
||||
}
|
||||
|
||||
void UpdateElements(float amount) {
|
||||
foreach (BeaconElement element in m_BeaconElements) {
|
||||
if (element.useLocalPosition && element.transform is not null) {
|
||||
float localPositionT = math.remap(element.startLocalPositionAt,
|
||||
element.endLocalPositionAt,
|
||||
0.0f,
|
||||
1.0f,
|
||||
amount);
|
||||
Vector3 localPosition =
|
||||
Vector3.Lerp(element.minLocalPosition, element.maxLocalPosition, Mathf.Clamp01(localPositionT));
|
||||
element.transform.localPosition = localPosition;
|
||||
}
|
||||
|
||||
if (element.useScale && element.transform is not null) {
|
||||
float scaleT = math.remap(element.startScaleAt,
|
||||
element.endScaleAt,
|
||||
0.0f,
|
||||
1.0f,
|
||||
amount);
|
||||
Vector3 scale = Vector3.Lerp(element.minScale, element.maxScale, Mathf.Clamp01(scaleT));
|
||||
element.transform.localScale = scale;
|
||||
}
|
||||
|
||||
if (element.useCutoff && element.meshRenderer is not null) {
|
||||
float cutoffT = math.remap(element.startCutoffAt,
|
||||
element.endCutoffAt,
|
||||
0.0f,
|
||||
1.0f,
|
||||
amount);
|
||||
float cutoff = Mathf.Lerp(0.0f, 1.0f, Mathf.Clamp01(cutoffT));
|
||||
|
||||
if (element.flipCutoffDirection) {
|
||||
cutoff = 1.0f - cutoff;
|
||||
}
|
||||
|
||||
Material material = element.meshRenderer.materials[element.materialIndex];
|
||||
material.SetFloat("_Cutoff", cutoff);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Grow() {
|
||||
m_CurrentGrowAmount = 0.0f;
|
||||
UpdateElements(m_CurrentGrowAmount);
|
||||
growAmount = 1.0f;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
struct BeaconElement {
|
||||
public Transform transform;
|
||||
public MeshRenderer meshRenderer;
|
||||
|
||||
[Header("Local Position(Transform)")]
|
||||
public bool useLocalPosition;
|
||||
|
||||
public Vector3 minLocalPosition;
|
||||
public Vector3 maxLocalPosition;
|
||||
public float startLocalPositionAt;
|
||||
public float endLocalPositionAt;
|
||||
|
||||
[Header("Scale (Transform)")]
|
||||
public bool useScale;
|
||||
public Vector3 minScale;
|
||||
public Vector3 maxScale;
|
||||
|
||||
public float startScaleAt;
|
||||
public float endScaleAt;
|
||||
|
||||
[Header("Mesh Cutoff (MeshRenderer)")]
|
||||
public bool useCutoff;
|
||||
public bool flipCutoffDirection;
|
||||
|
||||
public float startCutoffAt;
|
||||
public float endCutoffAt;
|
||||
|
||||
public int materialIndex;
|
||||
|
||||
[Header("Pulsing (Transform)")]
|
||||
public bool usePulsing;
|
||||
public float pulsingSpeed;
|
||||
public float pulsingMinScale;
|
||||
public float pulsingMaxScale;
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/jelycho/Code/Beacons/BeaconGraphics.cs.meta
Normal file
3
Assets/jelycho/Code/Beacons/BeaconGraphics.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7db2986869814a7495d4f30cbd35d713
|
||||
timeCreated: 1751312364
|
||||
Reference in New Issue
Block a user