コード例 #1
0
        public static void DrawCircle(Circle circle, VFXGizmo gizmo, IProperty <Vector3> centerProperty, IProperty <float> radiusProperty, IEnumerable <Vector3> radiusDirections, int countVisible = int.MaxValue)
        {
            gizmo.PositionGizmo(circle.center, centerProperty, true);

            // Radius controls
            if (radiusProperty.isEditable)
            {
                int cpt = 0;
                foreach (var dist in radiusDirections)
                {
                    EditorGUI.BeginChangeCheck();
                    Vector3 sliderPos = circle.center + dist * circle.radius;
                    Vector3 result    = Handles.Slider(sliderPos, dist, cpt < countVisible ? (handleSize * HandleUtility.GetHandleSize(sliderPos)) : 0, Handles.CubeHandleCap, 0);

                    ++cpt;
                    if (EditorGUI.EndChangeCheck())
                    {
                        circle.radius = (result - circle.center).magnitude;

                        if (float.IsNaN(circle.radius))
                        {
                            circle.radius = 0;
                        }
                        radiusProperty.SetValue(circle.radius);
                    }
                }
            }
        }
コード例 #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);
                        }
                    }
                }
            }
        }
コード例 #3
0
        public static void DrawSphere(Sphere sphere, VFXGizmo gizmo, IProperty <Vector3> centerProperty, IProperty <float> radiusProperty)
        {
            gizmo.PositionGizmo(sphere.center, centerProperty, true);

            // Radius controls
            if (radiusProperty.isEditable)
            {
                foreach (var dist in radiusDirections)
                {
                    EditorGUI.BeginChangeCheck();
                    Vector3 sliderPos = sphere.center + dist * sphere.radius;
                    Vector3 result    = Handles.Slider(sliderPos, dist, handleSize * HandleUtility.GetHandleSize(sliderPos), Handles.CubeHandleCap, 0);

                    if (EditorGUI.EndChangeCheck())
                    {
                        float newRadius = (result - sphere.center).magnitude;

                        if (float.IsNaN(newRadius))
                        {
                            newRadius = 0;
                        }
                        radiusProperty.SetValue(newRadius);
                    }
                }
            }
        }
コード例 #4
0
ファイル: VFXSphereGizmos.cs プロジェクト: vault51/Graphics
        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);
                        }
                    }
                }
            }
        }
コード例 #5
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);
                    }
                }
            }
        }
コード例 #6
0
ファイル: VFXSphereGizmos.cs プロジェクト: vault51/Graphics
 static public void DrawSpaceSphere(VFXGizmo gizmo, TSphere sphere, IProperty <Vector3> centerProperty, IProperty <Vector3> anglesProperty, IProperty <Vector3> scaleProperty, IProperty <float> radiusProperty)
 {
     using (new Handles.DrawingScope(Handles.matrix * sphere.transform))
     {
         Handles.DrawWireDisc(Vector3.zero, Vector3.forward, sphere.radius);
         Handles.DrawWireDisc(Vector3.zero, Vector3.up, sphere.radius);
         Handles.DrawWireDisc(Vector3.zero, Vector3.right, sphere.radius);
     }
     DrawSphere(gizmo, sphere, centerProperty, anglesProperty, scaleProperty, radiusProperty);
 }
