Пример #1
0
        protected virtual void OnInstantiateInNode_ServerClient(RpcArgs pArgs)
        {
            byte[]             data        = pArgs.GetNext <byte[]>();
            RPCServiceCallback callbackRPC = data.ByteArrayToObject <RPCServiceCallback>();
            NetworkBehavior    behavior;

            if (NodeManager.IsInitialized)
            {
                RPCInstantiateInNode instantiateInNodeRPC = callbackRPC.data.ByteArrayToObject <RPCInstantiateInNode>();
                behavior = NodeManager.Instance.InstantiateInScene(instantiateInNodeRPC.sceneName, instantiateInNodeRPC.createCode, null, instantiateInNodeRPC.position.ToVector3(), instantiateInNodeRPC.rotation.ToQuaternion(), instantiateInNodeRPC.sendTransform);
                if (behavior != null)
                {
                    IRPCSerializable behaviorData = behavior as IRPCSerializable;
                    if (behaviorData != null && instantiateInNodeRPC.behaviorData != null)
                    {
                        behaviorData.FromByteArray(instantiateInNodeRPC.behaviorData);
                    }
                }
            }
            else
            {
                behavior = null;
            }

            callbackRPC.state = (behavior != null) ? ServiceCallbackStateEnum.RESPONSE_SUCCESS : ServiceCallbackStateEnum.RESPONSE_FAILED;
            callbackRPC.data  = null;
            networkObject.SendRpc(RPC_RELAY_CONFIRM_INSTANTIATE_IN_NODE, Receivers.Server, callbackRPC.ObjectToByteArray());
        }
Пример #2
0
        public static ServiceCallback <RPCInstantiateInNode, ServiceCallbackStateEnum> InstantiateInNode(uint pSourceNodeId, uint pTargetNodeId, string pSceneName, int pCreateCode, IRPCSerializable pBehaviorData, Vector3?pPosition, Quaternion?pRotation, bool pSendTransform)
        {
            ServiceCallback <RPCInstantiateInNode, ServiceCallbackStateEnum> callback = new ServiceCallback <RPCInstantiateInNode, ServiceCallbackStateEnum>(0, pSourceNodeId, GameTime.fixedTime);

            if (!IsInitialized)
            {
                callback.State = ServiceCallbackStateEnum.ERROR_SERVICE_NOT_INITIALIZED;
                return(callback);
            }

            if (Instance.Manager == null || !Instance.Manager.HasNetworker || !Instance.Manager.Networker.IsConnected)
            {
                callback.State = ServiceCallbackStateEnum.ERROR_NO_CONNECTION;
                return(callback);
            }

            RPCInstantiateInNode requestData = new RPCInstantiateInNode()
            {
                targetNodeId = pTargetNodeId, sceneName = pSceneName, createCode = pCreateCode, sendTransform = pSendTransform
            };

            if (pBehaviorData != null)
            {
                requestData.behaviorData = pBehaviorData.ToByteArray();
            }

            if (pPosition != null)
            {
                requestData.position = pPosition.Value.ToRPC();
            }

            if (pRotation != null)
            {
                requestData.rotation = pRotation.Value.ToRPC();
            }

            callback.RequestDataOfT = requestData;
            callback.State          = ServiceCallbackStateEnum.AWAITING_RESPONSE;
            Instance.AddPendingServiceCallback(callback);
            MainThreadManager.Run(() => {
                if (!IsInitialized || Instance.networkObject == null)
                {
                    return;
                }

                Instance.networkObject.SendRpc(RPC_RELAY_INSTANTIATE_IN_NODE, Receivers.Server, callback.ToByteArray());
            });

            return(callback);
        }
Пример #3
0
        protected virtual void OnRelayInstantiateInNode_Server(RpcArgs pArgs)
        {
            // We relay the message to the right Node if possible
            byte[]               data                 = pArgs.GetNext <byte[]>();
            RPCServiceCallback   callbackRPC          = data.ByteArrayToObject <RPCServiceCallback>();
            RPCInstantiateInNode instantiateInNodeRPC = callbackRPC.data.ByteArrayToObject <RPCInstantiateInNode>();
            NetworkingPlayer     networkingPlayer;

            if (!_nodeToNetworkingPlayer.TryGetValue(instantiateInNodeRPC.targetNodeId, out networkingPlayer))
            {
                callbackRPC.state = ServiceCallbackStateEnum.RESPONSE_FAILED;
                callbackRPC.data  = null;
                networkObject.SendRpc(pArgs.Info.SendingPlayer, RPC_CONFIRM_INSTANTIATE_IN_NODE, callbackRPC.ObjectToByteArray());
                return;
            }

            networkObject.SendRpc(networkingPlayer, RPC_INSTANTIATE_IN_NODE, data);
        }