private void UpdateRenderMode() { if (panel.renderMode == MadPanel.RenderMode.DepthBased) { var loc = transform.localPosition; MadTransform.SetLocalPosition(transform, new Vector3(loc.x, loc.y, -guiDepth * 10)); } }
void Update() { // fix the offset if (halfPixelOffset) { var root = FindParent <MadRootNode>(); float pixelSize = root.pixelSize; float x = 0, y = 0; if (Screen.height % 2 == 0) { y = pixelSize; } if (Screen.width % 2 == 0) { x = pixelSize; } MadTransform.SetLocalPosition(transform, new Vector3(x, y, 0)); } UpdateInput(); }
public void Update() { if (sprite == null || sprite.texture == null) { return; } float screenLeft = 0; float screenBottom = 0; float screenRight = root.screenWidth; float screenTop = root.screenHeight; // margins can be only applied on fill and with no repeat if (scaleMode == ScaleMode.Fill && !repeatX && !repeatY) { screenLeft = fillMarginLeft; screenBottom = fillMarginBottom; screenRight -= fillMarginRight; screenTop -= fillMarginTop; } float screenWidth = screenRight - screenLeft; float screenHeight = screenTop - screenBottom; float scaleX = scale.x; float scaleY = scale.y; float spriteWidth = screenWidth; float spriteHeight = screenHeight; switch (scaleMode) { case ScaleMode.Fill: if (repeatX && repeatY) { scaleX = sprite.texture.width / screenWidth; scaleY = sprite.texture.height / screenHeight; } else if (repeatX || repeatY || dontStretch) { scaleX = (screenHeight / (float)sprite.texture.height) * (sprite.texture.width / (float)screenWidth); scaleY = (screenWidth / (float)sprite.texture.width) * (sprite.texture.height / (float)screenHeight); } break; case ScaleMode.Manual: spriteHeight = sprite.texture.height * scaleY; scaleX *= sprite.texture.width / (float)screenWidth; break; } bool stretchX = true; bool stretchY = true; if (dontStretch && !repeatX && !repeatY) { float ratio = (sprite.texture.width / (float)sprite.texture.height) / (screenWidth / screenHeight); if (ratio > 1) { stretchX = false; } else if (ratio < 1) { stretchY = false; } } // scale to fill whole screen, but keep the scale set by user sprite.size = new Vector2(spriteWidth, spriteHeight); if (scaleMode == ScaleMode.Manual) { switch (align) { case Align.None: MadTransform.SetLocalPosition( sprite.transform, new Vector3(0, Screen.height * position.y, sprite.transform.localPosition.z)); break; case Align.Middle: MadTransform.SetLocalPosition( sprite.transform, new Vector3(0, position.y, sprite.transform.localPosition.z)); break; case Align.Bottom: MadTransform.SetLocalPosition( sprite.transform, new Vector3( 0, screenHeight * (-0.5f) + position.y + (0.5f * scaleY * sprite.texture.height), sprite.transform.localPosition.z)); break; case Align.Top: MadTransform.SetLocalPosition( sprite.transform, new Vector3( 0, screenHeight * (0.5f) + position.y + (-0.5f * scaleY * sprite.texture.height), sprite.transform.localPosition.z)); break; } } else // ScaleMode.Fill { MadTransform.SetLocalPosition( sprite.transform, new Vector3(0, 0, sprite.transform.localPosition.z)); } // set proper repeat float rx = 1, ry = 1; // sprite.textureRepeat = new Vector2(rx * (1 / scaleX), ry * (1 / scaleY)); sprite.textureRepeat = new Vector2( repeatX || !stretchX ? rx * (1 / scaleX) : rx, repeatY || !stretchY ? ry * (1 / scaleY) : ry); // follow draggable var locPos = parent.UserPosition; float dx = -locPos.x * followSpeed; float dy = -locPos.y * followSpeed; dx /= root.screenWidth; dy /= root.screenHeight; float offsetX = 0; float offsetY = 0; if (!stretchX) { offsetX = -(sprite.textureRepeat.x - 1) / 2; } else if (!stretchY) { offsetY = -(sprite.textureRepeat.y - 1) / 2; } // sprite.textureOffset = new Vector2(dx * (1 / scaleX) + position.x, dy * (1 / scaleY) - position.y); sprite.textureOffset = new Vector2( repeatX || !stretchX ? dx * (1 / scaleX) + position.x + offsetX : dx, repeatY || !stretchY ? dy * (1 / scaleY) - position.y + offsetY : dy); if (Application.isPlaying && scrollSpeed != Vector2.zero) { scrollAccel += new Vector2( scrollSpeed.x * ScrollSpeedMultiplier / scale.x, scrollSpeed.y * ScrollSpeedMultiplier / scale.y) * deltaTime; scrollAccel = new Vector2(scrollAccel.x % 1, scrollAccel.y % 1); sprite.textureOffset += scrollAccel; } UpdateFillMargin(); lastTime = Time.realtimeSinceStartup; }