Example #1
0
        public static void DrawSphere(VFXGizmo gizmo, TSphere sphere, IProperty <Vector3> centerProperty, IProperty <Vector3> anglesProperty, IProperty <Vector3> scaleProperty, IProperty <float> radiusProperty)
        {
            gizmo.PositionGizmo(sphere.transform.position, sphere.transform.angles, centerProperty, false);
            gizmo.RotationGizmo(sphere.transform.position, sphere.transform.angles, anglesProperty, false);
            gizmo.ScaleGizmo(sphere.transform.position, sphere.transform.angles, sphere.transform.scale, scaleProperty, false);

            // Radius controls
            if (radiusProperty.isEditable)
            {
                using (new Handles.DrawingScope(Handles.matrix * sphere.transform))
                {
                    for (int i = 0; i < s_RadiusDirections.Length; ++i)
                    {
                        EditorGUI.BeginChangeCheck();
                        var dir       = s_RadiusDirections[i];
                        var sliderPos = dir * sphere.radius;
                        var result    = Handles.Slider(s_RadiusName[i], sliderPos, dir, handleSize * HandleUtility.GetHandleSize(sliderPos), CustomCubeHandleCap, 0);

                        if (EditorGUI.EndChangeCheck())
                        {
                            float newRadius = result.magnitude;
                            if (float.IsNaN(newRadius))
                            {
                                newRadius = 0;
                            }
                            radiusProperty.SetValue(newRadius);
                        }
                    }
                }
            }
        }
Example #2
0
        public static void DrawCircle(VFXGizmo gizmo, TCircle circle, IProperty <Vector3> centerProperty, IProperty <Vector3> anglesProperty, IProperty <Vector3> scaleProperty, IProperty <float> radiusProperty, int countVisible = int.MaxValue)
        {
            var radius = circle.radius;

            gizmo.PositionGizmo(circle.transform.position, circle.transform.angles, centerProperty, false);
            gizmo.RotationGizmo(circle.transform.position, circle.transform.angles, anglesProperty, false);
            gizmo.ScaleGizmo(circle.transform.position, circle.transform.angles, circle.transform.scale, scaleProperty, false);

            if (radiusProperty.isEditable)
            {
                using (new Handles.DrawingScope(Handles.matrix * circle.transform))
                {
                    for (int i = 0; i < countVisible && i < s_RadiusDirections.Length; ++i)
                    {
                        EditorGUI.BeginChangeCheck();
                        var dir       = s_RadiusDirections[i];
                        var sliderPos = dir * radius;
                        var result    = Handles.Slider(s_RadiusDirectionsName[i], sliderPos, dir, handleSize * HandleUtility.GetHandleSize(sliderPos), CustomCubeHandleCap, 0.0f);
                        if (EditorGUI.EndChangeCheck())
                        {
                            radius = result.magnitude;
                            if (float.IsNaN(radius))
                            {
                                radius = 0;
                            }

                            radiusProperty.SetValue(radius);
                        }
                    }
                }
            }
        }
Example #3
0
        public static void DrawCone(VFXGizmo gizmo, TCone cone, ref Extremities extremities, IProperty <Vector3> centerProperty, IProperty <Vector3> anglesProperty, IProperty <Vector3> scaleProperty, IProperty <float> baseRadiusProperty, IProperty <float> topRadiusProperty, IProperty <float> heightProperty, float baseRadiusScreen, float topRadiusScreen)
        {
            var center     = cone.transform.position;
            var scale      = cone.transform.scale;
            var angles     = cone.transform.angles;
            var baseRadius = cone.baseRadius;
            var topRadius  = cone.topRadius;
            var height     = cone.height;

            gizmo.PositionGizmo(center, angles, centerProperty, false);
            gizmo.RotationGizmo(center, angles, anglesProperty, false);
            gizmo.ScaleGizmo(center, angles, scale, scaleProperty, false);

            using (new Handles.DrawingScope(Handles.matrix * cone.transform))
            {
                if (baseRadiusScreen > 2 && baseRadiusProperty.isEditable)
                {
                    for (int i = extremities.extremities.Count / 2; i < extremities.extremities.Count && (i - extremities.extremities.Count / 2) < extremities.visibleCount; ++i)
                    {
                        EditorGUI.BeginChangeCheck();
                        var pos    = extremities.extremities[i];
                        var result = Handles.Slider(s_ExtremitiesNames[i], pos, pos - extremities.bottomCap, handleSize * HandleUtility.GetHandleSize(pos), CustomCubeHandleCap, 0);
                        if (EditorGUI.EndChangeCheck())
                        {
                            baseRadiusProperty.SetValue(result.magnitude);
                        }
                    }
                }

                if (topRadiusScreen > 2 && topRadiusProperty.isEditable)
                {
                    for (int i = 0; i < extremities.extremities.Count / 2 && i < extremities.visibleCount; ++i)
                    {
                        EditorGUI.BeginChangeCheck();

                        var pos    = extremities.extremities[i];
                        var dir    = pos - extremities.topCap;
                        var result = Handles.Slider(s_ExtremitiesNames[i], pos, dir, handleSize * HandleUtility.GetHandleSize(pos), CustomCubeHandleCap, 0);

                        if (EditorGUI.EndChangeCheck())
                        {
                            topRadiusProperty.SetValue((result - extremities.topCap).magnitude);
                        }
                    }
                }

                if (heightProperty.isEditable)
                {
                    EditorGUI.BeginChangeCheck();
                    var result = Handles.Slider(s_HeightCapName, extremities.topCap, Vector3.up, handleSize * HandleUtility.GetHandleSize(extremities.topCap), CustomCubeHandleCap, 0);
                    if (EditorGUI.EndChangeCheck())
                    {
                        heightProperty.SetValue(result.magnitude);
                    }
                }
            }
        }
