GetControlPointMode() public method

public GetControlPointMode ( int index ) : BezierControlPointMode
index int
return BezierControlPointMode
    private void DrawSelectedPointInspector()
    {
        EditorGUILayout.LabelField("", GUI.skin.horizontalSlider);

        GUILayout.Label("Selected Point N°" + selectedIndex);
        EditorGUI.BeginChangeCheck();
        Vector3 point = EditorGUILayout.Vector3Field("Position", spline.GetControlPoint(selectedIndex));

        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(spline, "Move Point");
            EditorUtility.SetDirty(spline);
            spline.SetControlPoint(selectedIndex, point);
        }
        EditorGUI.BeginChangeCheck();
        BezierControlPointMode mode = (BezierControlPointMode)EditorGUILayout.EnumPopup("Mode", spline.GetControlPointMode(selectedIndex));

        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(spline, "Change Point Mode");
            spline.SetControlPointMode(selectedIndex, mode);
            EditorUtility.SetDirty(spline);
        }
        GUILayout.Space(10);
        EditorGUILayout.LabelField("", GUI.skin.horizontalSlider);
    }
    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.DotHandleCap))
        {
            selectedIndex = index;
            Repaint();
        }

        if (selectedIndex == index)
        {
            EditorGUI.BeginChangeCheck();
            point = Handles.DoPositionHandle(point, handleRotation);


            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(spline, "Move Point");
                EditorUtility.SetDirty(spline);
                spline.SetControlPoint(index, handleTransform.InverseTransformPoint(point));
            }
        }


        return(point);
    }
    private void DrawSelectedPointInspector()
    {
        GUILayout.Label("Selected Point");
        EditorGUI.BeginChangeCheck();
        Vector3 point = EditorGUILayout.Vector3Field("Position", spline.GetControlPoint(selectedIndex));

        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(spline, "Move Point");
            spline.RecalculateSplineDistance();
            spline.SetControlPoint(selectedIndex, point);
            EditorUtility.SetDirty(spline);
        }
        EditorGUI.BeginChangeCheck();
        BezierControlPointMode mode = (BezierControlPointMode)
                                      EditorGUILayout.EnumPopup("Mode", spline.GetControlPointMode(selectedIndex));

        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(spline, "Change Point Mode");
            spline.SetControlPointMode(selectedIndex, mode);
            EditorUtility.SetDirty(spline);
        }
        if (selectedIndex % 3 == 0 && spline.points.Length > 4)
        {
            if (GUILayout.Button("Delete Curve Point"))
            {
                Undo.RecordObject(spline, "Delete Curve Point");
                spline.DeleteCurve(selectedIndex);
                spline.RecalculateSplineDistance();
                selectedIndex = -1;
                EditorUtility.SetDirty(spline);
            }
        }
    }
    // Allow the points to be dragged individually.
    private Vector3 ShowPoint(int index)
    {
        Vector3 point = handleTransform.TransformPoint(spline.GetControlPoint(index));

        float size = HandleUtility.GetHandleSize(point); // Keep the handle size constant regardless of view.

        if (index == 0)
        {
            size *= 2f; // Make the first point larger than the rest.
        }
        Handles.color = modeColors[(int)spline.GetControlPointMode(index)];
        // Show Button Handles for each point.
        if (Handles.Button(point, handleRotation, size * handleSize, size * pickSize, Handles.DotCap))
        {
            selectedIndex = index;
            Repaint(); // Force the Inspector GUI to refresh.
        }
        // Show the Transform Handle for the selected point.
        if (selectedIndex == index)
        {
            EditorGUI.BeginChangeCheck();
            point = Handles.DoPositionHandle(point, handleRotation);
            if (EditorGUI.EndChangeCheck())
            {
                // Enable Undo for this action.
                Undo.RecordObject(spline, "Move Point");
                // Let Unity know that a change was made.
                EditorUtility.SetDirty(spline);
                // Update the spline's point position in localspace.
                spline.SetControlPoint(index, handleTransform.InverseTransformPoint(point));
            }
        }
        return(point);
    }
