Example #1
0
        public void OnChildAddedCalled()
        {
            var layout = new CustomLayout();
            var button = new Button();

            Assert.AreEqual(0, layout.AddedCount);
            layout.Add(button);
            Assert.AreEqual(1, layout.AddedCount);
        }
Example #2
0
 public void Add(Side side, RectTransform content, CustomLayout caller = null)
 {
     if ((LayoutGroup is HorizontalLayoutGroup && (side == Side.Top || side == Side.Bottom)) || (LayoutGroup is VerticalLayoutGroup && (side == Side.Left || side == Side.Right)))
     {
         CustomLayout parentLayout = CheckParent();
         parentLayout.AddLayout(this, transform.GetSiblingIndex());
         int index;
         if (side == Side.Left || side == Side.Top)
         {
             index = transform.GetSiblingIndex();
         }
         else
         {
             index = transform.GetSiblingIndex() + 1;
         }
         parentLayout.Add(index, content);
     }
     else
     {
         if (ContentRectTransform.childCount > 0) // Content CustomLayout.
         {
             int index1, index2;
             if (side == Side.Left || side == Side.Top)
             {
                 index1 = 1;
                 index2 = 0;
             }
             else
             {
                 index1 = 0;
                 index2 = 1;
             }
             Add(index1, ContentRectTransform.GetChild(0).GetComponent <RectTransform>());
             Add(index2, content);
         }
         else // Intermediate CustomLayout.
         {
             int index = caller.transform.GetSiblingIndex();
             if (side == Side.Left || side == Side.Top)
             {
             }
             else
             {
                 index++;
             }
             Add(index, content);
         }
     }
 }
Example #3
0
    public void OnPointerUp(PointerEventData dt)
    {
        Debug.Log("Draggable mouse up");

        isMouseDown = false;

        if (shouldReturn)
        {
            Debug.Log("Retour à position initiale");
            target.position = startPosition;
        }


        List <RaycastResult> results = new List <RaycastResult>();

        EventSystem.current.RaycastAll(dt, results);

        if (results.Count > 0)
        {
            foreach (RaycastResult hit in results)
            {
                onRelease onR = hit.gameObject.GetComponent <onRelease>();
                if (onR != null)
                {
                    CustomLayout customLayout = onR.transform.parent.parent.GetComponent <CustomLayout>();
                    customLayout.Add(onR.Side, transform as RectTransform, customLayout);
                    if (showedOnRelease != null)
                    {
                        showedOnRelease.Hide();
                        showedOnRelease = null;
                    }
                    break;
                }
            }
        }
    }