/// <summary>
        /// Run a Function method on remote clients of this room (or on all, including this client).
        /// </summary>
        /// <param name="functionName">The name of a fitting function that was has the GsLiveFunction attribute.</param>
        /// <param name="type">The group of targets and the way the Function gets sent.</param>
        /// <param name="parameters">The Parameters that the Function method has.</param>
        public static void RunFunction <TFrom>(string functionName, FunctionType type, params object[] parameters)
        {
            if (!IsAvailable)
            {
                throw new GameServiceException("GsLiveRealtime is Not Available");
            }

            if (!FiroozehGameService.Core.GameService.GSLive.IsRealTimeAvailable())
            {
                throw new GameServiceException("RealTime is Not Available");
            }

            var objType = typeof(TFrom);

            _monoBehaviourHandler.RefreshMonoBehaviourCache();
            var isOk = _functionHandler.RunFunction(functionName, objType, type, parameters);

            if (!isOk)
            {
                return;
            }


            var extraBuffer  = GsSerializer.Function.SerializeParams(parameters);
            var functionData = new FunctionData(objType.FullName, functionName, type, extraBuffer);

            // run on this Client
            if (type == FunctionType.All || type == FunctionType.Buffered)
            {
                ActionUtil.ApplyFunction(functionData: functionData, monoBehaviourHandler: _monoBehaviourHandler);
            }

            SenderUtil.NetworkRunFunction(functionData);
        }
Beispiel #2
0
        internal static void ApplyFunction(byte[] buffer = null, FunctionData functionData = null, IMonoBehaviourHandler monoBehaviourHandler = null)
        {
            var func = functionData;

            object[] parameters = null;

            if (func == null && buffer != null)
            {
                func = new FunctionData();
                GsSerializer.Object.CallReadStream(func, buffer);
            }

            var haveBuffer = func.ExtraData != null;

            if (haveBuffer)
            {
                parameters = GsSerializer.Function.DeserializeParams(func.ExtraData);
            }

            monoBehaviourHandler.RefreshMonoBehaviourCache();
            var(baseObj, info) = ObjectUtil.GetFunction(func.MethodName, func.FullName, parameters);

            info.Invoke(baseObj, parameters);
        }