/*public static void SetSize(RectTransform rectTransform, Vector2 size) * { * Vector2 oldSize = rectTransform.rect.size; * Vector2 deltaSize = size - oldSize; * * rectTransform.offsetMin = rectTransform.offsetMin - new Vector2( * deltaSize.x * rectTransform.pivot.x, * deltaSize.y * rectTransform.pivot.y); * rectTransform.offsetMax = rectTransform.offsetMax + new Vector2( * deltaSize.x * (1f - rectTransform.pivot.x), * deltaSize.y * (1f - rectTransform.pivot.y)); * } * * public static void SetWidth(RectTransform rectTransform, float size) * { * SetSize(rectTransform, new Vector2(size, rectTransform.rect.size.y)); * } * * public static void SetHeight(RectTransform rectTransform, float size) * { * Debug.LogError("setHeight: " + size); * SetSize(rectTransform, new Vector2(rectTransform.rect.size.x, size)); * }*/ public static void SetHeight(RectTransform rectTransform, float size) { // Debug.LogError("setHeight: " + size); if (rectTransform.anchorMin.y == 1.0f && rectTransform.anchorMax.y == 1.0f && rectTransform.pivot.y == 1.0f) { rectTransform.offsetMin = new Vector2(rectTransform.offsetMin.x, rectTransform.anchoredPosition.y - size); rectTransform.sizeDelta = new Vector2(rectTransform.sizeDelta.x, size); } else if (rectTransform.anchorMin.y == 0.5f && rectTransform.anchorMax.y == 0.5f && rectTransform.pivot.y == 0.5f) { // offsetMin: (-180.0, -240.0); offsetMax: (180.0, 240.0); sizeDelta: (360.0, 480.0) rectTransform.offsetMin = new Vector2(rectTransform.offsetMin.x, -size / 2.0f); rectTransform.offsetMax = new Vector2(rectTransform.offsetMax.x, size / 2.0f); rectTransform.sizeDelta = new Vector2(rectTransform.sizeDelta.x, size); } else if (rectTransform.anchorMin.y == 0.0f && rectTransform.anchorMax.y == 0.0f && rectTransform.pivot.y == 0.0f) { rectTransform.offsetMax = new Vector2(rectTransform.offsetMax.x, rectTransform.anchoredPosition.y - size); rectTransform.sizeDelta = new Vector2(rectTransform.sizeDelta.x, size); } else { Logger.LogError("unknown rect type: " + UIRectTransform.PrintRectTransform(rectTransform)); } }
/** * get height * */ public static float SetPosY(Data data, UIRectTransform originRect, float posY) { float ret = 0; if (data != null) { RectTransform rectTransform = (RectTransform)Data.FindTransform(data); if (rectTransform != null) { if (originRect != null) { originRect.set(rectTransform); SetPosY(rectTransform, posY); ret = rectTransform.rect.height; } else { Logger.LogError("originRect null"); } } else { Logger.LogError("rectTransform null"); } } else { Logger.LogError("data null"); } return(ret); }
public static bool Set(Data data, UIRectTransform uiRectTransform) { bool ret = false; if (data != null) { RectTransform rectTransform = (RectTransform)Data.FindTransform(data); if (rectTransform != null) { if (uiRectTransform != null) { uiRectTransform.set(rectTransform); ret = true; } else { Logger.LogError("uiRectTransform null"); } } else { // Debug.LogError("rectTransform null"); } } else { // Debug.LogError("data null"); } return(ret); }
public UIRectTransform(UIRectTransform rectTransform) { this.anchoredPosition = rectTransform.anchoredPosition; this.anchorMin = rectTransform.anchorMin; this.anchorMax = rectTransform.anchorMax; this.pivot = rectTransform.pivot; this.offsetMin = rectTransform.offsetMin; this.offsetMax = rectTransform.offsetMax; this.sizeDelta = rectTransform.sizeDelta; this.rotation = rectTransform.rotation; this.scale = rectTransform.scale; }
public UIRectTransform(UIRectTransform rectTransform, float posY) { this.anchoredPosition = rectTransform.anchoredPosition; this.anchorMin = rectTransform.anchorMin; this.anchorMax = rectTransform.anchorMax; this.pivot = rectTransform.pivot; this.offsetMin = rectTransform.offsetMin; this.offsetMax = rectTransform.offsetMax; this.sizeDelta = rectTransform.sizeDelta; this.rotation = rectTransform.rotation; this.scale = rectTransform.scale; // posY this.setPosY(posY); }
public static UIRectTransform createRequestRect(float paddingLeft, float paddingRight, float height) { UIRectTransform rect = new UIRectTransform(); { rect.anchoredPosition = new Vector3((paddingLeft - paddingRight) / 2, 0f, 0f); rect.anchorMin = new Vector2(0.0f, 1.0f); rect.anchorMax = new Vector2(1.0f, 1.0f); rect.pivot = new Vector2(0.5f, 1f); rect.offsetMin = new Vector2(paddingLeft, -height); rect.offsetMax = new Vector2(-paddingRight, 0); rect.sizeDelta = new Vector2(-paddingLeft - paddingRight, height); } return(rect); }
public static UIRectTransform CreateCenterRect(float width, float height, float x, float y) { UIRectTransform ret = new UIRectTransform(); { ret.anchoredPosition = new Vector3(x, y, 0.0f); ret.anchorMin = new Vector2(0.5f, 0.5f); ret.anchorMax = new Vector2(0.5f, 0.5f); ret.pivot = new Vector2(0.5f, 0.5f); ret.offsetMin = new Vector2(x - width / 2, y - height / 2); ret.offsetMax = new Vector2(x + width / 2, y + height / 2); ret.sizeDelta = new Vector2(width, height); } return(ret); }
public static UIRectTransform CreateFullRect(float left, float right, float top, float bottom) { UIRectTransform ret = new UIRectTransform(UIConstants.FullParent); { // left 5, right 10, top 30, bottom 60 // anchoredPosition: (-2.5, 15.0); offsetMin: (5.0, 60.0); // offsetMax: (-10.0, -30.0); sizeDelta: (-15.0, -90.0); ret.anchoredPosition = new Vector3((left - right) / 2.0f, (bottom - top) / 2.0f, 0); ret.offsetMin = new Vector2(left, bottom); ret.offsetMax = new Vector2(-right, -top); ret.sizeDelta = new Vector2(-(left + right), -(top + bottom)); } return(ret); }
public static void SetWidth(RectTransform rectTransform, float size) { // Debug.LogError("setHeight: " + size); if (rectTransform.anchorMin.x == 0.0f && rectTransform.anchorMax.x == 0.0f && rectTransform.pivot.x == 0.0f) { rectTransform.offsetMin = new Vector2(rectTransform.anchoredPosition.x - size, rectTransform.offsetMin.y); rectTransform.sizeDelta = new Vector2(size, rectTransform.sizeDelta.y); } else { Logger.LogError("unknown rect type: " + UIRectTransform.PrintRectTransform(rectTransform)); } }
public static UIRectTransform CreateTopBottomRect(float height) { UIRectTransform rect = new UIRectTransform(); { // anchoredPosition: (0.0, 0.0); anchorMin: (0.0, 1.0); anchorMax: (1.0, 1.0); pivot: (0.5, 1.0); // offsetMin: (0.0, -300.0); offsetMax: (0.0, 0.0); sizeDelta: (0.0, 300.0); rect.anchoredPosition = new Vector3(0.0f, 0.0f, 0.0f); rect.anchorMin = new Vector2(0.0f, 1.0f); rect.anchorMax = new Vector2(1.0f, 1.0f); rect.pivot = new Vector2(0.5f, 1.0f); rect.offsetMin = new Vector2(0.0f, -height); rect.offsetMax = new Vector2(0.0f, 0.0f); rect.sizeDelta = new Vector2(0.0f, height); } return(rect); }
private static UIRectTransform CreateRect(float bottomY) { // anchoredPosition: (0.0, 25.0); anchorMin: (0.5, 0.0); anchorMax: (0.5, 0.0); pivot: (0.5, 0.0); offsetMin: (-300.0, 25.0); offsetMax: (300.0, 78.0); // sizeDelta: (600.0, 53.0); localRotation: (0.0, 0.0, 0.0, 1.0); localScale: (1.0, 1.0, 1.0); UIRectTransform rect = new UIRectTransform(); { rect.anchoredPosition = new Vector3(0.0f, bottomY, 0.0f); rect.anchorMin = new Vector2(0.5f, 0.0f); rect.anchorMax = new Vector2(0.5f, 0.0f); rect.pivot = new Vector2(0.5f, 0.0f); rect.offsetMin = new Vector2(-275.0f, bottomY); rect.offsetMax = new Vector2(275.0f, bottomY + 53.0f); rect.sizeDelta = new Vector2(550.0f, 53.0f); } return(rect); }
public static void SetPosY(RectTransform rectTransform, float posY) { if (rectTransform.anchorMin.y == 1.0f && rectTransform.anchorMax.y == 1.0f && rectTransform.pivot.y == 1.0f) { rectTransform.anchoredPosition = new Vector2(rectTransform.anchoredPosition.x, -posY); rectTransform.offsetMin = new Vector2(rectTransform.offsetMin.x, -rectTransform.sizeDelta.y - posY); rectTransform.offsetMax = new Vector2(rectTransform.offsetMax.x, -posY); } else if (rectTransform.anchorMin.y == 0.0f && rectTransform.anchorMax.y == 0.0f && rectTransform.pivot.y == 0.0f) { rectTransform.anchoredPosition = new Vector2(rectTransform.anchoredPosition.x, posY); rectTransform.offsetMin = new Vector2(rectTransform.offsetMin.x, posY); rectTransform.offsetMax = new Vector2(rectTransform.offsetMax.x, rectTransform.sizeDelta.y + posY); } else { Logger.LogError("unknown rect type: " + UIRectTransform.PrintRectTransform(rectTransform) + ", " + rectTransform.gameObject); } }
public static readonly UIRectTransform ShowRect; // = new UIRectTransform(); static ToastMessageUI() { HideRect = CreateRect(-5000); ShowRect = CreateRect(25); }
protected override void InitUIComponent() { this.m_sliderComponent = UIRectTransform.Find("Slider").GetComponent <Slider>(); this.m_sliderValueText = UIRectTransform.Find("Text").GetComponent <Text>(); }
public override void refresh() { if (dirty) { dirty = false; if (this.data != null) { State state = this.data.state.v; if (state != null) { switch (state.getType()) { case State.Type.Show: { Show show = state as Show; // time if (show.time.v <= show.duration.v) { if (Time.time == LastTime) { // Debug.LogError("the same last time: " + LastTime); dirty = true; } else { show.time.v += Time.fixedDeltaTime; } } else { // chuyen sang normal Normal normal = new Normal(); { normal.uid = this.data.state.makeId(); } this.data.state.v = normal; } // UI { RectTransform rectTransform = (RectTransform)this.transform; if (rectTransform != null) { if (rectTransform.rect.height > 0) { if (show.duration.v > 0) { UIRectTransform.SetPosY(rectTransform, Mathf.Clamp( ((show.duration.v - show.time.v) / show.duration.v) * (-rectTransform.rect.height), -rectTransform.rect.height, 0)); } else { Logger.LogError("show duration < 0: " + show.duration.v); } } else { Logger.LogError("rectTransform rect height 0"); } } else { Logger.LogError("rectTransform null"); } } } break; case State.Type.Normal: { UIRectTransform.SetPosY((RectTransform)this.transform, 0); } break; case State.Type.Hide: { Hide hide = state as Hide; if (hide.time.v <= hide.duration.v) { if (Time.time == LastTime) { // Debug.LogError("the same last time: " + LastTime); dirty = true; } else { hide.time.v += Time.fixedDeltaTime; } } else { // chuyen sang normal Normal normal = new Normal(); { normal.uid = this.data.state.makeId(); } this.data.state.v = normal; // event if (this.data.onHide.v != null) { this.data.onHide.v(); } else { Logger.LogError("onHide null"); } } // UI { RectTransform rectTransform = (RectTransform)this.transform; if (rectTransform != null) { if (rectTransform.rect.height > 0) { if (hide.duration.v > 0) { UIRectTransform.SetPosY(rectTransform, Mathf.Clamp( (hide.time.v / hide.duration.v) * (-rectTransform.rect.height), -rectTransform.rect.height, 0)); } else { Logger.LogError("show duration < 0: " + hide.duration.v); } } else { Logger.LogError("rectTransform rect height 0"); } } else { Logger.LogError("rectTransform null"); } } } break; default: Logger.LogError("unknown type: " + state.getType()); break; } LastTime = Time.time; } else { Logger.LogError("state null"); Normal normal = new Normal(); { normal.uid = this.data.state.makeId(); } this.data.state.v = normal; } } else { // Debug.LogError("data null"); } } }
private void setHidePosition() { UIRectTransform.SetPosY((RectTransform)this.transform, float.MinValue); }
static UIConstants() { // FullParent { // anchoredPosition: (0.0, 0.0); anchorMin: (0.0, 0.0); anchorMax: (1.0, 1.0); pivot: (0.5, 0.5); // offsetMin: (0.0, 0.0); offsetMax: (0.0, 0.0); sizeDelta: (0.0, 0.0); FullParent.anchoredPosition = Vector2.zero; FullParent.anchorMin = Vector2.zero; FullParent.anchorMax = new Vector2(1.0f, 1.0f); FullParent.pivot = new Vector2(0.5f, 0.5f); FullParent.offsetMin = Vector2.zero; FullParent.offsetMax = Vector2.zero; FullParent.sizeDelta = Vector2.zero; } // MiniGameDataUIRect { float padding = DefaultMiniGameDataUIPadding; MiniGameDataUIRect.anchoredPosition = new Vector2(0.0f, -HeaderHeight - padding); MiniGameDataUIRect.anchorMin = new Vector2(0.5f, 1f); MiniGameDataUIRect.anchorMax = new Vector2(0.5f, 1f); MiniGameDataUIRect.pivot = new Vector2(0.5f, 1f); MiniGameDataUIRect.offsetMin = new Vector2(-(DefaultMiniGameDataUISize - 2 * padding) / 2.0f, -150.0f); MiniGameDataUIRect.offsetMax = new Vector2((DefaultMiniGameDataUISize - padding) / 2.0f, -HeaderHeight - padding); MiniGameDataUIRect.sizeDelta = new Vector2(DefaultMiniGameDataUISize - 2 * padding, DefaultMiniGameDataUISize - 2 * padding); } // PostureGameDataUIRect { PostureMiniGameDataUIRect = new UIRectTransform(MiniGameDataUIRect); PostureMiniGameDataUIRect.setPosY(105.0f); } float paddingLeft = 90; float paddingRight = 10; // RequestBoolRect { RequestBoolRect.anchoredPosition = new Vector3(paddingLeft, 0, 0); RequestBoolRect.anchorMin = new Vector2(0.0f, 1.0f); RequestBoolRect.anchorMax = new Vector2(0.0f, 1.0f); RequestBoolRect.pivot = new Vector2(0.0f, 1.0f); RequestBoolRect.offsetMin = new Vector2(paddingLeft, -paddingLeft - RequestBoolDim); RequestBoolRect.offsetMax = new Vector2(paddingLeft + RequestBoolDim, -paddingLeft); RequestBoolRect.sizeDelta = new Vector2(RequestBoolDim, RequestBoolDim); } // RequestEnumRect { RequestEnumRect.anchoredPosition = new Vector3((paddingLeft - paddingRight) / 2, 0f, 0f); RequestEnumRect.anchorMin = new Vector2(0.0f, 1.0f); RequestEnumRect.anchorMax = new Vector2(1.0f, 1.0f); RequestEnumRect.pivot = new Vector2(0.5f, 1f); RequestEnumRect.offsetMin = new Vector2(paddingLeft, -RequestEnumHeight); RequestEnumRect.offsetMax = new Vector2(-paddingRight, 0); RequestEnumRect.sizeDelta = new Vector2(-paddingLeft - paddingRight, RequestEnumHeight); } // RequestIntLongFloatRect { RequestRect.anchoredPosition = new Vector3((paddingLeft - paddingRight) / 2, 0f, 0f); RequestRect.anchorMin = new Vector2(0.0f, 1.0f); RequestRect.anchorMax = new Vector2(1.0f, 1.0f); RequestRect.pivot = new Vector2(0.5f, 1f); RequestRect.offsetMin = new Vector2(paddingLeft, -RequestHeight); RequestRect.offsetMax = new Vector2(-paddingRight, 0); RequestRect.sizeDelta = new Vector2(-paddingLeft - paddingRight, RequestHeight); } // RequestChangeFullRect { // anchoredPosition: (0.0, 0.0); anchorMin: (0.0, 0.5); anchorMax: (1.0, 0.5); pivot: (0.5, 0.5); // offsetMin: (0.0, -15.0); offsetMax: (0.0, 15.0); sizeDelta: (0.0, 30.0); RequestChangeFullRect.anchoredPosition = new Vector3(0.0f, 0.0f, 0.0f); RequestChangeFullRect.anchorMin = new Vector2(0.0f, 0.5f); RequestChangeFullRect.anchorMax = new Vector2(1.0f, 0.5f); RequestChangeFullRect.pivot = new Vector2(0.5f, 0.5f); RequestChangeFullRect.offsetMin = new Vector2(0.0f, -15.0f); RequestChangeFullRect.offsetMax = new Vector2(0.0f, 15.0f); RequestChangeFullRect.sizeDelta = new Vector2(0.0f, 30.0f); } // RequestChangePartRect { // anchoredPosition: (2.5, 0.0); anchorMin: (0.5, 0.5); anchorMax: (1.0, 0.5); pivot: (0.5, 0.5); // offsetMin: (5.0, -15.0); offsetMax: (0.0, 15.0); sizeDelta: (-5.0, 30.0); RequestChangePartRect.anchoredPosition = new Vector3(2.5f, 0.0f, 0.0f); RequestChangePartRect.anchorMin = new Vector2(0.5f, 0.5f); RequestChangePartRect.anchorMax = new Vector2(1.0f, 0.5f); RequestChangePartRect.pivot = new Vector2(0.5f, 0.5f); RequestChangePartRect.offsetMin = new Vector2(5.0f, -15.0f); RequestChangePartRect.offsetMax = new Vector2(0.0f, 15.0f); RequestChangePartRect.sizeDelta = new Vector2(-5.0f, 30.0f); } }