public void Clear() { m_Component = null; m_OnDataReady = null; m_GetHighestPri = null; m_SurfaceObserver = null; }
private void PropagateDataReadyEventToComponents(SurfaceData sd, bool outputWritten, float elapsedBakeTimeSeconds, int inFlightIndex) { SpatialMappingBase.LODType lod = SpatialMappingBase.GetLODFromTPCM(sd.trianglesPerCubicMeter); SpatialMappingBase requester = GetSMComponentFromInFlightIndex(inFlightIndex); if (outputWritten) { // prop successes to anyone with a matching LOD; some screening will // be needed at the component level. foreach (SMComponentRecord comp in m_Components) { if (comp.m_Component.lodType == lod && comp.m_Component.bakePhysics == sd.bakeCollider) { comp.m_OnDataReady(requester, sd, outputWritten, elapsedBakeTimeSeconds); } } } else { // notify ONLY the requester of failure; no one else should care if (inFlightIndex != -1) { m_InFlightRequests[inFlightIndex].m_Requester.m_OnDataReady(requester, sd, outputWritten, elapsedBakeTimeSeconds); } else { Debug.LogError(System.String.Format("SpatialMappingContext unable to notify a component about a failure to cook surface {0}!", sd.id.handle)); } } }
private int m_NextIndex = 0; // next index for the m_InFlightRequests array // Add the specified component to the list of components with its delegates // and scripting API observer. Components are required to register with // the context prior to their first surface bake request. This method will // throw ArgumentException if this component already exists in the list // ArgumentNullException if any of the parameters are missing. public void RegisterComponent(SpatialMappingBase smComponent, SpatialMappingBase.SurfaceDataReadyCallback onDataReady, GetHighestPriorityCallback getHighestPri, SurfaceObserver observer) { if (smComponent == null) { throw new ArgumentNullException("smComponent"); } if (onDataReady == null) { throw new ArgumentNullException("onDataReady"); } if (getHighestPri == null) { throw new ArgumentNullException("getHighestPri"); } if (observer == null) { throw new ArgumentNullException("observer"); } SMComponentRecord findResult = m_Components.Find(record => record.m_Component == smComponent); if (findResult.m_Component != null) { throw new ArgumentException("RegisterComponent on a component already registered!"); } SMComponentRecord rec; rec.m_Component = smComponent; rec.m_OnDataReady = onDataReady; rec.m_GetHighestPri = getHighestPri; rec.m_SurfaceObserver = observer; m_Components.Add(rec); }
// Remove the specified component from the list of components. Argument // exceptions will be thrown if the specified component cannot be found // in the list. public void DeregisterComponent(SpatialMappingBase smComponent) { int removeCount = m_Components.RemoveAll(record => record.m_Component == smComponent); if (removeCount == 0) { throw new ArgumentException("DeregisterComponent for a component not registered!"); } }
public SurfaceObserver m_SurfaceObserver; // scripting API observer SMComponentRecord( SpatialMappingBase comp, SpatialMappingBase.SurfaceDataReadyCallback onDataReady, GetHighestPriorityCallback getHighestPri, SurfaceObserver observer) { m_Component = comp; m_OnDataReady = onDataReady; m_GetHighestPri = getHighestPri; m_SurfaceObserver = observer; }
protected virtual void OnEnable() { m_SMBase = this.target as SpatialMappingBase; m_SurfaceParentProp = this.serializedObject.FindProperty("m_SurfaceParent"); m_FreezeUpdatesProp = this.serializedObject.FindProperty("m_FreezeUpdates"); m_SecondsBetweenUpdatesProp = this.serializedObject.FindProperty("m_SecondsBetweenUpdates"); m_NumUpdatesBeforeRemovalProp = this.serializedObject.FindProperty("m_NumUpdatesBeforeRemoval"); m_LodProp = this.serializedObject.FindProperty("m_LodType"); m_VolumeProp = this.serializedObject.FindProperty("m_VolumeType"); m_SphereRadiusProp = this.serializedObject.FindProperty("m_SphereRadius"); m_HalfBoxExtentsProp = this.serializedObject.FindProperty("m_HalfBoxExtents"); }
protected override void OnSurfaceDataReady(SpatialMappingBase requester, SurfaceData bakedData, bool outputWritten, float elapsedBakeTimeSeconds) { SpatialMappingBase.Surface surface; if (!surfaceObjects.TryGetValue(bakedData.id.handle, out surface)) { // If we don't have the surface, ignore it because we may never // receive a removal for it. And then it will be a zombie. return; } //Debug.Log(string.Format("Baked \"{0}\" : \"{1}\"", surfaceData.m_GameObject.name, bakedData.id.handle)); // Let the component know that the current surface does not // need to be baked again until the system says the surface // has been updated. surface.awaitingBake = false; if (!outputWritten) { return; } if (surface.gameObject == null) { Debug.LogError(string.Format("A SpatialMappingRenderer component can not apply baked data to a surface with id \"{0}\" because its GameObject is null.", bakedData.id.handle)); return; } if (requester != this) { CloneBakedComponents(bakedData, surface); } if (surface.meshRenderer == null) { surface.meshRenderer = surface.gameObject.GetComponent <MeshRenderer>(); if (surface.meshRenderer == null) { surface.meshRenderer = surface.gameObject.AddComponent <MeshRenderer>(); } surface.meshRenderer.receiveShadows = false; surface.meshRenderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; } ApplyRenderSettings(surface.meshRenderer); }
protected override void OnSurfaceDataReady(SpatialMappingBase requester, SurfaceData bakedData, bool outputWritten, float elapsedBakeTimeSeconds) { SpatialMappingBase.Surface surfaceData; if (!surfaceObjects.TryGetValue(bakedData.id.handle, out surfaceData)) { // If we don't have the surface, ignore it because we may never // receive a removal for it. And then it will be a zombie. return; } // Let the component know that the current surface does not // need to be baked again until the system says the surface // has been updated. surfaceData.awaitingBake = false; if (!outputWritten) { return; } if (surfaceData.gameObject == null) { Debug.LogError(string.Format("A SpatialMappingCollider component can not apply baked data to the surface with id \"{0}\" because its GameObject is null.", bakedData.id.handle)); return; } if (bakedData.outputCollider == null) { return; } if (requester != this) { CloneBakedComponents(bakedData, surfaceData); } bakedData.outputCollider.gameObject.layer = layer; if (material != null) { bakedData.outputCollider.material = material; } }
// data ready event called by the context to inform the component that data is available from the request queue // This method should be implemented by derived components. protected abstract void OnSurfaceDataReady(SpatialMappingBase requester, SurfaceData bakedData, bool outputWritten, float elapsedBakeTimeSeconds);