Exemplo n.º 5
0
    private Vector3 ShowPoint(int index)
    {
        Vector3 point = _handleTransform.TransformPoint(_spline.GetControlPoint(index));
        float   size  = HandleUtility.GetHandleSize(point);

        if (index == 0)
        {
            size *= 2f;
        }

        Handles.color = MODE_COLORS[(int)_spline.GetControlPointMode(index)];

        if (Handles.Button(point, _handleRotation, size * HANDLE_SIZE, size * PICK_SIZE, 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);
                _spline.SetControlPoint(index, _handleTransform.InverseTransformPoint(point));
            }
        }

        return(point);
    }
    private void DrawSelectedPointInspector()
    {
        GUILayout.Label("Selected Point");
        EditorGUI.BeginChangeCheck();
        Vector3 point = EditorGUILayout.Vector3Field("Position", spline.GetControlPoint(selectedIndex));

        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(spline, "Move Point");
            EditorUtility.SetDirty(spline);
            spline.SetControlPoint(selectedIndex, point);
        }

        /* Now BezierSplineInspector can allow us to change the mode of the selected point.
         * You will notice that changing the mode of one point also appears to change the mode of the points that are linked to it.
         */
        EditorGUI.BeginChangeCheck();
        BezierControlPointMode mode = (BezierControlPointMode)
                                      EditorGUILayout.EnumPopup("Mode", spline.GetControlPointMode(selectedIndex));

        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(spline, "Change Point Mode");
            spline.SetControlPointMode(selectedIndex, mode);
            EditorUtility.SetDirty(spline);
        }
    }
    // ---------
    // Functions
    // ---------


    // Used to draw a new inspector based on the selected spline control point
    private void DrawSelectedPointInspector()
    {
        GUILayout.Label("Selected Point");
        EditorGUI.BeginChangeCheck();
        Vector3 point = EditorGUILayout.Vector3Field("Position", spline.GetControlPoint(selectedIndex));

        // Draw our spline control points
        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(spline, "Move Point");
            EditorUtility.SetDirty(spline);
            spline.SetControlPoint(selectedIndex, point);
        }

        // Draw the mode per point
        EditorGUI.BeginChangeCheck();

        // This probably should be its own class.
        BezierSpline.BezierControlPointMode mode = (BezierSpline.BezierControlPointMode)
                                                   EditorGUILayout.EnumPopup("Mode", spline.GetControlPointMode(selectedIndex));

        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(spline, "Change Point Mode");
            spline.SetControlPointMode(selectedIndex, mode);
            EditorUtility.SetDirty(spline);
        }
    }
Exemplo n.º 8
0
    private Vector3 ShowPoint(int p)
    {
        Vector3 point = t.TransformPoint(spline.GetControlPoint(p));
        float   zoom  = 1f;

        /* If the handle is active, mark the index as currently selected for then, draw the Handle */
        Handles.color = modeColor[(int)spline.GetControlPointMode(p)];
        if (p == 0)
        {
            zoom *= 2f;
        }
        if (Handles.Button(point, q, handleSize * zoom, pickSize, Handles.DotCap))
        {
            selectedIndex = p;
        }
        // refresh point in inspector - such that it is updated on the GUI upon selection
        Repaint();
        if (selectedIndex == p)
        {
            EditorGUI.BeginChangeCheck();
            point = Handles.DoPositionHandle(point, q);
            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(spline, "Move Cubic Curve Point");
                EditorUtility.SetDirty(spline);
                spline.SetControlPoint(p, t.InverseTransformPoint(point));
            }
        }
        return(point);
    }
    private void DrawSelectedPointInspector()
    {
        GUILayout.Label("Selected point");

        EditorGUI.BeginChangeCheck();
        Vector3 point = EditorGUILayout.Vector3Field("Position", spline.GetControlPoint(selectedIndex));

        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(spline, "Move point");
            EditorUtility.SetDirty(spline);
            spline.SetControlPoint(selectedIndex, point);
        }

        EditorGUI.BeginChangeCheck();
        BezierControlPointMode mode = (BezierControlPointMode)
                                      EditorGUILayout.EnumPopup("Mode", spline.GetControlPointMode(selectedIndex));

        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(spline, "Move point");
            EditorUtility.SetDirty(spline);
            spline.SetControlPointMode(selectedIndex, mode);
        }
    }
