Example #1
0
        private void DrawArcEditor(CylinderSurface surface)
        {
            float radious = surface.Radious;

            arcHandle.angle  = surface.Angle;
            arcHandle.radius = radious;

            Matrix4x4 handleMatrix = Matrix4x4.TRS(
                surface.StartPoint,
                Quaternion.LookRotation(surface.StartAngleDir, surface.Direction),
                Vector3.one
                );

            using (new Handles.DrawingScope(handleMatrix))
            {
                EditorGUI.BeginChangeCheck();
                arcHandle.DrawHandle();
                if (EditorGUI.EndChangeCheck())
                {
                    Undo.RecordObject(surface, "Change Cylinder Properties");
                    surface.Angle = arcHandle.angle;
                    radious       = arcHandle.radius;
                }
            }
        }
Example #2
0
        void DrawAngleHandle(TwirlDeformer twirl)
        {
            var radiusDistanceOffset = HandleUtility.GetHandleSize(twirl.Axis.position + twirl.Axis.right * twirl.Outer) * DeformEditorSettings.ScreenspaceSliderHandleCapSize * 2f;

            angleHandle.angle             = twirl.Angle;
            angleHandle.radius            = twirl.Outer + radiusDistanceOffset;
            angleHandle.fillColor         = Color.clear;
            angleHandle.angleHandleColor  = DeformEditorSettings.SolidHandleColor;
            angleHandle.radiusHandleColor = Color.clear;

            var matrix = Matrix4x4.TRS(twirl.transform.position, twirl.transform.rotation, twirl.transform.lossyScale);

            using (new Handles.DrawingScope(matrix))
            {
                DeformHandles.Circle(Vector3.zero, Vector3.forward, Vector3.right, angleHandle.radius);

                Handles.color = DeformEditorSettings.SolidHandleColor;

                using (var check = new EditorGUI.ChangeCheckScope())
                {
                    using (new Handles.DrawingScope(matrix * Matrix4x4.Rotate(Quaternion.LookRotation(Vector3.right, Vector3.forward))))
                    {
                        angleHandle.DrawHandle();
                        if (check.changed)
                        {
                            Undo.RecordObject(twirl, "Changed Angle");
                            twirl.Angle = angleHandle.angle;
                        }
                    }
                }
            }
        }
Example #3
0
        private void DrawAngleHandle(BendDeformer bend)
        {
            var handleRotation = bend.Axis.rotation * Quaternion.Euler(-90, 0f, 0f);
            // There's some weird issue where if you pass the normal lossyScale, the handle's scale on the y axis is changed when the transform's z axis is changed.
            // My simple solution is to swap the y and z.
            var handleScale = new Vector3
                              (
                x: bend.Axis.lossyScale.x,
                y: bend.Axis.lossyScale.z,
                z: bend.Axis.lossyScale.y
                              );

            var matrix = Matrix4x4.TRS(bend.Axis.position + bend.Axis.up * bend.Bottom * bend.Axis.lossyScale.y, handleRotation, handleScale);

            var radiusDistanceOffset = HandleUtility.GetHandleSize(bend.Axis.position + bend.Axis.up * bend.Top) * DeformEditorSettings.ScreenspaceSliderHandleCapSize * 2f;

            angleHandle.angle     = bend.Angle;
            angleHandle.radius    = (bend.Top - bend.Bottom) + radiusDistanceOffset;
            angleHandle.fillColor = Color.clear;

            using (new Handles.DrawingScope(DeformEditorSettings.SolidHandleColor, matrix))
            {
                using (var check = new EditorGUI.ChangeCheckScope())
                {
                    angleHandle.DrawHandle();
                    if (check.changed)
                    {
                        Undo.RecordObject(bend, "Changed Angle");
                        bend.Angle = angleHandle.angle;
                    }
                }
            }
        }
Example #4
0
        private void DrawArcEditor(HandGhost ghost)
        {
            CylinderSurface cylinder = ghost.SnapPoseVolume.Volume;
            float           radious  = cylinder.Radious;

            topArc.angle  = cylinder.Angle;
            topArc.radius = radious;
            Matrix4x4 handleMatrix = Matrix4x4.TRS(
                cylinder.StartPoint,
                Quaternion.LookRotation(cylinder.StartAngleDir, cylinder.Direction),
                Vector3.one
                );

            using (new Handles.DrawingScope(handleMatrix))
            {
                EditorGUI.BeginChangeCheck();

                Handles.color = Color.white;
                topArc.DrawHandle();
                if (EditorGUI.EndChangeCheck())
                {
                    Undo.RecordObject(ghost, "Change Cylinder Properties");
                    cylinder.Angle = topArc.angle;
                    radious        = topArc.radius;
                }
            }
        }
Example #5
0
    // the OnSceneGUI callback uses the Scene view camera for drawing handles by default
    protected virtual void OnSceneGUI()
    {
        ProjectileExample projectileExample = (ProjectileExample)target;

        // copy the target object's data to the handle
        m_ArcHandle.angle  = projectileExample.elevationAngle;
        m_ArcHandle.radius = projectileExample.impulse;

        // set the handle matrix so that angle extends upward from target's facing direction along ground
        Vector3 handleDirection = projectileExample.facingDirection;
        Vector3 handleNormal    = Vector3.Cross(handleDirection, Vector3.up);
        // https://docs.unity3d.com/ScriptReference/Matrix4x4.TRS.html
        Matrix4x4 handleMatrix = Matrix4x4.TRS(
            projectileExample.transform.position,
            Quaternion.LookRotation(handleDirection, handleNormal),
            Vector3.one
            );

        using (new Handles.DrawingScope(handleMatrix))
        {
            // draw the handle
            EditorGUI.BeginChangeCheck();
            m_ArcHandle.DrawHandle();
            if (EditorGUI.EndChangeCheck())
            {
                // record the target object before setting new values so changes can be undone/redone
                Undo.RecordObject(projectileExample, "Change Projectile Properties");

                // copy the handle's updated data back to the target object
                projectileExample.elevationAngle = m_ArcHandle.angle;
                projectileExample.impulse        = m_ArcHandle.radius;
            }
        }
    }
Example #6
0
    public static void ArcHandle(Vector3 center, Quaternion rotation, Vector3 size, ref float angle, ref float radius, Color fillColor, Color wireframeColor)
    {
        Matrix4x4 trs = Matrix4x4.TRS(center, rotation, size);

        using (new Handles.DrawingScope(trs)) {
            arcHandle.angle             = angle;
            arcHandle.radius            = radius;
            arcHandle.radiusHandleColor = Color.white;
            arcHandle.fillColor         = fillColor;
            arcHandle.wireframeColor    = wireframeColor;
            arcHandle.DrawHandle();
            angle  = arcHandle.angle;
            radius = arcHandle.radius;
        }
    }
    void OnSceneGUI()
    {
        Matrix4x4 handleMatrix = Matrix4x4.TRS(fOVVisualize.transform.position, fOVVisualize.transform.rotation, Vector3.one);

        arcHandle.angle  = fOVVisualize.angle;
        arcHandle.radius = fOVVisualize.radius;

        Handles.color = fOVVisualize.colorFov;
        using (new Handles.DrawingScope(handleMatrix))
        {
            Handles.DrawLine(Vector3.zero, Vector3.up * arcHandle.radius);
            arcHandle.DrawHandle();
        }
        fOVVisualize.radius = arcHandle.radius;
        fOVVisualize.angle  = arcHandle.angle;
    }
Example #8
0
    // the OnMultiGUI callback uses the scene view camera for drawing handles by default
    public override void OnMultiEdit(List <Object> targetList)
    {
        // Only render this stuff if we are selecting one object.
        if (targetList.Count == 1)
        {
            ProjectileArc arc = (ProjectileArc)target;

            Matrix4x4 handleMatrix;

            SetUpArcHandle(
                ref m_ArcHandle,
                out handleMatrix,
                arc
                );

            using (new Handles.DrawingScope(handleMatrix)) {
                // draw the handle
                EditorGUI.BeginChangeCheck();
                m_ArcHandle.DrawHandle();
                if (EditorGUI.EndChangeCheck())
                {
                    // record the target object before setting new values so changes can be undone/redone
                    Undo.RecordObject(arc, "Change Projectile Arc Angle");

                    // Just change the one handle; this usually is what runs
                    arc.fullAngle = m_ArcHandle.angle;
                }
            }

            // TODO: Make this render the lines even when multiple things are selected

            Handles.color = fireLineColor;

            // Draw lines
            foreach (FirePoint point in arc.points)
            {
                //Debug.Log(point.position + " faces " + point.rotation.eulerAngles);

                Vector3 startPoint = point.position;
                Vector3 endPoint   = startPoint +
                                     (point.rotation * Vector3.forward * FIRE_LINE_LENGTH * HandleUtility.GetHandleSize(point.position));

                Handles.DrawLine(startPoint, endPoint);
            }
        }
    }
