fishnet installed

This commit is contained in:
2023-05-31 11:32:21 -04:00
parent 47b25269f1
commit a001fe1b04
1291 changed files with 126631 additions and 1 deletions

View File

@ -0,0 +1,53 @@
using FishNet.Object;
using UnityEngine;
namespace FishNet.Demo.NetworkLod
{
public class MoveRandomly : NetworkBehaviour
{
//Colors green for client.
[SerializeField]
private Renderer _renderer;
//Time to move to new position.
private const float _moveRate = 3f;
//Maximum range for new position.
private const float _range = 10f;
//Position to move towards.
private Vector3 _goal;
//Position at spawn.
private Vector3 _start;
private void Update()
{
//Client should not move these.
if (base.IsClientOnly)
return;
//Server shouldn't move client one.
if (base.Owner.IsValid)
return;
transform.position = Vector3.MoveTowards(transform.position, _goal, _moveRate * Time.deltaTime);
if (transform.position == _goal)
RandomizeGoal();
}
public override void OnStartNetwork()
{
base.OnStartNetwork();
_start = transform.position;
RandomizeGoal();
if (_renderer != null && base.Owner.IsActive)
_renderer.material.color = Color.green;
}
private void RandomizeGoal()
{
_goal = _start + (Random.insideUnitSphere * _range);
}
}
}

View File

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

View File

@ -0,0 +1,51 @@
using FishNet.Managing.Observing;
using FishNet.Object;
using System.Collections.Generic;
using UnityEngine;
namespace FishNet.Demo.NetworkLod
{
public class NetworkLodTester : NetworkBehaviour
{
[SerializeField]
private NetworkObject _prefab;
[SerializeField]
private ObserverManager _observerManager;
[Range(1, 8)]
[SerializeField]
private byte _lodLevel = 8;
private const int _count = 500;
private const float _xyRange = 15f;
private const float _zRange = 100f;
private void Awake()
{
List<float> distances = _observerManager.GetLevelOfDetailDistances();
while (distances.Count > _lodLevel)
distances.RemoveAt(distances.Count - 1);
}
public override void OnStartServer()
{
base.OnStartServer();
for (int i = 0; i < _count; i++)
{
float x = Random.Range(-_xyRange, _xyRange);
float y = Random.Range(-_xyRange, _xyRange);
float z = Random.Range(0f, _zRange);
Vector3 position = new Vector3(x, y, z);
NetworkObject obj = Instantiate(_prefab, position, Quaternion.identity);
obj.name = $"Obj {i.ToString("0000")}";
base.Spawn(obj);
}
}
}
}

View File

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