Exemple #1
0
        public void OnStreamInstanceEvent(SyncedData <StreamAsset> stream, StreamEvent streamEvent)
        {
            if (streamEvent == StreamEvent.Added)
            {
                if (!PersistentKey.IsKeyFor <SyncObjectInstance>(stream.key.key))
                {
                    return;
                }

                EnqueueDownloadRequest(stream.data);
            }
            else if (streamEvent == StreamEvent.Changed)
            {
                if (PersistentKey.IsKeyFor <SyncObjectInstance>(stream.key.key))
                {
                    EnqueueDownloadRequest(stream.data);
                }
                else if (PersistentKey.IsKeyFor <SyncObject>(stream.key.key))
                {
                    var instances = m_Instances[stream.key];

                    foreach (var instance in instances)
                    {
                        m_DirtySyncObject.Add(instance.key);
                        EnqueueDownloadRequest(instance);
                    }
                }
            }
            else if (streamEvent == StreamEvent.Removed)
            {
                if (!PersistentKey.IsKeyFor <SyncObjectInstance>(stream.key.key))
                {
                    return;
                }

                var key = stream.key;
                if (m_Cache.TryGetValue(key, out var value))
                {
                    m_Cache.Remove(key);

                    // Removing the deleted instance from m_Instances
                    var persistentKey = PersistentKey.GetKey <SyncObject>(value.instance.ObjectId);
                    var objectKey     = new StreamKey(key.source, persistentKey);
                    var instances     = m_Instances[objectKey];
                    instances.Remove(stream.data);

                    m_InstanceDataOutput.SendStreamRemoved(new SyncedData <StreamInstance>(key, value));
                }
            }
        }
Exemple #2
0
        public void OnStreamRemoved(SyncedData <StreamInstance> stream)
        {
            var metadata = stream.data.instance.Metadata;

            if (metadata != null && metadata.Parameters.TryGetValue("Category", out var category))
            {
                if (m_Instances.TryGetValue(category.Value, out var filter))
                {
                    filter.streams.Remove(stream);
                }
            }

            m_StreamOutput.SendStreamRemoved(stream);
        }
Exemple #3
0
        protected override void UpdateInternal(float unscaledDeltaTime)
        {
            while (m_PendingRemoved.TryDequeue(out var stream))
            {
                var streamAsset = (StreamAsset)stream;
                var syncedData  = new SyncedData <StreamAsset>(streamAsset.key, streamAsset);
                m_AssetOutput.SendStreamRemoved(syncedData);
            }

            while (m_PendingAdded.TryDequeue(out var stream))
            {
                var streamAsset = (StreamAsset)stream;
                var syncedData  = new SyncedData <StreamAsset>(streamAsset.key, streamAsset);
                m_AssetOutput.SendStreamAdded(syncedData);
            }

            while (m_PendingModified.TryDequeue(out var stream))
            {
                var streamAsset = (StreamAsset)stream;
                var syncedData  = new SyncedData <StreamAsset>(streamAsset.key, streamAsset);
                m_AssetOutput.SendStreamChanged(syncedData);
            }

            if (m_Task != null && m_Task.IsCompleted)
            {
                m_AssetOutput.SendEnd();
                m_Task = null;

                LogTimes();
            }
        }
Exemple #4
0
        public void OnStreamEvent(SyncedData <StreamInstanceData> stream, StreamEvent streamEvent)
        {
            var objectKey = new StreamKey(stream.key.source, PersistentKey.GetKey <SyncObject>(stream.data.syncObject.Id));

            if (streamEvent == StreamEvent.Added)
            {
                m_SyncObjects[objectKey] = stream.data.syncObject;
                var syncObjectBinding = ImportInstance(stream.data.instance);

                var key = stream.data.instance.key;
                m_Instances[key]            = syncObjectBinding;
                syncObjectBinding.streamKey = key;

                m_Output.SendStreamAdded(new SyncedData <GameObject>(key, syncObjectBinding.gameObject));
            }
            else if (streamEvent == StreamEvent.Changed)
            {
                var key = stream.data.instance.key;
                // The instance moved, or the name/metadata changed.
                var syncObjectBinding = m_Instances[key];

                ImportersUtils.SetTransform(syncObjectBinding.transform, stream.data.instance.instance.Transform);
                ImportersUtils.SetMetadata(syncObjectBinding.gameObject, stream.data.instance.instance.Metadata);
                syncObjectBinding.gameObject.name = stream.data.instance.instance.Name;

                m_Output.SendStreamChanged(new SyncedData <GameObject>(key, syncObjectBinding.gameObject));
            }
            else if (streamEvent == StreamEvent.Removed)
            {
                var key = stream.data.instance.key;
                // The instance either moved, or the metadata changed.
                var syncObjectBinding = m_Instances[key];

                m_Instances.Remove(key);

                m_Output.SendStreamRemoved(new SyncedData <GameObject>(key, syncObjectBinding.gameObject));

                if (m_Originals.TryGetValue(objectKey, out var original))
                {
                    UntrackDependencies(original.Dependencies);

                    if (original.NbActiveInstances == 1)
                    {
                        m_Originals.Remove(objectKey);
                    }
                    else
                    {
                        --original.NbActiveInstances;
                        m_Originals[objectKey] = original;
                    }
                }

                Object.Destroy(syncObjectBinding.gameObject);
            }
        }
        // TODO Add event for modified / removed asset

        public void OnStreamInstanceEvent(SyncedData <StreamInstance> stream, StreamEvent streamEvent)
        {
            if (streamEvent == StreamEvent.Added)
            {
                EnqueueDownloadRequest(stream.data);
            }
            else if (streamEvent == StreamEvent.Changed)
            {
                EnqueueDownloadRequest(stream.data);
            }
            else if (streamEvent == StreamEvent.Removed)
            {
                var key = stream.key;

                if (m_InstanceCache.TryGetValue(key, out var instanceData))
                {
                    m_InstanceCache.Remove(key);
                    m_InstanceDataOutput.SendStreamRemoved(new SyncedData <StreamInstanceData>(key, instanceData));
                }
            }
        }