ConeFrustrumHandle() static private method

static private ConeFrustrumHandle ( Quaternion rotation, Vector3 position, Vector3 radiusAngleRange ) : Vector3
rotation UnityEngine.Quaternion
position Vector3
radiusAngleRange Vector3
return Vector3
示例#1
0
        public override void OnSceneGUI(ParticleSystem s, InitialModuleUI initial)
        {
            Color color = Handles.color;

            Handles.color = ShapeModuleUI.s_ShapeGizmoColor;
            Matrix4x4 matrix   = Handles.matrix;
            Matrix4x4 matrix4x = default(Matrix4x4);

            matrix4x.SetTRS(s.transform.position, s.transform.rotation, s.transform.lossyScale);
            Handles.matrix = matrix4x;
            EditorGUI.BeginChangeCheck();
            int intValue = this.m_Type.intValue;

            if (intValue == 0 || intValue == 1)
            {
                this.m_Radius.floatValue = Handles.DoSimpleRadiusHandle(Quaternion.identity, Vector3.zero, this.m_Radius.floatValue, false);
            }
            if (intValue == 10 || intValue == 11)
            {
                float floatValue  = this.m_Radius.floatValue;
                float floatValue2 = this.m_Arc.floatValue;
                Handles.DoSimpleRadiusArcHandleXY(Quaternion.identity, Vector3.zero, ref floatValue, ref floatValue2);
                this.m_Radius.floatValue = floatValue;
                this.m_Arc.floatValue    = floatValue2;
            }
            else if (intValue == 2 || intValue == 3)
            {
                this.m_Radius.floatValue = Handles.DoSimpleRadiusHandle(Quaternion.identity, Vector3.zero, this.m_Radius.floatValue, true);
            }
            else if (intValue == 4 || intValue == 7)
            {
                Vector3 radiusAngleRange = new Vector3(this.m_Radius.floatValue, this.m_Angle.floatValue, initial.m_Speed.scalar.floatValue);
                radiusAngleRange                  = Handles.ConeFrustrumHandle(Quaternion.identity, Vector3.zero, radiusAngleRange);
                this.m_Radius.floatValue          = radiusAngleRange.x;
                this.m_Angle.floatValue           = radiusAngleRange.y;
                initial.m_Speed.scalar.floatValue = radiusAngleRange.z;
            }
            else if (intValue == 8 || intValue == 9)
            {
                Vector3 radiusAngleRange2 = new Vector3(this.m_Radius.floatValue, this.m_Angle.floatValue, this.m_Length.floatValue);
                radiusAngleRange2        = Handles.ConeFrustrumHandle(Quaternion.identity, Vector3.zero, radiusAngleRange2);
                this.m_Radius.floatValue = radiusAngleRange2.x;
                this.m_Angle.floatValue  = radiusAngleRange2.y;
                this.m_Length.floatValue = radiusAngleRange2.z;
            }
            else if (intValue == 5)
            {
                Vector3 zero   = Vector3.zero;
                Vector3 vector = new Vector3(this.m_BoxX.floatValue, this.m_BoxY.floatValue, this.m_BoxZ.floatValue);
                if (this.m_BoxEditor.OnSceneGUI(matrix4x, ShapeModuleUI.s_ShapeGizmoColor, false, ref zero, ref vector))
                {
                    this.m_BoxX.floatValue = vector.x;
                    this.m_BoxY.floatValue = vector.y;
                    this.m_BoxZ.floatValue = vector.z;
                }
            }
            else if (intValue == 12)
            {
                this.m_Radius.floatValue = Handles.DoSimpleEdgeHandle(Quaternion.identity, Vector3.zero, this.m_Radius.floatValue);
            }
            else if (intValue == 6)
            {
                Mesh mesh = (Mesh)this.m_Mesh.objectReferenceValue;
                if (mesh)
                {
                    bool wireframe = GL.wireframe;
                    GL.wireframe = true;
                    this.m_Material.SetPass(0);
                    Graphics.DrawMeshNow(mesh, s.transform.localToWorldMatrix);
                    GL.wireframe = wireframe;
                }
            }
            if (EditorGUI.EndChangeCheck())
            {
                this.m_ParticleSystemUI.m_ParticleEffectUI.m_Owner.Repaint();
            }
            Handles.color  = color;
            Handles.matrix = matrix;
        }
        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;
        }
        public override void OnSceneGUI(ParticleSystem system, InitialModuleUI initial)
        {
            Color color = Handles.color;

            Handles.color = s_ShapeGizmoColor;
            Matrix4x4 matrix = Handles.matrix;

            EditorGUI.BeginChangeCheck();
            int       intValue  = this.m_Type.intValue;
            Matrix4x4 transform = new Matrix4x4();
            float     x         = (intValue != 6) ? 1f : this.m_MeshScale.floatValue;

            if (system.main.scalingMode == ParticleSystemScalingMode.Local)
            {
                transform.SetTRS(system.transform.position, system.transform.rotation, (Vector3)(system.transform.localScale * x));
            }
            else if (system.main.scalingMode == ParticleSystemScalingMode.Hierarchy)
            {
                transform = system.transform.localToWorldMatrix * Matrix4x4.Scale(new Vector3(x, x, x));
            }
            else
            {
                transform.SetTRS(system.transform.position, system.transform.rotation, (Vector3)(system.transform.lossyScale * x));
            }
            Handles.matrix = transform;
            switch (intValue)
            {
            case 0:
            case 1:
                this.m_Radius.floatValue = Handles.DoSimpleRadiusHandle(Quaternion.identity, Vector3.zero, this.m_Radius.floatValue, false);
                break;
            }
            if ((intValue == 10) || (intValue == 11))
            {
                float floatValue = this.m_Radius.floatValue;
                float arc        = this.m_Arc.floatValue;
                Handles.DoSimpleRadiusArcHandleXY(Quaternion.identity, Vector3.zero, ref floatValue, ref arc);
                this.m_Radius.floatValue = floatValue;
                this.m_Arc.floatValue    = arc;
            }
            else if ((intValue == 2) || (intValue == 3))
            {
                this.m_Radius.floatValue = Handles.DoSimpleRadiusHandle(Quaternion.identity, Vector3.zero, this.m_Radius.floatValue, true);
            }
            else if ((intValue == 4) || (intValue == 7))
            {
                Vector3 radiusAngleRange = new Vector3(this.m_Radius.floatValue, this.m_Angle.floatValue, initial.m_Speed.scalar.floatValue);
                radiusAngleRange                  = Handles.ConeFrustrumHandle(Quaternion.identity, Vector3.zero, radiusAngleRange);
                this.m_Radius.floatValue          = radiusAngleRange.x;
                this.m_Angle.floatValue           = radiusAngleRange.y;
                initial.m_Speed.scalar.floatValue = radiusAngleRange.z;
            }
            else if ((intValue == 8) || (intValue == 9))
            {
                Vector3 vector2 = new Vector3(this.m_Radius.floatValue, this.m_Angle.floatValue, this.m_Length.floatValue);
                vector2 = Handles.ConeFrustrumHandle(Quaternion.identity, Vector3.zero, vector2);
                this.m_Radius.floatValue = vector2.x;
                this.m_Angle.floatValue  = vector2.y;
                this.m_Length.floatValue = vector2.z;
            }
            else if (((intValue == 5) || (intValue == 15)) || (intValue == 0x10))
            {
                Vector3 zero = Vector3.zero;
                Vector3 size = new Vector3(this.m_BoxX.floatValue, this.m_BoxY.floatValue, this.m_BoxZ.floatValue);
                if (this.m_BoxEditor.OnSceneGUI(transform, s_ShapeGizmoColor, false, ref zero, ref size))
                {
                    this.m_BoxX.floatValue = size.x;
                    this.m_BoxY.floatValue = size.y;
                    this.m_BoxZ.floatValue = size.z;
                }
            }
            else if (intValue == 12)
            {
                this.m_Radius.floatValue = Handles.DoSimpleEdgeHandle(Quaternion.identity, Vector3.zero, this.m_Radius.floatValue);
            }
            else if (intValue == 6)
            {
                Mesh objectReferenceValue = (Mesh)this.m_Mesh.objectReferenceValue;
                if (objectReferenceValue != null)
                {
                    bool wireframe = GL.wireframe;
                    GL.wireframe = true;
                    this.m_Material.SetPass(0);
                    Graphics.DrawMeshNow(objectReferenceValue, transform);
                    GL.wireframe = wireframe;
                }
            }
            if (EditorGUI.EndChangeCheck())
            {
                base.m_ParticleSystemUI.m_ParticleEffectUI.m_Owner.Repaint();
            }
            Handles.color  = color;
            Handles.matrix = matrix;
        }
