Commit f6ed3c6f authored by cann-alberto's avatar cann-alberto
Browse files

first project commit

parent 4487b14f
// Applies HistoryBounds to the physics world by projecting to a trigger Collider.
// This way we can use Physics.Raycast on it.
using UnityEngine;
namespace Mirror
{
[DisallowMultipleComponent]
[AddComponentMenu("Network/ Lag Compensation/ History Collider")]
public class HistoryCollider : MonoBehaviour
{
[Header("Components")]
[Tooltip("The object's actual collider. We need to know where it is, and how large it is.")]
public Collider actualCollider;
[Tooltip("The helper collider that the history bounds are projected onto.\nNeeds to be added to a child GameObject to counter-rotate an axis aligned Bounding Box onto it.\nThis is only used by this component.")]
public BoxCollider boundsCollider;
[Header("History")]
[Tooltip("Keep this many past bounds in the buffer. The larger this is, the further we can raycast into the past.\nMaximum time := historyAmount * captureInterval")]
public int boundsLimit = 8;
[Tooltip("Gather N bounds at a time into a bucket for faster encapsulation. A factor of 2 will be twice as fast, etc.")]
public int boundsPerBucket = 2;
[Tooltip("Capture bounds every 'captureInterval' seconds. Larger values will require fewer computations, but may not capture every small move.")]
public float captureInterval = 0.100f; // 100 ms
double lastCaptureTime = 0;
[Header("Debug")]
public Color historyColor = new Color(1.0f, 0.5f, 0.0f, 1.0f);
public Color currentColor = Color.red;
protected HistoryBounds history = null;
protected virtual void Awake()
{
history = new HistoryBounds(boundsLimit, boundsPerBucket);
// ensure colliders were set.
// bounds collider should always be a trigger.
if (actualCollider == null) Debug.LogError("HistoryCollider: actualCollider was not set.");
if (boundsCollider == null) Debug.LogError("HistoryCollider: boundsCollider was not set.");
if (boundsCollider.transform.parent != transform) Debug.LogError("HistoryCollider: boundsCollider must be a child of this GameObject.");
if (!boundsCollider.isTrigger) Debug.LogError("HistoryCollider: boundsCollider must be a trigger.");
}
// capturing and projecting onto colliders should use physics update
protected virtual void FixedUpdate()
{
// capture current bounds every interval
if (NetworkTime.localTime >= lastCaptureTime + captureInterval)
{
lastCaptureTime = NetworkTime.localTime;
CaptureBounds();
}
// project bounds onto helper collider
ProjectBounds();
}
protected virtual void CaptureBounds()
{
// grab current collider bounds
// this is in world space coordinates, and axis aligned
// TODO double check
Bounds bounds = actualCollider.bounds;
// insert into history
history.Insert(bounds);
}
protected virtual void ProjectBounds()
{
// grab total collider encapsulating all of history
Bounds total = history.total;
// don't assign empty bounds, this will throw a Unity warning
if (history.boundsCount == 0) return;
// scale projection doesn't work yet.
// for now, don't allow scale changes.
if (transform.lossyScale != Vector3.one)
{
Debug.LogWarning($"HistoryCollider: {name}'s transform global scale must be (1,1,1).");
return;
}
// counter rotate the child collider against the gameobject's rotation.
// we need this to always be axis aligned.
boundsCollider.transform.localRotation = Quaternion.Inverse(transform.rotation);
// project world space bounds to collider's local space
boundsCollider.center = boundsCollider.transform.InverseTransformPoint(total.center);
boundsCollider.size = total.size; // TODO projection?
}
// TODO runtime drawing for debugging?
protected virtual void OnDrawGizmos()
{
// draw total bounds
Gizmos.color = historyColor;
Gizmos.DrawWireCube(history.total.center, history.total.size);
// draw current bounds
Gizmos.color = currentColor;
Gizmos.DrawWireCube(actualCollider.bounds.center, actualCollider.bounds.size);
}
}
}
fileFormatVersion: 2
guid: f5f2158d9776d4b569858f793be4da60
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: 7453abfe9e8b2c04a8a47eb536fe21eb, type: 3}
userData:
assetBundleName:
assetBundleVariant:
This diff is collapsed.
fileFormatVersion: 2
guid: a898831dd60c4cdfbfd9a6ea5702ed01
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: 7453abfe9e8b2c04a8a47eb536fe21eb, type: 3}
userData:
assetBundleName:
assetBundleVariant:
{
"name": "Mirror.Components",
"rootNamespace": "",
"references": [
"GUID:30817c1a0e6d646d99c048fc403f5979"
],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": true,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}
\ No newline at end of file
fileFormatVersion: 2
guid: 72872094b21c16e48b631b2224833d49
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
This diff is collapsed.
fileFormatVersion: 2
guid: 7f6f3bf89aa97405989c802ba270f815
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: 7453abfe9e8b2c04a8a47eb536fe21eb, type: 3}
userData:
assetBundleName:
assetBundleVariant:
using UnityEngine;
namespace Mirror
{
[AddComponentMenu("Network/Network Diagnostics Debugger")]
public class NetworkDiagnosticsDebugger : MonoBehaviour
{
public bool logInMessages = true;
public bool logOutMessages = true;
void OnInMessage(NetworkDiagnostics.MessageInfo msgInfo)
{
if (logInMessages)
Debug.Log(msgInfo);
}
void OnOutMessage(NetworkDiagnostics.MessageInfo msgInfo)
{
if (logOutMessages)
Debug.Log(msgInfo);
}
void OnEnable()
{
NetworkDiagnostics.InMessageEvent += OnInMessage;
NetworkDiagnostics.OutMessageEvent += OnOutMessage;
}
void OnDisable()
{
NetworkDiagnostics.InMessageEvent -= OnInMessage;
NetworkDiagnostics.OutMessageEvent -= OnOutMessage;
}
}
}
fileFormatVersion: 2
guid: bc9f0a0fe4124424b8f9d4927795ee01
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: 7453abfe9e8b2c04a8a47eb536fe21eb, type: 3}
userData:
assetBundleName:
assetBundleVariant:
using System;
using UnityEngine;
namespace Mirror
{
/// <summary>
/// This is a specialized NetworkManager that includes a networked lobby.
/// </summary>
/// <remarks>
/// <para>The lobby has slots that track the joined players, and a maximum player count that is enforced. It requires that the NetworkLobbyPlayer component be on the lobby player objects.</para>
/// <para>NetworkLobbyManager is derived from NetworkManager, and so it implements many of the virtual functions provided by the NetworkManager class. To avoid accidentally replacing functionality of the NetworkLobbyManager, there are new virtual functions on the NetworkLobbyManager that begin with "OnLobby". These should be used on classes derived from NetworkLobbyManager instead of the virtual functions on NetworkManager.</para>
/// <para>The OnLobby*() functions have empty implementations on the NetworkLobbyManager base class, so the base class functions do not have to be called.</para>
/// </remarks>
[AddComponentMenu("Network/Network Lobby Manager")]
[HelpURL("https://mirror-networking.gitbook.io/docs/components/network-room-manager")]
[Obsolete("Use / inherit from NetworkRoomManager instead")]
public class NetworkLobbyManager : NetworkRoomManager {}
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
fileFormatVersion: 2
guid: 80106690aef541a5b8e2f8fb3d5949ad
timeCreated: 1686733778
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment