public void Awake() { rect = GetComponent <RectTransform>().rect; // Update Overlay based on initial dimensions Overlay.SetTextureScreenSize(JigsawUtilities.RectTransformToScreenSpace(PreviewImage.rectTransform).size); }
private void OnGUI() { if (!DoDraw) { return; } if (OverlayColor != CachedOverlayColor) { OverlayTexture.SetPixel(0, 0, OverlayColor); OverlayTexture.Apply(); } // Compute the scale and offset, cutting off edges from the texture as needed (rather than letterboxing) float wScale = (float)TextureScreenWidth / (float)GridWidth; float hScale = (float)TextureScreenHeight / (float)GridHeight; float cellSize; Vector2 gridRoot = JigsawUtilities.RectTransformToScreenSpace(rectTransform).min; // Rect coords are [0,0] in the top-left to [ScreenWidth,ScreenHeight] in the bottom-right if (wScale < hScale) { cellSize = wScale; gridRoot += new Vector2(0.0f, 0.5f * (TextureScreenHeight - GridHeight * cellSize)); } else { cellSize = hScale; gridRoot += new Vector2(0.5f * (TextureScreenWidth - GridWidth * cellSize), 0.0f); } // Draw cells float halfLineThickness = 0.5f * LineThickness; Rect lineRect = new Rect(); lineRect.xMin = gridRoot.x - halfLineThickness; lineRect.xMax = gridRoot.x + (GridWidth * cellSize) + halfLineThickness; for (int i = 0; i <= GridHeight; ++i) { lineRect.yMin = gridRoot.y + (i * cellSize) - halfLineThickness; lineRect.yMax = lineRect.yMin + LineThickness; GUI.DrawTexture(lineRect, OverlayTexture); } lineRect.yMin = gridRoot.y - halfLineThickness; lineRect.yMax = gridRoot.y + (GridHeight * cellSize) + halfLineThickness; for (int j = 0; j <= GridWidth; ++j) { lineRect.xMin = gridRoot.x + (j * cellSize) - halfLineThickness; lineRect.xMax = lineRect.xMin + LineThickness; GUI.DrawTexture(lineRect, OverlayTexture); } }
private void Awake() { if (StaticJigsawData.ErrorHUD == null) { StaticJigsawData.ErrorHUD = this; } else { JigsawUtilities.RecursiveDestroy(gameObject); } }
public void UpdatePreviewImage(Texture2D PreviewTexture) { PreviewImage.texture = PreviewTexture; float texAspect = (float)PreviewTexture.width / (float)PreviewTexture.height; if (texAspect > 1.0f) { PreviewImage.rectTransform.sizeDelta = new Vector2(rect.width, rect.height / texAspect); } else { PreviewImage.rectTransform.sizeDelta = new Vector2(texAspect * rect.width, rect.height); } // Update Overlay based on new dimensions Overlay.SetTextureScreenSize(JigsawUtilities.RectTransformToScreenSpace(PreviewImage.rectTransform).size); }