Beispiel #1
0
        public void Initialize(NetworkObject obj)
        {
            // We have already initialized this object
            if (networkObject != null && networkObject.AttachedBehavior != null)
            {
                return;
            }

            networkObject = (TestNetworkObject)obj;

            networkObject.RegisterRpc("FuncBlank", FuncBlank);
            networkObject.RegisterRpc("FuncByte", FuncByte, typeof(byte));
            networkObject.RegisterRpc("FuncChar", FuncChar, typeof(char));
            networkObject.RegisterRpc("FuncShort", FuncShort, typeof(short));
            networkObject.RegisterRpc("FuncUShort", FuncUShort, typeof(ushort));
            networkObject.RegisterRpc("FuncBool", FuncBool, typeof(bool));
            networkObject.RegisterRpc("FuncInt", FuncInt, typeof(int));
            networkObject.RegisterRpc("FuncUInt", FuncUInt, typeof(uint));
            networkObject.RegisterRpc("FuncFloat", FuncFloat, typeof(float));
            networkObject.RegisterRpc("FuncLong", FuncLong, typeof(long));
            networkObject.RegisterRpc("FuncULong", FuncULong, typeof(ulong));
            networkObject.RegisterRpc("FuncDouble", FuncDouble, typeof(double));
            networkObject.RegisterRpc("FuncString", FuncString, typeof(string));
            networkObject.RegisterRpc("FuncByteArray", FuncByteArray, typeof(byte[]));
            networkObject.RegisterRpc("FuncAll", FuncAll, typeof(byte), typeof(char), typeof(short), typeof(ushort), typeof(bool), typeof(int), typeof(uint), typeof(float), typeof(long), typeof(ulong), typeof(double), typeof(string), typeof(byte[]));
            networkObject.RegisterRpc("FuncStringByteArray", FuncStringByteArray, typeof(string), typeof(byte[]));

            networkObject.onDestroy += DestroyGameObject;
        }
        protected void SetupServerBehavior()
        {
            // Make the network object on the client and make sure that the server creates it too
            serverBehavior = new RPCBehavior();
            serverBehavior.Initialize(server);
            serverObj = serverBehavior.networkObject;

            WaitFor(() => { return(clientObj != null); });
            clientBehavior = new RPCBehavior();
            clientBehavior.Initialize(clientObj);

            if (otherClient == null)
            {
                WaitFor(() => { return(client.NetworkObjects.Count == 1 && server.NetworkObjects.Count == 1); });
                return;
            }

            WaitFor(() => { return(otherClientObj != null); });
            otherClientBehavior = new RPCBehavior();
            otherClientBehavior.Initialize(otherClientObj);

            WaitFor(() =>
            {
                return(client.NetworkObjects.Count == 1 &&
                       otherClient.NetworkObjects.Count == 1 &&
                       server.NetworkObjects.Count == 1);
            });
        }
        protected void Destroy(TestNetworkObject obj)
        {
            obj.Destroy();

            // Make sure that the object was destroyed on the server and the client
            if (otherClient == null)
            {
                WaitFor(() => { return(server.NetworkObjectList.Count == 0 && client.NetworkObjectList.Count == 0); });
            }
            else
            {
                WaitFor(() =>
                {
                    return(server.NetworkObjectList.Count == 0 &&
                           client.NetworkObjectList.Count == 0 &&
                           otherClient.NetworkObjectList.Count == 0);
                });
            }

            serverBehavior      = null;
            clientBehavior      = null;
            otherClientBehavior = null;
            serverObj           = null;
            clientObj           = null;
            otherClientObj      = null;
        }
Beispiel #4
0
 private bool CheckTargetFields(TestNetworkObject target)
 {
     return(target.fieldByte == byte.MaxValue &&
            //target.fieldSByte == sbyte.MinValue &&
            target.fieldChar == 'F' &&
            target.fieldBool == true &&
            target.fieldShort == short.MinValue &&
            target.fieldUShort == ushort.MaxValue &&
            target.fieldInt == int.MinValue &&
            target.fieldUInt == uint.MaxValue &&
            target.fieldLong == long.MinValue &&
            target.fieldULong == ulong.MaxValue &&
            target.fieldFloat == float.MaxValue &&
            target.fieldDouble == double.MaxValue);
 }
Beispiel #5
0
 private void SetTargetFields(TestNetworkObject target)
 {
     target.fieldByte = byte.MaxValue;
     //target.fieldSByte = sbyte.MinValue;
     target.fieldChar   = 'F';
     target.fieldBool   = true;
     target.fieldShort  = short.MinValue;
     target.fieldUShort = ushort.MaxValue;
     target.fieldInt    = int.MinValue;
     target.fieldUInt   = uint.MaxValue;
     target.fieldLong   = long.MinValue;
     target.fieldULong  = ulong.MaxValue;
     target.fieldFloat  = float.MaxValue;
     target.fieldDouble = double.MaxValue;
 }
Beispiel #6
0
        public void NetworkCreateObject(NetWorker networker, int identity, uint id, FrameStream frame, System.Action <NetworkObject> callback)
        {
            bool          availableCallback = false;
            NetworkObject obj = null;

            switch (identity)
            {
            case TestNetworkObject.IDENTITY:
                availableCallback = true;
                obj = new TestNetworkObject(networker, id, frame);
                callback?.Invoke(obj);
                break;
            }

            if (!availableCallback)
            {
                if (callback != null)
                {
                    callback(obj);
                }
            }
        }
        protected static void ObjectCreated(NetworkObject target)
        {
            if (target is TestNetworkObject)
            {
                if (target.Networker.IsServer)
                {
                    serverObj = (TestNetworkObject)target;
                }
                else
                {
                    if (target.Networker == client)
                    {
                        clientObj = (TestNetworkObject)target;
                    }
                    else
                    {
                        otherClientObj = (TestNetworkObject)target;
                    }
                }

                target.ReleaseCreateBuffer();
            }
        }