fishnet installed
This commit is contained in:
18
Assets/FishNet/Runtime/Utility/Extension/Bool.cs
Normal file
18
Assets/FishNet/Runtime/Utility/Extension/Bool.cs
Normal file
@ -0,0 +1,18 @@
|
||||
|
||||
namespace FishNet.Utility.Extension
|
||||
{
|
||||
public static class BooleanExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts a boolean to an integer.
|
||||
/// </summary>
|
||||
/// <param name="b"></param>
|
||||
/// <returns></returns>
|
||||
public static int ToInt(this bool b)
|
||||
{
|
||||
return (b) ? 1 : 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
11
Assets/FishNet/Runtime/Utility/Extension/Bool.cs.meta
Normal file
11
Assets/FishNet/Runtime/Utility/Extension/Bool.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c688c9bd497f4a749b692b9b1d628c51
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
33
Assets/FishNet/Runtime/Utility/Extension/Collection.cs
Normal file
33
Assets/FishNet/Runtime/Utility/Extension/Collection.cs
Normal file
@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace FishNet.Utility.Extension
|
||||
{
|
||||
public static class CollectionFN
|
||||
{
|
||||
/// <summary>
|
||||
/// Random for shuffling.
|
||||
/// </summary>
|
||||
private static Random _random = new Random();
|
||||
|
||||
/// <summary>
|
||||
/// Shuffle based on Fisher-Yates shuffle.
|
||||
/// https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle
|
||||
/// https://stackoverflow.com/questions/273313/randomize-a-listt
|
||||
/// </summary>
|
||||
public static void Shuffle<T>(this IList<T> lst)
|
||||
{
|
||||
int n = lst.Count;
|
||||
while (n > 1)
|
||||
{
|
||||
n--;
|
||||
int k = _random.Next(n + 1);
|
||||
T value = lst[k];
|
||||
lst[k] = lst[n];
|
||||
lst[n] = value;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
11
Assets/FishNet/Runtime/Utility/Extension/Collection.cs.meta
Normal file
11
Assets/FishNet/Runtime/Utility/Extension/Collection.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9a6539089deb687469d1abdc1b8964a1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
35
Assets/FishNet/Runtime/Utility/Extension/Dictionary.cs
Normal file
35
Assets/FishNet/Runtime/Utility/Extension/Dictionary.cs
Normal file
@ -0,0 +1,35 @@
|
||||
using FishNet.Documenting;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace FishNet.Utility.Extension
|
||||
{
|
||||
[APIExclude]
|
||||
public static class DictionaryFN
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Uses a hacky way to TryGetValue on a dictionary when using IL2CPP and on mobile.
|
||||
/// This is to support older devices that don't properly handle IL2CPP builds.
|
||||
/// </summary>
|
||||
public static bool TryGetValueIL2CPP<TKey, TValue>(this IDictionary<TKey, TValue> dict, TKey key, out TValue value)
|
||||
{
|
||||
#if ENABLE_IL2CPP && UNITY_IOS || UNITY_ANDROID
|
||||
if (dict.ContainsKey(key))
|
||||
{
|
||||
value = dict[key];
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
value = default;
|
||||
return false;
|
||||
}
|
||||
#else
|
||||
return dict.TryGetValue(key, out value);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
11
Assets/FishNet/Runtime/Utility/Extension/Dictionary.cs.meta
Normal file
11
Assets/FishNet/Runtime/Utility/Extension/Dictionary.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d286695e7464ce943bc321215aaa2ee1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
31
Assets/FishNet/Runtime/Utility/Extension/Enum.cs
Normal file
31
Assets/FishNet/Runtime/Utility/Extension/Enum.cs
Normal file
@ -0,0 +1,31 @@
|
||||
using System;
|
||||
|
||||
namespace FishNet.Utility.Extension
|
||||
{
|
||||
public static class EnumFN
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Returns the highest numeric value for T.
|
||||
/// </summary>
|
||||
public static int GetHighestValue<T>()
|
||||
{
|
||||
Type enumType = typeof(T);
|
||||
/* Brute force enum values.
|
||||
* Linq Last/Max lookup throws for IL2CPP. */
|
||||
int highestValue = 0;
|
||||
Array pidValues = Enum.GetValues(enumType);
|
||||
foreach (T pid in pidValues)
|
||||
{
|
||||
object obj = Enum.Parse(enumType, pid.ToString());
|
||||
int value = Convert.ToInt32(obj);
|
||||
highestValue = Math.Max(highestValue, value);
|
||||
}
|
||||
|
||||
return highestValue;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
11
Assets/FishNet/Runtime/Utility/Extension/Enum.cs.meta
Normal file
11
Assets/FishNet/Runtime/Utility/Extension/Enum.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f58b410f20b8e694aa852d2ea5240626
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
24
Assets/FishNet/Runtime/Utility/Extension/List.cs
Normal file
24
Assets/FishNet/Runtime/Utility/Extension/List.cs
Normal file
@ -0,0 +1,24 @@
|
||||
using FishNet.Documenting;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace FishNet.Utility.Extension
|
||||
{
|
||||
[APIExclude]
|
||||
public static class ListFN
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Adds a value to the list only if the value does not already exist.
|
||||
/// </summary>
|
||||
/// <param name="lst">Collection being added to.</param>
|
||||
/// <param name="value">Value to add.</param>
|
||||
public static void AddUnique<T>(this List<T> lst, T value)
|
||||
{
|
||||
if (!lst.Contains(value))
|
||||
lst.Add(value);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
11
Assets/FishNet/Runtime/Utility/Extension/List.cs.meta
Normal file
11
Assets/FishNet/Runtime/Utility/Extension/List.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 953eb4b102d504544b49087104e6b747
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
34
Assets/FishNet/Runtime/Utility/Extension/Math.cs
Normal file
34
Assets/FishNet/Runtime/Utility/Extension/Math.cs
Normal file
@ -0,0 +1,34 @@
|
||||
namespace FishNet.Utility.Extension
|
||||
{
|
||||
|
||||
public static class MathFN
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Returns a clamped SBytte.
|
||||
/// </summary>
|
||||
public static sbyte ClampSByte(long value, sbyte min, sbyte max)
|
||||
{
|
||||
if (value < min)
|
||||
return min;
|
||||
else if (value > max)
|
||||
return max;
|
||||
else
|
||||
return (sbyte)value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a clamped double.
|
||||
/// </summary>
|
||||
public static double ClampDouble(double value, double min, double max)
|
||||
{
|
||||
if (value < min)
|
||||
return min;
|
||||
else if (value > max)
|
||||
return max;
|
||||
else
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
11
Assets/FishNet/Runtime/Utility/Extension/Math.cs.meta
Normal file
11
Assets/FishNet/Runtime/Utility/Extension/Math.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: feb978e97a6aa6b4cbb99481d925c00c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
27
Assets/FishNet/Runtime/Utility/Extension/Object.cs
Normal file
27
Assets/FishNet/Runtime/Utility/Extension/Object.cs
Normal file
@ -0,0 +1,27 @@
|
||||
using FishNet.Connection;
|
||||
using FishNet.Object;
|
||||
using System.Runtime.CompilerServices;
|
||||
using UnityEngine;
|
||||
|
||||
namespace FishNet.Utility.Extension
|
||||
{
|
||||
|
||||
public static class ObjectFN
|
||||
{
|
||||
/// <summary>
|
||||
/// Spawns an object over the network using InstanceFinder. Only call from the server.
|
||||
/// </summary>
|
||||
public static void Spawn(this NetworkObject nob, NetworkConnection owner = null)
|
||||
{
|
||||
InstanceFinder.ServerManager.Spawn(nob, owner);
|
||||
}
|
||||
/// <summary>
|
||||
/// Spawns an object over the network using InstanceFinder. Only call from the server.
|
||||
/// </summary>
|
||||
public static void Spawn(this GameObject go, NetworkConnection owner = null)
|
||||
{
|
||||
InstanceFinder.ServerManager.Spawn(go, owner);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
11
Assets/FishNet/Runtime/Utility/Extension/Object.cs.meta
Normal file
11
Assets/FishNet/Runtime/Utility/Extension/Object.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3d1cdee4c45e73a4fa9adba1177483ca
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
43
Assets/FishNet/Runtime/Utility/Extension/Quaternion.cs
Normal file
43
Assets/FishNet/Runtime/Utility/Extension/Quaternion.cs
Normal file
@ -0,0 +1,43 @@
|
||||
using FishNet.Documenting;
|
||||
using UnityEngine;
|
||||
|
||||
namespace FishNet.Utility.Extension
|
||||
{
|
||||
[APIExclude]
|
||||
public static class QuaternionFN
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Returns if two quaternions match.
|
||||
/// </summary>
|
||||
/// <param name="precise">True to use a custom implementation with no error tolerance. False to use Unity's implementation which may return a match even when not true due to error tolerance.</param>
|
||||
/// <returns></returns>
|
||||
public static bool Matches(this Quaternion a, Quaternion b, bool precise = false)
|
||||
{
|
||||
if (precise)
|
||||
return (a.w == b.w && a.x == b.x && a.y == b.y && a.z == b.z);
|
||||
else
|
||||
return (a == b);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the angle between two quaterions.
|
||||
/// </summary>
|
||||
/// <param name="precise">True to use a custom implementation with no error tolerance. False to use Unity's implementation which may return 0f due to error tolerance, even while there is a difference.</param>
|
||||
/// <returns></returns>
|
||||
public static float Angle(this Quaternion a, Quaternion b, bool precise = false)
|
||||
{
|
||||
if (precise)
|
||||
{
|
||||
//This is run Unitys implementation without the error tolerance.
|
||||
float dot = (a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w);
|
||||
return (Mathf.Acos(Mathf.Min(Mathf.Abs(dot), 1f)) * 2f * 57.29578f);
|
||||
}
|
||||
else
|
||||
{
|
||||
return Quaternion.Angle(a, b);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
11
Assets/FishNet/Runtime/Utility/Extension/Quaternion.cs.meta
Normal file
11
Assets/FishNet/Runtime/Utility/Extension/Quaternion.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4b8122e8a7592784896b4173707188ce
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
76
Assets/FishNet/Runtime/Utility/Extension/Scene.cs
Normal file
76
Assets/FishNet/Runtime/Utility/Extension/Scene.cs
Normal file
@ -0,0 +1,76 @@
|
||||
using FishNet.Object;
|
||||
using FishNet.Utility.Performance;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
namespace FishNet.Utility.Extension
|
||||
{
|
||||
|
||||
public static class SceneFN
|
||||
{
|
||||
#region Private.
|
||||
|
||||
/// <summary>
|
||||
/// Used for performance gains when getting objects.
|
||||
/// </summary>
|
||||
private static List<GameObject> _gameObjectList = new List<GameObject>();
|
||||
/// <summary>
|
||||
/// List for NetworkObjects.
|
||||
/// </summary>
|
||||
private static List<NetworkObject> _networkObjectListA = new List<NetworkObject>();
|
||||
/// <summary>
|
||||
/// List for NetworkObjects.
|
||||
/// </summary>
|
||||
private static List<NetworkObject> _networkObjectListB = new List<NetworkObject>();
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Gets all NetworkObjects in a scene.
|
||||
/// </summary>
|
||||
/// <param name="s">Scene to get objects in.</param>
|
||||
/// <param name="firstOnly">True to only return the first NetworkObject within an object chain. False will return nested NetworkObjects.</param>
|
||||
/// <param name="cache">ListCache of found NetworkObjects.</param>
|
||||
/// <returns></returns>
|
||||
public static void GetSceneNetworkObjects(Scene s, bool firstOnly, out ListCache<NetworkObject> nobCache)
|
||||
{
|
||||
nobCache = ListCaches.GetNetworkObjectCache();
|
||||
//Iterate all root objects for the scene.
|
||||
s.GetRootGameObjects(_gameObjectList);
|
||||
foreach (GameObject go in _gameObjectList)
|
||||
{
|
||||
|
||||
//Get NetworkObjects within children of each root.
|
||||
go.GetComponentsInChildren<NetworkObject>(true, _networkObjectListA);
|
||||
//If network objects are found.
|
||||
if (_networkObjectListA.Count > 0)
|
||||
{
|
||||
//Add only the first networkobject
|
||||
if (firstOnly)
|
||||
{
|
||||
/* The easiest way to see if a nob is nested is to
|
||||
* get nobs in parent and if the count is greater than 1, then
|
||||
* it is nested. The technique used here isn't exactly fast but
|
||||
* it will only occur during scene loads, so I'm trading off speed
|
||||
* for effort and readability. */
|
||||
foreach (NetworkObject nob in _networkObjectListA)
|
||||
{
|
||||
nob.GetComponentsInParent<NetworkObject>(true, _networkObjectListB);
|
||||
//No extra nobs, only this one.
|
||||
if (_networkObjectListB.Count == 1)
|
||||
nobCache.AddValue(nob);
|
||||
}
|
||||
}
|
||||
//Not first only, add them all.
|
||||
else
|
||||
{
|
||||
nobCache.AddValues(_networkObjectListA);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
11
Assets/FishNet/Runtime/Utility/Extension/Scene.cs.meta
Normal file
11
Assets/FishNet/Runtime/Utility/Extension/Scene.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a02f3d03f737e304e9854278f4e9211d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
42
Assets/FishNet/Runtime/Utility/Extension/Transforms.cs
Normal file
42
Assets/FishNet/Runtime/Utility/Extension/Transforms.cs
Normal file
@ -0,0 +1,42 @@
|
||||
using FishNet.Documenting;
|
||||
using UnityEngine;
|
||||
|
||||
namespace FishNet.Utility.Extension
|
||||
{
|
||||
[APIExclude]
|
||||
public static class TransformFN
|
||||
{
|
||||
/// <summary>
|
||||
/// Sets the offset values of target from a transform.
|
||||
/// </summary>
|
||||
/// <param name="pos">Position offset result.</param>
|
||||
/// <param name="rot">Rotation offset result.</param>
|
||||
public static void SetTransformOffsets(this Transform t, Transform target, ref Vector3 pos, ref Quaternion rot)
|
||||
{
|
||||
if (target == null)
|
||||
return;
|
||||
pos = (t.position - target.position);
|
||||
rot = (t.rotation * Quaternion.Inverse(target.rotation));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets local position and rotation for a transform.
|
||||
/// </summary>
|
||||
public static void SetLocalPositionAndRotation(this Transform t, Vector3 pos, Quaternion rot)
|
||||
{
|
||||
t.localPosition = pos;
|
||||
t.localRotation = rot;
|
||||
}
|
||||
/// <summary>
|
||||
/// Sets local position, rotation, and scale for a transform.
|
||||
/// </summary>
|
||||
public static void SetLocalPositionRotationAndScale(this Transform t, Vector3 pos, Quaternion rot, Vector3 scale)
|
||||
{
|
||||
t.localPosition = pos;
|
||||
t.localRotation = rot;
|
||||
t.localScale = scale;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
11
Assets/FishNet/Runtime/Utility/Extension/Transforms.cs.meta
Normal file
11
Assets/FishNet/Runtime/Utility/Extension/Transforms.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3d311fc1bf09b9e4fbc5a17a9c50ab0d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user