Exemple #1
0
 public void SetUI(Camera camera, ref Transform canvas, LoaderButtonOnClickCallBack buttonCallBack)
 {
     mCamera         = camera;
     mCanvas         = canvas;
     mButtonCallBack = buttonCallBack;
 }
Exemple #2
0
    /*
     * Instantiate 된 object여야 함.
     * 이미 생성한 object의 위치만 잡아주는 기능.
     * 위치 잡다 포기. 걍 content에 Horizon/Vertical Layout Group 추가해서 쓰는게 젤 깔끔함
     * 스크롤바 초기 위치는 content의 rect > pivot으로 설정
     */
    public void CreateScrollViewItems(List <GameObject> objects,
                                      Vector2 margin,
                                      Vector2 spacing,
                                      LoaderButtonOnClickCallBack onClickCallBack,
                                      GameObject scrollview,
                                      int colCount,
                                      string viewportName = "Viewport",
                                      string contentName  = "Content")
    {
        int count = objects.Count;

        if (count == 0)
        {
            return;
        }

        Vector2 scrollviewSize = scrollview.GetComponent <RectTransform>().sizeDelta;

        GameObject content = scrollview.transform.Find(viewportName).transform.Find(contentName).gameObject;

        Vector2 objectSize = objects[0].GetComponent <RectTransform>().sizeDelta;
        Vector2 contentSize;

        contentSize = new Vector2(
            (margin.x * 2) + (colCount * (objectSize.x + spacing.x)),
            (margin.y * 2) + (((int)(objects.Count / colCount) + 1) * (objectSize.y + spacing.x))
            );

        /*
         * if(isHorizon)
         * {
         *  objectSize.x += margin;
         *  contentSize = new Vector2(objectSize.x * count + (margin * 2), objectSize.y);
         * }
         * else
         * {
         *  objectSize.y += margin;
         *  contentSize = new Vector2(objectSize.x, objectSize.y * count + (margin * 2));
         * }
         */
        content.GetComponent <RectTransform>().sizeDelta = contentSize;

        for (int n = 0; n < count; n++)
        {
            /*
             * Vector3 pos;
             * Vector3 contentPos = content.transform.position;
             *
             * if(isHorizon)
             * {
             *  pos = new Vector3(margin + (n* objectSize.x) + (objectSize.x * 0.5f) - (contentSize.x * 0.5f), 0, 0);
             *  objects[n].transform.position = pos;
             * }
             * else
             * {
             *  pos = new Vector3(0, 0, 0);
             *  objects[n].transform.position = pos;
             *  Debug.Log(pos);
             * }
             */


            objects[n].transform.SetParent(content.transform);

            Button btn = objects[n].GetComponentInChildren <Button>();
            if (btn != null)
            {
                GameObject o = objects[n];
                btn.onClick.AddListener(() => { onClickCallBack(o); });
            }
        }
    }