Example #1
0
        private void AddCurvePoint()
        {
            linePoints = serializedObject.FindProperty("points");
            linePoints.InsertArrayElementAtIndex(linePoints.arraySize);

            CustomCurve.CurvePoint newCurvePoint = line.NewCurvePoint();

            SerializedProperty curvePoint = linePoints.GetArrayElementAtIndex(linePoints.arraySize - 1);

            curvePoint.FindPropertyRelative("curvePoint").vector3Value   = newCurvePoint.curvePoint;
            curvePoint.FindPropertyRelative("curveTangent").vector3Value = newCurvePoint.curveTangent;

            selectedIndex = linePoints.arraySize - 1;
        }
Example #2
0
        private void DrawAddButton(CustomCurve.CurvePoint curvePoint)
        {
            Handles.BeginGUI();

            //float size = HandleUtility.GetHandleSize(curvePoint.curvePoint + curvePoint.curveTangent.normalized);
            Vector3 screenPoint = Camera.current.WorldToScreenPoint(curvePoint.curvePoint + curvePoint.curveTangent * 0.5f);


            if (GUI.Button(new Rect(screenPoint.x - 10, Screen.height - screenPoint.y - 50, 20, 20), "+"))
            {
                AddCurvePoint();
            }

            Handles.EndGUI();
        }
Example #3
0
        private void OnSceneGUI()
        {
            // Disable selecting under mouse if we have a selected index.
            if (Event.current.type == EventType.Layout)
            {
                if (selectedIndex != -1)
                {
                    HandleUtility.AddDefaultControl(0);
                }
            }

            // Drop the selected index if mouse up over no handle.
            if (Event.current.type == EventType.MouseUp)
            {
                if (GUIUtility.hotControl == 0)
                {
                    selectedIndex = -1;
                }
            }

            serializedObject.Update();
            handleTransform = line.transform;

            Handles.color = Color.white;

            Tools.hidden = selectedIndex != -1;

            linePoints = serializedObject.FindProperty("points");

            CustomCurve.CurvePoint p0 = ShowPoint(0);
            for (int i = 1; i < line.points.Length; i += 1)
            {
                Handles.zTest = UnityEngine.Rendering.CompareFunction.Always;
                CustomCurve.CurvePoint p1 = ShowPoint(i);

                Handles.zTest = UnityEngine.Rendering.CompareFunction.LessEqual;
                Handles.DrawBezier(p0.curvePoint, p1.curvePoint, p0.curvePoint + p0.curveTangent, p1.curvePoint - p1.curveTangent, Color.white, null, curveLineWidth);

                Handles.zTest = UnityEngine.Rendering.CompareFunction.Greater;
                Handles.DrawBezier(p0.curvePoint, p1.curvePoint, p0.curvePoint + p0.curveTangent, p1.curvePoint - p1.curveTangent, Color.grey, null, curveLineWidth);

                Handles.zTest = UnityEngine.Rendering.CompareFunction.Always;

                if (i == linePoints.arraySize - 1)
                {
                    DrawAddButton(p1);
                }

                p0 = p1;
            }

            if (Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.Delete)
            {
                if (selectedIndex != -1)
                {
                    Event.current.Use();
                    DeleteSelectedCurvePoint();
                }
            }

            if (serializedObject.ApplyModifiedProperties() ||
                line.transform.hasChanged ||
                (Event.current.type == EventType.ValidateCommand && Event.current.commandName == "UndoRedoPerformed"))
            {
                line.CurveModified();
                line.transform.hasChanged = false;
            }

            DrawRuler();
            //ShowDirections();
        }