Пример #1
0
        protected override void OnSceneGUI()
        {
            // Bounds
            if (CurvyGlobalManager.Gizmos.HasFlag(CurvySplineGizmos.Bounds))
            {
                DTHandles.PushHandlesColor(new Color(0.3f, 0, 0));
                DTHandles.WireCubeCap(Target.Bounds.center, Target.Bounds.size);
                DTHandles.PopHandlesColor();
            }
            Handles.BeginGUI();

            mUserValuesLabel = new GUIStyle(EditorStyles.boldLabel);
            mUserValuesLabel.normal.textColor = Color.green;


            if (CurvyGlobalManager.Gizmos.HasFlag(CurvySplineGizmos.Labels))
            {
                GUIStyle stLabel = new GUIStyle(EditorStyles.boldLabel);
                stLabel.normal.textColor = Color.white;
                Handles.Label(Target.transform.position - new Vector3(-0.5f, 0.2f, 0), Target.name, stLabel);
                stLabel.normal.textColor = Color.red;
                foreach (CurvySplineSegment cp in Target.ControlPoints)
                {
                    Handles.Label(cp.transform.position + new Vector3(-0.5f, HandleUtility.GetHandleSize(cp.transform.position) * 0.35f, 0), cp.name, stLabel);
                }
            }

            Handles.EndGUI();
            // Snap Transform
            if (Target && DT._UseSnapValuePrecision)
            {
                Target.transform.localPosition    = DTMath.SnapPrecision(Target.transform.localPosition, 3);
                Target.transform.localEulerAngles = DTMath.SnapPrecision(Target.transform.localEulerAngles, 3);
            }
        }
Пример #2
0
        public static void SceneGUIPoly(IEnumerable <Vector3> vertices, Color col)
        {
            DTHandles.PushHandlesColor(col);

            Handles.DrawPolyLine(vertices as Vector3[]);
            DTHandles.PopHandlesColor();
        }
Пример #3
0
        void itemGUI(Rect rect, int index, bool isActive, bool isFocused)
        {
            var item = sorted[index];
            var r    = getRects(rect);

            if (item.gameObject == Selection.activeGameObject)
            {
                DTHandles.DrawSolidRectangleWithOutline(rect.ScaleBy(4, 2), new Color(0, 0, 0.2f, 0.1f), new Color(.24f, .37f, .59f));
            }
            else if (index > 0)
            {
                DTHandles.PushHandlesColor(new Color(0.1f, 0.1f, 0.1f));
                Handles.DrawLine(new Vector2(rect.xMin - 5, rect.yMin), new Vector2(rect.xMax + 4, rect.yMin));
                DTHandles.PopHandlesColor();
            }

            bool repaint = false;
            var  cnt     = new GUIContent(item.ToString(), "Click to select");

            r[0].width = DTStyles.HtmlLinkLabel.CalcSize(cnt).x;
            if (DTGUI.LinkButton(r[0], cnt, ref repaint))// EditorStyles.label))
            {
                DTSelection.SetGameObjects(sorted[index]);
            }
            if (repaint)
            {
                Repaint();
            }

            item.ConnectionSyncPosition = GUI.Toggle(r[1], item.ConnectionSyncPosition, "");
            item.ConnectionSyncRotation = GUI.Toggle(r[8], item.ConnectionSyncRotation, "");
            if (GUI.Button(r[2], new GUIContent(CurvyStyles.DeleteSmallTexture, "Delete"), CurvyStyles.ImageButton))
            {
                item.Disconnect();
                CurvyProject.Instance.ScanConnections();
                GUIUtility.ExitGUI();
            }
            if (item.CanHaveFollowUp)
            {
                GUI.Label(r[3], "Head to");
                doFollowUpPopup(r[4], item);
                bool b = item.FollowUpHeading == ConnectionHeadingEnum.Minus;
                if (GUI.Toggle(r[5], b, new GUIContent("", "Head to spline start")) != b)
                {
                    item.FollowUpHeading = (!b) ? ConnectionHeadingEnum.Minus : ConnectionHeadingEnum.Auto;
                }
                b = item.FollowUpHeading == ConnectionHeadingEnum.Sharp;
                if (GUI.Toggle(r[6], b, new GUIContent("", "No Heading")) != b)
                {
                    item.FollowUpHeading = (!b) ? ConnectionHeadingEnum.Sharp : ConnectionHeadingEnum.Auto;
                }
                b = item.FollowUpHeading == ConnectionHeadingEnum.Plus;
                if (GUI.Toggle(r[7], b, new GUIContent("", "Head to spline end")) != b)
                {
                    item.FollowUpHeading = (!b) ? ConnectionHeadingEnum.Plus : ConnectionHeadingEnum.Auto;
                }
            }
        }