Exemplo n.º 10
0
    private Vector3 ShowPoint(int pointIndex, bool pointIsAnchor)
    {
        Vector3 point = handleTransform.TransformPoint(mySpline.GetControlPoint(pointIndex));
        //Vector3 point = mySpline.GetControlPoint(pointIndex);

        float size = HandleUtility.GetHandleSize(point);

        if (pointIndex == 0)
        {
            size *= addPointCapScale;
        }
        Handles.color = modeColors[(int)mySpline.GetControlPointMode(pointIndex)];
        if (selectedIndex == pointIndex)
        {
            Handles.color = Color.magenta;
        }

        //Choose cap type
        if (pointIsAnchor)
        {
            Handles.SphereCap(pointIndex, point, handleRotation, size * sphereCapSize);
        }
        else
        {
            Handles.DotCap(pointIndex, point, handleRotation, size * dotCapSize);
        }

        return(point);
    }
Exemplo n.º 11
0
        // Draw the line, and record any changes performed via the GUI
        private Vector3 ShowPoint(int i)
        {
            Vector3 point = handleTransform.TransformPoint(spline.GetControlPoint(i));

            // Scale the points' cube size with screen size
            float screenSize = HandleUtility.GetHandleSize(point);

            Handles.color = modeColors[(int)spline.GetControlPointMode(i)];

            // Draw cube buttons on each point
            if (Handles.Button(point, handleRotation, screenSize * handleSize, screenSize * pickSize, Handles.DotHandleCap)) {
                selectedIndex = i;
            }

            // If we've selected the current point, then draw a Position Handle
            if (selectedIndex == i) {
                EditorGUI.BeginChangeCheck();
                point = Handles.DoPositionHandle(point, handleRotation);

                if (EditorGUI.EndChangeCheck()) {
                    Undo.RecordObject(spline, "Move Point");
                    EditorUtility.SetDirty(spline);

                    spline.SetControlPoint(i, handleTransform.InverseTransformPoint(point));
                }
            }

            return point;
        }
Exemplo n.º 12
0
    /// <summary>
    /// 改变控制点
    /// </summary>
    private void DrawSelectedPointInspector()
    {
        GUILayout.Label("Selected Point");

        //在Inspector面板上显示已选择点的信息
        EditorGUI.BeginChangeCheck();
        Vector3 point = EditorGUILayout.Vector3Field("Position", spline.GetControlPoint(selectIndex));

        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(spline, "Move Point");
            EditorUtility.SetDirty(spline);
            spline.SetControlPoint(selectIndex, point);
        }



        //改变已选择的点的模式
        EditorGUI.BeginChangeCheck();
        //inspector面板上显示Mode属性,可以弹出枚举选择菜单
        //这里可以实时获取当前选择的点的模式(传入点的索引,找出对应的模式索引下的模式)
        BezierControlPointMode mode = (BezierControlPointMode)EditorGUILayout.EnumPopup("Mode", spline.GetControlPointMode(selectIndex));

        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(spline, "Change Point Mode");
            spline.SetControlPointMode(selectIndex, mode);
            EditorUtility.SetDirty(spline);
        }
    }
Exemplo n.º 13
0
    //Returns position of the control point
    private Vector3 ShowPoint(int index)
    {
        //Position of spline's control point at index in array of control points
        Vector3 point = handleTransform.TransformPoint(spline.GetControlPoint(index));

        //Set the size of control point
        float size = HandleUtility.GetHandleSize(point);

        if (index == 0)
        {
            size *= 2f; //Increase size of first control point (useful when spline is looping)
        }

        //Change color based on controlmode (none, aligned, mirrored)
        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); //Show position tool at controlpoint
            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(spline, "Move Point");
                EditorUtility.SetDirty(spline);
                spline.SetControlPoint(index, handleTransform.InverseTransformPoint(point)); //Set controlpoint at new position
            }
        }
        return(point);
    }
