Hello guys,
My name is Víctor and I’m trying to make my own visual Behaviour Tree Editor in order to make IA faster.
I’m starting with Editor Customization in Unity so by now my doubt is about making drag and drop of a box ( will be a node on my tree ) to re-position and later to connect with another box.
My code is:
private void OnGUI(){
gridRect = new Rect(verticalRect.width, 0, position.width-verticalRect.width, position.height);
GUILayout.BeginArea(gridRect);
GUI.color = Color.white;
GUI.Box(new Rect(500, 500, 100, 100), "test");
DropAreaGUI();
GUILayout.EndArea();
}
and
private Vector2 currentMousePosition;
private bool isDragging = false;
Vector2 mouseDragStart;
public void DropAreaGUI()
{
Event evt = Event.current;
//GUI.Box(gridRect, "Add Trigger");
switch (evt.type)
{
case EventType.DragUpdated:
break;
case EventType.MouseDown:
mouseDragStart = evt.mousePosition;
Debug.Log(mouseDragStart);
break;
case EventType.MouseDrag:
if (evt.type == EventType.MouseDrag)
{
currentMousePosition = Event.current.mousePosition;
}
Debug.Log(currentMousePosition);
GUI.Box(new Rect(currentMousePosition.x,currentMousePosition.y,100,100), "test");
Repaint();
break;
}
if (evt.isMouse)
{
evt.Use();
}
}
Here you find and Image of the box I would like to move “Test” box.
Any idea ?
My approach is to “re-paint” the box while updating mousePosition but it’s not working.
I tried with many tutorials on forum questions but doesn’t work, they seem to work about GameObjects or items in inspector.
Regards, Víctor.