Пример #4
0
 public static void SceneGUIPlot(IList <Vector3> vertices, float size, Color col)
 {
     DTHandles.PushHandlesColor(col);
     foreach (var v in vertices)
     {
         Handles.CubeCap(0, v, Quaternion.identity, size * HandleUtility.GetHandleSize(v));
     }
     DTHandles.PopHandlesColor();
 }
Пример #5
0
        public static void SceneGUIPlot(IList <Vector3> vertices, float size, Color col)
        {
            DTHandles.PushHandlesColor(col);
            foreach (var v in vertices)
#if UNITY_5_6_OR_NEWER
            { Handles.CubeHandleCap(0, v, Quaternion.identity, size * HandleUtility.GetHandleSize(v), EventType.Repaint); }
#else
            { Handles.CubeCap(0, v, Quaternion.identity, size * HandleUtility.GetHandleSize(v)); }
#endif
            DTHandles.PopHandlesColor();
        }
Пример #6
0
        void drawSlot(Rect rect, int index, bool isActive, bool isFocused)
        {
            var  slot = Target.Splines[index];
            Rect r    = new Rect(rect);

            r.height       = 19;
            r.width        = rect.width - 60;
            r.y           += 2;
            slot.Spline    = EditorGUI.ObjectField(r, slot.Spline, typeof(CurvySplineBase), true) as CurvySplineBase;
            r.x           += r.width + 2;
            r.width        = 50;
            slot.LineColor = EditorGUI.ColorField(r, slot.LineColor);

            // Separator
            if (index > 0)
            {
                DTHandles.PushHandlesColor(new Color(0.1f, 0.1f, 0.1f));
                Handles.DrawLine(new Vector2(rect.xMin - 5, rect.yMin), new Vector2(rect.xMax + 4, rect.yMin));
                DTHandles.PopHandlesColor();
            }
        }
