Example #1
0
    public static void JustPosBase()
    {
        for (int i = 0; i < UnityEditor.Selection.objects.Length; i++)
        {
            GameObject obj = (GameObject)UnityEditor.Selection.objects[i];

            GroupOffset s = obj.GetComponent <GroupOffset>();



            if (s != null)
            {
                Vector3 basePos = obj.transform.GetChild(0).transform.localPosition;
                for (int j = 1; j < obj.transform.childCount; j++)
                {
                    Transform c = obj.transform.GetChild(j);
                    c.localPosition = basePos + s.offset * j;
                }
            }
        }
    }
Example #2
0
    public static void JustPos()
    {
        for (int i = 0; i < UnityEditor.Selection.objects.Length; i++)
        {
            GameObject obj = (GameObject)UnityEditor.Selection.objects[i];

            GroupOffset s = obj.GetComponent <GroupOffset>();



            if (s != null)
            {
                for (int j = 0; j < obj.transform.childCount; j++)
                {
                    int x = j;

                    if (s.lineCount > 0)
                    {
                        x = j % s.lineCount;
                    }



                    Transform c = obj.transform.GetChild(j);
                    c.localPosition = x * s.offset;
                    c.localScale    = Vector3.one;

                    Image  img = c.gameObject.GetComponent <Image> ();
                    Sprite spr = img.sprite;

                    float sc = 1;
                    if (s.offset.x != 0)
                    {
                        if (spr.texture.width != s.offset.x)
                        {
                            sc = Mathf.Abs(s.offset.x / spr.texture.width);
                        }
                        c.localPosition += new Vector3(s.off, 0, 0) * x;

                        if (s.justCount > 0)
                        {
                            c.localPosition += new Vector3(s.justOff, 0, 0) * (j / s.justCount);
                        }
                    }
                    else
                    {
                        if (spr.texture.height != s.offset.y)
                        {
                            sc = Mathf.Abs(s.offset.y / spr.texture.height);
                        }
                        c.localPosition += new Vector3(0, s.off, 0) * x;

                        if (s.justCount > 0)
                        {
                            c.localPosition += new Vector3(0, s.justOff, 0) * (j / s.justCount);
                        }
                    }

                    RectTransform rtTrans = c.transform as RectTransform;
                    rtTrans.sizeDelta = new Vector2(spr.texture.width * sc, spr.texture.height * sc);

                    if (s.lineCount > 0)
                    {
                        if (s.offset.x != 0)
                        {
                            c.localPosition += new Vector3(0, (j / s.lineCount) * s.lineHeight);
                        }
                        else
                        {
                            c.localPosition += new Vector3((j / s.lineCount) * s.lineHeight, 0);
                        }
                    }
                }
            }
        }
    }