/// <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);
        }
        /// <summary>
        ///  Destroy the GameObject For All PLayers in Room
        /// </summary>
        /// <param name="gameObjName"> the Game Object Name You Want To Destroy</param>
        public static void DestroyWithName(string gameObjName)
        {
            if (!IsAvailable)
            {
                throw new GameServiceException("GsLiveRealtime is Not Available");
            }

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

            if (string.IsNullOrEmpty(gameObjName))
            {
                throw new GameServiceException("Failed to Destroy GameObject because gameObjName Is NullOrEmpty");
            }

            var isDone = _prefabHandler.DestroyWithName(gameObjName);

            if (!isDone)
            {
                throw new GameServiceException("Failed to Destroy GameObject because GameObject With this Name Not Found!");
            }

            var gameObjData = new GameObjectData(false, gameObjName);

            SenderUtil.NetworkDestroy(gameObjData);
        }
Esempio n. 3
0
 private void OnUpdate(object sender, Event e)
 {
     if (serializableComponent == null)
     {
         return;
     }
     SenderUtil.NetworkObserver(id, serializableComponent as IGsLiveSerializable);
 }
 private void OnUpdate(object sender, EventUtil e)
 {
     if (serializableComponent == null)
     {
         return;
     }
     if (FiroozehGameService.Core.GameService.GSLive.IsRealTimeAvailable())
     {
         SenderUtil.NetworkObserver(id, serializableComponent as IGsLiveSerializable);
         isAvailable = true;
     }
     else
     {
         isAvailable = false;
     }
 }
        /// <summary>
        /// Remove a Property With propertyName
        /// </summary>
        /// <param name="propertyName">The name of a Property You Want To Remove it</param>
        public static void RemoveProperty(string propertyName)
        {
            if (!IsAvailable)
            {
                throw new GameServiceException("GsLiveRealtime is Not Available");
            }

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

            _propertyHandler.RemoveProperty(CurrentPlayerMemberId, propertyName);

            var property = new PropertyData(propertyName);

            SenderUtil.NetworkProperty(property, PropertyAction.Remove);
        }
        /// <summary>
        /// Apply a Property ,You Can Add or Edit A Property
        /// </summary>
        /// <param name="property">The Property You Want To Add or Edit</param>
        public static void SetProperty(Property property)
        {
            if (!IsAvailable)
            {
                throw new GameServiceException("GsLiveRealtime is Not Available");
            }

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

            _propertyHandler.ApplyProperty(CurrentPlayerMemberId, property);

            var propertyData = new PropertyData(property.PropertyName, property.PropertyData);

            SenderUtil.NetworkProperty(propertyData, PropertyAction.Apply);
        }
        /// <summary>
        ///  Instantiate the GameObject For All PLayers in Room
        ///  notes : Your prefab Must Save in Resources folder
        /// </summary>
        public static GameObject Instantiate(string prefabName, Vector3 position, Quaternion rotation)
        {
            if (!IsAvailable)
            {
                throw new GameServiceException("GsLiveRealtime is Not Available");
            }

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


            var instantiateData = new InstantiateData(prefabName, position, rotation);
            var gameObject      = _prefabHandler.Instantiate(prefabName, position, rotation, CurrentPlayerMemberId, true);

            SenderUtil.NetworkInstantiate(instantiateData);
            return(gameObject);
        }