Пример #7
0
        public override void OnModuleSceneDebugGUI()
        {
            base.OnModuleSceneDebugGUI();
            CGVolume vol = Target.InData.GetData <CGVolume>();

            if (vol)
            {
                Handles.matrix = Target.Generator.transform.localToWorldMatrix;

                if (Target.ShowPathSamples)
                {
                    CGEditorUtility.SceneGUIPlot(vol.Position, 0.1f, Target.PathColor);
                    if (Target.ShowIndex)
                    {
                        var labels = Enumerable.Range(0, vol.Count).Select(i => i.ToString()).ToArray <string>();
                        CGEditorUtility.SceneGUILabels(vol.Position, labels, Color.black, Vector2.zero);
                    }
                }
                if (Target.ShowCrossSamples)
                {
                    int vtLo = Target.LimitCross.From * vol.CrossSize;
                    int vtHi = vtLo + vol.CrossSize;
                    if (!Target.LimitCross.SimpleValue)
                    {
                        vtLo = Target.LimitCross.Low * vol.CrossSize;
                        vtHi = (Target.LimitCross.High + 1) * vol.CrossSize;
                    }

                    vtLo = Mathf.Clamp(vtLo, 0, vol.VertexCount);
                    vtHi = Mathf.Clamp(vtHi, vtLo, vol.VertexCount);
                    var range = vol.Vertex.SubArray <Vector3>(vtLo, vtHi - vtLo);
                    CGEditorUtility.SceneGUIPlot(range, 0.1f, Color.white);

                    if (Target.ShowIndex)
                    {
                        var labels = Enumerable.Range(vtLo, vtHi).Select(i => i.ToString()).ToArray <string>();
                        CGEditorUtility.SceneGUILabels(range, labels, Color.black, Vector2.zero);
                    }

                    if (Target.ShowMap)
                    {
                        var labels = Enumerable.Range(vtLo, vtHi).Select(i => DTMath.SnapPrecision(vol.CrossMap[i], 3).ToString()).ToArray <string>();
                        CGEditorUtility.SceneGUILabels(range, labels, new Color(1, 0, 1), new Vector2(10, 20));
                    }

                    if (Target.ShowNormals)
                    {
                        DTHandles.PushHandlesColor(Target.NormalColor);

                        for (int i = vtLo; i < vtHi; i++)
                        {
                            Handles.DrawLine(vol.Vertex[i], vol.Vertex[i] + vol.VertexNormal[i] * 2);
                        }

                        DTHandles.PopHandlesColor();
                    }
                }
                if (Target.Interpolate)
                {
                    Vector3 pos;
                    Vector3 tan;
                    Vector3 up;
                    vol.InterpolateVolume(Target.InterpolatePathF, Target.InterpolateCrossF, out pos, out tan, out up);
                    Handles.ConeCap(0, pos, Quaternion.LookRotation(up, tan), 1f);
                }
                Handles.matrix = Matrix4x4.identity;
            }
        }
        protected override void OnSceneGUI()
        {
            // Bounds
            if (CurvyGlobalManager.Gizmos.HasFlag(CurvySplineGizmos.Bounds))
            {
                DTHandles.PushHandlesColor(Color.gray);
                DTHandles.WireCubeCap(Target.Bounds.center, Target.Bounds.size);
                DTHandles.PopHandlesColor();
            }
            checkHotkeys();
            if (Target.Spline.RestrictTo2D && Tools.current == Tool.Move && !SceneView.currentDrawingSceneView.in2DMode)
            {
                Tools.hidden = true;
                Vector3 handlePos = (Tools.handlePosition != Target.transform.position) ? DTSelection.GetPosition() : Tools.handlePosition;
                Vector3 delta;
                EditorGUI.BeginChangeCheck();


                if (CurvyProject.Instance.UseTiny2DHandles)
                {
                    delta = DTHandles.TinyHandle2D(GUIUtility.GetControlID(GetHashCode(), FocusType.Passive), handlePos, Target.Spline.transform.rotation, 1) - handlePos;
                }
                else
                {
                    delta = DTHandles.PositionHandle2D(GUIUtility.GetControlID(GetHashCode(), FocusType.Passive), handlePos, Target.Spline.transform.rotation, 1) - handlePos;
                }

                if (EditorGUI.EndChangeCheck())
                {
                    foreach (var t in Selection.transforms)
                    {
                        Undo.ClearUndo(t);
                        Undo.RecordObject(t, "Move");
                        t.position += delta;
                    }
                }
            }
            else
            {
                Tools.hidden = false;
            }


            // Bezier-Handles
            if (Target.Spline.Interpolation == CurvyInterpolation.Bezier && !Target.AutoHandles)
            {
                #region --- Bezier Rotation Handling ---
                if (Tools.current == Tool.Rotate)
                {
                    Event e = Event.current;
                    if (e.shift && DTHandles.MouseOverSceneView)
                    {
                        Tools.hidden = true;
                        DTToolbarItem._StatusBar.Set("BezierRotate");
                        // This looks good, but then diff down below isn't working like intended:
                        //mBezierRot = Quaternion.LookRotation(Vector3.Cross(Target.HandleIn, Target.GetOrientationUpFast(0)), Target.GetOrientationUpFast(0));
                        Quaternion newRot = Handles.RotationHandle(mBezierRot, Target.transform.position);
                        if (newRot != mBezierRot)
                        {
                            Quaternion diff = Quaternion.Inverse(mBezierRot) * newRot;
                            mBezierRot = newRot;
                            var mode = CurvyProject.Instance.BezierMode | CurvyBezierModeEnum.Direction;
                            Undo.RecordObject(Target, "Rotate Handles");
                            Target.SetBezierHandleIn(diff * Target.HandleIn, Space.Self, mode);
                            Target.SetDirty();
                            EditorUtility.SetDirty(Target);
                        }
                    }
                    else
                    {
                        DTToolbarItem._StatusBar.Set("Hold <b>[Shift]</b> to rotate Handles", "BezierRotate");
                        Tools.hidden = false;
                    }
                }
                else
                {
                    DTToolbarItem._StatusBar.Set("BezierRotate");
                }
                #endregion

                #region --- Bezier Movement Handling ---
                //Belongs to Constraint Length:
                //Vector3 handleOut = Target.HandleOutPosition;
                //Vector3 handleIn = Target.HandleInPosition;

                EditorGUI.BeginChangeCheck();
                Vector3 pOut;
                Vector3 pIn;
                bool    chgOut = false;
                bool    chgIn  = false;
                if (Target.Spline.RestrictTo2D)
                {
                    Quaternion r = (Tools.pivotRotation == PivotRotation.Global) ? Target.Spline.transform.localRotation : Target.Spline.transform.rotation;
                    Handles.color = Color.yellow;
                    pIn           = Target.HandleInPosition;
                    pIn           = DTHandles.TinyHandle2D(GUIUtility.GetControlID(FocusType.Passive), pIn, r, CurvyGlobalManager.GizmoControlPointSize * 0.7f, Handles.CubeCap);
                    if (!CurvyProject.Instance.UseTiny2DHandles)
                    {
                        pIn = DTHandles.PositionHandle2D(GUIUtility.GetControlID(FocusType.Passive), pIn, r, 1);
                    }
                    chgIn         = Target.HandleInPosition != pIn;
                    Handles.color = Color.green;
                    pOut          = Target.HandleOutPosition;
                    pOut          = DTHandles.TinyHandle2D(GUIUtility.GetControlID(FocusType.Passive), pOut, r, CurvyGlobalManager.GizmoControlPointSize * 0.7f, Handles.CubeCap);
                    if (!CurvyProject.Instance.UseTiny2DHandles)
                    {
                        pOut = DTHandles.PositionHandle2D(GUIUtility.GetControlID(FocusType.Passive), pOut, r, 1);
                    }

                    chgOut = Target.HandleOutPosition != pOut;
                }
                else
                {
                    pIn   = Handles.PositionHandle(Target.HandleInPosition, Tools.handleRotation);
                    chgIn = Target.HandleInPosition != pIn;
                    DTHandles.PushHandlesColor(Color.yellow);
                    Handles.CubeCap(0, pIn, Quaternion.identity, HandleUtility.GetHandleSize(pIn) * CurvyGlobalManager.GizmoControlPointSize * 0.7f);
                    DTHandles.PopHandlesColor();
                    pOut   = Handles.PositionHandle(Target.HandleOutPosition, Tools.handleRotation);
                    chgOut = Target.HandleOutPosition != pOut;
                    DTHandles.PushHandlesColor(Color.green);
                    Handles.CubeCap(0, pOut, Quaternion.identity, HandleUtility.GetHandleSize(pOut) * CurvyGlobalManager.GizmoControlPointSize * 0.7f);
                    DTHandles.PopHandlesColor();
                }

                Handles.color = Color.yellow;
                Handles.DrawLine(pIn, Target.transform.position);
                Handles.color = Color.green;
                Handles.DrawLine(pOut, Target.transform.position);


                if (chgOut || chgIn)
                {
                    Undo.RecordObject(Target, "Move Handle");
                    if (chgOut)
                    {
                        Target.SetBezierHandleOut(pOut, Space.World, CurvyProject.Instance.BezierMode);
                        Target.HandleOut = DTMath.SnapPrecision(Target.HandleOut, 3);
                    }
                    else
                    {
                        Target.SetBezierHandleIn(pIn, Space.World, CurvyProject.Instance.BezierMode);
                        Target.HandleIn = DTMath.SnapPrecision(Target.HandleIn, 3);
                    }
                }

                if (EditorGUI.EndChangeCheck())
                {
                    EditorUtility.SetDirty(Target);
                    Target.SetDirty();

                    /*
                     * var lcons = CurvyProject.Instance.FindItem<TBCPLengthConstraint>();
                     * if (lcons.On && Target.Spline.Length > lcons.MaxSplineLength)
                     * {
                     *  Target.HandleOutPosition = handleOut;
                     *  Target.HandleInPosition = handleIn;
                     *  Target.SetDirty();
                     * }
                     */
                }
                #endregion
            }
            if (mConnectionEditor)
            {
                mConnectionEditor.OnSceneGUI();
            }
            // Snap Transform
            if (Target && DT._UseSnapValuePrecision)
            {
                Target.transform.localPosition    = DTMath.SnapPrecision(Target.transform.localPosition, 3);
                Target.transform.localEulerAngles = DTMath.SnapPrecision(Target.transform.localEulerAngles, 3);
                //Target.TTransform.FromTransform(Target.transform);
            }
        }