示例#4
0
        public override void OnSceneViewGUI()
        {
            Color color = Handles.color;

            Handles.color = ShapeModuleUI.s_ShapeGizmoColor;
            Matrix4x4 matrix = Handles.matrix;

            EditorGUI.BeginChangeCheck();
            ParticleSystem[] particleSystems = this.m_ParticleSystemUI.m_ParticleSystems;
            for (int i = 0; i < particleSystems.Length; i++)
            {
                ParticleSystem             particleSystem = particleSystems[i];
                ParticleSystem.ShapeModule shape          = particleSystem.shape;
                ParticleSystem.MainModule  main           = particleSystem.main;
                ParticleSystemShapeType    shapeType      = shape.shapeType;
                Matrix4x4 matrix4x = default(Matrix4x4);
                if (main.scalingMode == ParticleSystemScalingMode.Local)
                {
                    matrix4x.SetTRS(particleSystem.transform.position, particleSystem.transform.rotation, particleSystem.transform.localScale);
                }
                else if (main.scalingMode == ParticleSystemScalingMode.Hierarchy)
                {
                    matrix4x = particleSystem.transform.localToWorldMatrix;
                }
                else
                {
                    matrix4x.SetTRS(particleSystem.transform.position, particleSystem.transform.rotation, particleSystem.transform.lossyScale);
                }
                bool      flag = shapeType == ParticleSystemShapeType.Box || shapeType == ParticleSystemShapeType.BoxShell || shapeType == ParticleSystemShapeType.BoxEdge || shapeType == ParticleSystemShapeType.Rectangle;
                Vector3   s    = (!flag) ? shape.scale : Vector3.one;
                Matrix4x4 rhs  = Matrix4x4.TRS(shape.position, Quaternion.Euler(shape.rotation), s);
                matrix4x      *= rhs;
                Handles.matrix = matrix4x;
                if (shapeType == ParticleSystemShapeType.Sphere)
                {
                    EditorGUI.BeginChangeCheck();
                    float radius = Handles.DoSimpleRadiusHandle(Quaternion.identity, Vector3.zero, shape.radius, false);
                    if (EditorGUI.EndChangeCheck())
                    {
                        Undo.RecordObject(particleSystem, "Sphere Handle Change");
                        shape.radius = radius;
                    }
                    Matrix4x4 transform = matrix4x * Matrix4x4.TRS(Vector3.zero, Quaternion.identity, Vector3.one * shape.radius * 2f);
                    this.OnSceneViewTextureGUI(shape, ShapeModuleUI.s_SphereMesh, false, ShapeModuleUI.s_SphereTextureMaterial, transform);
                }
                else if (shapeType == ParticleSystemShapeType.Circle)
                {
                    EditorGUI.BeginChangeCheck();
                    this.m_ArcHandle.radius = shape.radius;
                    this.m_ArcHandle.angle  = shape.arc;
                    this.m_ArcHandle.SetColorWithRadiusHandle(Color.white, 0f);
                    using (new Handles.DrawingScope(Handles.matrix * ShapeModuleUI.s_ArcHandleOffsetMatrix))
                    {
                        this.m_ArcHandle.DrawHandle();
                    }
                    if (EditorGUI.EndChangeCheck())
                    {
                        Undo.RecordObject(particleSystem, "Circle Handle Change");
                        shape.radius = this.m_ArcHandle.radius;
                        shape.arc    = this.m_ArcHandle.angle;
                    }
                    Matrix4x4 transform2 = matrix4x * Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(90f, 0f, 180f), Vector3.one * shape.radius * 2f);
                    this.OnSceneViewTextureGUI(shape, ShapeModuleUI.s_CircleMesh, true, ShapeModuleUI.s_TextureMaterial, transform2);
                }
                else if (shapeType == ParticleSystemShapeType.Hemisphere)
                {
                    EditorGUI.BeginChangeCheck();
                    float radius2 = Handles.DoSimpleRadiusHandle(Quaternion.identity, Vector3.zero, shape.radius, true);
                    if (EditorGUI.EndChangeCheck())
                    {
                        Undo.RecordObject(particleSystem, "Hemisphere Handle Change");
                        shape.radius = radius2;
                    }
                    Matrix4x4 transform3 = matrix4x * Matrix4x4.TRS(Vector3.zero, Quaternion.identity, Vector3.one * shape.radius * 2f);
                    this.OnSceneViewTextureGUI(shape, ShapeModuleUI.s_HemisphereMesh, false, ShapeModuleUI.s_SphereTextureMaterial, transform3);
                }
                else if (shapeType == ParticleSystemShapeType.Cone)
                {
                    EditorGUI.BeginChangeCheck();
                    Vector3 radiusAngleRange = new Vector3(shape.radius, shape.angle, main.startSpeedMultiplier);
                    radiusAngleRange = Handles.ConeFrustrumHandle(Quaternion.identity, Vector3.zero, radiusAngleRange);
                    if (EditorGUI.EndChangeCheck())
                    {
                        Undo.RecordObject(particleSystem, "Cone Handle Change");
                        shape.radius = radiusAngleRange.x;
                        shape.angle  = radiusAngleRange.y;
                        main.startSpeedMultiplier = radiusAngleRange.z;
                    }
                    Matrix4x4 transform4 = matrix4x * Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(90f, 0f, 180f), Vector3.one * shape.radius * 2f);
                    this.OnSceneViewTextureGUI(shape, ShapeModuleUI.s_CircleMesh, true, ShapeModuleUI.s_TextureMaterial, transform4);
                }
                else if (shapeType == ParticleSystemShapeType.ConeVolume)
                {
                    EditorGUI.BeginChangeCheck();
                    Vector3 radiusAngleRange2 = new Vector3(shape.radius, shape.angle, shape.length);
                    radiusAngleRange2 = Handles.ConeFrustrumHandle(Quaternion.identity, Vector3.zero, radiusAngleRange2);
                    if (EditorGUI.EndChangeCheck())
                    {
                        Undo.RecordObject(particleSystem, "Cone Volume Handle Change");
                        shape.radius = radiusAngleRange2.x;
                        shape.angle  = radiusAngleRange2.y;
                        shape.length = radiusAngleRange2.z;
                    }
                    Matrix4x4 transform5 = matrix4x * Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(90f, 0f, 180f), Vector3.one * shape.radius * 2f);
                    this.OnSceneViewTextureGUI(shape, ShapeModuleUI.s_CircleMesh, true, ShapeModuleUI.s_TextureMaterial, transform5);
                }
                else if (shapeType == ParticleSystemShapeType.Box || shapeType == ParticleSystemShapeType.BoxShell || shapeType == ParticleSystemShapeType.BoxEdge)
                {
                    EditorGUI.BeginChangeCheck();
                    this.m_BoxBoundsHandle.center = Vector3.zero;
                    this.m_BoxBoundsHandle.size   = shape.scale;
                    this.m_BoxBoundsHandle.DrawHandle();
                    if (EditorGUI.EndChangeCheck())
                    {
                        Undo.RecordObject(particleSystem, "Box Handle Change");
                        shape.scale = this.m_BoxBoundsHandle.size;
                    }
                    Matrix4x4 transform6 = matrix4x * Matrix4x4.TRS(new Vector3(0f, 0f, -this.m_BoxBoundsHandle.size.z * 0.5f), Quaternion.identity, this.m_BoxBoundsHandle.size);
                    this.OnSceneViewTextureGUI(shape, ShapeModuleUI.s_QuadMesh, true, ShapeModuleUI.s_TextureMaterial, transform6);
                }
                else if (shapeType == ParticleSystemShapeType.Donut)
                {
                    EditorGUI.BeginChangeCheck();
                    this.m_ArcHandle.radius = shape.radius;
                    this.m_ArcHandle.angle  = shape.arc;
                    this.m_ArcHandle.SetColorWithRadiusHandle(Color.white, 0f);
                    this.m_ArcHandle.wireframeColor = Color.clear;
                    using (new Handles.DrawingScope(Handles.matrix * ShapeModuleUI.s_ArcHandleOffsetMatrix))
                    {
                        this.m_ArcHandle.DrawHandle();
                    }
                    if (EditorGUI.EndChangeCheck())
                    {
                        Undo.RecordObject(particleSystem, "Donut Handle Change");
                        shape.radius = this.m_ArcHandle.radius;
                        shape.arc    = this.m_ArcHandle.angle;
                    }
                    using (new Handles.DrawingScope(Handles.matrix * ShapeModuleUI.s_ArcHandleOffsetMatrix))
                    {
                        float num   = shape.arc % 360f;
                        float angle = (Mathf.Abs(shape.arc) < 360f) ? num : 360f;
                        Handles.DrawWireArc(new Vector3(0f, shape.donutRadius, 0f), Vector3.up, Vector3.forward, angle, shape.radius);
                        Handles.DrawWireArc(new Vector3(0f, -shape.donutRadius, 0f), Vector3.up, Vector3.forward, angle, shape.radius);
                        Handles.DrawWireArc(Vector3.zero, Vector3.up, Vector3.forward, angle, shape.radius + shape.donutRadius);
                        Handles.DrawWireArc(Vector3.zero, Vector3.up, Vector3.forward, angle, shape.radius - shape.donutRadius);
                        if (shape.arc != 360f)
                        {
                            Quaternion rotation = Quaternion.AngleAxis(shape.arc, Vector3.up);
                            Vector3    center   = rotation * Vector3.forward * shape.radius;
                            Handles.DrawWireDisc(center, rotation * Vector3.right, shape.donutRadius);
                        }
                    }
                    this.m_SphereBoundsHandle.axes   = (PrimitiveBoundsHandle.Axes.X | PrimitiveBoundsHandle.Axes.Y);
                    this.m_SphereBoundsHandle.radius = shape.donutRadius;
                    this.m_SphereBoundsHandle.center = Vector3.zero;
                    this.m_SphereBoundsHandle.SetColor(Color.white);
                    float     num2 = 90f;
                    int       num3 = Mathf.Max(1, (int)Mathf.Ceil(shape.arc / num2));
                    Matrix4x4 rhs2 = Matrix4x4.TRS(new Vector3(shape.radius, 0f, 0f), Quaternion.Euler(90f, 0f, 0f), Vector3.one);
                    for (int j = 0; j < num3; j++)
                    {
                        EditorGUI.BeginChangeCheck();
                        using (new Handles.DrawingScope(Handles.matrix * (Matrix4x4.Rotate(Quaternion.Euler(0f, 0f, num2 * (float)j)) * rhs2)))
                        {
                            this.m_SphereBoundsHandle.DrawHandle();
                        }
                        if (EditorGUI.EndChangeCheck())
                        {
                            Undo.RecordObject(particleSystem, "Donut Radius Handle Change");
                            shape.donutRadius = this.m_SphereBoundsHandle.radius;
                        }
                    }
                    Matrix4x4 transform7 = matrix4x * Matrix4x4.TRS(new Vector3(shape.radius, 0f, 0f), Quaternion.Euler(180f, 0f, 180f), Vector3.one * shape.donutRadius * 2f);
                    this.OnSceneViewTextureGUI(shape, ShapeModuleUI.s_CircleMesh, true, ShapeModuleUI.s_TextureMaterial, transform7);
                }
                else if (shapeType == ParticleSystemShapeType.SingleSidedEdge)
                {
                    EditorGUI.BeginChangeCheck();
                    float radius3 = Handles.DoSimpleEdgeHandle(Quaternion.identity, Vector3.zero, shape.radius);
                    if (EditorGUI.EndChangeCheck())
                    {
                        Undo.RecordObject(particleSystem, "Edge Handle Change");
                        shape.radius = radius3;
                    }
                }
                else if (shapeType == ParticleSystemShapeType.Mesh)
                {
                    Mesh mesh = shape.mesh;
                    if (mesh)
                    {
                        bool wireframe = GL.wireframe;
                        GL.wireframe = true;
                        ShapeModuleUI.s_Material.SetPass(0);
                        Graphics.DrawMeshNow(mesh, matrix4x);
                        GL.wireframe = wireframe;
                        this.OnSceneViewTextureGUI(shape, mesh, false, ShapeModuleUI.s_TextureMaterial, matrix4x);
                    }
                }
                else if (shapeType == ParticleSystemShapeType.Rectangle)
                {
                    EditorGUI.BeginChangeCheck();
                    this.m_BoxBoundsHandle.center = Vector3.zero;
                    this.m_BoxBoundsHandle.size   = new Vector3(shape.scale.x, shape.scale.y, 0f);
                    this.m_BoxBoundsHandle.DrawHandle();
                    if (EditorGUI.EndChangeCheck())
                    {
                        Undo.RecordObject(particleSystem, "Rectangle Handle Change");
                        shape.scale = new Vector3(this.m_BoxBoundsHandle.size.x, this.m_BoxBoundsHandle.size.y, 0f);
                    }
                    this.OnSceneViewTextureGUI(shape, ShapeModuleUI.s_QuadMesh, true, ShapeModuleUI.s_TextureMaterial, matrix4x * Matrix4x4.Scale(this.m_BoxBoundsHandle.size));
                }
            }
            if (EditorGUI.EndChangeCheck())
            {
                this.m_ParticleSystemUI.m_ParticleEffectUI.m_Owner.Repaint();
            }
            Handles.color  = color;
            Handles.matrix = matrix;
        }
