protected override void OnResize() { var baseSize = Responsive.GetAreaSizeByMode(AreaMode.Viewport); var rect = this.CalcWithScreen(UnityExtension.ScreenSafeAreaRect); this.UpdateSafeArea(rect, baseSize); }
public float GetContentScale() { var areaSize = Responsive.GetAreaSizeByMode(AreaMode.Safe); var baseSize = Responsive.GetAreaSizeByMode(AreaMode.Viewport); var scale = UnityExtension.GetScaleOfAreaSize(areaSize, baseSize); return(scale); }
//public void ResetManualResolution(Vector2 manualArea) //{ // this.manualResolution = manualArea; // this.UpdateResolution(); //} public void ResetManualResolution() { var safeArea = Responsive.GetAreaSizeByMode(AreaMode.Safe); var scale = UnityExtension.GetScaleOfAreaSize(safeArea, Responsive.GetAreaSizeByMode(AreaMode.Viewport)); var manualArea = safeArea / scale; this.manualResolution = manualArea; }
public static void UpdateViews() { var screenSize = UnityExtension.ScreenSizeI; if (screenSize == Responsive.keepScreenSize) { return; } Responsive.keepScreenSize = screenSize; Responsive.ResetLayoutAll(true); }
public static Rect GetViewportRect(RectTransform trans, Canvas canvas) { if (!trans) { return(Rect.zero); } var rect = trans.rect; var size = rect.size; var offset = Vector2.Scale(size, trans.pivot); var posMin = -offset; var posMax = size - offset; // TODO: Not supported rotation! var camera = canvas ? canvas.worldCamera : null; if (!camera) { camera = Camera.main; } var min = (Vector2)camera.WorldToViewportPoint(trans.TransformPoint(posMin)); var max = (Vector2)camera.WorldToViewportPoint(trans.TransformPoint(posMax)); var resolution = Responsive.GetAreaSizeByMode(AreaMode.Screen); var resolutionHalf = resolution * 0.5f; var viewportMin = new Vector2(min.x * resolution.x - resolutionHalf.x, min.y * resolution.y - resolutionHalf.y); var viewportMax = new Vector2(max.x * resolution.x - resolutionHalf.x, max.y * resolution.y - resolutionHalf.y); var viewportRect = Rect.MinMaxRect(viewportMin.x, viewportMin.y, viewportMax.x, viewportMax.y); #if LOG_SOFTMASK Debug.Log(new System.Text.StringBuilder().Append("SOFTMASK:GETRECT:") .Append("MIN:").Append("(X:").Append(min.x).Append(", Y:").Append(min.y).Append("), ") .Append("MAX:").Append("(X:").Append(max.x).Append(", Y:").Append(max.y).Append("),\n") //.Append("OFFMIN:").Append(offMin).Append(", ") //.Append("OFFMAX:").Append(offMax).Append(", ") .Append("VP_MIN:").Append(viewportMin).Append(", ") .Append("VP_MAX:").Append(viewportMax).Append(", ") .Append("SIZE:").Append(size).Append(", ") .Append("RESOLUTION:").Append(resolution).Append(",\n") .Append("RC:").Append(rect).Append(", ") .Append("VP_RC:").Append(viewportRect).Append(",\n") .ToString()); #endif// LOG_SOFTMASK return(viewportRect); }
public static void Remove(Responsive responsive) { var reg = Responsive.registry; if (null == reg) { return; } HashSet <Responsive> set = null; var order = responsive.Order; if (reg.ContainsKey(order)) { set = reg[order]; set.Remove(responsive); } }
public void Add(SortedDictionary <int, HashSet <Responsive> > dict, Responsive responsive) { if (null == dict) { return; } HashSet <Responsive> set = null; var order = responsive.Order; if (dict.ContainsKey(order)) { set = dict[order]; } else { set = new HashSet <Responsive>(); dict.Add(order, set); } set.Add(responsive); }
protected override void OnResize() { var safeAreaSize = Responsive.GetAreaSizeByMode(AreaMode.Safe); var viewportSize = Responsive.GetAreaSizeByMode(AreaMode.Viewport); var scale = UnityExtension.GetScaleOfAreaSize(safeAreaSize, viewportSize); var transform = this.CachedRectTransform; var newScaleDelta = new Vector3(this.originScale.x, this.originScale.y, 1); if (this.horizontal) { newScaleDelta.x /= scale; } if (this.vertical) { newScaleDelta.y /= scale; } newScaleDelta.x = Mathf.Clamp(newScaleDelta.x, this.minScale.x, this.maxScale.x); newScaleDelta.y = Mathf.Clamp(newScaleDelta.y, this.minScale.y, this.maxScale.y); transform.localScale = newScaleDelta; }
Rect CalcWithScreen(Rect safeAreaRect) { return(UnityExtension.GetCalculatedSafeAreaRect(safeAreaRect, Responsive.GetAreaSizeByMode(AreaMode.Viewport))); }
public void UpdateSize() { // TODO: must be remove after whole components serialize it if (this.isFirst) { this.isFirst = false; this.ResetOriginOffsets(); } var position = this.originPosition; var size = this.originSize; var scaledScreenSize = Responsive.GetAreaSizeByMode(AreaMode.Screen); var baseArea = Responsive.GetAreaRectByMode(AreaMode.Safe); var baseContentSize = Responsive.GetAreaSizeByMode(AreaMode.Viewport); var contentScale = UnityExtension.GetScaleOfAreaSize(baseArea.size, baseContentSize); var scaleFactor = 1f / contentScale; var baseAreaRect = baseArea; var baseRectSize = new Vector2(baseContentSize.x * contentScale, baseContentSize.y * contentScale); var baseAreaRectSize = new Vector2(baseAreaRect.size.x, baseAreaRect.size.y); var actualContentSize = baseRectSize; var actualSafeAreaSize = baseAreaRectSize; var areaPosition = baseArea.position; var halfArea = scaledScreenSize * 0.5f; var halfActualContentSize = actualContentSize * 0.5f; var halfActualSafeAreaSize = actualSafeAreaSize * 0.5f; this.rightBlankValue = Mathf.CeilToInt(scaledScreenSize.x - (halfArea.x + (this.ignoreContentTrasnformRight ? halfActualSafeAreaSize.x : halfActualContentSize.x)) - areaPosition.x); this.leftBlankValue = Mathf.CeilToInt(halfArea.x - (this.ignoreContentTrasnformLeft ? halfActualSafeAreaSize.x : halfActualContentSize.x) + areaPosition.x); this.topBlankValue = Mathf.CeilToInt(scaledScreenSize.y - (halfArea.y + (this.ignoreContentTrasnformTop ? halfActualSafeAreaSize.y : halfActualContentSize.y)) - areaPosition.y); this.bottomBlankValue = Mathf.CeilToInt(halfArea.y - (this.ignoreContentTrasnformBottom ? halfActualSafeAreaSize.y : halfActualContentSize.y) + areaPosition.y); var leftSize = this.normalizedOffset.left * this.leftBlankValue; var rightSize = this.normalizedOffset.right * this.rightBlankValue; var topSize = this.normalizedOffset.top * this.topBlankValue; var bottomSize = this.normalizedOffset.bottom * this.bottomBlankValue; this.resultLeft = leftSize * scaleFactor; this.resultRight = rightSize * scaleFactor; this.resultTop = topSize * scaleFactor; this.resultBottom = bottomSize * scaleFactor; if (this.useSizeLimit) { var blankMin = (this.minSize - size) * 0.5f; var blankMax = (this.maxSize - size) * 0.5f; this.resultLeft = Mathf.Clamp(resultLeft, blankMin.x, blankMax.x); this.resultRight = Mathf.Clamp(resultRight, blankMin.x, blankMax.x); this.resultTop = Mathf.Clamp(resultTop, blankMin.y, blankMax.y); this.resultBottom = Mathf.Clamp(resultBottom, blankMin.y, blankMax.y); } var trans = this.CachedRectTransform; //TODO : Remove #if LOG_DEBUG if (null == trans) { Debug.LogError("rt null"); } #endif// LOG_DEBUG this.SetSizeWithEdge(trans, RectTransform.Edge.Left, this.resultLeft); this.SetSizeWithEdge(trans, RectTransform.Edge.Right, this.resultRight); this.SetSizeWithEdge(trans, RectTransform.Edge.Top, this.resultTop); this.SetSizeWithEdge(trans, RectTransform.Edge.Bottom, this.resultBottom); #if LOG_DEBUG if (this.calibrateCenter > CalibrateCenter.Both) { Debug.LogError("Invalid CalibrateCenter"); } #endif// LOG_DEBUG var anchorMax = trans.anchorMax; var anchorMin = trans.anchorMin; switch (this.calibrateCenter) { case CalibrateCenter.Horizontal: this.CalibratePositionX(trans, areaPosition, position, anchorMax, anchorMin, scaleFactor); break; case CalibrateCenter.Vertical: this.CalibratePositionY(trans, areaPosition, position, anchorMax, anchorMin, scaleFactor); break; case CalibrateCenter.Both: this.CalibratePositionXY(trans, areaPosition, position, anchorMax, anchorMin, scaleFactor); break; } }
public Vector2 GetAreaSizeByCurrent() { return(Responsive.GetAreaSizeByMode(this.areaMode)); }
public static Vector2 GetAreaSizeByMode(AreaMode mode) { var areaRect = Responsive.GetAreaRectByMode(mode); return(areaRect.size); }
//public void AddNewObject(Responsive responsive) //{ // this.Add(Responsive.newObjects, responsive); //} // public static void UpdateNewObjects() // { // var reg = Responsive.newObjects; // if (null == reg) // return; // if (reg.Count <= 0) // return; // foreach (var pair in reg) // { // var obj = pair.Value; // if (null == obj) // continue; // foreach (var responsive in obj) // { // if (null != responsive) // responsive.UpdateResize(); // else // { //#if LOG_DEBUG // Debug.LogWarning(string.Format("RESPONSIVE_NEW_OBJECT_IS_NULL:{0}", obj.ToString())); //#endif// LOG_DEBUG // } // } // obj.Clear(); // } // } protected virtual void OnDestroyed() { Responsive.Remove(this); }