BeardedManStudios.Network.NetworkedMonoBehavior.AddNetworkVariable C# (CSharp) Method

AddNetworkVariable() protected method

Add a network variable to the NetworkedMonoBehavior to use
protected AddNetworkVariable ( Func getter, Action setter, NetSync netSync = null, bool manualProperty = false, bool serverOnly = false ) : void
getter Func Variable to get
setter Action Variable to set
netSync NetSync
manualProperty bool
serverOnly bool
return void
		protected void AddNetworkVariable(Func<object> getter, Action<object> setter, NetSync netSync = null, bool manualProperty = false, bool serverOnly = false)
		{
			if (IsSetup)
				throw new NetworkException(6, "Network variables can not be added after the Awake method of this MonoBehaviour");

			Action callback = null;
			NetworkCallers callers = NetworkCallers.Everyone;
			NetSync.Interpolate useInterpolation = NetSync.Interpolate.True;

			if (netSync != null)
			{
				if (!string.IsNullOrEmpty(netSync.method))
				{
#if NETFX_CORE
					callback = () => { this.GetType().GetRuntimeMethod(netSync.method, null).Invoke(this, new object[] { }); };
#else
					callback = (Action)Delegate.CreateDelegate(typeof(Action), this, netSync.method);
#endif
				}

				callers = netSync.callers;
				useInterpolation = netSync.interpolate;
			}

			if (manualProperty)
				ManualProperties.Add(new NetRef<object>(getter, setter, callback, callers, useInterpolation == NetSync.Interpolate.False));
			else
				Properties.Add(new NetRef<object>(getter, setter, callback, callers, useInterpolation == NetSync.Interpolate.False, serverOnly));
		}