Exemplo n.º 14
0
    private void OnSceneGUI()
    {
        spline = target as BezierSpline;
        t      = spline.transform;
        q      = Tools.pivotRotation == PivotRotation.Local ? t.rotation : Quaternion.identity;

        /* Draw a line for every pair of ponits */
        for (int i = 0; i < spline.Curves * 3; i += 3)
        {
            Vector3 pA = ShowPoint(i);
            Vector3 pB = ShowPoint(i + 1);
            Vector3 pC = ShowPoint(i + 2);
            Vector3 pD = ShowPoint(i + 3);

            /* Draw control points lines */
            Handles.color = modeColor[(int)spline.GetControlPointMode(i)];
            Handles.DrawLine(pA, pB);
            Handles.color = modeColor[(int)spline.GetControlPointMode(i + 2)];
            Handles.DrawLine(pC, pD);
        }

        Vector3 lineStart = spline.GetPoint(0f);

        Handles.color = Color.green;
        Handles.DrawLine(lineStart, lineStart + spline.GetDirection(0f, 0) * directionVectorsScale);

        for (int j = 0; j < spline.Curves; ++j)
        {
            for (int i = 1; i <= steps; i++)
            {
                float   normalizedStep = i / (float)steps;
                Vector3 lineEnd        = spline.GetPoint(normalizedStep, j);

                /* Draw curve */
                Handles.color = Color.white;
                Handles.DrawLine(lineStart, lineEnd);

                /* Draw Direction */
                Handles.color = Color.green;
                Handles.DrawLine(lineEnd, lineEnd + spline.GetDirection(normalizedStep, j) * directionVectorsScale);

                lineStart = lineEnd;
            }
        }
    }
Exemplo n.º 15
0
        /// <summary>
        /// Draws the inspector for the selected point
        /// </summary>
        private void DrawSelectedPointEditor()
        {
            GUILayout.Label("Selected Point (" + selectedIndex + ")", EditorStyles.boldLabel);

            // Position
            EditorGUI.BeginChangeCheck();
            Vector3 _point = EditorGUILayout.Vector3Field("Position", spline[selectedIndex]);

            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(spline, "Move Point");
                EditorUtility.SetDirty(spline);

                spline[selectedIndex] = _point;
                Undo.FlushUndoRecordObjects();
            }

            // ControlPointMode
            EditorGUI.BeginChangeCheck();
            BezierControlPointMode _mode = (BezierControlPointMode)EditorGUILayout.EnumPopup(
                "Mode", spline.GetControlPointMode(selectedIndex)
                );

            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(spline, "Control Point Mode change");
                EditorUtility.SetDirty(spline);

                spline.SetControlPointMode(selectedIndex, _mode);
                Undo.FlushUndoRecordObjects();
            }

            // Remove button
            if (GUILayout.Button("Remove point"))
            {
                Undo.RecordObject(spline, "Removed curve");
                EditorUtility.SetDirty(spline);

                spline.RemoveCurve(selectedIndex);
                Undo.FlushUndoRecordObjects();
            }
        }
    Vector3 ShowPoint(int idx)
    {
        // convert to world space since handles are in local space
        Vector3 point = _splineT.TransformPoint(_spline.GetControlPoint(idx));

        Handles.color = Color.white;
        float size = HandleUtility.GetHandleSize(point);

        if (idx == 0)
        {
            size *= 2f;
        }

        Handles.color = modeColors[(int)_spline.GetControlPointMode(idx)];

        // If this point is selected
        if (Handles.Button(point, _splineR, size * HANDLE_SIZE, size * PICK_SIZE, Handles.DotCap))
        {
            _selectedIndex = idx;
            Repaint();
        }

        // If point is selected and position is changed
        if (_selectedIndex == idx)
        {
            EditorGUI.BeginChangeCheck();
            point = Handles.DoPositionHandle(point, _splineR);
            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(_spline, "Move Point");
                EditorUtility.SetDirty(_spline);
                // convert back to local space
                _spline.SetControlPoint(idx, _splineT.InverseTransformPoint(point));
            }
        }

        return(point);
    }
