Exemplo n.º 1
0
    private void addChildren()
    {
        //data.attributes = new SSRP_attribute[] { };
        Vector2 newCanvasDimensions = new Vector2(0f, 0f);
        int     m = data.attributes.Length;
        int     i = 0;

        /*
         * // debug purposes
         * string childDescription = "";
         * foreach (SSRP_attribute childObj in data.attributes)
         * {
         *  childDescription += childObj.description() + ",\n";
         * }
         * Debug.LogFormat("Element Controller :  canLocateBaseGO:{1} and canRenderMeta:{2}, add {0} Children, attributes = [{3}]", m, canLocateBaseGO, canRenderChildData, childDescription);
         * // */

        if (canLocateBaseGO && canRenderChildData)
        {
            if (m == 0)
            {
                //newCanvasDimensions = childPrefab_canvas_init_dimension;
            }
            else
            {
                Vector3 newCanvasPosition = new Vector3(0f, 0f, 0f);
                Vector2 origin            = new Vector2(0f, 0f);
                Vector2 offset            = new Vector2(10, -10f);
                Vector2 dim        = new Vector2(210f, 126f);
                Vector2 step       = new Vector2(0f, 0f);
                Vector2 stepOffset = new Vector2(0, 0);
                Vector2 pos        = new Vector2(0f, 0f);
                int     rowNo      = 0;
                int     colCount   = 0;

                // rough GRID LAY OUT FOR ATTRIBUTESs - this should be have one level of recursion and to resize 6 boxes, into 2 rows of 3, and not 1 row of 5 and one row of 1.

                // scrollview.transform
                float scrollbarSize = 25;
                if (maxColSize > 0)
                {
                    float rows = 0;
                    float cols = maxColSize;
                    if (m <= maxColSize)
                    {
                        cols = m;
                        rows = 1;
                    }
                    else
                    {
                        rows = Mathf.Floor(m / maxColSize) + 1;
                    }

                    float height = Mathf.Ceil((dim.y + Mathf.Abs(offset.y)) * rows) + scrollbarSize;
                    float width  = offset.x + (dim.x * cols) + scrollbarSize;
                    //       Debug.LogFormat("We have {0} attribute and a maxColSize of {1}, giving us a height:{2} and width:{3}", m, maxColSize, height, width);
                    try
                    {
                        scrollview        = contextEntityViewGameObject.transform.Find("scrollView").gameObject;
                        scrollview_canvas = scrollview.transform.GetComponent <RectTransform>();

                        scrollview_canvas.sizeDelta = new Vector2(width, height);
                    }
                    catch
                    {
                        Debug.LogFormat("couldn't link to scrollview Canvas");
                    }
                }



                // loop through list of Child data and generate their UI
                for (i = 0; i < m; i++)
                {
                    if (maxColSize > 0 && colCount == maxColSize)
                    {
                        colCount = 0;
                        rowNo++;
                    }
                    step.Set(colCount, -rowNo);

                    stepOffset = Vector2.Scale(step, dim);

                    SSRP_attribute childData = data.attributes[i];
                    pos = origin + offset + stepOffset;
                    GameObject data_MVC;

                    data_MVC = (GameObject)Instantiate(attributGameObjectPrefab, pos, Quaternion.identity);
                    data_MVC.transform.SetParent(ViewPortContentTarget.transform, false);
                    prefabChildList.Add(data_MVC);
                    SSRP_Attribute_Controller child_controller = data_MVC.GetComponent <SSRP_Attribute_Controller>();
                    //     Debug.LogFormat("SSRP_attribute childData = [{0}]", childData.description());
                    child_controller.importData(childData);
                    colCount++;
                }


                //resize base canvas
                //newCanvasDimensions = new Vector2(200f, (m + 1) * childPrefab_canvas_init_dimension.y);
                //entity_canvas.sizeDelta = newCanvasDimensions;
            }
        }
    }
    private void addChildren()
    {
        //data.attributes = new SSRP_attribute[] { };
        Vector2 newCanvasDimensions = new Vector2(0f, 0f);
        int     m = data.attributes.Length;
        int     i = 0;


        if (canRenderChildData)
        {
            if (m == 0)
            {
                //newCanvasDimensions = childPrefab_canvas_init_dimension;
            }
            else
            {
                Vector3 newCanvasPosition = new Vector3(0f, 0f, 0f);
                Vector2 origin            = new Vector2(0f, 0f); // new Vector2(0f, -126f);
                Vector2 offset            = new Vector2(10, -10f);
                Vector2 dim        = new Vector2(210f, 126f);
                Vector2 step       = new Vector2(0f, 0f);
                Vector2 stepOffset = new Vector2(0, 0);
                Vector2 pos        = new Vector2(0f, 0f);
                int     rowNo      = 0;
                int     colCount   = 0;

                // rough GRID LAY OUT FOR ATTRIBUTESs - this should be have one level of recursion and to resize 6 boxes, into 2 rows of 3, and not 1 row of 5 and one row of 1.


                float scrollbarSize = 25;
                if (maxColSize > 0)
                {
                    float rows = 0;
                    float cols = maxColSize;
                    if (m <= maxColSize)
                    {
                        cols = m;
                        rows = 1;
                    }
                    else
                    {
                        rows = Mathf.Floor(m / maxColSize) + 1;
                    }

                    float height = Mathf.Ceil((dim.y + Mathf.Abs(offset.y)) * rows) + scrollbarSize;
                    float width  = offset.x + (dim.x * cols) + scrollbarSize;

                    try
                    {
                        scrollview        = transform.Find("popup").gameObject;
                        scrollview_canvas = scrollview.transform.GetComponent <RectTransform>();

                        scrollview_canvas.sizeDelta = new Vector2(width, height);
                    }
                    catch
                    {
                        Debug.LogFormat("couldn't link to scrollview Canvas");
                    }
                }



                // loop through list of Child data and generate their UI
                for (i = 0; i < m; i++)
                {
                    if (maxColSize > 0 && colCount == maxColSize)
                    {
                        colCount = 0;
                        rowNo++;
                    }
                    step.Set(colCount, -rowNo);

                    stepOffset = Vector2.Scale(step, dim);

                    SSRP_attribute childData = data.attributes[i];
                    pos = origin + offset + stepOffset;
                    GameObject data_MVC;

                    Debug.Log(scrollview);
                    if (scrollview == null || scrollview.transform == null)
                    {
                        return;
                    }


                    data_MVC = (GameObject)Instantiate(attributGameObjectPrefab, pos, Quaternion.identity);
                    data_MVC.transform.SetParent(scrollview.transform, false);
                    prefabChildList.Add(data_MVC);
                    SSRP_Attribute_Controller child_controller = data_MVC.GetComponent <SSRP_Attribute_Controller>();
                    //     Debug.LogFormat("SSRP_attribute childData = [{0}]", childData.description());
                    child_controller.importData(childData);
                    colCount++;
                }


                //resize base canvas
                //newCanvasDimensions = new Vector2(200f, (m + 1) * childPrefab_canvas_init_dimension.y);
                //entity_canvas.sizeDelta = newCanvasDimensions;
            }
        }
    }