Bezier with texture

Hi,
any idea how to use texture2d property of bezier curves so that we could draw f.eg. an arrow instead of just a line in the Dialogue Nodes?

I played around with this, and it doesn’t appear the Bezier curve uses the entire texture provided. I tried several textures and all I seemed to get was what was essentially the color of part of the texture.

I did find this link which would at least allow you to put an arrow at the end of the bezier curve: c# - Why when adding Handles.ArrowHandleCap to a line it's not drawing the ArrowHandleCap? - Stack Overflow

Hi Brian,
I have found the same link but it did not work as intended.

Below is my solution for those interested in:

        private void DrawConnectins(DialogueNode node)
        {
            Vector3 startPosition = new Vector2(node.GetRect().xMax, node.GetRect().center.y);

            Texture2D myTexture = (Texture2D)EditorGUIUtility.Load("Assets/Editor Default Resources/arrow-icon-14-ff0000-16.png");

            foreach (DialogueNode childNode in selectedDialogue.GetAllChildren(node))
            {
                Vector3 endPosition = new Vector2(childNode.GetRect().xMin, childNode.GetRect().center.y);
                
                Vector3 controlPointOffset = endPosition-startPosition;
                controlPointOffset.y = 0;
                controlPointOffset.x *= 0.8f;

                Handles.DrawBezier(
                    startPosition, endPosition, 
                    startPosition + controlPointOffset, 
                    endPosition - controlPointOffset, 
                    Color.white, null, 4f);

                if (!myTexture) Debug.Log("texture missing");
                GUI.DrawTexture(new Rect(endPosition.x-16, endPosition.y-8, 16, 16), myTexture, ScaleMode.StretchToFill);
            }
        }

Please, do mind that we need to create an Editor resource folder with the exact name and location, according to Manual(Unity - Manual: Special folder names):
Assets/Editor Default Resources

The texture should be placed in there. (You can right-click it and copy the path to update it in the code).

You may decide to add variables for the position offsets mine are this way as the texture I use is 16/16.

1 Like

Privacy & Terms