This commit is contained in:
2025-06-16 15:14:23 +02:00
commit 074e590073
3174 changed files with 428263 additions and 0 deletions

View File

@ -0,0 +1,27 @@
using UnityEngine;
namespace Mirror.Examples.RigidbodyBenchmark
{
[RequireComponent(typeof(Rigidbody))]
public class AddForce : NetworkBehaviour
{
public Rigidbody rigidbody3d;
public float force = 500f;
protected override void OnValidate()
{
base.OnValidate();
rigidbody3d = GetComponent<Rigidbody>();
}
void Update()
{
// do we have authority over this?
if (!rigidbody3d.isKinematic)
{
if (Input.GetKeyDown(KeyCode.Space))
rigidbody3d.AddForce(Vector3.up * force);
}
}
}
}

View File

@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: a0e44d14fc08546319793f1932832d13
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 129321
packageName: Mirror
packageVersion: 96.0.1
assetPath: Assets/Mirror/Examples/RigidbodyBenchmark/Scripts/AddForce.cs
uploadId: 736421

View File

@ -0,0 +1,32 @@
using UnityEngine;
using Random = UnityEngine.Random;
namespace Mirror.Examples.RigidbodyBenchmark
{
[RequireComponent(typeof(Rigidbody))]
public class AutoForce : NetworkBehaviour
{
public Rigidbody rigidbody3d;
public float force = 500;
public float forceProbability = 0.05f;
protected override void OnValidate()
{
base.OnValidate();
rigidbody3d = GetComponent<Rigidbody>();
}
[ServerCallback]
void FixedUpdate()
{
// do we have authority over this?
if (rigidbody3d.isKinematic) return;
// time to apply force?
if (Random.value < forceProbability * Time.deltaTime)
{
rigidbody3d.AddForce(Vector3.up * force);
}
}
}
}

View File

@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: e7cfbc91b3df3449dba2d6585082228e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 129321
packageName: Mirror
packageVersion: 96.0.1
assetPath: Assets/Mirror/Examples/RigidbodyBenchmark/Scripts/AutoForce.cs
uploadId: 736421

View File

@ -0,0 +1,52 @@
using UnityEngine;
namespace Mirror.Examples.RigidbodyBenchmark
{
[AddComponentMenu("")]
public class RigidbodyBenchmarkNetworkManager : NetworkManager
{
[Header("Spawns")]
public GameObject spawnPrefab;
public int spawnAmount = 2000;
public float interleave = 2;
void SpawnAll()
{
// calculate sqrt so we can spawn N * N = Amount
float sqrt = Mathf.Sqrt(spawnAmount);
// calculate spawn xz start positions
// based on spawnAmount * distance
float offset = -sqrt / 2 * interleave;
// spawn exactly the amount, not one more.
int spawned = 0;
for (int spawnX = 0; spawnX < sqrt; ++spawnX)
{
for (int spawnZ = 0; spawnZ < sqrt; ++spawnZ)
{
// spawn exactly the amount, not any more
// (our sqrt method isn't 100% precise)
if (spawned < spawnAmount)
{
// instantiate & position
GameObject go = Instantiate(spawnPrefab);
float x = offset + spawnX * interleave;
float z = offset + spawnZ * interleave;
go.transform.position = new Vector3(x, 0, z);
// spawn
NetworkServer.Spawn(go);
++spawned;
}
}
}
}
public override void OnStartServer()
{
base.OnStartServer();
SpawnAll();
}
}
}

View File

@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: b21e2d778c62d40e69f03e5c9624ddf1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 129321
packageName: Mirror
packageVersion: 96.0.1
assetPath: Assets/Mirror/Examples/RigidbodyBenchmark/Scripts/RigidbodyBenchmarkNetworkManager.cs
uploadId: 736421