Пример #1
0
    /*This method will take in the nodeObject list, iterate through it, and output it in levels
     *
     */
    internal void DrawASTTemplate2(List <GameObject> nodeObjects, int depth)
    {
        int pathLength = depth;
        int y          = 0;
        int x          = 0;

        //J > 0 too since we really start with length of 1 at the root
        //change the rest of the branches
        for (int j = pathLength; j > 0; j--)
        {
            for (int i = 0; i < nodeObjects.Count; i++)
            {
                NodeScript nodeScript = nodeObjects[i].GetComponent <NodeScript>();
                if (nodeScript.path.Length == j)
                {
                    GameObject myObject = nodeScript.gameObject;
                    int        temp     = Convert.ToInt32(nodeScript.path, 2);

                    Vector3 pos          = myObject.GetComponent <RectTransform>().anchoredPosition;
                    float   leftShiftedX = (temp * nodeInBetweenWidth) - ((Mathf.Pow(2, j) / 4) * nodeInBetweenWidth);
                    myObject.GetComponent <RectTransform>().anchoredPosition = new Vector3(leftShiftedX, -j * nodeInBetweenHeight, pos.z);
                    //myObject.GetComponent<RectTransform>().anchoredPosition = new Vector3(leftShiftedX, pos.y, -j * 300);
                }
            }
        }

        //shifts parents to middle of children
        for (int j = pathLength; j > 0; j--)
        {
            for (int i = 0; i < nodeObjects.Count; i++)
            {
                NodeScript nodeScript = nodeObjects[i].GetComponent <NodeScript>();
                if (nodeScript.path.Length == j)
                {
                    GameObject myObject = nodeScript.gameObject;
                    if (nodeScript.leftGameObjectChild != null)
                    {
                        GameObject leftObject  = nodeScript.leftGameObjectChild;
                        GameObject rightObject = nodeScript.rightGameObjectChild;
                        Vector3    pos         = myObject.GetComponent <RectTransform>().anchoredPosition;
                        Vector3    leftPos     = leftObject.GetComponent <RectTransform>().anchoredPosition;
                        Vector3    rightPos    = rightObject.GetComponent <RectTransform>().anchoredPosition;
                        float      midX        = (rightPos.x - leftPos.x) / 2.0f + leftPos.x;
                        myObject.GetComponent <RectTransform>().anchoredPosition = new Vector3(midX, pos.y, pos.z);
                    }
                }
            }
        }

        //attach lines to parents
        for (int i = 1; i < nodeObjects.Count; i++)
        {
            NodeScript nodeScript  = nodeObjects[i].GetComponent <NodeScript>();
            Vector3    anchoredPos = nodeScript.gameObjectParent.GetComponent <RectTransform>().anchoredPosition;
            nodeScript.GenerateLine(anchoredPos);
        }
    }