// Use this for initialization void Start() { myRect = GetComponent<RectTransform>(); if (!MaskArea) { MaskArea = myRect; } if (GetComponent<Graphic>() != null) { mat = new Material(Shader.Find("UI Extensions/SoftMaskShader")); GetComponent<Graphic>().material = mat; } if (GetComponent<Text>()) { isText = true; mat = new Material(Shader.Find("UI Extensions/SoftMaskShaderText")); GetComponent<Text>().material = mat; GetCanvas(); // For some reason, having the mask control on the parent and disabled stops the mouse interacting // with the texture layer that is not visible.. Not needed for the Image. if (transform.parent.GetComponent<Mask>() == null) transform.parent.gameObject.AddComponent<Mask>(); transform.parent.GetComponent<Mask>().enabled = false; } }
public static void ForceRebuildLayoutImmediate(RectTransform layoutRoot) { var rebuilder = s_Rebuilders.Get(); rebuilder.Initialize(layoutRoot); rebuilder.Rebuild(CanvasUpdate.Layout); s_Rebuilders.Release(rebuilder); }
/// <summary> /// <para>Forces an immediate rebuild of the layout element and child layout elements affected by the calculations.</para> /// </summary> /// <param name="layoutRoot">The layout element to perform the layout rebuild on.</param> public static void ForceRebuildLayoutImmediate(RectTransform layoutRoot) { LayoutRebuilder element = LayoutRebuilder.s_Rebuilders.Get(); element.Initialize(layoutRoot); element.Rebuild(CanvasUpdate.Layout); LayoutRebuilder.s_Rebuilders.Release(element); }
public int KeepWindowInCanvas = 5; // # of pixels of the window that must stay inside the canvas view. // Use this for initialization void Start() { m_transform = GetComponent<RectTransform>(); m_originalCoods = m_transform.position; m_canvas = GetComponentInParent<Canvas>(); m_canvasRectTransform = m_canvas.GetComponent<RectTransform>(); }
private void PerformLayoutControl(RectTransform rect, UnityAction<Component> action) { if (rect == null) return; var components = ListPool<Component>.Get(); rect.GetComponents(typeof(ILayoutController), components); StripDisabledBehavioursFromList(components); // If there are no controllers on this rect we can skip this entire sub-tree // We don't need to consider controllers on children deeper in the sub-tree either, // since they will be their own roots. if (components.Count > 0) { // Layout control needs to executed top down with parents being done before their children, // because the children rely on the sizes of the parents. // First call layout controllers that may change their own RectTransform for (int i = 0; i < components.Count; i++) if (components[i] is ILayoutSelfController) action(components[i]); // Then call the remaining, such as layout groups that change their children, taking their own RectTransform size into account. for (int i = 0; i < components.Count; i++) if (!(components[i] is ILayoutSelfController)) action(components[i]); for (int i = 0; i < rect.childCount; i++) PerformLayoutControl(rect.GetChild(i) as RectTransform, action); } ListPool<Component>.Release(components); }
public static RectOffset GetMargin(RectTransform rect, RectOffset defaultValue) { if (rect == null) return new RectOffset(0, 0, 0, 0); RectOffset currentMargin = defaultValue; LayoutElementExtended[] list = rect.GetComponents<LayoutElementExtended>(); for (int i = 0; i < list.Length; i++) { LayoutElementExtended layoutElementExtended = list[i]; if (layoutElementExtended.enabled) { RectOffset elementMargin = layoutElementExtended.margin; currentMargin.top += elementMargin.top; currentMargin.bottom += elementMargin.bottom; currentMargin.left += elementMargin.left; currentMargin.right += elementMargin.right; } } return currentMargin; }
void Awake() { rectTransform = transform.parent.GetComponent<RectTransform>(); goTransform = transform.parent; thisRectTransform = GetComponent<RectTransform>(); sizeDelta = thisRectTransform.sizeDelta; }
public DropDownListButton(GameObject btnObj) { gameobject = btnObj; rectTransform = btnObj.GetComponent<RectTransform>(); btnImg = btnObj.GetComponent<Image>(); btn = btnObj.GetComponent<Button>(); txt = rectTransform.FindChild("Text").GetComponent<Text>(); img = rectTransform.FindChild("Image").GetComponent<Image>(); }
protected override void OnValidate() { base.OnValidate(); if (rectTrans == null) rectTrans = GetComponent<RectTransform>(); if (curveForText[curveForText.length - 1].time != rectTrans.rect.width) OnRectTransformDimensionsChange(); }
public Rect GetCanvasRect(RectTransform t, Canvas c) { t.GetWorldCorners(m_WorldCorners); var canvasTransform = c.GetComponent<Transform>(); for (int i = 0; i < 4; ++i) m_CanvasCorners[i] = canvasTransform.InverseTransformPoint(m_WorldCorners[i]); return new Rect(m_CanvasCorners[0].x, m_CanvasCorners[0].y, m_CanvasCorners[2].x - m_CanvasCorners[0].x, m_CanvasCorners[2].y - m_CanvasCorners[0].y); }
public void Init(ReorderableList extList) { _extList = extList; _rect = GetComponent<RectTransform>(); _cachedChildren = new List<Transform>(); _cachedListElement = new List<ReorderableListElement>(); StartCoroutine(RefreshChildren()); }
protected override void Awake() { base.Awake(); base.transition = Transition.None; base.toggleTransition = ToggleTransition.None; this.m_Accordion = this.gameObject.GetComponentInParent<Accordion>(); this.m_RectTransform = this.transform as RectTransform; this.m_LayoutElement = this.gameObject.GetComponent<LayoutElement>(); this.onValueChanged.AddListener(OnValueChanged); }
public Rect GetCanvasRect(RectTransform t, Canvas c) { if ((Object) c == (Object) null) return new Rect(); t.GetWorldCorners(this.m_WorldCorners); Transform component = c.GetComponent<Transform>(); for (int index = 0; index < 4; ++index) this.m_CanvasCorners[index] = component.InverseTransformPoint(this.m_WorldCorners[index]); return new Rect(this.m_CanvasCorners[0].x, this.m_CanvasCorners[0].y, this.m_CanvasCorners[2].x - this.m_CanvasCorners[0].x, this.m_CanvasCorners[2].y - this.m_CanvasCorners[0].y); }
void Awake() { Canvas canvas = GetComponentInParent<Canvas>(); if (canvas != null) { canvasRectTransform = canvas.transform as RectTransform; panelRectTransform = transform.parent as RectTransform; goTransform = transform.parent; } }
/// <summary> /// Converts the anchoredPosition of the first RectTransform to the second RectTransform, /// taking into consideration offset, anchors and pivot, and returns the new anchoredPosition /// </summary> public static Vector2 switchToRectTransform(this RectTransform from, RectTransform to) { Vector2 localPoint; Vector2 fromPivotDerivedOffset = new Vector2(from.rect.width * from.pivot.x + from.rect.xMin, from.rect.height * from.pivot.y + from.rect.yMin); Vector2 screenP = RectTransformUtility.WorldToScreenPoint(null, from.position); screenP += fromPivotDerivedOffset; RectTransformUtility.ScreenPointToLocalPointInRectangle(to, screenP, null, out localPoint); Vector2 pivotDerivedOffset = new Vector2(to.rect.width * to.pivot.x + to.rect.xMin, to.rect.height * to.pivot.y + to.rect.yMin); return to.anchoredPosition + localPoint - pivotDerivedOffset; }
void Awake() { rectTransform = transform.parent.GetComponent<RectTransform>(); float originalWidth; float originalHeight; originalWidth = rectTransform.rect.width; originalHeight = rectTransform.rect.height; ratio = originalHeight / originalWidth; minSize = new Vector2(0.1f * originalWidth, 0.1f * originalHeight); maxSize = new Vector2(10f * originalWidth, 10f * originalHeight); }
protected override void OnValidate() { base.OnValidate(); if (curveForText[0].time != 0) { var tmpRect = curveForText[0]; tmpRect.time = 0; curveForText.MoveKey(0, tmpRect); } if (rectTrans == null) rectTrans = GetComponent<RectTransform>(); if (curveForText[curveForText.length - 1].time != rectTrans.rect.width) OnRectTransformDimensionsChange(); }
private bool Initialize() { bool success = true; try { _rectTransform = GetComponent<RectTransform>(); _inputRT = _rectTransform.FindChild("InputField").GetComponent<RectTransform>(); _mainInput = _inputRT.GetComponent<InputField>(); _overlayRT = _rectTransform.FindChild("Overlay").GetComponent<RectTransform>(); _overlayRT.gameObject.SetActive(false); _scrollPanelRT = _overlayRT.FindChild("ScrollPanel").GetComponent<RectTransform>(); _scrollBarRT = _scrollPanelRT.FindChild("Scrollbar").GetComponent<RectTransform>(); _slidingAreaRT = _scrollBarRT.FindChild("SlidingArea").GetComponent<RectTransform>(); // scrollHandleRT = slidingAreaRT.FindChild("Handle").GetComponent<RectTransform>(); _itemsPanelRT = _scrollPanelRT.FindChild("Items").GetComponent<RectTransform>(); //itemPanelLayout = itemsPanelRT.gameObject.GetComponent<LayoutGroup>(); _canvas = GetComponentInParent<Canvas>(); _canvasRT = _canvas.GetComponent<RectTransform>(); _scrollRect = _scrollPanelRT.GetComponent<ScrollRect>(); _scrollRect.scrollSensitivity = _rectTransform.sizeDelta.y / 2; _scrollRect.movementType = ScrollRect.MovementType.Clamped; _scrollRect.content = _itemsPanelRT; itemTemplate = _rectTransform.FindChild("ItemTemplate").gameObject; itemTemplate.SetActive(false); } catch (System.NullReferenceException ex) { Debug.LogException(ex); Debug.LogError("Something is setup incorrectly with the dropdownlist component causing a Null Refernece Exception"); success = false; } panelObjects = new Dictionary<string, GameObject>(); _panelItems = AvailableOptions.ToList(); RebuildPanel(); //RedrawPanel(); - causes an initialisation failure in U5 return success; }
private bool Initialize() { bool success = true; try { _rectTransform = GetComponent<RectTransform>(); _mainButton = new DropDownListButton(_rectTransform.FindChild("MainButton").gameObject); _overlayRT = _rectTransform.FindChild("Overlay").GetComponent<RectTransform>(); _overlayRT.gameObject.SetActive(false); _scrollPanelRT = _overlayRT.FindChild("ScrollPanel").GetComponent<RectTransform>(); _scrollBarRT = _scrollPanelRT.FindChild("Scrollbar").GetComponent<RectTransform>(); _slidingAreaRT = _scrollBarRT.FindChild("SlidingArea").GetComponent<RectTransform>(); // scrollHandleRT = slidingAreaRT.FindChild("Handle").GetComponent<RectTransform>(); _itemsPanelRT = _scrollPanelRT.FindChild("Items").GetComponent<RectTransform>(); //itemPanelLayout = itemsPanelRT.gameObject.GetComponent<LayoutGroup>(); _canvas = GetComponentInParent<Canvas>(); _canvasRT = _canvas.GetComponent<RectTransform>(); _scrollRect = _scrollPanelRT.GetComponent<ScrollRect>(); _scrollRect.scrollSensitivity = _rectTransform.sizeDelta.y / 2; _scrollRect.movementType = ScrollRect.MovementType.Clamped; _scrollRect.content = _itemsPanelRT; _itemTemplate = _rectTransform.FindChild("ItemTemplate").gameObject; _itemTemplate.SetActive(false); } catch (System.NullReferenceException ex) { Debug.LogException(ex); Debug.LogError("Something is setup incorrectly with the dropdownlist component causing a Null Refernece Exception"); success = false; } _panelItems = new List<DropDownListButton>(); RebuildPanel(); RedrawPanel(); return success; }
// Use this for initialization void Start() { myRect = GetComponent<RectTransform>(); if (!MaskArea) { MaskArea = myRect; } if (GetComponent<Graphic>() != null) { mat = new Material(Shader.Find("UI Extensions/SoftMaskShader")); GetComponent<Graphic>().material = mat; } if (GetComponent<Text>()) { isText = true; mat = new Material(Shader.Find("UI Extensions/SoftMaskShaderText")); GetComponent<Text>().material = mat; GetCanvas(); // For some reason, having the mask control on the parent and disabled stops the mouse interacting // with the texture layer that is not visible.. Not needed for the Image. if (transform.parent.GetComponent<Button>() == null && transform.parent.GetComponent<Mask>() == null) transform.parent.gameObject.AddComponent<Mask>(); if (transform.parent.GetComponent<Mask>() != null) transform.parent.GetComponent<Mask>().enabled = false; } if (CascadeToALLChildren) { for (int c = 0; c < transform.childCount; c++) { SetSAM(transform.GetChild(c)); } } MaterialNotSupported = mat == null; }
// Use this for initialization public void Awake() { var _canvas = GetComponentInParent<Canvas>(); _guiCamera = _canvas.worldCamera; _guiMode = _canvas.renderMode; _rectTransform = GetComponent<RectTransform>(); _text = GetComponentInChildren<Text>(); _inside = false; //size of the screen // screenWidth = Screen.width; // screenHeight = Screen.height; xShift = 0f; YShift = -30f; // _xShifted = _yShifted = false; this.gameObject.SetActive(false); }
void OnEnable() { if (effector == null) { GameObject effectorobj = new GameObject("effector"); effectRoot = new GameObject("ShineEffect"); effectRoot.transform.SetParent(this.transform); effectRoot.AddComponent<Image>().sprite = gameObject.GetComponent<Image>().sprite; effectRoot.GetComponent<Image>().type = gameObject.GetComponent<Image>().type; effectRoot.AddComponent<Mask>().showMaskGraphic = false; effectRoot.transform.localScale = Vector3.one; effectRoot.GetComponent<RectTransform>().anchoredPosition3D = Vector3.zero; effectRoot.GetComponent<RectTransform>().anchorMax = Vector2.one; effectRoot.GetComponent<RectTransform>().anchorMin = Vector2.zero; effectRoot.GetComponent<RectTransform>().offsetMax = Vector2.zero; effectRoot.GetComponent<RectTransform>().offsetMin = Vector2.zero; effectRoot.transform.SetAsFirstSibling(); effectorobj.AddComponent<RectTransform>(); effectorobj.transform.SetParent(effectRoot.transform); effectorRect = effectorobj.GetComponent<RectTransform>(); effectorRect.localScale = Vector3.one; effectorRect.anchoredPosition3D = Vector3.zero; effectorRect.gameObject.AddComponent<ShineEffect>(); effectorRect.anchorMax = Vector2.one; effectorRect.anchorMin = Vector2.zero; effectorRect.Rotate(0, 0, -8); effector = effectorobj.GetComponent<ShineEffect>(); effectorRect.offsetMax = Vector2.zero; effectorRect.offsetMin = Vector2.zero; OnValidate(); } }
public void Awake() { var scrollRect = GetComponent<ScrollRect>(); if (!_scrollingPanel) { _scrollingPanel = scrollRect.content; } if (!_center) { Debug.LogError("Please define the RectTransform for the Center viewport of the scrollable area"); } if (_arrayOfElements == null || _arrayOfElements.Length == 0) { var childCount = scrollRect.content.childCount; if (childCount > 0) { _arrayOfElements = new GameObject[childCount]; for (int i = 0; i < childCount; i++) { _arrayOfElements[i] = scrollRect.content.GetChild(i).gameObject; } } } }
protected void OnTransformParentChanged() { parentTransform = rectTransform.parent as RectTransform; }
protected override void OnEnable() { base.OnEnable(); rectTrans = GetComponent<RectTransform>(); OnRectTransformDimensionsChange(); }
private void updateSwitchPlayerUI() { int deltaCount = currentCharacters.Count - switchCharacterButtons.Count; if (deltaCount > 0) { //Create missings Pointers for (int i = currentCharacters.Count - deltaCount; i < currentCharacters.Count; i++) { GameObject newPointer = (GameObject)Instantiate(Resources.Load("Character-Pointer")); newPointer.transform.SetParent(GameObject.Find("UI").transform); newPointer.transform.localScale = new Vector3(1, 1, 1); newPointer.transform.localPosition = new Vector3(-Screen.width, -Screen.height, 1); newPointer.transform.SetSiblingIndex(0); switchCharacterButtons.Add(newPointer); } } Vector2 cameraSize = new Vector2(2 * camera.orthographicSize * camera.pixelWidth / camera.pixelHeight, 2 * camera.orthographicSize); Vector2 cameraPosition = camera.transform.position; Rect cameraRect = new Rect(cameraPosition - 0.5f * cameraSize, cameraSize); for (int i = 0; i < switchCharacterButtons.Count; i++) { switchCharacterButtons[i].transform.localPosition = new Vector3(-Screen.width, -Screen.height, 1); if (i < currentCharacters.Count) { Vector2 distance = ((Vector2)(currentCharacters[i].transform.position - camera.transform.position)); if (cameraRect.Contains(currentCharacters[i].transform.position)) { if (!currentCharacters[i].active && inputController.isClickedOnCharacter(currentCharacters[i])) { this.switchCharacter(i); inputController.clickActionPerformed(); } continue; //Dont show pointer } Vector2 direction = distance.normalized; float angle = Mathf.Atan2(direction.y, direction.x); float length = Mathf.Abs(camera.pixelHeight / (2 * Mathf.Sin(angle))); if (Mathf.Abs(direction.x) > (new Vector2(camera.pixelWidth, camera.pixelHeight).normalized).x) { length = Mathf.Abs(camera.pixelWidth / (2 * Mathf.Cos(angle))); } Vector3 newPosition = new Vector3(direction.x * length, direction.y * length, 1); RectTransform HUD = GameObject.Find("HUD").GetComponent <RectTransform>(); Vector2 hudPosition = (Vector2)(HUD.position) - new Vector2(HUD.rect.width, HUD.rect.height) - new Vector2(Screen.width / 2f, Screen.height / 2f); //Inside Pause HUD if (newPosition.x > hudPosition.x && newPosition.y > hudPosition.y) { float xFactor = (hudPosition.x - newPosition.x) / direction.x; float yFactor = (hudPosition.y - newPosition.y) / direction.y; float factor = xFactor > yFactor ? xFactor : yFactor; newPosition += new Vector3(direction.x, direction.y, 0) * factor; } //Sledged Edge of Pause HUD //subtract own length newPosition -= new Vector3(direction.x * 0.5f * switchCharacterButtons[i].GetComponent <RectTransform>().rect.width, direction.y * 0.5f * switchCharacterButtons[i].GetComponent <RectTransform>().rect.height); switchCharacterButtons[i].transform.localPosition = newPosition; switchCharacterButtons[i].transform.localRotation = Quaternion.AngleAxis(angle * 180 / Mathf.PI + 90, new Vector3(0, 0, 1)); switchCharacterButtons[i].transform.Find("color_1").GetComponent <Image>().color = currentCharacters[i].transform.Find("color-container").GetComponent <SpriteRenderer>().color; switchCharacterButtons[i].transform.Find("color_2").GetComponent <Image>().color = currentCharacters[i].transform.Find("color-container").GetComponent <SpriteRenderer>().color; switchCharacterButtons[i].transform.Find("color_3").GetComponent <Image>().color = currentCharacters[i].transform.Find("color-container").GetComponent <SpriteRenderer>().color; switchCharacterButtons[i].transform.Find("color_4").GetComponent <Image>().color = currentCharacters[i].transform.Find("color-container").GetComponent <SpriteRenderer>().color; if (inputController.isClickedOnUIElement(switchCharacterButtons[i].GetComponent <RectTransform>().position, switchCharacterButtons[i].GetComponent <RectTransform>().rect.width, switchCharacterButtons[i].GetComponent <RectTransform>().rect.height)) { this.switchCharacter(i); inputController.clickActionPerformed(); } } } }
// Use this for initialization void Start() { RectTransform t_rt = GetComponent <RectTransform>(); Debug.LogError("----:" + transform.localPosition + " " + t_rt.rect + " " + t_rt.anchoredPosition); }
// Use this for initialization private void Awake() { lerp = false; scrollRect = gameObject.GetComponent<ScrollRect>(); scrollRectTransform = gameObject.GetComponent<RectTransform>(); listContainerTransform = scrollRect.content; listContainerRectTransform = listContainerTransform.GetComponent<RectTransform>(); rectTransform = listContainerTransform.gameObject.GetComponent<RectTransform>(); UpdateListItemsSize(); UpdateListItemPositions(); PageChanged(CurrentPage()); if (nextButton) { nextButton.GetComponent<Button>().onClick.AddListener(() => { NextScreen(); }); } if (prevButton) { prevButton.GetComponent<Button>().onClick.AddListener(() => { PreviousScreen(); }); } }
/// <summary> /// <para>Returns the preferred height of the layout element.</para> /// </summary> /// <param name="rect">The RectTransform of the layout element to query.</param> public static float GetPreferredHeight(RectTransform rect) { return Mathf.Max(LayoutUtility.GetLayoutProperty(rect, (Func<ILayoutElement, float>) (e => e.minHeight), 0.0f), LayoutUtility.GetLayoutProperty(rect, (Func<ILayoutElement, float>) (e => e.preferredHeight), 0.0f)); }
/// <summary> /// <para>Returns the minimum height of the layout element.</para> /// </summary> /// <param name="rect">The RectTransform of the layout element to query.</param> public static float GetMinHeight(RectTransform rect) { return LayoutUtility.GetLayoutProperty(rect, (Func<ILayoutElement, float>) (e => e.minHeight), 0.0f); }
/// <summary> /// <para>Returns the flexible width of the layout element.</para> /// </summary> /// <param name="rect">The RectTransform of the layout element to query.</param> public static float GetFlexibleWidth(RectTransform rect) { return LayoutUtility.GetLayoutProperty(rect, (Func<ILayoutElement, float>) (e => e.flexibleWidth), 0.0f); }
protected void Awake() { rectTransform = GetComponent <RectTransform>(); OnTransformParentChanged(); CheckSize(); }
public static RectOffset GetMargin(RectTransform rect) { return LayoutUtilityExtended.GetMargin(rect, new RectOffset(0, 0, 0, 0)); }
public static TooltipInformations GetUsableCompetenceTooltip(Competence competence, RectTransform forcedPosition, TooltipForcedPositionType tooltipForcedPositionType) { if (competence == null) return new TooltipInformations(); TooltipInformations infos = new TooltipInformations(); infos.tooltipName = competence.GetCompetenceName; infos.tooltipDescription = competence.GetCompetenceTooltip; infos.tooltipAdditionalInformationType = TooltipAdditionalInformationType.ActionPointsCost; infos.tooltipAdditionalInformationValue = competence.GetActionPointsCost; infos.forcedTooltipLPosition = forcedPosition; infos.tooltipForcedPositionType = tooltipForcedPositionType; return infos; }
private static Vector3 GetPointOnRectEdge(RectTransform rect, Vector2 dir) { if ((UnityEngine.Object) rect == (UnityEngine.Object) null) return Vector3.zero; if (dir != Vector2.zero) dir /= Mathf.Max(Mathf.Abs(dir.x), Mathf.Abs(dir.y)); dir = rect.rect.center + Vector2.Scale(rect.rect.size, dir * 0.5f); return (Vector3) dir; }
public static TooltipInformations GetDiscTypeInformations(DiscInformations discInformations, RectTransform forcedPosition, TooltipForcedPositionType tooltipForcedPositionType) { if (discInformations == null) return new TooltipInformations(); TooltipInformations infos = new TooltipInformations(); infos.tooltipName = discInformations.tooltipName; infos.tooltipDescription = discInformations.tooltipDescription; infos.tooltipAdditionalInformationType = TooltipAdditionalInformationType.Damage; infos.tooltipAdditionalInformationValue = discInformations.damagesValue; infos.forcedTooltipLPosition = forcedPosition; infos.tooltipForcedPositionType = tooltipForcedPositionType; return infos; }