Example #9
0
    private void OnSceneGUI()
    {
        if (!target)
        {
            return;
        }

        Color        oldColor   = Handles.color;
        AIPerception perception = target as AIPerception;

        float halfFOV = perception.fovAngle * 0.5f;
        float coneDir = -90f;

        Quaternion leftRayRotation  = Quaternion.AngleAxis(-halfFOV + coneDir, Vector3.up);
        Quaternion rightRayRotation = Quaternion.AngleAxis(halfFOV + coneDir, Vector3.up);

        Vector3 leftRayDir  = leftRayRotation * perception.transform.right * perception.perceptionRadius;
        Vector3 rightRayDir = rightRayRotation * perception.transform.right * perception.perceptionRadius;

        arcHandle.angle  = perception.fovAngle;
        arcHandle.radius = perception.perceptionRadius;

        Vector3   handleDir    = leftRayDir;
        Vector3   handleNormal = Vector3.Cross(handleDir, perception.transform.forward);
        Matrix4x4 handleMatrix = Matrix4x4.TRS(
            perception.transform.position,
            Quaternion.LookRotation(handleDir, handleNormal),
            Vector3.one);

        using (new Handles.DrawingScope(handleMatrix))
        {
            EditorGUI.BeginChangeCheck();
            arcHandle.DrawHandle();
            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(perception, "Changed perception properties");
                perception.fovAngle         = Mathf.Clamp(arcHandle.angle, 0f, 359f);
                perception.perceptionRadius = Mathf.Max(arcHandle.radius, 1f);
            }
        }

        Handles.color = new Color(1f, 0f, 0f, 0.15f);
        Handles.DrawSolidArc(perception.transform.position, Vector3.up, rightRayDir, 360f - perception.fovAngle, perception.perceptionRadius);
        Handles.color = oldColor;
    }
Example #10
0
        private void DrawAngleHandles(TwistDeformer twist)
        {
            startAngleHandle.angle     = twist.StartAngle;
            startAngleHandle.radius    = HandleUtility.GetHandleSize(twist.transform.position) * DeformEditorSettings.ScreenspaceAngleHandleSize;
            startAngleHandle.fillColor = Color.clear;
            endAngleHandle.angle       = twist.EndAngle;
            endAngleHandle.radius      = HandleUtility.GetHandleSize(twist.transform.position) * DeformEditorSettings.ScreenspaceAngleHandleSize;
            endAngleHandle.fillColor   = Color.clear;

            var normal       = -twist.Axis.forward;
            var direction    = twist.Axis.right;
            var bottomMatrix = Matrix4x4.TRS(twist.transform.position + (twist.Axis.forward * twist.Bottom * twist.Axis.lossyScale.z), Quaternion.LookRotation(direction, normal), Vector3.one);
            var topMatrix    = Matrix4x4.TRS(twist.transform.position + (twist.Axis.forward * twist.Top * twist.Axis.lossyScale.z), Quaternion.LookRotation(direction, normal), Vector3.one);

            using (new Handles.DrawingScope(Handles.matrix))
            {
                Handles.color = DeformEditorSettings.SolidHandleColor;

                Handles.matrix = bottomMatrix;
                using (var check = new EditorGUI.ChangeCheckScope())
                {
                    startAngleHandle.DrawHandle();
                    if (check.changed)
                    {
                        Undo.RecordObject(twist, "Changed Start Angle");
                        twist.StartAngle = startAngleHandle.angle;
                    }
                }

                Handles.matrix = topMatrix;
                using (var check = new EditorGUI.ChangeCheckScope())
                {
                    endAngleHandle.DrawHandle();
                    if (check.changed)
                    {
                        Undo.RecordObject(twist, "Changed End Angle");
                        twist.EndAngle = endAngleHandle.angle;
                    }
                }
            }
        }
    void OnSceneGUI()
    {
        m_Target = (ArcHandleDemo)target;

        Matrix4x4 handleMatrix = Matrix4x4.TRS(
            m_Target.transform.position,
            m_Target.transform.rotation,
            Vector3.one
            );

        m_Arc.angle  = m_Target.Angle;
        m_Arc.radius = m_Target.Radius;

        Handles.color = Color.white;
        using (new Handles.DrawingScope(handleMatrix))
        {
            m_Arc.DrawHandle();
        }
        m_Target.Angle  = m_Arc.angle;
        m_Target.Radius = m_Arc.radius;
    }
Example #12
0
        private void DrawHandles()
        {
            var tf = m_Comp.transform;

            // Latitude North & Max. Distance.

            Vector3   fwd    = tf.forward;
            Vector3   normal = Vector3.Cross(fwd, tf.up);
            Matrix4x4 matrix = Matrix4x4.TRS(
                tf.position,
                Quaternion.LookRotation(fwd, normal),
                Vector3.one
                );

            using (new Handles.DrawingScope(matrix))
            {
                EditorGUI.BeginChangeCheck();
                {
                    m_ArcHandleLatN.angle  = m_Comp.LatAngleNorth;
                    m_ArcHandleLatN.radius = m_Comp.MaxDistance;
                    m_ArcHandleLatN.DrawHandle();
                }
                if (EditorGUI.EndChangeCheck())
                {
                    RecordUpdate();

                    if (m_Comp.LatAngleNorth != m_ArcHandleLatN.angle)
                    {
                        m_Comp.LatAngleNorth = m_ArcHandleLatN.angle;
                    }
                    else if (m_Comp.MaxDistance != m_ArcHandleLatN.radius)
                    {
                        m_Comp.MaxDistance = m_ArcHandleLatN.radius;
                    }
                }
            }

            // Latitude South & Max. Distance.

            normal = Vector3.Cross(fwd, -tf.up);
            matrix = Matrix4x4.TRS(
                tf.position,
                Quaternion.LookRotation(fwd, normal),
                Vector3.one
                );

            using (new Handles.DrawingScope(matrix))
            {
                EditorGUI.BeginChangeCheck();
                {
                    m_ArcHandleLatS.angle  = m_Comp.LatAngleSouth;
                    m_ArcHandleLatS.radius = m_Comp.MaxDistance;
                    m_ArcHandleLatS.DrawHandle();
                }
                if (EditorGUI.EndChangeCheck())
                {
                    RecordUpdate();

                    if (m_Comp.LatAngleSouth != m_ArcHandleLatS.angle)
                    {
                        m_Comp.LatAngleSouth = m_ArcHandleLatS.angle;
                    }
                    else if (m_Comp.MaxDistance != m_ArcHandleLatS.radius)
                    {
                        m_Comp.MaxDistance = m_ArcHandleLatS.radius;
                    }
                }
            }

            // Longitude & Max. Distance.

            normal = Vector3.Cross(fwd, tf.right);
            matrix = Matrix4x4.TRS(
                tf.position,
                Quaternion.LookRotation(fwd, normal),
                Vector3.one
                );

            using (new Handles.DrawingScope(matrix))
            {
                EditorGUI.BeginChangeCheck();
                {
                    m_ArcHandleLon.angle  = m_Comp.LonAngle;
                    m_ArcHandleLon.radius = m_Comp.MaxDistance;
                    m_ArcHandleLon.DrawHandle();
                }
                if (EditorGUI.EndChangeCheck())
                {
                    RecordUpdate();

                    if (m_Comp.LonAngle != m_ArcHandleLon.angle)
                    {
                        m_Comp.LonAngle = m_ArcHandleLon.angle;
                    }
                    else if (m_Comp.MaxDistance != m_ArcHandleLon.radius)
                    {
                        m_Comp.MaxDistance = m_ArcHandleLon.radius;
                    }
                }
            }

            // Minimum Distance.

            float min = m_Comp.MinDistance;

            EditorGUI.BeginChangeCheck();
            {
                min = Handles.RadiusHandle(tf.rotation, tf.position, min);
            }
            if (EditorGUI.EndChangeCheck())
            {
                RecordUpdate();
                m_Comp.MinDistance = min;
            }
        }
