#pragma warning restore 649 protected override void Import(RpcContext <ConvertResource <SyncMesh> > ctx, SyncedData <SyncMesh> resource) { MeshImportJob jobData; var vCount = resource.data.Vertices.Count; if (vCount > k_MaxUInt16VertexCount) { jobData = ImportMesh <uint>(resource.data); } else { jobData = ImportMesh <ushort>(resource.data); } var rpc = m_DelegateJobOutput.Call(this, ctx, jobData, new DelegateJob(jobData, MeshConverterMainThreadJob)); rpc.Success <MeshImportJob>((self, ctx, jobData, _) => { ctx.SendSuccess(new ConvertedResource { MainResource = jobData.Result, Dependencies = new List <Guid>() }); }); rpc.Failure((self, ctx, meshImport, ex) => { ctx.SendFailure(ex); }); }
static void ForwardCall <T, TResult>(RpcContext <T> rpcCtx, RpcOutput <T> rpcOutput) where T : class where TResult : class { var rpc = rpcOutput.Call((object)null, rpcCtx, (object)null, rpcCtx.Data); rpc.Success <TResult>((self, ctx, userCtx, res) => ctx.SendSuccess(res)); rpc.Failure((self, ctx, userCtx, ex) => ctx.SendFailure(ex)); }
void SendUpdateManifests() { var rpc = m_UpdateManifestsOutput.Call(this, (object)null, (object)null, new UpdateManifests()); rpc.Success <object>((self, ctx, userCtx, res) => { Debug.Log("Manifests loaded"); }); rpc.Failure((self, ctx, userCtx, ex) => { Debug.LogException(ex); }); }
void PickFromDistance(int distance, Action <List <ISpatialObject> > callback) { var rpc = m_PickFromDistanceOutput.Call((object)null, (object)null, callback, new PickFromDistance(distance)); rpc.Success <List <ISpatialObject> >((self, ctx, callback, result) => { callback(result); }); rpc.Failure((self, ctx, userCtx, ex) => { Debug.LogException(ex); }); }
void PickFromSamplePoints(Vector3[] samplePoints, int count, Action <List <ISpatialObject> > callback) { var rpc = m_PickFromSamplePointsOutput.Call((object)null, (object)null, callback, new PickFromSamplePoints(samplePoints, count)); rpc.Success <List <ISpatialObject> >((self, ctx, callback, result) => { callback(result); }); rpc.Failure((self, ctx, userCtx, ex) => { Debug.LogException(ex); }); }
void GetFilterStates(string groupKey, Action <List <FilterState> > callback) { var rpc = m_GetFilterStatesOutput.Call((object)null, (object)null, callback, new GetFilterStates(groupKey)); rpc.Success <List <FilterState> >((self, ctx, callback, result) => { callback(result); }); rpc.Failure((self, ctx, userCtx, ex) => { Debug.LogException(ex); }); }
void OnCreateGameObject(RpcContext <CreateGameObject> ctx) { if (!m_EmbeddedProject) { ForwardCall <CreateGameObject, GameObject>(ctx, m_CreateGameObjectFallback); return; } var tracker = new Tracker(); var instanceEntryRpc = m_AcquireDynamicEntryDataOutput.Call(this, ctx, tracker, new AcquireDynamicEntry(ctx.Data.InstanceId)); instanceEntryRpc.Success <DynamicEntry>((self, ctx, tracker, entryData) => { var streamKey = new StreamKey(entryData.Data.SourceId, entryData.Data.IdInSource); var original = m_GameObjectLookup[streamKey]; original.SetActive(true); ctx.SendSuccess(original); }); }
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)); }); }