示例#1
0
        public override void Import(SWBytes buffer)
        {
            UInt16 behaviourCount = buffer.PopUInt16();

            if (behaviourCount != _behaviours.Count)
            {
                throw new Exception($"StaticFrameSyncBehaviourManager: Import importBehaviourCount={behaviourCount} behaviourCount={ _behaviours.Count}");
            }

            foreach (var pair in _behaviours)
            {
                UInt16 id = pair.Key;
                StaticFrameSyncBehaviour behaviour = pair.Value;

                UInt16 importId = buffer.PopUInt16();

                if (importId != id)
                {
                    throw new Exception($"StaticFrameSyncBehaviourManager: Import importID={importId} id={id}");
                }

                behaviour.ImportData(buffer);
            }
        }
示例#2
0
        internal void ImportData(SWBytes buffer)
        {
            _byteBuffer.Reset();

            if (largeDataContainer)
            {
                UInt16 size = _byteBuffer.PopUInt16();
                buffer.PopByteBuffer(_byteBuffer, 0, size);
            }
            else
            {
                byte size = buffer.PopByte();
                buffer.PopByteBuffer(_byteBuffer, 0, size);
            }

            foreach (IFrameSyncData frameSyncData in _frameSyncDatas)
            {
                frameSyncData.Import(_byteBuffer);
            }
        }
示例#3
0
        public void Import(SWBytes buffer)
        {
            UInt16 dataLength = buffer.PopUInt16();

            buffer.PopByteBuffer(bytes, 0, (int)dataLength);
        }
示例#4
0
        public override void Import(SWBytes buffer)
        {
            _nextDynamicBehaviourIndex = buffer.PopUInt16();
            UInt16 importBehaviourCount = buffer.PopUInt16();

            //index always starts from 1
            UInt16 importBehaviourIndex = 1;
            UInt16 selfBehaviourIndex   = 1;

            UInt16 importBehaviourRead = 0;
            UInt16 selfBehaviourRead   = 0;

            UInt16 selfKeyIndex = 0;

            UInt16 selfBehaviourCount = (UInt16)_behaviours.Count;

            if (selfBehaviourCount > 0)
            {
                selfBehaviourIndex = _behaviours.Keys[selfKeyIndex];
            }

            if (importBehaviourCount > 0)
            {
                importBehaviourIndex = buffer.PopUInt16();
            }

            bool shouldReadImport = false;
            bool shouldReadSelf   = false;

            while (importBehaviourRead < importBehaviourCount && selfBehaviourRead < selfBehaviourCount)
            {
                if (shouldReadImport)
                {
                    importBehaviourIndex = buffer.PopUInt16();
                }

                if (shouldReadSelf)
                {
                    selfBehaviourIndex = _behaviours.Keys[selfKeyIndex];
                }

                if (importBehaviourIndex == selfBehaviourIndex)
                {
                    //id matched
                    DynamicFrameSyncBehaviour behaviour = _behaviours[selfBehaviourIndex];

                    //check prefab
                    UInt16 importPrefebId = buffer.PopUInt16();
                    UInt16 selfPrefabId   = behaviour.prefabID;

                    if (importPrefebId == selfPrefabId)
                    {
                        //prefab matched
                        behaviour.ImportData(buffer);
                    }
                    else
                    {
                        //self behaviour was spawned with a different prefab

                        //remove self wrong GameObject
                        Remove(selfBehaviourIndex);

                        //create a new GameObject with the correct prefab
                        DynamicFrameSyncBehaviour newBehaviour = Add(importBehaviourIndex, importPrefebId);
                        newBehaviour.ImportData(buffer);
                    }

                    importBehaviourRead++;
                    selfBehaviourRead++;
                    selfKeyIndex++;

                    shouldReadImport = true;
                    shouldReadSelf   = true;
                }
                else if (importBehaviourIndex > selfBehaviourIndex)
                {
                    //remove extra self behaviour
                    Remove(selfBehaviourIndex);

                    selfBehaviourRead++;

                    //read next self behaviour only
                    shouldReadImport = false;
                    shouldReadSelf   = true;
                }
                else
                {
                    //add missing import entity
                    UInt16 importPrefabId = buffer.PopUInt16();
                    DynamicFrameSyncBehaviour newBehaviour = Add(importBehaviourIndex, importPrefabId);
                    newBehaviour.ImportData(buffer);

                    importBehaviourRead++;

                    //key just added, we want to skip the just added index
                    selfKeyIndex++;

                    //just increase key index, no need to read self behaviour
                    shouldReadImport = true;
                    shouldReadSelf   = false;
                }
            }

            while (importBehaviourRead < importBehaviourCount)
            {
                if (shouldReadImport)
                {
                    importBehaviourIndex = buffer.PopUInt16();
                }

                UInt16 importPrefabId = buffer.PopUInt16();
                DynamicFrameSyncBehaviour newBehaviour = Add(importBehaviourIndex, importPrefabId);
                newBehaviour.ImportData(buffer);

                importBehaviourRead++;

                //read next remote behaviour
                shouldReadImport = true;
            }

            while (selfBehaviourRead < selfBehaviourCount)
            {
                if (shouldReadSelf)
                {
                    selfBehaviourIndex = _behaviours.Keys[selfKeyIndex];
                }

                Remove(selfBehaviourIndex);

                selfBehaviourRead++;

                //read next self behaviour
                shouldReadSelf = true;
            }
        }