Exemplo n.º 17
0
        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);

            if (e.Button == MouseButtons.Right)
            {
                SelectedTransform = GetSpline.TryGetTransformFromPosition(new Vector2(e.X, e.Y));
                if (SelectedTransform != null && !SelectedTransform.IsCenterSpline)
                {
                    BezierSpline.BezierControlPointMode nextMode = MySpline.GetControlPointMode(SelectedTransform.Index).Next();
                    MySpline.SetControlPointMode(SelectedTransform.Index, nextMode);
                }
            }
        }
Exemplo n.º 18
0
    // ######################## UNITY EVENT FUNCTIONS ######################## //
    protected override void OnSceneGUI()
    {
        base.OnSceneGUI();
        _spline = target as BezierSpline;

        // draw the spline
        Vector3 p0 = ShowPoint(0, MODE_COLORS[(int)_spline.GetControlPointMode(0)]);

        for (int i = 1; i < _spline.ControlPointCount; i += 3)
        {
            Vector3 p1 = ShowPoint(i, MODE_COLORS[(int)_spline.GetControlPointMode(i)]);
            Vector3 p2 = ShowPoint(i + 1, MODE_COLORS[(int)_spline.GetControlPointMode(i + 1)]);
            Vector3 p3 = ShowPoint(i + 2, MODE_COLORS[(int)_spline.GetControlPointMode(i + 2)]);

            Handles.color = Color.gray;
            Handles.DrawLine(p0, p1);
            Handles.DrawLine(p2, p3);

            Handles.DrawBezier(p0, p3, p1, p2, Color.white, null, 2f);
            p0 = p3;
        }

        ShowDirections();
    }
Exemplo n.º 19
0
    protected virtual void DrawSelectedPointInspector()
    {
        GUILayout.Label("Selected Point");
        EditorGUI.BeginChangeCheck();
        Vector3 point = EditorGUILayout.Vector3Field("Position", _spline.GetControlPoint(_selectedIndex));

        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(_spline, "Move Point");
            EditorUtility.SetDirty(_spline);
            _spline.SetControlPoint(_selectedIndex, point);
        }

        EditorGUI.BeginChangeCheck();
        BezierControlPointMode mode = (BezierControlPointMode)EditorGUILayout.EnumPopup("Mode", _spline.GetControlPointMode(_selectedIndex));

        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(_spline, "Change Point Mode");
            _spline.SetControlPointMode(_selectedIndex, mode);
            EditorUtility.SetDirty(_spline);
        }

        // Draw Node Data if ADV SPLINE
        // Would be in AdvSplineInspector, except AdvSpline is generic meaning
        // we can't use the CustomEditor attribute and force child types to use its inspector
        // which means either this is here or every AdvSpline child needs an associated TypeInspector script
        if (_selectedIndex % 3 == 0)
        {
            int advNodeIndex                = _selectedIndex / 3;
            SerializedObject   so           = serializedObject;
            SerializedProperty nodeDataProp = so.FindProperty(string.Format("{0}.Array.data[{1}]", "_nodeData", advNodeIndex));
            if (nodeDataProp != null)
            {
                EditorGUI.BeginChangeCheck();

                EditorGUILayout.PropertyField(nodeDataProp, new GUIContent("Node Data"), true);

                if (EditorGUI.EndChangeCheck())
                {
                    so.ApplyModifiedProperties();
                }
            }
        }
    }
Exemplo n.º 20
0
    // ######################## FUNCTIONALITY ######################## //
    /// <summary>
    /// Draws the Properties of the selected point
    /// </summary>
    protected override void DrawSelectedPointInspector()
    {
        base.DrawSelectedPointInspector();

        EditorGUI.BeginChangeCheck();
        Bezier.BezierControlPointMode mode = (Bezier.BezierControlPointMode)
                                             EditorGUILayout.EnumPopup("Mode", _spline.GetControlPointMode(SelectedIndex));
        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(_spline, "Change Point Mode");
            _spline.SetControlPointMode(SelectedIndex, mode);
            EditorUtility.SetDirty(_spline);
            if (AutoPresampleInEditMode)
            {
                _spline.Presample();
            }
        }
    }
