Пример #1
0
        /// <summary>
        /// Invokes the RPC.
        /// </summary>
        /// <param name="rpcMethodIndex">Index of the RPC method.</param>
        /// <param name="reader">The reader.</param>
        /// <returns></returns>
        public virtual bool InvokeRPC(int rpcMethodIndex, TinyNetStateReader reader)
        {
            if (rpcHandlers[rpcMethodIndex] == null)
            {
                if (TinyNetLogLevel.logError)
                {
                    TinyLogger.LogError("TinyNetBehaviour::InvokeRPC netId:" + TinyInstanceID + " RPCDelegate is not registered.");
                }
                return(false);
            }

            rpcHandlers[rpcMethodIndex].Invoke(reader);

            return(true);
        }
Пример #2
0
        /// <summary>
        /// Deserializes all <see cref="ITinyNetComponent"/> data.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <param name="bInitialState">if set to <c>true</c> [b initial state].</param>
        public virtual void TinyDeserialize(TinyNetStateReader reader, bool firstStateUpdate)
        {
            if (firstStateUpdate && _tinyNetComponents == null)
            {
                if (TinyNetLogLevel.logWarn)
                {
                    TinyLogger.LogWarning("TinyNetIdentity::TinyDeserialize called with firstStateUpdate true, but _tinyNetComponents is null.");
                }
                CacheTinyNetObjects();
            }

            if (firstStateUpdate)
            {
                for (int i = 0; i < _tinyNetComponents.Length; i++)
                {
                    _tinyNetComponents[i].ReceiveNetworkID(new TinyNetworkID(TinyInstanceID.NetworkID, (byte)(i + 1)));

                    _recycleReader.Clear();
                    int rSize = reader.GetInt();
                    _recycleReader.SetSource(reader.RawData, reader.Position, rSize);

                    _recycleReader.SetFrameTick(reader.FrameTick);
                    _tinyNetComponents[i].TinyDeserialize(_recycleReader, firstStateUpdate);
                    // We jump the reader position to the amount of data we read.
                    reader.SkipBytes(rSize);
                }

                return;
            }

            switch (_dirtyFlag.Length)
            {
            case 8:
                TinyBitArrayUtil.U64ToBitArray(reader.GetByte(), _dirtyFlag);
                break;

            case 16:
                TinyBitArrayUtil.U64ToBitArray(reader.GetUShort(), _dirtyFlag);
                break;

            case 32:
                TinyBitArrayUtil.U64ToBitArray(reader.GetUInt(), _dirtyFlag);
                break;

            case 64:
                TinyBitArrayUtil.U64ToBitArray(reader.GetULong(), _dirtyFlag);
                break;
            }

            for (int i = 0; i < _tinyNetComponents.Length; i++)
            {
                if (_dirtyFlag[i] == true)
                {
                    _recycleReader.Clear();
                    int rSize = reader.GetInt();
                    _recycleReader.SetSource(reader.RawData, reader.Position, rSize);

                    _recycleReader.SetFrameTick(reader.FrameTick);
                    //Debug.Log("[Deserialize] Size: " + rSize + ", DirtyFlag: " + TinyBitArrayUtil.Display(_recycleReader.PeekByte()));
                    _tinyNetComponents[i].TinyDeserialize(_recycleReader, firstStateUpdate);
                    // We jump the reader position to the amount of data we read.
                    reader.SkipBytes(rSize);
                }
            }
        }
Пример #3
0
        /// <inheritdoc />
        public virtual void TinyDeserialize(TinyNetStateReader reader, bool firstStateUpdate)
        {
            if (!firstStateUpdate)
            {
                //uint dFlag = reader.GetUInt();
                //TinyBitArrayUtil.U64ToBitArray(dFlag, _dirtyFlag);
                switch (_dirtyFlag.Length)
                {
                case 0:
                    break;

                case 8:
                    //Debug.Log("Deserialize DirtyFlag: " + reader.PeekByte());
                    TinyBitArrayUtil.U64ToBitArray(reader.GetByte(), _dirtyFlag);
                    break;

                case 16:
                    TinyBitArrayUtil.U64ToBitArray(reader.GetUShort(), _dirtyFlag);
                    break;

                case 32:
                    TinyBitArrayUtil.U64ToBitArray(reader.GetUInt(), _dirtyFlag);
                    break;

                case 64:
                    TinyBitArrayUtil.U64ToBitArray(reader.GetULong(), _dirtyFlag);
                    break;
                }
            }

            //Debug.Log("DirtyFlag: " + _dirtyFlag[0]);
            //Debug.Log("DirtyFlag: " + TinyBitArrayUtil.Display(_dirtyFlag));

            Type type;
            int  maxSyncVar = propertiesName.Length;

            for (int i = 0; i < maxSyncVar; i++)
            {
                if (!firstStateUpdate && _dirtyFlag[i] == false)
                {
                    continue;
                }

                type = propertiesTypes[i];

                if (type == typeof(byte))
                {
                    byteAccessor[propertiesName[i]].Set(this, reader.GetByte());
                }
                else if (type == typeof(sbyte))
                {
                    sbyteAccessor[propertiesName[i]].Set(this, reader.GetSByte());
                }
                else if (type == typeof(short))
                {
                    shortAccessor[propertiesName[i]].Set(this, reader.GetShort());
                }
                else if (type == typeof(ushort))
                {
                    ushortAccessor[propertiesName[i]].Set(this, reader.GetUShort());
                }
                else if (type == typeof(int))
                {
                    intAccessor[propertiesName[i]].Set(this, reader.GetInt());
                }
                else if (type == typeof(uint))
                {
                    uintAccessor[propertiesName[i]].Set(this, reader.GetUInt());
                }
                else if (type == typeof(long))
                {
                    longAccessor[propertiesName[i]].Set(this, reader.GetLong());
                }
                else if (type == typeof(ulong))
                {
                    ulongAccessor[propertiesName[i]].Set(this, reader.GetULong());
                }
                else if (type == typeof(float))
                {
                    floatAccessor[propertiesName[i]].Set(this, reader.GetFloat());
                }
                else if (type == typeof(double))
                {
                    doubleAccessor[propertiesName[i]].Set(this, reader.GetDouble());
                }
                else if (type == typeof(bool))
                {
                    boolAccessor[propertiesName[i]].Set(this, reader.GetBool());
                }
                else if (type == typeof(string))
                {
                    stringAccessor[propertiesName[i]].Set(this, reader.GetString());
                }
            }
        }