Added Unity project files
This commit is contained in:
@ -0,0 +1,12 @@
|
||||
using System;
|
||||
|
||||
namespace VRC.SDK3.ClientSim
|
||||
{
|
||||
/// <summary>
|
||||
/// A wrapper for exceptions that can easily be checked in Tests.
|
||||
/// </summary>
|
||||
public class ClientSimException : Exception
|
||||
{
|
||||
public ClientSimException(string message) : base(message) { }
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e2f5207114724364a99c23559907bd69
|
||||
timeCreated: 1640206766
|
||||
@ -0,0 +1,74 @@
|
||||
using UnityEngine;
|
||||
using VRC.SDKBase;
|
||||
|
||||
namespace VRC.SDK3.ClientSim
|
||||
{
|
||||
public static class ClientSimExtensions
|
||||
{
|
||||
#region VRCPlayerApi
|
||||
|
||||
public static ClientSimPlayerController GetPlayerController(this VRCPlayerApi player)
|
||||
{
|
||||
return player.GetClientSimPlayer().GetPlayerController();
|
||||
}
|
||||
|
||||
public static ClientSimPlayer GetClientSimPlayer(this VRCPlayerApi player)
|
||||
{
|
||||
// Check if the object exists and has not been destroyed due to playmode end.
|
||||
if (player.gameObject != null)
|
||||
{
|
||||
return player.gameObject.GetComponent<ClientSimPlayer>();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ClientSimBehaviour
|
||||
|
||||
internal static void PreventComponentFromSaving(this MonoBehaviour behaviour)
|
||||
{
|
||||
// Ensure that no components are ever saved in user project files.
|
||||
behaviour.hideFlags = HideFlags.DontSaveInEditor | HideFlags.DontSaveInBuild;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Logging
|
||||
|
||||
internal static void Log(string area, string message)
|
||||
{
|
||||
if (ClientSimSettings.Instance.displayLogs)
|
||||
{
|
||||
Debug.Log("[" + System.DateTime.Now.ToString("hh:mm:ss.fff") + "][" + area + "] " + message);
|
||||
}
|
||||
}
|
||||
|
||||
internal static void Log(this object obj, string message)
|
||||
{
|
||||
Log(obj.GetType().Name, message);
|
||||
}
|
||||
|
||||
internal static void LogWarning(string area, string message)
|
||||
{
|
||||
Debug.LogWarning("[" + System.DateTime.Now.ToString("hh:mm:ss.fff") + "][" + area + "] " + message);
|
||||
}
|
||||
|
||||
internal static void LogWarning(this object obj, string message)
|
||||
{
|
||||
LogWarning(obj.GetType().Name, message);
|
||||
}
|
||||
|
||||
internal static void LogError(string area, string message)
|
||||
{
|
||||
Debug.LogError("[" + System.DateTime.Now.ToString("hh:mm:ss.fff") + "][" + area + "] " + message);
|
||||
}
|
||||
|
||||
internal static void LogError(this object obj, string message)
|
||||
{
|
||||
LogError(obj.GetType().Name, message);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2aa1cbed33daf8245ab8d7cef3540953
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,94 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace VRC.SDK3.ClientSim
|
||||
{
|
||||
/// <summary>
|
||||
/// This class is for holding a container of objects that can be deleted at any time.
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
public class ClientSimObjectCollection<T>
|
||||
{
|
||||
private bool _shouldVerifyObjectList;
|
||||
private readonly Queue<T> _toBeAdded = new Queue<T>();
|
||||
private readonly Queue<T> _toBeRemoved = new Queue<T>();
|
||||
private List<T> _allObjects = new List<T>();
|
||||
|
||||
public void AddObject(T obj)
|
||||
{
|
||||
if (obj == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_toBeAdded.Enqueue(obj);
|
||||
}
|
||||
|
||||
public void RemoveObject(T obj)
|
||||
{
|
||||
_shouldVerifyObjectList = true;
|
||||
_toBeRemoved.Enqueue(obj);
|
||||
}
|
||||
|
||||
public void ShouldVerifyObjects()
|
||||
{
|
||||
_shouldVerifyObjectList = true;
|
||||
}
|
||||
|
||||
public void ProcessAddedAndRemovedObjects()
|
||||
{
|
||||
if (_toBeAdded.Count > 0)
|
||||
{
|
||||
foreach (var objs in _toBeAdded)
|
||||
{
|
||||
if (objs == null)
|
||||
{
|
||||
_shouldVerifyObjectList = true;
|
||||
continue;
|
||||
}
|
||||
_allObjects.Add(objs);
|
||||
}
|
||||
_toBeAdded.Clear();
|
||||
}
|
||||
if (_toBeRemoved.Count > 0)
|
||||
{
|
||||
foreach (var objs in _toBeRemoved)
|
||||
{
|
||||
if (objs == null)
|
||||
{
|
||||
_shouldVerifyObjectList = true;
|
||||
continue;
|
||||
}
|
||||
_allObjects.Remove(objs);
|
||||
}
|
||||
_toBeRemoved.Clear();
|
||||
}
|
||||
|
||||
if (_shouldVerifyObjectList)
|
||||
{
|
||||
List<T> allObjs = new List<T>();
|
||||
foreach (var objs in _allObjects)
|
||||
{
|
||||
if (objs == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
allObjs.Add(objs);
|
||||
}
|
||||
|
||||
_allObjects = allObjs;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<T> GetObjects()
|
||||
{
|
||||
foreach (var obj in _allObjects)
|
||||
{
|
||||
if (obj == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
yield return obj;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e25aff8547ec4e39afc88d6b02fd56d2
|
||||
timeCreated: 1638897075
|
||||
@ -0,0 +1,51 @@
|
||||
#if UNITY_EDITOR
|
||||
|
||||
using UnityEditor.PackageManager;
|
||||
|
||||
namespace VRC.SDK3.ClientSim
|
||||
{
|
||||
public static class ClientSimResourceLoader
|
||||
{
|
||||
private const string PACKAGE_PATH = "Packages/com.vrchat.clientsim";
|
||||
|
||||
public static PackageInfo GetPackageInfo()
|
||||
{
|
||||
return PackageInfo.FindForAssetPath(PACKAGE_PATH);
|
||||
}
|
||||
|
||||
public static string GetVersion()
|
||||
{
|
||||
var package = GetPackageInfo();
|
||||
if (package != null)
|
||||
{
|
||||
return package.version;
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
public static string GetPackagePath()
|
||||
{
|
||||
var package = GetPackageInfo();
|
||||
if (package != null)
|
||||
{
|
||||
return package.assetPath;
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
public static string GetResolvePath()
|
||||
{
|
||||
var package = GetPackageInfo();
|
||||
if (package != null)
|
||||
{
|
||||
return package.resolvedPath;
|
||||
}
|
||||
|
||||
// TODO find package path based on known asset in the case where a user installs ClientSim not as a package.
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ad42e5696f9d49de93f3282a9b9de082
|
||||
timeCreated: 1638822659
|
||||
Reference in New Issue
Block a user