示例#5
0
        public override void OnSceneViewGUI()
        {
            Color color = Handles.color;

            Handles.color = ShapeModuleUI.s_ShapeGizmoColor;
            Matrix4x4 matrix = Handles.matrix;

            EditorGUI.BeginChangeCheck();
            ParticleSystem[] particleSystems = this.m_ParticleSystemUI.m_ParticleSystems;
            for (int i = 0; i < particleSystems.Length; i++)
            {
                ParticleSystem             particleSystem = particleSystems[i];
                ParticleSystem.ShapeModule shape          = particleSystem.shape;
                ParticleSystem.MainModule  main           = particleSystem.main;
                ParticleSystemShapeType    shapeType      = shape.shapeType;
                Matrix4x4 matrix2 = default(Matrix4x4);
                float     num     = (shapeType != ParticleSystemShapeType.Mesh) ? 1f : shape.meshScale;
                if (main.scalingMode == ParticleSystemScalingMode.Local)
                {
                    matrix2.SetTRS(particleSystem.transform.position, particleSystem.transform.rotation, particleSystem.transform.localScale * num);
                }
                else if (main.scalingMode == ParticleSystemScalingMode.Hierarchy)
                {
                    matrix2 = particleSystem.transform.localToWorldMatrix * Matrix4x4.Scale(new Vector3(num, num, num));
                }
                else
                {
                    matrix2.SetTRS(particleSystem.transform.position, particleSystem.transform.rotation, particleSystem.transform.lossyScale * num);
                }
                Handles.matrix = matrix2;
                if (shapeType == ParticleSystemShapeType.Sphere || shapeType == ParticleSystemShapeType.SphereShell)
                {
                    EditorGUI.BeginChangeCheck();
                    float radius = Handles.DoSimpleRadiusHandle(Quaternion.identity, Vector3.zero, shape.radius, false);
                    if (EditorGUI.EndChangeCheck())
                    {
                        Undo.RecordObject(particleSystem, "Sphere Handle Change");
                        shape.radius = radius;
                    }
                }
                else if (shapeType == ParticleSystemShapeType.Circle || shapeType == ParticleSystemShapeType.CircleEdge)
                {
                    EditorGUI.BeginChangeCheck();
                    float radius2 = shape.radius;
                    float arc     = shape.arc;
                    Handles.DoSimpleRadiusArcHandleXY(Quaternion.identity, Vector3.zero, ref radius2, ref arc);
                    if (EditorGUI.EndChangeCheck())
                    {
                        Undo.RecordObject(particleSystem, "Circle Handle Change");
                        shape.radius = radius2;
                        shape.arc    = arc;
                    }
                }
                else if (shapeType == ParticleSystemShapeType.Hemisphere || shapeType == ParticleSystemShapeType.HemisphereShell)
                {
                    EditorGUI.BeginChangeCheck();
                    float radius3 = Handles.DoSimpleRadiusHandle(Quaternion.identity, Vector3.zero, shape.radius, true);
                    if (EditorGUI.EndChangeCheck())
                    {
                        Undo.RecordObject(particleSystem, "Hemisphere Handle Change");
                        shape.radius = radius3;
                    }
                }
                else if (shapeType == ParticleSystemShapeType.Cone || shapeType == ParticleSystemShapeType.ConeShell)
                {
                    EditorGUI.BeginChangeCheck();
                    Vector3 radiusAngleRange = new Vector3(shape.radius, shape.angle, main.startSpeedMultiplier);
                    radiusAngleRange = Handles.ConeFrustrumHandle(Quaternion.identity, Vector3.zero, radiusAngleRange);
                    if (EditorGUI.EndChangeCheck())
                    {
                        Undo.RecordObject(particleSystem, "Cone Handle Change");
                        shape.radius = radiusAngleRange.x;
                        shape.angle  = radiusAngleRange.y;
                        main.startSpeedMultiplier = radiusAngleRange.z;
                    }
                }
                else if (shapeType == ParticleSystemShapeType.ConeVolume || shapeType == ParticleSystemShapeType.ConeVolumeShell)
                {
                    EditorGUI.BeginChangeCheck();
                    Vector3 radiusAngleRange2 = new Vector3(shape.radius, shape.angle, shape.length);
                    radiusAngleRange2 = Handles.ConeFrustrumHandle(Quaternion.identity, Vector3.zero, radiusAngleRange2);
                    if (EditorGUI.EndChangeCheck())
                    {
                        Undo.RecordObject(particleSystem, "Cone Volume Handle Change");
                        shape.radius = radiusAngleRange2.x;
                        shape.angle  = radiusAngleRange2.y;
                        shape.length = radiusAngleRange2.z;
                    }
                }
                else if (shapeType == ParticleSystemShapeType.Box || shapeType == ParticleSystemShapeType.BoxShell || shapeType == ParticleSystemShapeType.BoxEdge)
                {
                    EditorGUI.BeginChangeCheck();
                    this.m_BoxBoundsHandle.center = Vector3.zero;
                    this.m_BoxBoundsHandle.size   = shape.box;
                    this.m_BoxBoundsHandle.DrawHandle();
                    if (EditorGUI.EndChangeCheck())
                    {
                        Undo.RecordObject(particleSystem, "Box Handle Change");
                        shape.box = this.m_BoxBoundsHandle.size;
                    }
                }
                else if (shapeType == ParticleSystemShapeType.SingleSidedEdge)
                {
                    EditorGUI.BeginChangeCheck();
                    float radius4 = Handles.DoSimpleEdgeHandle(Quaternion.identity, Vector3.zero, shape.radius);
                    if (EditorGUI.EndChangeCheck())
                    {
                        Undo.RecordObject(particleSystem, "Edge Handle Change");
                        shape.radius = radius4;
                    }
                }
                else if (shapeType == ParticleSystemShapeType.Mesh)
                {
                    Mesh mesh = shape.mesh;
                    if (mesh)
                    {
                        bool wireframe = GL.wireframe;
                        GL.wireframe = true;
                        this.m_Material.SetPass(0);
                        Graphics.DrawMeshNow(mesh, matrix2);
                        GL.wireframe = wireframe;
                    }
                }
            }
            if (EditorGUI.EndChangeCheck())
            {
                this.m_ParticleSystemUI.m_ParticleEffectUI.m_Owner.Repaint();
            }
            Handles.color  = color;
            Handles.matrix = matrix;
        }