public void RegisterMWB_Object(MWB_Object mwb_object)
    {
        m_objectList.AddToObjectList(mwb_object);

        // give the registering mwbObject its transform name
        mwb_object.hierachyName = TransformNameUtility.GetTransformPathName(transform, mwb_object.transform);

        mwb_object.Init();
    }
    static void mouseEvent(SceneView sceneView)
    {
        Event curr = Event.current;

        if (!curr.isMouse)
        {
            return;
        }

        Camera camera = sceneView.camera;

        s_MouseCurrentPosition   = curr.mousePosition;
        s_MouseCurrentPosition.y = camera.pixelHeight - s_MouseCurrentPosition.y;

        // Mouse Down
        if (curr.type == EventType.MouseDown)
        {
            switch (curr.button)
            {
            case 0:
            {
                if (s_IsLeftMouseDragging == false)
                {
                    s_IsLeftMouseDragging = true;
                    s_MouseStartPosition  = s_MouseCurrentPosition;
                }
            }
            break;

            case 1:
                break;
            }
        }

        // Drag
        if (curr.type == EventType.MouseDrag)
        {
            switch (curr.button)
            {
            case 0:
            {
                if (s_IsLeftMouseDragging == false)
                {
                    s_IsLeftMouseDragging = true;
                    s_MouseStartPosition  = s_MouseCurrentPosition;
                }
            }
            break;
            }
        }

        // Mouse Up
        if (curr.type == EventType.MouseUp)
        {
            switch (curr.button)
            {
            case 0:
            {
                if (s_IsLeftMouseDragging)
                {
                    var endPos   = s_MouseCurrentPosition;
                    var startPos = s_MouseStartPosition;

                    if ((endPos - startPos).sqrMagnitude < c_MousePointSelectionThreshold)
                    {
                        // first check if selecting object?
                        bool       isSelectingObj = false;
                        Ray        ray            = HandleUtility.GUIPointToWorldRay(curr.mousePosition);
                        RaycastHit hit;
                        if (Physics.Raycast(ray, out hit))
                        {
                            GameObject hitObj = hit.collider.gameObject;
                            MWB_Object mwbObj = hitObj.GetComponent <MWB_Object>();
                            if (mwbObj)
                            {
                                int index = s_SimulatedObjects.MWB_Objects.FindIndex(obj => obj == mwbObj);
                                if (index >= 0)
                                {
                                    selectObject(index);
                                    isSelectingObj = true;
                                }
                            }
                        }

                        if (!isSelectingObj)
                        {
                            //Debug.Log("Point Selection");
                            s_SelectionQuery.PositivePointSelection((startPos + endPos) / 2);
                        }
                    }
                    else
                    {
                        //Debug.Log("Quad Selection");
                        s_SelectionQuery.PositiveQuadSelection(startPos, endPos);
                    }
                }

                s_IsLeftMouseDragging = false;
            }
            break;

            case 1:
            {
                s_IsLeftMouseDragging = false;
                //s_SelectionQuery.DeselectAll();
            }
            break;
            }
        }
    }
Exemple #3
0
 public void AddToObjectList(MWB_Object mwbObject)
 {
     MWB_Objects.Add(mwbObject);
 }