コード例 #7
0
        public static void DrawCone(Cone cone, VFXGizmo gizmo, ref Extremities extremities, IProperty <Vector3> centerProperty, IProperty <float> radius0Property, IProperty <float> radius1Property, IProperty <float> heightProperty, float radius0Screen, float radius1Screen)
        {
            gizmo.PositionGizmo(cone.center, centerProperty, true);

            using (new Handles.DrawingScope(Handles.matrix * Matrix4x4.Translate(cone.center)))
            {
                if (radius0Screen > 2 && radius0Property.isEditable)
                {
                    for (int i = extremities.extremities.Count / 2; i < extremities.extremities.Count; ++i)
                    {
                        EditorGUI.BeginChangeCheck();

                        Vector3 pos    = extremities.extremities[i];
                        Vector3 result = Handles.Slider(pos, pos - extremities.bottomCap, (i - extremities.extremities.Count / 2) < extremities.visibleCount ? handleSize * HandleUtility.GetHandleSize(pos) : 0, Handles.CubeHandleCap, 0);

                        if (EditorGUI.EndChangeCheck())
                        {
                            radius0Property.SetValue(result.magnitude);
                        }
                    }
                }

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

                        Vector3 pos    = extremities.extremities[i];
                        Vector3 dir    = pos - extremities.topCap;
                        Vector3 result = Handles.Slider(pos, dir, i < extremities.visibleCount ? handleSize * HandleUtility.GetHandleSize(pos) : 0, Handles.CubeHandleCap, 0);

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

                if (heightProperty.isEditable)
                {
                    EditorGUI.BeginChangeCheck();
                    Vector3 result = Handles.Slider(extremities.topCap, Vector3.up, handleSize * HandleUtility.GetHandleSize(extremities.topCap), Handles.CubeHandleCap, 0);

                    if (EditorGUI.EndChangeCheck())
                    {
                        heightProperty.SetValue(result.magnitude);
                    }
                }
            }
        }
コード例 #8
0
        public static bool DrawBoxSizeDataAnchorGizmo(AABox box,
                                                      VisualEffect component,
                                                      VFXGizmo gizmo,
                                                      IProperty <Vector3> centerProperty,
                                                      IProperty <float> sizeXProperty,
                                                      IProperty <float> sizeYProperty,
                                                      IProperty <float> sizeZProperty,
                                                      Matrix4x4 centerMatrix)
        {
            Vector3[] points = new Vector3[8];

            Vector3 center = box.center;
            Vector3 size   = box.size;

            points[0] = center + new Vector3(size.x * 0.5f, size.y * 0.5f, size.z * 0.5f);
            points[1] = center + new Vector3(size.x * 0.5f, -size.y * 0.5f, size.z * 0.5f);

            points[2] = center + new Vector3(-size.x * 0.5f, size.y * 0.5f, size.z * 0.5f);
            points[3] = center + new Vector3(-size.x * 0.5f, -size.y * 0.5f, size.z * 0.5f);

            points[4] = center + new Vector3(size.x * 0.5f, size.y * 0.5f, -size.z * 0.5f);
            points[5] = center + new Vector3(size.x * 0.5f, -size.y * 0.5f, -size.z * 0.5f);

            points[6] = center + new Vector3(-size.x * 0.5f, size.y * 0.5f, -size.z * 0.5f);
            points[7] = center + new Vector3(-size.x * 0.5f, -size.y * 0.5f, -size.z * 0.5f);


            for (int i = 0; i < points.Length; ++i)
            {
                points[i] = centerMatrix.MultiplyPoint(points[i]);
            }

            Handles.DrawLine(points[0], points[1]);
            Handles.DrawLine(points[2], points[3]);
            Handles.DrawLine(points[4], points[5]);
            Handles.DrawLine(points[6], points[7]);

            Handles.DrawLine(points[0], points[2]);
            Handles.DrawLine(points[0], points[4]);
            Handles.DrawLine(points[1], points[3]);
            Handles.DrawLine(points[1], points[5]);

            Handles.DrawLine(points[2], points[6]);
            Handles.DrawLine(points[3], points[7]);
            Handles.DrawLine(points[4], points[6]);
            Handles.DrawLine(points[5], points[7]);

            bool changed = false;

            Vector3 xFaceMiddle      = (points[0] + points[1] + points[4] + points[5]) * 0.25f;
            Vector3 minusXFaceMiddle = (points[2] + points[3] + points[6] + points[7]) * 0.25f;

            changed = TwoSidedSizeHandle(Color.red, xFaceMiddle, minusXFaceMiddle, center, sizeXProperty, centerProperty);


            Vector3 yFaceMiddle      = (points[0] + points[2] + points[4] + points[6]) * 0.25f;
            Vector3 minusYFaceMiddle = (points[1] + points[3] + points[5] + points[7]) * 0.25f;

            changed = TwoSidedSizeHandle(Color.green, yFaceMiddle, minusYFaceMiddle, center, sizeYProperty, centerProperty) || changed;

            Vector3 zFaceMiddle      = (points[0] + points[1] + points[2] + points[3]) * 0.25f;
            Vector3 minusZFaceMiddle = (points[4] + points[5] + points[6] + points[7]) * 0.25f;

            changed = TwoSidedSizeHandle(Color.blue, zFaceMiddle, minusZFaceMiddle, center, sizeZProperty, centerProperty) || changed;


            changed = gizmo.PositionGizmo(box.center, Vector3.zero, centerProperty, true) || changed;

            return(changed);
        }
