Esempio n. 1
0
    private void DrawHandler(Stretch st, ref bool elementClicked)
    {
        float buttonRadius = netDisplaySettings.handlerRadius;

        Handles.color = netDisplaySettings.handlerColor;

        if (selectedStretch == st)
        {
            MoveHandler(st, selectedControlPointSide, ref elementClicked);
        }
        else
        {
            if (Handles.Button(st.ControlA, Quaternion.identity, buttonRadius, buttonRadius, Handles.SphereHandleCap))
            {
                selectedStretch          = st;
                selectedControlPointSide = Stretch.CurveSide.A;
                selectedNode             = null;
                transformingNode         = false;
                elementClicked           = true;
            }
            if (Handles.Button(st.ControlB, Quaternion.identity, buttonRadius, buttonRadius, Handles.SphereHandleCap))
            {
                selectedStretch          = st;
                selectedControlPointSide = Stretch.CurveSide.B;
                selectedNode             = null;
                transformingNode         = false;
                elementClicked           = true;
            }
        }
    }
Esempio n. 2
0
    private void MoveHandler(Stretch st, Stretch.CurveSide side, ref bool elementClicked)
    {
        float buttonRadius = netDisplaySettings.handlerRadius;

        Handles.color = netDisplaySettings.handlerColor;

        Vector3    handlerInitialPos;
        Quaternion handlerRot = Quaternion.identity;
        Vector3    newPos;

        switch (side)
        {
        case Stretch.CurveSide.A:
            handlerInitialPos = st.ControlA;
            handlerRot        = Quaternion.LookRotation(Camera.current.transform.position - handlerInitialPos);
            EditorGUI.BeginChangeCheck();
            newPos = Handles.PositionHandle(handlerInitialPos, Quaternion.identity);
            if (EditorGUI.EndChangeCheck())
            {
                st.OnPathModified();
                Undo.RecordObject(creator, "Move ControlA");
                EditorUtility.SetDirty(creator);

                Vector3 oldPos = st.ControlA;
                st.ControlA = newPos;
                if (Event.current.shift)
                {
                    DoMirrorPairs(st, st.AnchorA, oldPos, newPos);
                }
            }
            if (Handles.Button(st.ControlB, Quaternion.identity, buttonRadius, buttonRadius, Handles.SphereHandleCap))
            {
                selectedControlPointSide = Stretch.CurveSide.B;
                selectedNode             = null;
                transformingNode         = false;
                elementClicked           = true;
            }
            break;

        case Stretch.CurveSide.B:
            handlerInitialPos = st.ControlB;
            handlerRot        = Quaternion.LookRotation(Camera.current.transform.position - handlerInitialPos);
            EditorGUI.BeginChangeCheck();
            newPos = Handles.PositionHandle(handlerInitialPos, Quaternion.identity);
            if (EditorGUI.EndChangeCheck())
            {
                st.OnPathModified();
                Undo.RecordObject(creator, "Move ControlB");
                EditorUtility.SetDirty(creator);

                Vector3 oldPos = st.ControlB;
                st.ControlB = newPos;
                if (Event.current.shift)
                {
                    DoMirrorPairs(st, st.AnchorB, oldPos, newPos);
                }
            }
            if (Handles.Button(st.ControlA, Quaternion.identity, buttonRadius, buttonRadius, Handles.SphereHandleCap))
            {
                selectedControlPointSide = Stretch.CurveSide.A;
                selectedNode             = null;
                transformingNode         = false;
                elementClicked           = true;
            }
            break;
        }

        Handles.DrawLine(st.ControlA, st.AnchorA.Pos);
        Handles.DrawLine(st.ControlB, st.AnchorB.Pos);
        SceneView.RepaintAll();
    }