/// <summary>
        ///  Destroy the GameObject For All PLayers in Room
        /// </summary>
        /// <param name="gameObjTag"> the Game Object Tag You Want To Destroy</param>
        public static void DestroyWithTag(string gameObjTag)
        {
            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(gameObjTag))
            {
                throw new GameServiceException("Failed to Destroy GameObject because gameObjTag Is NullOrEmpty");
            }


            var isDone = _prefabHandler.DestroyWithTag(gameObjTag);

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

            var gameObjData = new GameObjectData(true, gameObjTag);

            SenderUtil.NetworkDestroy(gameObjData);
        }
Пример #2
0
        private static void ApplyObject(byte objectAction, byte[] data, string ownerId, IPrefabHandler handler)
        {
            var action = (ObjectActions)objectAction;

            switch (action)
            {
            case ObjectActions.Instantiate:
                var instantiateData = new InstantiateData();
                GsSerializer.Object.CallReadStream(instantiateData, data);

                // Call Callback
                GsLiveRealtime.Callbacks.OnBeforeInstantiateHandler?.Invoke(null,
                                                                            new OnBeforeInstantiate(instantiateData.PrefabName, ownerId, instantiateData.Position, instantiateData.Rotation));

                var obj = handler.Instantiate(instantiateData.PrefabName, instantiateData.Position, instantiateData.Rotation, ownerId, ownerId == GsLiveRealtime.CurrentPlayerMemberId);

                // Call Callback
                GsLiveRealtime.Callbacks.OnAfterInstantiateHandler?.Invoke(null,
                                                                           new OnAfterInstantiate(obj, instantiateData.PrefabName, ownerId, instantiateData.Position, instantiateData.Rotation));
                break;

            case ObjectActions.Destroy:
                var objectHandler = new GameObjectData();
                GsSerializer.Object.CallReadStream(objectHandler, data);

                // Call Callback
                GsLiveRealtime.Callbacks.OnDestroyObjectHandler?.Invoke(null,
                                                                        new OnDestroyObject(objectHandler.ObjectNameOrTag, objectHandler.IsTag));

                if (objectHandler.IsTag)
                {
                    handler.DestroyWithTag(objectHandler.ObjectNameOrTag);
                }
                else
                {
                    handler.DestroyWithName(objectHandler.ObjectNameOrTag);
                }
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }