コード例 #1
0
        public void SelectControlPoint(Camera camera, Vector2 point)
        {
            if (m_selectionComponentState == null)
            {
                return;
            }

            if (m_selectionComponentState.Component.IsPositionHandleEnabled)
            {
                BaseSpline spline = m_controlPointPicker.Selection != null?m_controlPointPicker.Selection.GetSpline() : null;

                if (spline != null && !(spline is Deformer))
                {
                    return;
                }

                m_editor.Undo.BeginRecord();
                PickResult oldSelection = m_controlPointPicker.Selection != null ? new PickResult(m_controlPointPicker.Selection) : null;
                PickResult newSelection = m_controlPointPicker.Pick(camera, point);
                if (newSelection != null && newSelection.Spline != null && newSelection.Spline.GetComponent <Deformer>() == null)
                {
                    newSelection = null;
                }

                GameObject deformerGo = null;
                if (newSelection == null)
                {
                    RaycastHit hit;
                    if (Physics.Raycast(camera.ScreenPointToRay(point), out hit))
                    {
                        Segment segment = hit.collider.GetComponent <Segment>();
                        if (segment != null)
                        {
                            Deformer deformer = segment.GetComponentInParent <Deformer>();
                            if (deformer != null)
                            {
                                deformerGo = deformer.gameObject;
                            }
                        }
                    }
                }

                if (deformerGo != null)
                {
                    m_editor.Selection.Select(deformerGo, new[] { deformerGo });
                }

                m_controlPointPicker.ApplySelection(newSelection, true);
                newSelection = newSelection != null ? new PickResult(newSelection) : null;
                m_editor.Undo.CreateRecord(record =>
                {
                    m_controlPointPicker.Selection = newSelection;
                    if (deformerGo != null)
                    {
                        m_editor.Selection.Select(deformerGo, new[] { deformerGo });
                    }
                    return(true);
                },
                                           record =>
                {
                    m_controlPointPicker.Selection = oldSelection;
                    if (deformerGo != null)
                    {
                        m_editor.Selection.Select(deformerGo, new[] { deformerGo });
                    }
                    return(true);
                });
                m_editor.Undo.EndRecord();
            }
        }