Ejemplo n.º 1
0
        void OnSpatialDataChanged(NetContext <SpatialDataChanged> ctx)
        {
            var added   = ctx.Data.Added.Select(x => x.Id).ToList();
            var removed = ctx.Data.Removed.Select(x => x.Id).ToList();

            m_UpdateStreamingOutput.Send(new UpdateStreaming(added, removed));
        }
Ejemplo n.º 2
0
        void OnGameObjectCreating(PipeContext <GameObjectCreating> ctx)
        {
            var idToGroupToFilterKeys = new List <(DynamicGuid, Dictionary <string, string>)>();
            var toggleCounts          = new List <(DynamicGuid, int)>();

            foreach (var go in ctx.Data.GameObjectIds)
            {
                if (!go.GameObject.TryGetComponent <Metadata>(out var metadata))
                {
                    continue;
                }

                var groupToFilterKeys = new Dictionary <string, string>();

                foreach (var groupKey in m_SafeList)
                {
                    if (!metadata.GetParameters().TryGetValue(groupKey, out Metadata.Parameter category))
                    {
                        continue;
                    }

                    if (string.IsNullOrEmpty(category.value))
                    {
                        continue;
                    }

                    if (!m_FilterGroups.TryGetValue(groupKey, out var dicFilterData))
                    {
                        dicFilterData = m_FilterGroups[groupKey] = new Dictionary <string, List <DynamicGuid> >();
                        m_MetadataGroupsChangedOutput.Broadcast(new MetadataGroupsChanged(m_FilterGroups.Keys.OrderBy(e => e).ToList()));
                    }

                    if (!dicFilterData.TryGetValue(category.value, out var filterData))
                    {
                        filterData = dicFilterData[category.value] = new List <DynamicGuid>();
                        var diff = new Diff <string>();
                        diff.Added.Add(category.value);
                        m_MetadataCategoriesChangedOutput.Broadcast(new MetadataCategoriesChanged(groupKey, diff));
                    }

                    filterData.Add(go.Id);
                    groupToFilterKeys.Add(groupKey, category.value);
                }

                if (groupToFilterKeys.Count == 0)
                {
                    continue;
                }

                idToGroupToFilterKeys.Add((go.Id, groupToFilterKeys));
                var nbEnabled = -groupToFilterKeys.Count(x => m_DisabledGroups.TryGetValue(x.Key, out var filterKeys) && filterKeys.Contains(x.Value));
                if (nbEnabled < 0)
                {
                    toggleCounts.Add((go.Id, nbEnabled));
                }
            }

            if (idToGroupToFilterKeys.Count > 0)
            {
                m_ObjectMetadataChanged.Broadcast(new ObjectMetadataChanged(idToGroupToFilterKeys));
            }

            if (toggleCounts.Count > 0)
            {
                m_ToggleGameObjectOutput.Send(new ToggleGameObject(toggleCounts));
            }

            ctx.Continue();
        }
        void OnAcquireUnityResource(RpcContext <AcquireUnityResource> ctx)
        {
            if (CompleteIfStreamCanceled(ctx))
            {
                return;
            }

            if (CompleteIfResourceInCache(ctx))
            {
                return;
            }

            var tracker = new Tracker {
                Ctx = ctx
            };

            if (m_Waiters.TryGetValue(ctx.Data.ResourceData.Id, out var trackers))
            {
                trackers.Add(tracker);
                return;
            }

            m_Waiters.Add(ctx.Data.ResourceData.Id, new List <Tracker> {
                tracker
            });

            // From this point a request won't be cancellable because it's too complicated to track interlaced resource requests.
            // We may implement it later but the overhead may outweigh the benefits
            var rpc = m_AcquireResourceOutput.Call(this, ctx, (object)null, new AcquireResource(new StreamState(), ctx.Data.ResourceData));

            rpc.Success <ISyncModel>((self, ctx, _, syncModel) =>
            {
                var(entry, trackers) = self.GetCommonData(ctx);

                RpcOutput <ConvertResource <object> > output;
                object msg;
                // Hack to toggle between different output based on previous request result.
                // Needs a standard way to do this. It could be a native mechanism that does the same as this
                if (syncModel is SyncMesh mesh)
                {
                    output = Unsafe.As <RpcOutput <ConvertResource <object> > >(m_ConvertMeshOutput);
                    msg    = new ConvertResource <SyncMesh>(ctx.Data.ResourceData, mesh);
                }
                else if (syncModel is SyncMaterial material)
                {
                    output = Unsafe.As <RpcOutput <ConvertResource <object> > >(m_ConvertMaterialOutput);
                    msg    = new ConvertResource <SyncMaterial>(ctx.Data.ResourceData, material);
                }
                else if (syncModel is SyncTexture texture)
                {
                    output = Unsafe.As <RpcOutput <ConvertResource <object> > >(m_ConvertTextureOutput);
                    msg    = new ConvertResource <SyncTexture>(ctx.Data.ResourceData, texture);
                }
                else
                {
                    foreach (var tracker in trackers)
                    {
                        tracker.Ctx.SendFailure(new Exception($"No converter exists for type {syncModel.GetType()}"));
                    }

                    self.m_ReleaseResourceOutput.Send(new ReleaseResource(entry.Id));
                    self.m_Waiters.Remove(entry.Id);
                    return;
                }

                var rpc = output.Call(self, ctx, (object)null, Unsafe.As <ConvertResource <object> >(msg));
                rpc.Success <ConvertedResource>((self, ctx, _, convertedResource) =>
                {
                    var(entry, trackers) = self.GetCommonData(ctx);
                    var resource         = new Resource {
                        MainResource = convertedResource.MainResource, Dependencies = convertedResource.Dependencies
                    };

                    self.m_LoadedResources[entry.Id] = resource;

                    foreach (var tracker in trackers)
                    {
                        tracker.Ctx.SendSuccess(resource.MainResource);
                    }

                    self.m_Waiters.Remove(entry.Id);
                    resource.Count = trackers.Count;

                    self.m_ReleaseResourceOutput.Send(new ReleaseResource(entry.Id));
                });

                rpc.Failure((self, ctx, _, ex) =>
                {
                    var(entry, trackers) = self.GetCommonData(ctx);

                    foreach (var tracker in trackers)
                    {
                        tracker.Ctx.SendFailure(ex);
                    }

                    self.m_Waiters.Remove(entry.Id);

                    self.m_ReleaseResourceOutput.Send(new ReleaseResource(entry.Id));
                });
            });

            rpc.Failure((self, ctx, _, ex) =>
            {
                var(entry, trackers) = GetCommonData(ctx);

                foreach (var tracker in trackers)
                {
                    tracker.Ctx.SendFailure(ex);
                }

                m_Waiters.Remove(entry.Id);

                m_ReleaseResourceOutput.Send(new ReleaseResource(entry.Id));
            });
        }
Ejemplo n.º 4
0
 void SetHighlightFilter(string groupKey, string filterKey)
 {
     m_SetHighlightFilterOutput.Send(new SetHighlightFilter(groupKey, filterKey));
 }
Ejemplo n.º 5
0
 void SetHighlightVisibility(string groupKey, string filterKey, bool isVisible)
 {
     m_SetHighlightVisibilityOutput.Send(new SetHighlightVisibility(groupKey, filterKey, isVisible));
 }