Example #13
0
        void DrawHandle(int i)
        {
            Vector3 handlePosition = MathUtility.TransformPoint(bezierPath[i], creator.transform, bezierPath.Space);

            float anchorHandleSize  = GetHandleDiameter(globalDisplaySettings.anchorSize * data.bezierHandleScale, bezierPath[i]);
            float controlHandleSize = GetHandleDiameter(globalDisplaySettings.controlSize * data.bezierHandleScale, bezierPath[i]);

            bool  isAnchorPoint     = i % 3 == 0;
            bool  isInteractive     = isAnchorPoint || bezierPath.ControlPointMode != BezierPath.ControlMode.Automatic;
            float handleSize        = (isAnchorPoint) ? anchorHandleSize : controlHandleSize;
            bool  doTransformHandle = i == handleIndexToDisplayAsTransform;

            PathHandle.HandleColours handleColours = (isAnchorPoint) ? splineAnchorColours : splineControlColours;
            if (i == handleIndexToDisplayAsTransform)
            {
                handleColours.defaultColour = (isAnchorPoint) ? globalDisplaySettings.anchorSelected : globalDisplaySettings.controlSelected;
            }
            var cap = capFunctions[(isAnchorPoint) ? globalDisplaySettings.anchorShape : globalDisplaySettings.controlShape];

            PathHandle.HandleInputType handleInputType;
            handlePosition = PathHandle.DrawHandle(handlePosition, bezierPath.Space, isInteractive, handleSize, cap, handleColours, out handleInputType, i);

            if (doTransformHandle)
            {
                // Show normals rotate tool
                if (data.showNormals && Tools.current == Tool.Rotate && isAnchorPoint && bezierPath.Space == PathSpace.xyz)
                {
                    Handles.color = handlesStartCol;

                    int     attachedControlIndex = (i == bezierPath.NumPoints - 1) ? i - 1 : i + 1;
                    Vector3 dir             = (bezierPath[attachedControlIndex] - handlePosition).normalized;
                    float   handleRotOffset = (360 + bezierPath.GlobalNormalsAngle) % 360;
                    anchorAngleHandle.radius = handleSize * 3;
                    anchorAngleHandle.angle  = handleRotOffset + bezierPath.GetAnchorNormalAngle(i / 3);
                    Vector3   handleDirection = Vector3.Cross(dir, Vector3.up);
                    Matrix4x4 handleMatrix    = Matrix4x4.TRS(
                        handlePosition,
                        Quaternion.LookRotation(handleDirection, dir),
                        Vector3.one
                        );

                    using (new Handles.DrawingScope(handleMatrix)) {
                        // draw the handle
                        EditorGUI.BeginChangeCheck();
                        anchorAngleHandle.DrawHandle();
                        if (EditorGUI.EndChangeCheck())
                        {
                            Undo.RecordObject(creator, "Set angle");
                            bezierPath.SetAnchorNormalAngle(i / 3, anchorAngleHandle.angle - handleRotOffset);
                        }
                    }
                }
                else
                {
                    handlePosition = Handles.DoPositionHandle(handlePosition, Quaternion.identity);
                }
            }

            switch (handleInputType)
            {
            case PathHandle.HandleInputType.LMBDrag:
                draggingHandleIndex             = i;
                handleIndexToDisplayAsTransform = -1;
                Repaint();
                break;

            case PathHandle.HandleInputType.LMBRelease:
                draggingHandleIndex             = -1;
                handleIndexToDisplayAsTransform = -1;
                Repaint();
                break;

            case PathHandle.HandleInputType.LMBClick:
                draggingHandleIndex = -1;
                if (Event.current.shift)
                {
                    handleIndexToDisplayAsTransform = -1;     // disable move tool if new point added
                }
                else
                {
                    if (handleIndexToDisplayAsTransform == i)
                    {
                        handleIndexToDisplayAsTransform = -1;     // disable move tool if clicking on point under move tool
                    }
                    else
                    {
                        handleIndexToDisplayAsTransform = i;
                    }
                }
                Repaint();
                break;

            case PathHandle.HandleInputType.LMBPress:
                if (handleIndexToDisplayAsTransform != i)
                {
                    handleIndexToDisplayAsTransform = -1;
                    Repaint();
                }
                break;
            }

            Vector3 localHandlePosition = MathUtility.InverseTransformPoint(handlePosition, creator.transform, bezierPath.Space);

            if (bezierPath[i] != localHandlePosition)
            {
                Undo.RecordObject(creator, "Move point");
                bezierPath.MovePoint(i, localHandlePosition);
            }
        }
