Example #1
0
        private void Update()
        {
            if (Input.GetMouseButtonDown(0))
            {
                RaycastHit hit;
                Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                if (Physics.Raycast(ray, out hit, float.MaxValue, mask))
                {
                    spline.AddCurve(hit.point);

                    if (spline.IsThereAPath)
                    {
                        if (decorator != null)
                        {
                            decorator.DoUpdate();
                        }
                        if (splineString != null)
                        {
                            splineString.DoUpdate();
                        }
                        if (walker != null)
                        {
                            walker.DoUpdate();
                        }
                    }
                }
            }
        }
        private Vector3 ShowPoint(int index)
        {
            Vector3 point = handleTransform.TransformPoint(spline.GetControlPoint(index));
            float   size  = HandleUtility.GetHandleSize(point);

//			if (index == 0) {
//				size *= 2f;
//			}
            Handles.color = modeColors[(int)spline.GetControlPointMode(index)];

            if (Handles.Button(point, handleRotation, size * handleSize, size * pickSize, Handles.DotCap))
            {
                selectedIndex = index;
                Repaint();
            }
            if (selectedIndex == index)
            {
                EditorGUI.BeginChangeCheck();
                point = Handles.DoPositionHandle(point, handleRotation);
                if (EditorGUI.EndChangeCheck())
                {
                    Undo.RecordObject(spline, "Move Point");
                    EditorUtility.SetDirty(spline);

                    //TODO: Do what you need before change any point.
                    spline.DoBeforeSetControlPoint();
                    //Set the control point to a new position.
                    spline.SetControlPoint(index, handleTransform.InverseTransformPoint(point));
                    //TODO: Do what you need after change any point.
                    spline.DoAfterSetControlPoint();

                    //Updating spline string.
                    if (splineString != null)
                    {
                        splineString.DoUpdate();
                    }
                }
            }

            return(point);
        }