public bool Equals(Text2DPrivateCacheBitmap t) { if (math.abs(size - t.size) > 0.001f) { return(false); } if (math.abs(minSizeAutoFit - t.minSizeAutoFit) > 0.001f || math.abs(maxSizeAutoFit - t.maxSizeAutoFit) > 0.001f) { return(false); } if (math.abs(rect.x - t.rect.x) > 0.001f || math.abs(rect.y - t.rect.y) > 0.001f) { return(false); } if (color != t.color) { return(false); } return(true); }
protected override void OnUpdate() { EntityManager em = EntityManager; EntityCommandBuffer ecb = new EntityCommandBuffer(Allocator.Temp); //Check bitmap font components Entities.With(groupAddBitmapFontPrivateC).ForEach((Entity e, ref Text2DRenderer tr, ref Text2DStyleBitmapFont bf) => { if (CheckBitmapFontComponents(em, ref tr, ref bf)) { BitmapFont bitmapFont = em.GetComponentData <BitmapFont>(bf.font); Image2D image2D = em.GetComponentData <Image2D>(bitmapFont.textureAtlas); if (image2D.status == ImageStatus.Loaded) { //Add private compo ecb.AddComponent(e, new Text2DPrivateBitmap()); ecb.AddComponent(e, new Text2DPrivateCacheBitmap()); ecb.AddBuffer <GlyphPrivateBuffer>(e); ecb.AddBuffer <TextPrivateString>(e); } } }); ecb.Playback(em); ecb.Dispose(); Entities.ForEach((Entity e, ref Text2DRenderer tr, ref Text2DPrivateBitmap textP, ref Text2DPrivateCacheBitmap textHtmlP) => { Text2DStyle textStyle = em.GetComponentData <Text2DStyle>(tr.style); Text2DStyleBitmapFont styleBitmap = em.GetComponentData <Text2DStyleBitmapFont>(e); BitmapFont bitmapFont = em.GetComponentData <BitmapFont>(styleBitmap.font); Text2DPrivateCacheBitmap temp = new Text2DPrivateCacheBitmap(); temp.size = textStyle.size; temp.color = textStyle.color; if (em.HasComponent <Text2DAutoFit>(e)) { Text2DAutoFit autoFit = em.GetComponentData <Text2DAutoFit>(e); temp.minSizeAutoFit = autoFit.minSize; temp.maxSizeAutoFit = autoFit.maxSize; } if (em.HasComponent <RectTransformFinalSize>(e)) { temp.rect = em.GetComponentData <RectTransformFinalSize>(e).size; } var newText = em.GetBufferAsString <TextString>(e); var privText = em.GetBufferAsString <TextPrivateString>(e); if (!textHtmlP.Equals(temp) || newText != privText) { // Re-compute text size float newSize = MeasureBitmapFontText(em, ref e, ref textP, newText, temp.rect); textP.size = newSize; } //Update private text component em.SetBufferFromString <TextPrivateString>(e, newText); textHtmlP = temp; }); ecb = new EntityCommandBuffer(Allocator.Temp); Entities.With(groupRemoveBitmapFontPrivateC).ForEach((Entity e, ref Text2DPrivateBitmap tr, ref Text2DPrivateCacheBitmap nc) => { ecb.RemoveComponent <Text2DPrivateBitmap>(e); ecb.RemoveComponent <Text2DPrivateCacheBitmap>(e); ecb.RemoveComponent <GlyphPrivateBuffer>(e); ecb.RemoveComponent <TextPrivateString>(e); }); ecb.Playback(em); ecb.Dispose(); }