コード例 #9
0
ファイル: VFXTorusGizmos.cs プロジェクト: vault51/Graphics
        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);
                        }
                    }
                }
            }
        }
コード例 #10
0
        public static void DrawTorus(Torus torus, VFXGizmo gizmo, IProperty <Vector3> centerProperty, IProperty <float> minorRadiusProperty, IProperty <float> majorRadiusProperty, IEnumerable <float> angles, float maxAngle = Mathf.PI * 2)
        {
            gizmo.PositionGizmo(torus.center, centerProperty, true);

            // Radius controls

            using (new Handles.DrawingScope(Handles.matrix * Matrix4x4.Translate(torus.center) * Matrix4x4.Rotate(Quaternion.Euler(-90.0f, 0.0f, 0.0f))))
            {
                foreach (var arcAngle in angles)
                {
                    Quaternion arcRotation = Quaternion.AngleAxis(arcAngle, Vector3.up);
                    Vector3    capCenter   = arcRotation * Vector3.forward * torus.majorRadius;
                    Handles.DrawWireDisc(capCenter, arcRotation * Vector3.right, torus.minorRadius);

                    if (minorRadiusProperty.isEditable)
                    {
                        // Minor radius
                        foreach (var dist in radiusDirections)
                        {
                            Vector3 distRotated = Matrix4x4.Rotate(Quaternion.Euler(0.0f, arcAngle + 90.0f, 0.0f)) * dist;

                            EditorGUI.BeginChangeCheck();
                            Vector3 sliderPos = capCenter + distRotated * torus.minorRadius;
                            Vector3 result    = Handles.Slider(sliderPos, distRotated, arcAngle <= maxAngle ? handleSize * HandleUtility.GetHandleSize(sliderPos) : 0, Handles.CubeHandleCap, 0);

                            if (EditorGUI.EndChangeCheck())
                            {
                                float newRadius = (result - capCenter).magnitude;

                                if (float.IsNaN(newRadius))
                                {
                                    newRadius = 0;
                                }
                                minorRadiusProperty.SetValue(newRadius);
                            }
                        }
                    }

                    if (majorRadiusProperty.isEditable)
                    {
                        // Major radius
                        {
                            Vector3 distRotated = Matrix4x4.Rotate(Quaternion.Euler(0.0f, arcAngle + 90.0f, 0.0f)) * Vector3.left;

                            EditorGUI.BeginChangeCheck();
                            Vector3 sliderPos = distRotated * torus.majorRadius;
                            Vector3 result    = Handles.Slider(sliderPos, distRotated, handleSize * HandleUtility.GetHandleSize(sliderPos), Handles.CubeHandleCap, 0);

                            if (EditorGUI.EndChangeCheck())
                            {
                                float newRadius = (result).magnitude;

                                if (float.IsNaN(newRadius))
                                {
                                    newRadius = 0;
                                }
                                majorRadiusProperty.SetValue(newRadius);
                            }
                        }
                    }
                }
            }
        }