Example #14
0
    protected virtual void OnSceneGUI(SceneView sceneView)
    {
        MeleeWep wep = target as MeleeWep;

        m_ArcHandle.angle  = wep.arcAngle;
        m_ArcHandle.radius = wep.arcRadius;

        m_ArcHandleUp.angle  = wep.knockBackAngle;
        m_ArcHandleUp.radius = wep.knockBackForce;

        if (GameObject.FindGameObjectWithTag("Player") == null)
        {
            return;
        }
        Transform player          = GameObject.FindGameObjectWithTag("Player").GetComponent <Transform>();
        Vector3   handleDirection = player.forward;
        Matrix4x4 handleMatrix    = Matrix4x4.TRS(
            player.position,
            Quaternion.LookRotation(player.forward, player.up),
            Vector3.one
            );

        using (new Handles.DrawingScope(handleMatrix))
        {
            EditorGUI.BeginChangeCheck();
            m_ArcHandle.DrawHandle();
            if (EditorGUI.EndChangeCheck())
            {
                // record the target object before setting new values so changes can be undone/redone
                Undo.RecordObject(wep, "Change Projectile Properties");

                // copy the handle's updated data back to the target object
                wep.arcAngle  = m_ArcHandle.angle;
                wep.arcRadius = m_ArcHandle.radius;
                EditorUtility.SetDirty(wep);
            }
        }
        handleMatrix = Matrix4x4.TRS(
            player.position,
            Quaternion.LookRotation(player.forward, -player.up),
            Vector3.one
            );
        using (new Handles.DrawingScope(handleMatrix))
        {
            EditorGUI.BeginChangeCheck();
            m_ArcHandle.DrawHandle();
            if (EditorGUI.EndChangeCheck())
            {
                // record the target object before setting new values so changes can be undone/redone
                Undo.RecordObject(wep, "Change Projectile Properties");

                // copy the handle's updated data back to the target object
                wep.arcAngle  = m_ArcHandle.angle;
                wep.arcRadius = m_ArcHandle.radius;
                EditorUtility.SetDirty(wep);
            }
        }
        handleMatrix = Matrix4x4.TRS(
            player.position,
            Quaternion.LookRotation(player.forward, -player.right),
            Vector3.one
            );
        using (new Handles.DrawingScope(handleMatrix))
        {
            EditorGUI.BeginChangeCheck();
            m_ArcHandleUp.DrawHandle();
            if (EditorGUI.EndChangeCheck())
            {
                // record the target object before setting new values so changes can be undone/redone
                Undo.RecordObject(wep, "Change Projectile Properties");

                // copy the handle's updated data back to the target object
                wep.knockBackAngle = m_ArcHandleUp.angle;
                wep.knockBackForce = m_ArcHandleUp.radius;
                EditorUtility.SetDirty(wep);
            }
        }
        AssetDatabase.SaveAssets();
    }
        void OnSceneGUI()
        {
            Color origCol = Handles.color;

            Handles.color = s_GizmoColor;

            Matrix4x4 orgMatrix = Handles.matrix;

            EditorGUI.BeginChangeCheck();

            foreach (UIParticle uip in _particles)
            {
                ParticleSystem ps = uip.cachedParticleSystem;
                if (!ps || !uip.canvas)
                {
                    continue;
                }

                var shapeModule = ps.shape;
                var mainModule  = ps.main;

                ParticleSystemShapeType type = shapeModule.shapeType;

                Matrix4x4 transformMatrix = new Matrix4x4();
                if (mainModule.scalingMode == ParticleSystemScalingMode.Local)
                {
                    transformMatrix.SetTRS(ps.transform.position, ps.transform.rotation, ps.transform.localScale);
                }
                else if (mainModule.scalingMode == ParticleSystemScalingMode.Hierarchy)
                {
                    transformMatrix = ps.transform.localToWorldMatrix;
                }
                else
                {
                    transformMatrix.SetTRS(ps.transform.position, ps.transform.rotation, ps.transform.lossyScale);
                }

                bool isBox = (type == ParticleSystemShapeType.Box || type == ParticleSystemShapeType.BoxShell || type == ParticleSystemShapeType.BoxEdge || type == ParticleSystemShapeType.Rectangle);

                Vector3   emitterScale  = isBox ? Vector3.one : shapeModule.scale;
                Matrix4x4 emitterMatrix = Matrix4x4.TRS(shapeModule.position, Quaternion.Euler(shapeModule.rotation), emitterScale);
                transformMatrix *= emitterMatrix;
                Handles.matrix   = transformMatrix;

                if (uip.canvas.renderMode == RenderMode.ScreenSpaceOverlay || ps.main.scalingMode == ParticleSystemScalingMode.Hierarchy)
                {
                    Handles.matrix = Handles.matrix * Matrix4x4.Scale(Vector3.one * uip.scale);
                }
                else
                {
                    Handles.matrix = Handles.matrix * Matrix4x4.Scale(uip.canvas.rootCanvas.transform.localScale * uip.scale);
                }

                if (type == ParticleSystemShapeType.Sphere)
                {
                    // Thickness
                    Handles.color *= s_ShapeGizmoThicknessTint;
                    EditorGUI.BeginChangeCheck();
                    //float radiusThickness = Handles.DoSimpleRadiusHandle (Quaternion.identity, Vector3.zero, shapeModule.radius * (1.0f - shapeModule.radiusThickness), false, shapeModule.arc);
                    float radiusThickness = Handles.RadiusHandle(Quaternion.identity, Vector3.zero, shapeModule.radius * (1.0f - shapeModule.radiusThickness), false);
                    if (EditorGUI.EndChangeCheck())
                    {
                        Undo.RecordObject(ps, "Sphere Thickness Handle Change");
                        shapeModule.radiusThickness = 1.0f - (radiusThickness / shapeModule.radius);
                    }

                    // Sphere
                    Handles.color = s_GizmoColor;
                    EditorGUI.BeginChangeCheck();
                    //float radius = Handles.DoSimpleRadiusHandle (Quaternion.identity, Vector3.zero, shapeModule.radius, false, shapeModule.arc);
                    float radius = Handles.RadiusHandle(Quaternion.identity, Vector3.zero, shapeModule.radius, false);
                    if (EditorGUI.EndChangeCheck())
                    {
                        Undo.RecordObject(ps, "Sphere Handle Change");
                        shapeModule.radius = radius;
                    }

                    // Texture
                    //Matrix4x4 textureTransform = transformMatrix * Matrix4x4.TRS (Vector3.zero, Quaternion.identity, Vector3.one * shapeModule.radius * 2.0f);
                    //OnSceneViewTextureGUI (shapeModule, s_SphereMesh, false, s_SphereTextureMaterial, textureTransform);
                }
                else if (type == ParticleSystemShapeType.Circle)
                {
                    // Thickness
                    EditorGUI.BeginChangeCheck();

                    _arcHandle.angle  = shapeModule.arc;
                    _arcHandle.radius = shapeModule.radius * (1.0f - shapeModule.radiusThickness);
                    _arcHandle.SetColorWithRadiusHandle(s_ShapeGizmoThicknessTint, 0f);
                    _arcHandle.angleHandleColor = Color.clear;

                    using (new Handles.DrawingScope(Handles.matrix * s_ArcHandleOffsetMatrix))
                        _arcHandle.DrawHandle();

                    if (EditorGUI.EndChangeCheck())
                    {
                        Undo.RecordObject(ps, "Circle Thickness Handle Change");
                        shapeModule.radiusThickness = 1.0f - (_arcHandle.radius / shapeModule.radius);
                    }

                    // Circle
                    EditorGUI.BeginChangeCheck();

                    _arcHandle.radius = shapeModule.radius;
                    _arcHandle.SetColorWithRadiusHandle(Color.white, 0f);

                    using (new Handles.DrawingScope(Handles.matrix * s_ArcHandleOffsetMatrix))
                        _arcHandle.DrawHandle();

                    if (EditorGUI.EndChangeCheck())
                    {
                        Undo.RecordObject(ps, "Circle Handle Change");
                        shapeModule.radius = _arcHandle.radius;
                        shapeModule.arc    = _arcHandle.angle;
                    }

                    // Texture
                    //Matrix4x4 textureTransform = transformMatrix * Matrix4x4.TRS (Vector3.zero, Quaternion.Euler (90.0f, 0.0f, 180.0f), Vector3.one * shapeModule.radius * 2.0f);
                    //OnSceneViewTextureGUI (shapeModule, s_CircleMesh, true, s_TextureMaterial, textureTransform);
                }
                else if (type == ParticleSystemShapeType.Hemisphere)
                {
                    // Thickness
                    Handles.color *= s_ShapeGizmoThicknessTint;
                    EditorGUI.BeginChangeCheck();
                    //float radiusThickness = Handles.DoSimpleRadiusHandle (Quaternion.identity, Vector3.zero, shapeModule.radius * (1.0f - shapeModule.radiusThickness), true, shapeModule.arc);
                    //float radiusThickness = Call<float> (typeof (Handles), "DoSimpleRadiusHandle", Quaternion.identity, Vector3.zero, shapeModule.radius * (1.0f - shapeModule.radiusThickness), true, shapeModule.arc);
                    float radiusThickness = Handles.RadiusHandle(Quaternion.identity, Vector3.zero, shapeModule.radius * (1.0f - shapeModule.radiusThickness), true);
                    if (EditorGUI.EndChangeCheck())
                    {
                        Undo.RecordObject(ps, "Hemisphere Thickness Handle Change");
                        shapeModule.radiusThickness = 1.0f - (radiusThickness / shapeModule.radius);
                    }

                    // Hemisphere
                    Handles.color = s_GizmoColor;
                    EditorGUI.BeginChangeCheck();
                    //float radius = Handles.DoSimpleRadiusHandle (Quaternion.identity, Vector3.zero, shapeModule.radius, true, shapeModule.arc);
                    float radius = Handles.RadiusHandle(Quaternion.identity, Vector3.zero, shapeModule.radius, true);
                    if (EditorGUI.EndChangeCheck())
                    {
                        Undo.RecordObject(ps, "Hemisphere Handle Change");
                        shapeModule.radius = radius;
                    }

                    // Texture
                    //Matrix4x4 textureTransform = transformMatrix * Matrix4x4.TRS (Vector3.zero, Quaternion.identity, Vector3.one * shapeModule.radius * 2.0f);
                    //OnSceneViewTextureGUI (shapeModule, s_HemisphereMesh, false, s_SphereTextureMaterial, textureTransform);
                }
                else if (type == ParticleSystemShapeType.Cone)
                {
                    // Thickness
                    Handles.color *= s_ShapeGizmoThicknessTint;
                    EditorGUI.BeginChangeCheck();
                    float   angleThickness            = Mathf.Lerp(shapeModule.angle, 0.0f, shapeModule.radiusThickness);
                    Vector3 radiusThicknessAngleRange = new Vector3(shapeModule.radius * (1.0f - shapeModule.radiusThickness), angleThickness, mainModule.startSpeedMultiplier);
                    //radiusThicknessAngleRange = Handles.ConeFrustrumHandle (Quaternion.identity, Vector3.zero, radiusThicknessAngleRange, Handles.ConeHandles.Radius);
#if UNITY_2018_3_OR_NEWER
                    radiusThicknessAngleRange = Call <Vector3> (typeof(Handles), "ConeFrustrumHandle", Quaternion.identity, Vector3.zero, radiusThicknessAngleRange, 1);
#else
                    radiusThicknessAngleRange = Call <Vector3> (typeof(Handles), "ConeFrustrumHandle", Quaternion.identity, Vector3.zero, radiusThicknessAngleRange);
#endif
                    if (EditorGUI.EndChangeCheck())
                    {
                        Undo.RecordObject(ps, "Cone Thickness Handle Change");
                        shapeModule.radiusThickness = 1.0f - (radiusThicknessAngleRange.x / shapeModule.radius);
                    }

                    // Cone
                    Handles.color = s_GizmoColor;
                    EditorGUI.BeginChangeCheck();
                    Vector3 radiusAngleRange = new Vector3(shapeModule.radius, shapeModule.angle, mainModule.startSpeedMultiplier);
                    //radiusAngleRange = Handles.ConeFrustrumHandle (Quaternion.identity, Vector3.zero, radiusAngleRange);
#if UNITY_2018_3_OR_NEWER
                    radiusAngleRange = Call <Vector3> (typeof(Handles), "ConeFrustrumHandle", Quaternion.identity, Vector3.zero, radiusAngleRange, 7);
#else
                    radiusAngleRange = Call <Vector3> (typeof(Handles), "ConeFrustrumHandle", Quaternion.identity, Vector3.zero, radiusAngleRange);
#endif
                    if (EditorGUI.EndChangeCheck())
                    {
                        Undo.RecordObject(ps, "Cone Handle Change");
                        shapeModule.radius = radiusAngleRange.x;
                        shapeModule.angle  = radiusAngleRange.y;
                        mainModule.startSpeedMultiplier = radiusAngleRange.z;
                    }

                    // Texture
                    //Matrix4x4 textureTransform = transformMatrix * Matrix4x4.TRS (Vector3.zero, Quaternion.Euler (90.0f, 0.0f, 180.0f), Vector3.one * shapeModule.radius * 2.0f);
                    //OnSceneViewTextureGUI (shapeModule, s_CircleMesh, true, s_TextureMaterial, textureTransform);
                }
                else if (type == ParticleSystemShapeType.ConeVolume)
                {
                    // Thickness
                    Handles.color *= s_ShapeGizmoThicknessTint;
                    EditorGUI.BeginChangeCheck();
                    float   angleThickness             = Mathf.Lerp(shapeModule.angle, 0.0f, shapeModule.radiusThickness);
                    Vector3 radiusThicknessAngleLength = new Vector3(shapeModule.radius * (1.0f - shapeModule.radiusThickness), angleThickness, shapeModule.length);
                    //radiusThicknessAngleLength = Handles.ConeFrustrumHandle (Quaternion.identity, Vector3.zero, radiusThicknessAngleLength, Handles.ConeHandles.Radius);
#if UNITY_2018_3_OR_NEWER
                    radiusThicknessAngleLength = Call <Vector3> (typeof(Handles), "ConeFrustrumHandle", Quaternion.identity, Vector3.zero, radiusThicknessAngleLength, 1);
#else
                    radiusThicknessAngleLength = Call <Vector3> (typeof(Handles), "ConeFrustrumHandle", Quaternion.identity, Vector3.zero, radiusThicknessAngleLength);
#endif
                    if (EditorGUI.EndChangeCheck())
                    {
                        Undo.RecordObject(ps, "Cone Volume Thickness Handle Change");
                        shapeModule.radiusThickness = 1.0f - (radiusThicknessAngleLength.x / shapeModule.radius);
                    }

                    // Cone
                    Handles.color = s_GizmoColor;
                    EditorGUI.BeginChangeCheck();
                    Vector3 radiusAngleLength = new Vector3(shapeModule.radius, shapeModule.angle, shapeModule.length);
                    //radiusAngleLength = Handles.ConeFrustrumHandle (Quaternion.identity, Vector3.zero, radiusAngleLength);
#if UNITY_2018_3_OR_NEWER
                    radiusAngleLength = Call <Vector3> (typeof(Handles), "ConeFrustrumHandle", Quaternion.identity, Vector3.zero, radiusAngleLength, 7);
#else
                    radiusAngleLength = Call <Vector3> (typeof(Handles), "ConeFrustrumHandle", Quaternion.identity, Vector3.zero, radiusAngleLength);
#endif
                    if (EditorGUI.EndChangeCheck())
                    {
                        Undo.RecordObject(ps, "Cone Volume Handle Change");
                        shapeModule.radius = radiusAngleLength.x;
                        shapeModule.angle  = radiusAngleLength.y;
                        shapeModule.length = radiusAngleLength.z;
                    }

                    // Texture
                    //Matrix4x4 textureTransform = transformMatrix * Matrix4x4.TRS (Vector3.zero, Quaternion.Euler (90.0f, 0.0f, 180.0f), Vector3.one * shapeModule.radius * 2.0f);
                    //OnSceneViewTextureGUI (shapeModule, s_CircleMesh, true, s_TextureMaterial, textureTransform);
                }
                else if (type == ParticleSystemShapeType.Box || type == ParticleSystemShapeType.BoxShell || type == ParticleSystemShapeType.BoxEdge)
                {
                    EditorGUI.BeginChangeCheck();

                    _boxBoundsHandle.center = Vector3.zero;
                    _boxBoundsHandle.size   = shapeModule.scale;
                    _boxBoundsHandle.DrawHandle();

                    if (EditorGUI.EndChangeCheck())
                    {
                        Undo.RecordObject(ps, "Box Handle Change");
                        shapeModule.scale = _boxBoundsHandle.size;
                    }

                    //Matrix4x4 textureTransform = transformMatrix * Matrix4x4.TRS (new Vector3 (0.0f, 0.0f, -m_BoxBoundsHandle.size.z * 0.5f), Quaternion.identity, m_BoxBoundsHandle.size);
                    //OnSceneViewTextureGUI (shapeModule, s_QuadMesh, true, s_TextureMaterial, textureTransform);
                }
                else if (type == ParticleSystemShapeType.Donut)
                {
                    // Radius
                    EditorGUI.BeginChangeCheck();

                    _arcHandle.radius = shapeModule.radius;
                    _arcHandle.angle  = shapeModule.arc;
                    _arcHandle.SetColorWithRadiusHandle(Color.white, 0f);
                    _arcHandle.wireframeColor = Color.clear;

                    using (new Handles.DrawingScope(Handles.matrix * s_ArcHandleOffsetMatrix))
                        _arcHandle.DrawHandle();

                    if (EditorGUI.EndChangeCheck())
                    {
                        Undo.RecordObject(ps, "Donut Handle Change");
                        shapeModule.radius = _arcHandle.radius;
                        shapeModule.arc    = _arcHandle.angle;
                    }

                    // Donut extents
                    using (new Handles.DrawingScope(Handles.matrix * s_ArcHandleOffsetMatrix))
                    {
                        float excessAngle = shapeModule.arc % 360f;
                        float angle       = Mathf.Abs(shapeModule.arc) >= 360f ? 360f : excessAngle;

                        Handles.DrawWireArc(new Vector3(0.0f, shapeModule.donutRadius, 0.0f), Vector3.up, Vector3.forward, angle, shapeModule.radius);
                        Handles.DrawWireArc(new Vector3(0.0f, -shapeModule.donutRadius, 0.0f), Vector3.up, Vector3.forward, angle, shapeModule.radius);
                        Handles.DrawWireArc(Vector3.zero, Vector3.up, Vector3.forward, angle, shapeModule.radius + shapeModule.donutRadius);
                        Handles.DrawWireArc(Vector3.zero, Vector3.up, Vector3.forward, angle, shapeModule.radius - shapeModule.donutRadius);

                        if (shapeModule.arc != 360.0f)
                        {
                            Quaternion arcRotation = Quaternion.AngleAxis(shapeModule.arc, Vector3.up);
                            Vector3    capCenter   = arcRotation * Vector3.forward * shapeModule.radius;
                            Handles.DrawWireDisc(capCenter, arcRotation * Vector3.right, shapeModule.donutRadius);
                        }
                    }

                    // Donut thickness
                    _sphereBoundsHandle.axes   = PrimitiveBoundsHandle.Axes.X | PrimitiveBoundsHandle.Axes.Y;
                    _sphereBoundsHandle.radius = shapeModule.donutRadius * (1.0f - shapeModule.radiusThickness);
                    _sphereBoundsHandle.center = Vector3.zero;
                    _sphereBoundsHandle.SetColor(s_ShapeGizmoThicknessTint);

                    const float handleInterval         = 90.0f;
                    int         numOuterRadii          = Mathf.Max(1, (int)Mathf.Ceil(shapeModule.arc / handleInterval));
                    Matrix4x4   donutRadiusStartMatrix = Matrix4x4.TRS(new Vector3(shapeModule.radius, 0.0f, 0.0f), Quaternion.Euler(90.0f, 0.0f, 0.0f), Vector3.one);

                    for (int i = 0; i < numOuterRadii; i++)
                    {
                        EditorGUI.BeginChangeCheck();
                        using (new Handles.DrawingScope(Handles.matrix * (Matrix4x4.Rotate(Quaternion.Euler(0.0f, 0.0f, handleInterval * i)) * donutRadiusStartMatrix)))
                            _sphereBoundsHandle.DrawHandle();
                        if (EditorGUI.EndChangeCheck())
                        {
                            Undo.RecordObject(ps, "Donut Radius Thickness Handle Change");
                            shapeModule.radiusThickness = 1.0f - (_sphereBoundsHandle.radius / shapeModule.donutRadius);
                        }
                    }

                    // Donut radius
                    _sphereBoundsHandle.radius = shapeModule.donutRadius;
                    _sphereBoundsHandle.SetColor(Color.white);

                    for (int i = 0; i < numOuterRadii; i++)
                    {
                        EditorGUI.BeginChangeCheck();
                        using (new Handles.DrawingScope(Handles.matrix * (Matrix4x4.Rotate(Quaternion.Euler(0.0f, 0.0f, handleInterval * i)) * donutRadiusStartMatrix)))
                            _sphereBoundsHandle.DrawHandle();
                        if (EditorGUI.EndChangeCheck())
                        {
                            Undo.RecordObject(ps, "Donut Radius Handle Change");
                            shapeModule.donutRadius = _sphereBoundsHandle.radius;
                        }
                    }

                    // Texture
                    //Matrix4x4 textureTransform = transformMatrix * Matrix4x4.TRS (new Vector3 (shapeModule.radius, 0.0f, 0.0f), Quaternion.Euler (180.0f, 0.0f, 180.0f), Vector3.one * shapeModule.donutRadius * 2.0f);
                    //OnSceneViewTextureGUI (shapeModule, s_CircleMesh, true, s_TextureMaterial, textureTransform);
                }
                else if (type == ParticleSystemShapeType.SingleSidedEdge)
                {
                    EditorGUI.BeginChangeCheck();
                    //float radius = Handles.DoSimpleEdgeHandle (Quaternion.identity, Vector3.zero, shapeModule.radius);
                    float radius = Call <float> (typeof(Handles), "DoSimpleEdgeHandle", Quaternion.identity, Vector3.zero, shapeModule.radius);
                    if (EditorGUI.EndChangeCheck())
                    {
                        Undo.RecordObject(ps, "Edge Handle Change");
                        shapeModule.radius = radius;
                    }
                }
                else if (type == ParticleSystemShapeType.Mesh)
                {
                    Mesh mesh = shapeModule.mesh;
                    if (mesh)
                    {
                        bool orgWireframeMode = GL.wireframe;
                        GL.wireframe = true;
                        s_Material.SetPass(0);
                        Graphics.DrawMeshNow(mesh, transformMatrix);
                        GL.wireframe = orgWireframeMode;

                        //OnSceneViewTextureGUI (shapeModule, mesh, false, s_TextureMaterial, transformMatrix);
                    }
                }
                else if (type == ParticleSystemShapeType.Rectangle)
                {
                    EditorGUI.BeginChangeCheck();

                    _boxBoundsHandle.center = Vector3.zero;
                    _boxBoundsHandle.size   = new Vector3(shapeModule.scale.x, shapeModule.scale.y, 0.0f);
                    _boxBoundsHandle.DrawHandle();

                    if (EditorGUI.EndChangeCheck())
                    {
                        Undo.RecordObject(ps, "Rectangle Handle Change");
                        shapeModule.scale = new Vector3(_boxBoundsHandle.size.x, _boxBoundsHandle.size.y, 0.0f);
                    }

                    //OnSceneViewTextureGUI (shapeModule, s_QuadMesh, true, s_TextureMaterial, transformMatrix * Matrix4x4.Scale (m_BoxBoundsHandle.size));
                }
                else if (type == ParticleSystemShapeType.Sprite)
                {
                    Sprite sprite = shapeModule.sprite;
                    if (sprite)
                    {
                        if (!_spriteMesh)
                        {
                            _spriteMesh            = new Mesh();
                            _spriteMesh.name       = "ParticleSpritePreview";
                            _spriteMesh.hideFlags |= HideFlags.HideAndDontSave;
                        }

                        _spriteMesh.vertices  = Array.ConvertAll(sprite.vertices, i => (Vector3)i);
                        _spriteMesh.uv        = sprite.uv;
                        _spriteMesh.triangles = Array.ConvertAll(sprite.triangles, i => (int)i);

                        bool orgWireframeMode = GL.wireframe;
                        GL.wireframe = true;
                        s_Material.SetPass(0);
                        Graphics.DrawMeshNow(_spriteMesh, transformMatrix);
                        GL.wireframe = orgWireframeMode;

                        //OnSceneViewTextureGUI (shapeModule, m_SpriteMesh, false, s_TextureMaterial, transformMatrix);
                    }
                }
            }
            Handles.color  = origCol;
            Handles.matrix = orgMatrix;
        }
        override public void OnSceneViewGUI()
        {
            Color origCol = Handles.color;

            Handles.color = s_ShapeGizmoColor;

            Matrix4x4 orgMatrix = Handles.matrix;

            EditorGUI.BeginChangeCheck();

            foreach (ParticleSystem ps in m_ParticleSystemUI.m_ParticleSystems)
            {
                var shapeModule = ps.shape;
                var mainModule  = ps.main;

                ParticleSystemShapeType type = shapeModule.shapeType;

                Matrix4x4 transformMatrix = new Matrix4x4();
                if (mainModule.scalingMode == ParticleSystemScalingMode.Local)
                {
                    transformMatrix.SetTRS(ps.transform.position, ps.transform.rotation, ps.transform.localScale);
                }
                else if (mainModule.scalingMode == ParticleSystemScalingMode.Hierarchy)
                {
                    transformMatrix = ps.transform.localToWorldMatrix;
                }
                else
                {
                    transformMatrix.SetTRS(ps.transform.position, ps.transform.rotation, ps.transform.lossyScale);
                }

                bool isBox = (type == ParticleSystemShapeType.Box || type == ParticleSystemShapeType.BoxShell || type == ParticleSystemShapeType.BoxEdge || type == ParticleSystemShapeType.Rectangle);

                Vector3   emitterScale  = isBox ? Vector3.one : shapeModule.scale;
                Matrix4x4 emitterMatrix = Matrix4x4.TRS(shapeModule.position, Quaternion.Euler(shapeModule.rotation), emitterScale);
                transformMatrix *= emitterMatrix;
                Handles.matrix   = transformMatrix;

                if (type == ParticleSystemShapeType.Sphere)
                {
                    EditorGUI.BeginChangeCheck();
                    float radius = Handles.DoSimpleRadiusHandle(Quaternion.identity, Vector3.zero, shapeModule.radius, false);
                    if (EditorGUI.EndChangeCheck())
                    {
                        Undo.RecordObject(ps, "Sphere Handle Change");
                        shapeModule.radius = radius;
                    }

                    Matrix4x4 textureTransform = transformMatrix * Matrix4x4.TRS(Vector3.zero, Quaternion.identity, Vector3.one * shapeModule.radius * 2.0f);
                    OnSceneViewTextureGUI(shapeModule, s_SphereMesh, false, s_SphereTextureMaterial, textureTransform);
                }
                else if (type == ParticleSystemShapeType.Circle)
                {
                    EditorGUI.BeginChangeCheck();

                    m_ArcHandle.radius = shapeModule.radius;
                    m_ArcHandle.angle  = shapeModule.arc;
                    m_ArcHandle.SetColorWithRadiusHandle(Color.white, 0f);

                    using (new Handles.DrawingScope(Handles.matrix * s_ArcHandleOffsetMatrix))
                        m_ArcHandle.DrawHandle();

                    if (EditorGUI.EndChangeCheck())
                    {
                        Undo.RecordObject(ps, "Circle Handle Change");
                        shapeModule.radius = m_ArcHandle.radius;
                        shapeModule.arc    = m_ArcHandle.angle;
                    }

                    Matrix4x4 textureTransform = transformMatrix * Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(90.0f, 0.0f, 180.0f), Vector3.one * shapeModule.radius * 2.0f);
                    OnSceneViewTextureGUI(shapeModule, s_CircleMesh, true, s_TextureMaterial, textureTransform);
                }
                else if (type == ParticleSystemShapeType.Hemisphere)
                {
                    EditorGUI.BeginChangeCheck();
                    float radius = Handles.DoSimpleRadiusHandle(Quaternion.identity, Vector3.zero, shapeModule.radius, true);
                    if (EditorGUI.EndChangeCheck())
                    {
                        Undo.RecordObject(ps, "Hemisphere Handle Change");
                        shapeModule.radius = radius;
                    }

                    Matrix4x4 textureTransform = transformMatrix * Matrix4x4.TRS(Vector3.zero, Quaternion.identity, Vector3.one * shapeModule.radius * 2.0f);
                    OnSceneViewTextureGUI(shapeModule, s_HemisphereMesh, false, s_SphereTextureMaterial, textureTransform);
                }
                else if (type == ParticleSystemShapeType.Cone)
                {
                    EditorGUI.BeginChangeCheck();

                    Vector3 radiusAngleRange = new Vector3(shapeModule.radius, shapeModule.angle, mainModule.startSpeedMultiplier);
                    radiusAngleRange = Handles.ConeFrustrumHandle(Quaternion.identity, Vector3.zero, radiusAngleRange);

                    if (EditorGUI.EndChangeCheck())
                    {
                        Undo.RecordObject(ps, "Cone Handle Change");
                        shapeModule.radius = radiusAngleRange.x;
                        shapeModule.angle  = radiusAngleRange.y;
                        mainModule.startSpeedMultiplier = radiusAngleRange.z;
                    }

                    Matrix4x4 textureTransform = transformMatrix * Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(90.0f, 0.0f, 180.0f), Vector3.one * shapeModule.radius * 2.0f);
                    OnSceneViewTextureGUI(shapeModule, s_CircleMesh, true, s_TextureMaterial, textureTransform);
                }
                else if (type == ParticleSystemShapeType.ConeVolume)
                {
                    EditorGUI.BeginChangeCheck();

                    Vector3 radiusAngleLength = new Vector3(shapeModule.radius, shapeModule.angle, shapeModule.length);
                    radiusAngleLength = Handles.ConeFrustrumHandle(Quaternion.identity, Vector3.zero, radiusAngleLength);

                    if (EditorGUI.EndChangeCheck())
                    {
                        Undo.RecordObject(ps, "Cone Volume Handle Change");
                        shapeModule.radius = radiusAngleLength.x;
                        shapeModule.angle  = radiusAngleLength.y;
                        shapeModule.length = radiusAngleLength.z;
                    }

                    Matrix4x4 textureTransform = transformMatrix * Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(90.0f, 0.0f, 180.0f), Vector3.one * shapeModule.radius * 2.0f);
                    OnSceneViewTextureGUI(shapeModule, s_CircleMesh, true, s_TextureMaterial, textureTransform);
                }
                else if (type == ParticleSystemShapeType.Box || type == ParticleSystemShapeType.BoxShell || type == ParticleSystemShapeType.BoxEdge)
                {
                    EditorGUI.BeginChangeCheck();

                    m_BoxBoundsHandle.center = Vector3.zero;
                    m_BoxBoundsHandle.size   = shapeModule.scale;
                    m_BoxBoundsHandle.DrawHandle();

                    if (EditorGUI.EndChangeCheck())
                    {
                        Undo.RecordObject(ps, "Box Handle Change");
                        shapeModule.scale = m_BoxBoundsHandle.size;
                    }

                    Matrix4x4 textureTransform = transformMatrix * Matrix4x4.TRS(new Vector3(0.0f, 0.0f, -m_BoxBoundsHandle.size.z * 0.5f), Quaternion.identity, m_BoxBoundsHandle.size);
                    OnSceneViewTextureGUI(shapeModule, s_QuadMesh, true, s_TextureMaterial, textureTransform);
                }
                else if (type == ParticleSystemShapeType.Donut)
                {
                    // radius
                    EditorGUI.BeginChangeCheck();

                    m_ArcHandle.radius = shapeModule.radius;
                    m_ArcHandle.angle  = shapeModule.arc;
                    m_ArcHandle.SetColorWithRadiusHandle(Color.white, 0f);
                    m_ArcHandle.wireframeColor = Color.clear;

                    using (new Handles.DrawingScope(Handles.matrix * s_ArcHandleOffsetMatrix))
                        m_ArcHandle.DrawHandle();

                    if (EditorGUI.EndChangeCheck())
                    {
                        Undo.RecordObject(ps, "Donut Handle Change");
                        shapeModule.radius = m_ArcHandle.radius;
                        shapeModule.arc    = m_ArcHandle.angle;
                    }

                    // donut extents
                    using (new Handles.DrawingScope(Handles.matrix * s_ArcHandleOffsetMatrix))
                    {
                        float excessAngle = shapeModule.arc % 360f;
                        float angle       = Mathf.Abs(shapeModule.arc) >= 360f ? 360f : excessAngle;

                        Handles.DrawWireArc(new Vector3(0.0f, shapeModule.donutRadius, 0.0f), Vector3.up, Vector3.forward, angle, shapeModule.radius);
                        Handles.DrawWireArc(new Vector3(0.0f, -shapeModule.donutRadius, 0.0f), Vector3.up, Vector3.forward, angle, shapeModule.radius);
                        Handles.DrawWireArc(Vector3.zero, Vector3.up, Vector3.forward, angle, shapeModule.radius + shapeModule.donutRadius);
                        Handles.DrawWireArc(Vector3.zero, Vector3.up, Vector3.forward, angle, shapeModule.radius - shapeModule.donutRadius);

                        if (shapeModule.arc != 360.0f)
                        {
                            Quaternion arcRotation = Quaternion.AngleAxis(shapeModule.arc, Vector3.up);
                            Vector3    capCenter   = arcRotation * Vector3.forward * shapeModule.radius;
                            Handles.DrawWireDisc(capCenter, arcRotation * Vector3.right, shapeModule.donutRadius);
                        }
                    }

                    // donut radius
                    m_SphereBoundsHandle.axes   = PrimitiveBoundsHandle.Axes.X | PrimitiveBoundsHandle.Axes.Y;
                    m_SphereBoundsHandle.radius = shapeModule.donutRadius;
                    m_SphereBoundsHandle.center = Vector3.zero;
                    m_SphereBoundsHandle.SetColor(Color.white);

                    float     handleInterval         = 90.0f;
                    int       numOuterRadii          = Mathf.Max(1, (int)Mathf.Ceil(shapeModule.arc / handleInterval));
                    Matrix4x4 donutRadiusStartMatrix = Matrix4x4.TRS(new Vector3(shapeModule.radius, 0.0f, 0.0f), Quaternion.Euler(90.0f, 0.0f, 0.0f), Vector3.one);
                    for (int i = 0; i < numOuterRadii; i++)
                    {
                        EditorGUI.BeginChangeCheck();
                        using (new Handles.DrawingScope(Handles.matrix * (Matrix4x4.Rotate(Quaternion.Euler(0.0f, 0.0f, handleInterval * i)) * donutRadiusStartMatrix)))
                            m_SphereBoundsHandle.DrawHandle();
                        if (EditorGUI.EndChangeCheck())
                        {
                            Undo.RecordObject(ps, "Donut Radius Handle Change");
                            shapeModule.donutRadius = m_SphereBoundsHandle.radius;
                        }
                    }

                    // texture
                    Matrix4x4 textureTransform = transformMatrix * Matrix4x4.TRS(new Vector3(shapeModule.radius, 0.0f, 0.0f), Quaternion.Euler(180.0f, 0.0f, 180.0f), Vector3.one * shapeModule.donutRadius * 2.0f);
                    OnSceneViewTextureGUI(shapeModule, s_CircleMesh, true, s_TextureMaterial, textureTransform);
                }
                else if (type == ParticleSystemShapeType.SingleSidedEdge)
                {
                    EditorGUI.BeginChangeCheck();
                    float radius = Handles.DoSimpleEdgeHandle(Quaternion.identity, Vector3.zero, shapeModule.radius);
                    if (EditorGUI.EndChangeCheck())
                    {
                        Undo.RecordObject(ps, "Edge Handle Change");
                        shapeModule.radius = radius;
                    }
                }
                else if (type == ParticleSystemShapeType.Mesh)
                {
                    Mesh mesh = shapeModule.mesh;
                    if (mesh)
                    {
                        bool orgWireframeMode = GL.wireframe;
                        GL.wireframe = true;
                        s_Material.SetPass(0);
                        Graphics.DrawMeshNow(mesh, transformMatrix);
                        GL.wireframe = orgWireframeMode;

                        OnSceneViewTextureGUI(shapeModule, mesh, false, s_TextureMaterial, transformMatrix);
                    }
                }
                else if (type == ParticleSystemShapeType.Rectangle)
                {
                    EditorGUI.BeginChangeCheck();

                    m_BoxBoundsHandle.center = Vector3.zero;
                    m_BoxBoundsHandle.size   = new Vector3(shapeModule.scale.x, shapeModule.scale.y, 0.0f);
                    m_BoxBoundsHandle.DrawHandle();

                    if (EditorGUI.EndChangeCheck())
                    {
                        Undo.RecordObject(ps, "Rectangle Handle Change");
                        shapeModule.scale = new Vector3(m_BoxBoundsHandle.size.x, m_BoxBoundsHandle.size.y, 0.0f);
                    }

                    OnSceneViewTextureGUI(shapeModule, s_QuadMesh, true, s_TextureMaterial, transformMatrix * Matrix4x4.Scale(m_BoxBoundsHandle.size));
                }
                else if (type == ParticleSystemShapeType.Sprite)
                {
                    Sprite sprite = shapeModule.sprite;
                    if (sprite)
                    {
                        if (!m_SpriteMesh)
                        {
                            m_SpriteMesh            = new Mesh();
                            m_SpriteMesh.name       = "ParticleSpritePreview";
                            m_SpriteMesh.hideFlags |= HideFlags.HideAndDontSave;
                        }

                        m_SpriteMesh.vertices  = Array.ConvertAll(sprite.vertices, i => (Vector3)i);
                        m_SpriteMesh.uv        = sprite.uv;
                        m_SpriteMesh.triangles = Array.ConvertAll(sprite.triangles, i => (int)i);

                        bool orgWireframeMode = GL.wireframe;
                        GL.wireframe = true;
                        s_Material.SetPass(0);
                        Graphics.DrawMeshNow(m_SpriteMesh, transformMatrix);
                        GL.wireframe = orgWireframeMode;

                        OnSceneViewTextureGUI(shapeModule, m_SpriteMesh, false, s_TextureMaterial, transformMatrix);
                    }
                }
            }

            if (EditorGUI.EndChangeCheck())
            {
                m_ParticleSystemUI.m_ParticleEffectUI.m_Owner.Repaint();
            }

            Handles.color  = origCol;
            Handles.matrix = orgMatrix;
        }
