Add StickGame Assets

This commit is contained in:
Dzejkobik007
2024-03-24 22:21:16 +01:00
parent 5a5812c0c7
commit 6c8b523d1f
6643 changed files with 596260 additions and 0 deletions

View File

@@ -0,0 +1,79 @@
using FishNet.Object;
using UnityEngine;
namespace FishNet.Demo.NetworkLod
{
public class MoveRandomly : NetworkBehaviour
{
[SerializeField]
private float _moveRate = 3f;
//Colors green for client.
[SerializeField]
private Renderer _renderer;
[SerializeField]
private bool _updateRotation;
//Maximum range for new position.
private const float _range = 10f;
//Position to move towards.
private Vector3 _goalPosition;
//Rotation to move towards.
private Quaternion _goalRotation;
//Position at spawn.
private Vector3 _startPosition;
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, _goalPosition, _moveRate * Time.deltaTime);
if (_updateRotation)
transform.rotation = Quaternion.RotateTowards(transform.rotation, _goalRotation, 15f * Time.deltaTime);
if (transform.position == _goalPosition)
RandomizeGoal();
}
public override void OnStartNetwork()
{
_startPosition = transform.position;
RandomizeGoal();
if (_renderer != null && base.Owner.IsActive)
_renderer.material.color = Color.green;
if (!base.Owner.IsValid)
gameObject.name = "LOD " + base.ObjectId;
else
gameObject.name = "Owned " + base.ObjectId;
}
private void RandomizeGoal()
{
_goalPosition = _startPosition + (Random.insideUnitSphere * _range);
if (_updateRotation)
{
bool rotate = (Random.Range(0f, 1f) <= 0.33f);
if (rotate)
{
Vector3 euler = Random.insideUnitSphere * 180f;
_goalRotation = Quaternion.Euler(euler);
}
else
{
_goalRotation = transform.rotation;
}
}
}
}
}

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,74 @@
using FishNet.Managing.Observing;
using FishNet.Object;
using System.Collections.Generic;
using UnityEngine;
namespace FishNet.Demo.NetworkLod
{
public class NetworkLodTester : NetworkBehaviour
{
[Header("General")]
[SerializeField]
private NetworkObject _prefab;
[SerializeField]
private ObserverManager _observerManager;
[Range(1, 8)]
[SerializeField]
private byte _lodLevel = 8;
[Header("Spawning")]
[SerializeField]
private int _count = 500;
[SerializeField]
private float _xyRange = 15f;
[SerializeField]
private float _zRange = 100f;
private void Awake()
{
//Check for pro...this will stay false if not on a pro package.
bool isPro = false;
if (!isPro)
{
Debug.LogError($"Network Level of Detail demo requires Fish-Networking Pro to work.");
DestroyImmediate(this);
return;
}
List<float> distances = _observerManager.GetLevelOfDetailDistances();
while (distances.Count > _lodLevel)
distances.RemoveAt(distances.Count - 1);
}
public override void OnStartServer()
{
//Spawn objects going down the range to make it easier to debug.
float xySpacing = (_xyRange / _count);
float zSpacing = (_zRange / _count);
float x = 0f;
float y = 0f;
float z = 0f;
for (int i = 0; i < _count; i++)
{
//Z cannot be flipped.
float nextZ = z;
x += xySpacing;
y += xySpacing;
z += zSpacing;
float nextX = 0;
float nextY = 0;
Vector3 position = new Vector3(nextX, nextY, nextZ);
NetworkObject obj = Instantiate(_prefab, position, Quaternion.identity);
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: