/// <summary> /// Refreshes the sprite's anchoring offsets according to its parent and position. /// </summary> /// <param name="sprite"></param> public static void refreshAnchorInformation(this IPositionable sprite) { // Get anchor info UIAnchorInfo anchorInfo = sprite.anchorInfo; // Get anchor positions Vector3 parentPosition = parentAnchorPosition(anchorInfo.ParentUIObject, anchorInfo.ParentUIyAnchor, anchorInfo.ParentUIxAnchor); Vector3 diffAnchor = sprite.position - parentPosition; // Adjust for sprite anchor offset diffAnchor.x += UIRelative.xAnchorAdjustment(anchorInfo.UIxAnchor, sprite.width, anchorInfo.OriginUIxAnchor); diffAnchor.y -= UIRelative.yAnchorAdjustment(anchorInfo.UIyAnchor, sprite.height, anchorInfo.OriginUIyAnchor); // Adjust parent anchor offsets if (anchorInfo.UIPrecision == UIPrecision.Percentage) { anchorInfo.OffsetX = UIRelative.xPercentTo(anchorInfo.UIxAnchor, parentWidth(anchorInfo.ParentUIObject), diffAnchor.x); anchorInfo.OffsetY = -UIRelative.yPercentTo(anchorInfo.UIyAnchor, parentHeight(anchorInfo.ParentUIObject), diffAnchor.y); } else { anchorInfo.OffsetX = UIRelative.xPixelsTo(anchorInfo.UIxAnchor, diffAnchor.x); anchorInfo.OffsetY = -UIRelative.yPixelsTo(anchorInfo.UIyAnchor, diffAnchor.y); } // Set update anchor info sprite.anchorInfo = anchorInfo; }