Ejemplo n.º 1
0
    void Update()
    {
        if (!shouldUpdate)
        {
            return;
        }

        InitNodes();

        if (nodeUI1 == null)
        {
            //Debug.Log("null node, mang.");
            return;
        }

        Vector3 pos1 = Camera.main.WorldToViewportPoint(node1.transform.position + nodeUI1.GetOffset() * .1f);
        Vector3 pos2 = Camera.main.WorldToViewportPoint(node2.transform.position + nodeUI2.GetOffset() * .1f);

        float canvasDistX = (pos2.x - pos1.x) * levelCreationCanvas.pixelRect.width;
        float canvasDistY = (pos2.y - pos1.y) * levelCreationCanvas.pixelRect.height;

        float len  = Mathf.Sqrt(Mathf.Pow(canvasDistX, 2) + Mathf.Pow(canvasDistY, 2));
        float rads = Mathf.Atan2(canvasDistY, canvasDistX);

        tendrilImage.rectTransform.anchoredPosition = new Vector2((pos1.x - .5f) * levelCreationCanvas.pixelRect.width + len * Mathf.Cos(rads) / 2,
                                                                  (pos1.y - .5f) * levelCreationCanvas.pixelRect.height + len * Mathf.Sin(rads) / 2);
        tendrilImage.rectTransform.sizeDelta = new Vector2(length, tendrilImage.rectTransform.sizeDelta.y);
        tendrilImage.rectTransform.rotation  = Quaternion.Euler(0, 0, rads * Mathf.Rad2Deg);

        Image tendrilChild = tendrilImage.transform.GetChild(0).GetComponent <Image>();

        tendrilChild.rectTransform.sizeDelta = new Vector2(length, 60);
    }