Exemplo n.º 21
0
    private void DrawSelectedPointInspector()
    {
        string displayText = "Selected Point (index " + selectedIndex;

        if ((selectedIndex % 3) != 0)
        {
            displayText += " cp";
        }
        displayText += ")";

        GUILayout.Label(displayText);
        EditorGUI.BeginChangeCheck();
        Vector3 point = EditorGUILayout.Vector3Field("Position", spline.GetControlPoint(selectedIndex));

        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(spline, "Move Point");
            EditorUtility.SetDirty(spline);
            spline.SetControlPoint(selectedIndex, point);
        }
        EditorGUI.BeginChangeCheck();
        BezierControlPointMode mode = (BezierControlPointMode)EditorGUILayout.EnumPopup("Mode", spline.GetControlPointMode(selectedIndex));

        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(spline, "Change Point Mode");
            spline.SetControlPointMode(selectedIndex, mode);
            EditorUtility.SetDirty(spline);
        }
    }
    private void DrawSelectedPointInspector()
    {
        GUILayout.BeginVertical("box");
        GUILayout.Label("Selected Point: " + selectedIndex);
        GUILayout.Space(5);

        EditorGUI.BeginChangeCheck();
        Vector3 point = EditorGUILayout.Vector3Field("Position", spline.GetControlPoint(selectedIndex));

        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(spline, "Move Point");
            EditorUtility.SetDirty(spline);
            spline.SetControlPoint(selectedIndex, point);
        }
        GUILayout.Space(5);

        EditorGUI.BeginChangeCheck();
        BezierControlPointMode mode = (BezierControlPointMode)
                                      EditorGUILayout.EnumPopup("Mode", spline.GetControlPointMode(selectedIndex));

        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(spline, "Change Point Mode");
            spline.SetControlPointMode(selectedIndex, mode);
            EditorUtility.SetDirty(spline);
        }

        GUILayout.Space(5);

        EditorGUI.BeginChangeCheck();
        float zRotation = EditorGUILayout.FloatField("Z Rotation At Point", spline.zRotationAtPoint[(selectedIndex + 1) / 3]);

        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(spline, "Variable change");
            int index = (selectedIndex + 1) / 3;
            EditorUtility.SetDirty(spline);
            spline.zRotationAtPoint[index] = zRotation;

            if (spline.Loop && (index == spline.zRotationAtPoint.Length - 1 || index == 0))
            {
                spline.zRotationAtPoint[index] = spline.zRotationAtPoint[0] = zRotation;
            }
        }
        GUILayout.Space(5);

        EditorGUI.BeginChangeCheck();
        Vector3 scale = EditorGUILayout.Vector3Field("Scale Factor", spline.scaleFactor3d[(selectedIndex + 1) / 3]);

        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(spline, "Variable change");
            int index = (selectedIndex + 1) / 3;
            EditorUtility.SetDirty(spline);
            spline.scaleFactor3d[index] = scale;

            if (spline.Loop && (index == spline.zRotationAtPoint.Length - 1 || index == 0))
            {
                spline.scaleFactor3d[index] = spline.scaleFactor3d[0] = scale;
            }
        }


        GUILayout.Space(5);
        GUILayout.EndVertical();
    }