Example #17
0
        void DrawHandle(int i)
        {
            var handlePosition = BezierPath[i];

            var anchorHandleSize = GetHandleDiameter(
                _globalDisplaySettings.anchorSize * Data.bezierHandleScale,
                BezierPath[i]);
            var controlHandleSize = GetHandleDiameter(
                _globalDisplaySettings.controlSize * Data.bezierHandleScale,
                BezierPath[i]);

            var isAnchorPoint     = i % 3 == 0;
            var isInteractive     = isAnchorPoint || BezierPath.ControlPointMode != BezierPath.ControlMode.Automatic;
            var handleSize        = (isAnchorPoint) ? anchorHandleSize : controlHandleSize;
            var doTransformHandle = i == _handleIndexToDisplayAsTransform;

            var handleColours = (isAnchorPoint) ? _splineAnchorColours : _splineControlColours;
            var cap           = _capFunctions[(isAnchorPoint) ? _globalDisplaySettings.anchorShape : _globalDisplaySettings.controlShape];

            PathHandle.HandleInputType handleInputType;
            handlePosition = PathHandle.DrawHandle(
                handlePosition,
                BezierPath.Space,
                isInteractive,
                handleSize,
                cap,
                handleColours,
                out handleInputType,
                i);

            if (doTransformHandle)
            {
                // Show normals rotate tool
                if (Data.showNormals && Tools.current == Tool.Rotate && isAnchorPoint && BezierPath.Space == PathSpace.Xyz)
                {
                    Handles.color = _handlesStartCol;

                    var attachedControlIndex = (i == BezierPath.NumPoints - 1) ? i - 1 : i + 1;
                    var dir             = (BezierPath[attachedControlIndex] - handlePosition).normalized;
                    var handleRotOffset = (360 + BezierPath.GlobalNormalsAngle) % 360;
                    _anchorAngleHandle.radius = handleSize * 3;
                    _anchorAngleHandle.angle  = handleRotOffset + BezierPath.GetAnchorNormalAngle(i / 3);
                    var handleDirection = Vector3.Cross(dir, Vector3.up);
                    var handleMatrix    = Matrix4x4.TRS(
                        handlePosition,
                        Quaternion.LookRotation(handleDirection, dir),
                        Vector3.one);

                    using (new Handles.DrawingScope(handleMatrix)) {
                        // draw the handle
                        EditorGUI.BeginChangeCheck();
                        _anchorAngleHandle.DrawHandle();
                        if (EditorGUI.EndChangeCheck())
                        {
                            Undo.RecordObject(_creator, "Set angle");
                            BezierPath.SetAnchorNormalAngle(i / 3, _anchorAngleHandle.angle - handleRotOffset);
                        }
                    }
                }
                else
                {
                    handlePosition = Handles.DoPositionHandle(handlePosition, Quaternion.identity);
                }
            }

            switch (handleInputType)
            {
            case PathHandle.HandleInputType.LmbDrag:
                _draggingHandleIndex             = i;
                _handleIndexToDisplayAsTransform = -1;
                break;

            case PathHandle.HandleInputType.LmbRelease:
                _draggingHandleIndex             = -1;
                _handleIndexToDisplayAsTransform = -1;
                break;

            case PathHandle.HandleInputType.LmbClick:
                if (Event.current.shift)
                {
                    _handleIndexToDisplayAsTransform = -1; // disable move tool if new point added
                }
                else
                {
                    if (_handleIndexToDisplayAsTransform == i)
                    {
                        _handleIndexToDisplayAsTransform = -1; // disable move tool if clicking on point under move tool
                    }
                    else
                    {
                        _handleIndexToDisplayAsTransform = i;
                    }
                }

                break;

            case PathHandle.HandleInputType.LmbPress:
                if (_handleIndexToDisplayAsTransform != i)
                {
                    _handleIndexToDisplayAsTransform = -1;
                }

                break;
            }

            if (BezierPath[i] != handlePosition)
            {
                Undo.RecordObject(_creator, "Move point");
                BezierPath.MovePoint(i, handlePosition);
            }
        }
