Exemplo n.º 1
0
        private void CreateBorder(UIElement element, Color color)
        {
            GameObject[] bLine = new GameObject[4];

            // create 4 lines
            for (int i = 0; i < 4; i++)
            {
                bLine[i]     = new GameObject("Border" + i);
                bLine[i].tag = element.GetTag();
                bLine[i].AddComponent <UnityEngine.UI.Image>().color = color;
                bLine[i].transform.SetParent(element.GetTransform());
            }

            // Set the thickness of the lines
            float thick = 0.05f * UIScaler.GetPixelsPerUnit();

            bLine[0].GetComponent <RectTransform>().SetInsetAndSizeFromParentEdge(RectTransform.Edge.Bottom, 0, thick);
            bLine[0].GetComponent <RectTransform>().SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, -thick, element.GetRectTransform().rect.width);

            bLine[1].GetComponent <RectTransform>().SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, -thick, thick);
            bLine[1].GetComponent <RectTransform>().SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, -thick, element.GetRectTransform().rect.width);

            bLine[2].GetComponent <RectTransform>().SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, -thick, element.GetRectTransform().rect.height);
            bLine[2].GetComponent <RectTransform>().SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, -thick, thick);

            bLine[3].GetComponent <RectTransform>().SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, -thick, element.GetRectTransform().rect.height);
            bLine[3].GetComponent <RectTransform>().SetInsetAndSizeFromParentEdge(RectTransform.Edge.Right, 0, thick);
        }
Exemplo n.º 2
0
 public UIElementBorder(UIElement element, Color color, float thickness = 0.05f)
 {
     CreateBorder(element.GetTransform(), element.GetRectTransform(), element.GetTag(), color, thickness);
 }
Exemplo n.º 3
0
 public UIElementBorder(UIElement element)
 {
     CreateBorder(element.GetTransform(), element.GetRectTransform(), element.GetTag(), Color.white);
 }
Exemplo n.º 4
0
 public UIElementBorder(UIElement element, Color color)
 {
     CreateBorder(element.GetTransform(), element.GetRectTransform(), element.GetTag(), color);
 }