HiddenMonk / Unity3DRuntimeTransformGizmo

A runtime transform gizmo similar to unitys editor so you can translate (move, rotate, scale) objects at runtime.
MIT License
703 stars 129 forks source link

TransformGizmo - Through / Over UI Issue (IsPointerOverGameObject) #38

Open flogli opened 6 months ago

flogli commented 6 months ago

Hi, I've work with this asset and find out that the method GetTarget() - TransformGizmo.cs going through the UI elements

Here my solution if you need it: I'm sure there is a better option to do that but it's working as expected now

Hope you find it useful

void GetTarget() {
    if (nearAxis == Axis.None && Input.GetMouseButtonDown(0))
    {
        bool isAdding = Input.GetKey(AddSelection);
        bool isRemoving = Input.GetKey(RemoveSelection);
        RaycastHit hitInfo;
        if (Physics.Raycast(myCamera.ScreenPointToRay(Input.mousePosition), out hitInfo, Mathf.Infinity, selectionMask))
        {
            if (!EventSystem.current.IsPointerOverGameObject())
            {
                Transform target = hitInfo.transform;

                if (isAdding)
                {
                    AddTarget(target);
                }
                else if (isRemoving)
                {
                    RemoveTarget(target);
                }
                else if (!isAdding && !isRemoving)
                {
                    ClearAndAddTarget(target);
                }
            }
            else
            {
                ClearTargets();
            }
        }
        else
        {
            if (!isAdding && !isRemoving)
            {
                ClearTargets();
            }
        }
    }
}