Example #4
0
        public static void DrawTorus(VFXGizmo gizmo, TTorus torus, IProperty <Vector3> centerProperty, IProperty <Vector3> anglesProperty, IProperty <Vector3> scaleProperty, IProperty <float> thicknessProperty, IProperty <float> radiusProperty, IEnumerable <float> angles, float maxAngle = Mathf.PI * 2)
        {
            gizmo.PositionGizmo(torus.transform.position, torus.transform.angles, centerProperty, false);
            gizmo.RotationGizmo(torus.transform.position, torus.transform.angles, anglesProperty, false);
            gizmo.ScaleGizmo(torus.transform.position, torus.transform.angles, torus.transform.scale, scaleProperty, false);

            // Radius controls
            using (new Handles.DrawingScope(Handles.matrix * torus.transform * Matrix4x4.Rotate(Quaternion.Euler(-90.0f, 0.0f, 0.0f))))
            {
                for (int i = 0; i < angles.Count(); ++i)
                {
                    var arcAngle = angles.ElementAt(i);
                    if (arcAngle > maxAngle)
                    {
                        continue;
                    }

                    var angleName   = s_AngleNames[i];
                    var arcRotation = Quaternion.AngleAxis(arcAngle, Vector3.up);
                    var capCenter   = arcRotation * Vector3.forward * torus.majorRadius;
                    Handles.DrawWireDisc(capCenter, arcRotation * Vector3.right, torus.minorRadius);

                    if (thicknessProperty.isEditable)
                    {
                        // Minor radius
                        for (int j = 0; j < s_RadiusDirections.Length; ++j)
                        {
                            var     composedName = (angleName * 397) ^ s_RadiusDirectionsNames[j];
                            Vector3 distRotated  = Matrix4x4.Rotate(Quaternion.Euler(0.0f, arcAngle + 90.0f, 0.0f)) * s_RadiusDirections[j];
                            Vector3 sliderPos    = capCenter + distRotated * torus.minorRadius;

                            EditorGUI.BeginChangeCheck();
                            var result = Handles.Slider(composedName, sliderPos, distRotated, arcAngle <= maxAngle ? handleSize * HandleUtility.GetHandleSize(sliderPos) : 0, CustomCubeHandleCap, 0);
                            if (EditorGUI.EndChangeCheck())
                            {
                                var newRadius = (result - capCenter).magnitude;
                                if (float.IsNaN(newRadius))
                                {
                                    newRadius = 0;
                                }

                                thicknessProperty.SetValue(newRadius);
                            }
                        }
                    }

                    if (radiusProperty.isEditable)
                    {
                        // Major radius
                        var composedName = (angleName * 397) ^ s_MajorRadius;

                        Vector3 distRotated = Matrix4x4.Rotate(Quaternion.Euler(0.0f, arcAngle + 90.0f, 0.0f)) * Vector3.left;
                        Vector3 sliderPos   = distRotated * torus.majorRadius;

                        EditorGUI.BeginChangeCheck();
                        Vector3 result = Handles.Slider(composedName, sliderPos, distRotated, handleSize * HandleUtility.GetHandleSize(sliderPos), CustomCubeHandleCap, 0);
                        if (EditorGUI.EndChangeCheck())
                        {
                            float newRadius = (result).magnitude;
                            if (float.IsNaN(newRadius))
                            {
                                newRadius = 0;
                            }
                            radiusProperty.SetValue(newRadius);
                        }
                    }
                }
            }
        }