This repository has been archived on 2023-09-13. You can view files and clone it, but cannot push or open issues or pull requests.
station_obscurum_unity/Assets/Packages/FishNet/CodeGenerating/Helpers/AttributeHelper.cs
2023-06-01 11:21:49 -07:00

95 lines
3.4 KiB
C#

using FishNet.CodeGenerating.Helping.Extension;
using FishNet.Object;
using FishNet.Object.Helping;
using FishNet.Object.Prediction;
using FishNet.Object.Synchronizing;
using MonoFN.Cecil;
namespace FishNet.CodeGenerating.Helping
{
internal class AttributeHelper : CodegenBase
{
#region Reflection references.
internal string ReplicateAttribute_FullName;
internal string ReconcileAttribute_FullName;
private string ServerAttribute_FullName;
private string ClientAttribute_FullName;
private string ServerRpcAttribute_FullName;
private string ObserversRpcAttribute_FullName;
private string TargetRpcAttribute_FullName;
private string SyncVarAttribute_FullName;
private string SyncObjectAttribute_FullName;
#endregion
public override bool ImportReferences()
{
ServerAttribute_FullName = typeof(ServerAttribute).FullName;
ClientAttribute_FullName = typeof(ClientAttribute).FullName;
ServerRpcAttribute_FullName = typeof(ServerRpcAttribute).FullName;
ObserversRpcAttribute_FullName = typeof(ObserversRpcAttribute).FullName;
TargetRpcAttribute_FullName = typeof(TargetRpcAttribute).FullName;
SyncVarAttribute_FullName = typeof(SyncVarAttribute).FullName;
SyncObjectAttribute_FullName = typeof(SyncObjectAttribute).FullName;
ReplicateAttribute_FullName = typeof(ReplicateAttribute).FullName;
ReconcileAttribute_FullName = typeof(ReconcileAttribute).FullName;
return true;
}
/// <summary>
/// Returns type of Rpc attributeFullName is for.
/// </summary>
/// <param name="attributeFullName"></param>
/// <returns></returns>
public RpcType GetRpcAttributeType(CustomAttribute ca)
{
if (ca.Is(ServerRpcAttribute_FullName))
return RpcType.Server;
else if (ca.Is(ObserversRpcAttribute_FullName))
return RpcType.Observers;
else if (ca.Is(TargetRpcAttribute_FullName))
return RpcType.Target;
else
return RpcType.None;
}
/// <summary>
/// Returns type of Rpc attributeFullName is for.
/// </summary>
/// <param name="attributeFullName"></param>
/// <returns></returns>
internal QolAttributeType GetQolAttributeType(string attributeFullName)
{
if (attributeFullName == ServerAttribute_FullName)
return QolAttributeType.Server;
else if (attributeFullName == ClientAttribute_FullName)
return QolAttributeType.Client;
else
return QolAttributeType.None;
}
/// <summary>
/// Returns if attribute if a SyncVarAttribute.
/// </summary>
/// <param name="attributeFullName"></param>
/// <returns></returns>
public bool IsSyncVarAttribute(string attributeFullName)
{
return (attributeFullName == SyncVarAttribute_FullName);
}
/// <summary>
/// Returns if attribute if a SyncObjectAttribute.
/// </summary>
/// <param name="attributeFullName"></param>
/// <returns></returns>
public bool IsSyncObjectAttribute(string attributeFullName)
{
return (attributeFullName == SyncObjectAttribute_FullName);
}
}
}