Exemplo n.º 23
0
    private void DiscreteDecoration()
    {
        if (transform.childCount == 0)
        {
            decorationList = new List <Transform>();
            hookList       = new List <Transform>();
        }
        else if (decorationList == null || decorationList.Count != decorationFrequency || hookList.Count + decorationList.Count != transform.childCount)
        {
            while (transform.childCount != 0)
            {
                DestroyImmediate(transform.GetChild(0).gameObject);
                Debug.Log("Destrps");
            }
            decorationList = new List <Transform>();
            hookList       = new List <Transform>();
        }
        float stepSize       = 1.0f / (decorationFrequency + 3);
        bool  hasDecorations = decorationList != null && decorationList.Count > 0;
        int   d = 0;

        for (int f = 0; f < decorationFrequency + 2; f++)
        {
            if (f != 0 && f != decorationFrequency + 1)
            {
                float   t        = f * stepSize;
                Vector3 position = spline.GetPoint(t);
                if (hasDecorations)
                {
                    decorationList[d].position = position;
                    d++;
                }
                else
                {
                    Transform item = Instantiate(decoration) as Transform;
                    item.transform.localPosition = position;
                    item.transform.parent        = transform;
                    decorationList.Add(item);
                }
            }
        }


        int  ctrlPtCnt = spline.ControlPointCount; //
        bool hasHooks  = hookList != null && hookList.Count > 0;
        int  j         = 0;                        //index for existing hooks

        for (int i = 0; i < ctrlPtCnt; i++)
        {
            if (spline.GetControlPointMode(i) == BezierControlPointMode.Free)
            {
                if (i != 0)
                {
                    i++;                     //gets to middle free ctrl pt
                }
                Vector3 position = spline.GetPoint(i / ((ctrlPtCnt - 1) * 1.0f));
                if (hasHooks)
                {
                    hookList[j].position = position;
                    j++;
                }
                else
                {
                    Transform item = Instantiate(hook) as Transform;
                    hookList.Add(item);
                    item.transform.localPosition = position;
                    item.transform.parent        = transform;
                }
                i++;                 //skips right hand free ctrl pt
            }
        }
    }
Exemplo n.º 24
0
        private void SectionDrawSelectedPoint()
        {
            if (selectedIndex >= 0 && selectedIndex < spline.ControlPointCount)
            {
                Header("Selected Point");

                GUILayout.Label("Selected Point");
                EditorGUI.BeginChangeCheck();

                EditorGUILayout.BeginHorizontal();
                {
                    EditorGUILayout.BeginVertical();
                    {
                        GUILayout.Space(4);

                        pointBuffer = spline.GetControlPoint(selectedIndex) + spline.transform.position;
                        Vector3 point = isWorldSpace ? pointBuffer : spline.GetControlPoint(selectedIndex);
                        pointSelected = EditorGUILayout.Vector3Field("Position", point);

                        if (EditorGUI.EndChangeCheck())
                        {
                            Undo.RecordObject(spline, "Move Point");
                            EditorUtility.SetDirty(spline);
                            spline.SetControlPoint(selectedIndex, pointSelected);
                        }
                    }
                    EditorGUILayout.EndVertical();

                    if (GUILayout.Button(isWorldSpace ? "W" : "L", GUILayout.MaxHeight(BUTTONS_SIZE), GUILayout.MaxWidth(BUTTONS_SIZE)))
                    {
                        isWorldSpace = !isWorldSpace;
                    }

                    if (GUILayout.Button("C", GUILayout.MaxHeight(BUTTONS_SIZE), GUILayout.MaxWidth(BUTTONS_SIZE)))
                    {
                        string posSaved = string.Format("{0},{1},{2}", pointBuffer.x, pointBuffer.y, pointBuffer.z);
                        EditorGUIUtility.systemCopyBuffer = posSaved;
                        Debug.Log(EditorGUIUtility.systemCopyBuffer);
                    }

                    if (GUILayout.Button("P", GUILayout.MaxHeight(BUTTONS_SIZE), GUILayout.MaxWidth(BUTTONS_SIZE)))
                    {
                        Debug.Log(EditorGUIUtility.systemCopyBuffer);
                        Vector3 point = StringToVector3(EditorGUIUtility.systemCopyBuffer);
                        spline.SetControlPoint(selectedIndex, point - spline.transform.position);
                    }
                }
                EditorGUILayout.EndHorizontal();

                GUILayout.Space(4);
                EditorGUI.BeginChangeCheck();
                BezierControlPointMode mode = (BezierControlPointMode)EditorGUILayout.EnumPopup("Mode", spline.GetControlPointMode(selectedIndex));
                GUILayout.Space(4);

                if (EditorGUI.EndChangeCheck())
                {
                    Undo.RecordObject(spline, "Change Point Mode");
                    spline.SetControlPointMode(selectedIndex, mode);
                    EditorUtility.SetDirty(spline);
                }

                Footer();
            }
        }