void OnBuildGameObject(RpcContext <BuildGameObject> ctx) { var materialCache = new MaterialCache { Materials = ctx.Data.Materials }; var meshCache = new MeshCache { Meshes = ctx.Data.Meshes }; var configs = new SyncObjectImportConfig { settings = new SyncObjectImportSettings { defaultMaterial = ReflectMaterialManager.defaultMaterial, importLights = true }, materialCache = materialCache, meshCache = meshCache }; var gameObject = m_Importer.Import(ctx.Data.InstanceData.SourceId, ctx.Data.Object, configs); gameObject.name = ctx.Data.Instance.Name; gameObject.transform.SetParent(m_Settings.Root); ImportersUtils.SetTransform(gameObject.transform, ctx.Data.Instance.Transform); ImportersUtils.SetMetadata(gameObject, ctx.Data.Instance.Metadata); ctx.SendSuccess(gameObject); }
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); } }