Example #18
0
        void DrawHandle(int i)
        {
            Vector3 handlePosition = bezierPath[i];

            float anchorHandleSize  = GetHandleDiameter(globalDisplaySettings.anchorSize * data.bezierHandleScale, bezierPath[i]);
            float controlHandleSize = GetHandleDiameter(globalDisplaySettings.controlSize * data.bezierHandleScale, bezierPath[i]);

            bool  isAnchorPoint     = i % 3 == 0;
            bool  isInteractive     = isAnchorPoint || bezierPath.ControlPointMode != BezierPath.ControlMode.Automatic;
            float handleSize        = (isAnchorPoint) ? anchorHandleSize : controlHandleSize;
            bool  doTransformHandle = i == handleIndexToDisplayAsTransform;

            PathHandle.HandleColours handleColours = (isAnchorPoint) ? splineAnchorColours : splineControlColours;
            if (i == handleIndexToDisplayAsTransform)
            {
                handleColours.defaultColour = (isAnchorPoint) ? globalDisplaySettings.anchorSelected : globalDisplaySettings.controlSelected;
            }
            var cap = capFunctions[(isAnchorPoint) ? globalDisplaySettings.anchorShape : globalDisplaySettings.controlShape];

            PathHandle.HandleInputType handleInputType;
            handlePosition = PathHandle.DrawHandle(handlePosition, bezierPath.Space, isInteractive, handleSize, cap, handleColours, out handleInputType, i);

            if (doTransformHandle)
            {
                // Show normals rotate tool
                if (data.showNormals && Tools.current == Tool.Rotate && isAnchorPoint && bezierPath.Space == PathSpace.xyz)
                {
                    Handles.color = handlesStartCol;

                    int     attachedControlIndex = (i == bezierPath.NumPoints - 1) ? i - 1 : i + 1;
                    Vector3 dir             = (bezierPath[attachedControlIndex] - handlePosition).normalized;
                    float   handleRotOffset = (360 + bezierPath.GlobalNormalsAngle) % 360;
                    anchorAngleHandle.radius = handleSize * 3;
                    anchorAngleHandle.angle  = handleRotOffset + bezierPath.GetAnchorNormalAngle(i / 3);
                    Vector3   handleDirection = Vector3.Cross(dir, Vector3.up);
                    Matrix4x4 handleMatrix    = Matrix4x4.TRS(
                        handlePosition,
                        Quaternion.LookRotation(handleDirection, dir),
                        Vector3.one
                        );

                    using (new Handles.DrawingScope(handleMatrix)) {
                        // draw the handle
                        EditorGUI.BeginChangeCheck();
                        anchorAngleHandle.DrawHandle();
                        if (EditorGUI.EndChangeCheck())
                        {
                            Undo.RecordObject(creator, "Set angle");
                            bezierPath.SetAnchorNormalAngle(i / 3, anchorAngleHandle.angle - handleRotOffset);
                        }
                    }
                }
                else
                {
                    handlePosition = Handles.DoPositionHandle(handlePosition, Quaternion.identity);
                }
            }

            switch (handleInputType)
            {
            case PathHandle.HandleInputType.LMBDrag:
                draggingHandleIndex             = i;
                handleIndexToDisplayAsTransform = -1;
                Repaint();
                break;

            case PathHandle.HandleInputType.LMBRelease:
                draggingHandleIndex             = -1;
                handleIndexToDisplayAsTransform = -1;
                Repaint();
                break;

            case PathHandle.HandleInputType.LMBClick:
                if (Event.current.shift)
                {
                    handleIndexToDisplayAsTransform = -1;     // disable move tool if new point added
                }
                else
                {
                    if (handleIndexToDisplayAsTransform == i)
                    {
                        handleIndexToDisplayAsTransform = -1;     // disable move tool if clicking on point under move tool
                    }
                    else
                    {
                        handleIndexToDisplayAsTransform = i;
                    }
                }
                Repaint();
                break;

            case PathHandle.HandleInputType.LMBPress:
                if (handleIndexToDisplayAsTransform != i)
                {
                    handleIndexToDisplayAsTransform = -1;
                    Repaint();
                }
                break;
            }

            if (bezierPath[i] != handlePosition)
            {
                Undo.RecordObject(creator, "Move point");
                bezierPath.MovePoint(i, handlePosition);

                // If the use is holding alt, try and mirror the control point.
                if (Event.current.modifiers == EventModifiers.Alt)
                {
                    // 0 = Anchor, 1 = Left Control, 2 = Right Control
                    var pointType = i % 3;

                    // If we are selecting a control point
                    if (pointType != 0)
                    {
                        // If we are selecting the left control point
                        if (pointType == 2)
                        {
                            // If the path doesn't loop and the user is selecting the last control point there isn't a control point to mirror
                            if (i < bezierPath.NumPoints - 2 && !bezierPath.IsClosed)
                            {
                                return;
                            }
                            // Get the index of this control's anchor.
                            var anchorIndex = (i + 1) % bezierPath.NumPoints;
                            var anchorPoint = bezierPath[anchorIndex];
                            // Get the index of the anchors other control.
                            // We don't have to loop this index b/c if it's the last control, it's anchors index will be 1.
                            var otherControlPointIndex = anchorIndex + 1;
                            // Move the other control point to the opposite of the selected control point's position relative to it's anchor.
                            bezierPath.MovePoint(otherControlPointIndex, anchorPoint - (handlePosition - anchorPoint));
                        }
                        // If we are selecting the right control point
                        else if (pointType == 1)
                        {
                            // If the path doesn't loop and the user is selecting the first control point there isn't a control point to mirror.
                            if (i > 1 && !bezierPath.IsClosed)
                            {
                                return;
                            }
                            // Get the index of this control's anchor.
                            var anchorIndex = i - 1;
                            var anchorPoint = bezierPath[anchorIndex];
                            // Get the index of the anchors other control.
                            var otherControlPointIndex = anchorIndex - 1;
                            // Make sure to loop this index back around if it is < 1.
                            if (otherControlPointIndex < 0)
                            {
                                otherControlPointIndex = bezierPath.NumPoints - Mathf.Abs(otherControlPointIndex);
                            }
                            // Move the other control point to the opposite of the selected control point's position relative to it's anchor.
                            bezierPath.MovePoint(otherControlPointIndex, anchorPoint - (handlePosition - anchorPoint));
                        }
                    }
                }
            }
        }