This commit is contained in:
2023-11-28 11:41:03 +05:30
commit da3b6cf083
1281 changed files with 97466 additions and 0 deletions

View File

@@ -0,0 +1,51 @@
using UnityEngine;
namespace Mirror.Examples.Benchmark
{
public class BenchmarkNetworkManager : NetworkManager
{
[Header("Spawns")]
public GameObject spawnPrefab;
public int spawnAmount = 5000;
public float interleave = 1;
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,11 @@
fileFormatVersion: 2
guid: f0f6e2c4566084948a433ee5285d3fb7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,50 @@
using UnityEngine;
namespace Mirror.Examples.Benchmark
{
public class MonsterMovement : NetworkBehaviour
{
public float speed = 1;
public float movementProbability = 0.5f;
public float movementDistance = 20;
bool moving;
Vector3 start;
Vector3 destination;
public override void OnStartServer()
{
start = transform.position;
}
[ServerCallback]
void Update()
{
if (moving)
{
if (Vector3.Distance(transform.position, destination) <= 0.01f)
{
moving = false;
}
else
{
transform.position = Vector3.MoveTowards(transform.position, destination, speed * Time.deltaTime);
}
}
else
{
float r = Random.value;
if (r < movementProbability * Time.deltaTime)
{
Vector2 circlePos = Random.insideUnitCircle;
Vector3 dir = new Vector3(circlePos.x, 0, circlePos.y);
// set destination on random pos in a circle around start.
// (don't want to wander off)
destination = start + dir * movementDistance;
moving = true;
}
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9cddc2e496c474e538a494465be0192a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,20 @@
using UnityEngine;
namespace Mirror.Examples.Benchmark
{
public class PlayerMovement : NetworkBehaviour
{
public float speed = 5;
void Update()
{
if (!isLocalPlayer) return;
float h = Input.GetAxis("Horizontal");
float v = Input.GetAxis("Vertical");
Vector3 dir = new Vector3(h, 0, v);
transform.position += dir.normalized * (Time.deltaTime * speed);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c482338c8cc6d4a3cba81934c0151972
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: