Example #1
0
        void PlayParticleEffect(ParticleSystemShapeType shape, Vector3 scale, Vector3 position)
        {
            if (m_ParticleSystem)
            {
                var shapeModule = m_ParticleSystem.shape;
                shapeModule.shapeType = shape;

                int burstParticleCount;
                // Scale particle burst with volume or area depending on shape parameter.
                if (shape == ParticleSystemShapeType.Box)
                {
                    m_ParticleSystem.transform.rotation = Quaternion.identity;
                    shapeModule.scale = scale;

                    var volume = scale.x * scale.y * scale.z;
                    burstParticleCount = Mathf.RoundToInt(Mathf.Clamp(k_ParticleBurstPerModuleVolume * volume / LEGOModuleVolume, k_MinParticleBurst, k_MaxParticleBurst));
                }
                else
                {
                    // Rectangle - we need to rotate it to make it match the bottom of the bounds.
                    m_ParticleSystem.transform.rotation = Quaternion.Euler(-90f, 0f, 0f);
                    shapeModule.scale = Quaternion.Euler(90f, 0f, 0f) * scale;

                    var area = scale.x * scale.z;
                    burstParticleCount = Mathf.RoundToInt(Mathf.Clamp(k_ParticleBurstPerModuleArea * area / (LEGOHorizontalModule * LEGOHorizontalModule), k_MinParticleBurst, k_MaxParticleBurst));
                }

                m_ParticleSystem.transform.position = position;
                m_ParticleSystem.Emit(burstParticleCount);
            }
        }
        override public void UpdateCullingSupportedString(ref string text)
        {
            Init();

            bool animatedShape = false;
            ParticleSystemShapeType shapeType = (ParticleSystemShapeType)m_Type.intValue;

            switch (shapeType)
            {
            case ParticleSystemShapeType.Cone:
            case ParticleSystemShapeType.ConeVolume:
            case ParticleSystemShapeType.Donut:
            case ParticleSystemShapeType.Circle:
                animatedShape = (m_Arc.m_Mode.intValue != (int)MultiModeParameter.ValueMode.Random);
                break;

            case ParticleSystemShapeType.SingleSidedEdge:
                animatedShape = (m_Radius.m_Mode.intValue != (int)MultiModeParameter.ValueMode.Random);
                break;

            default:
                break;
            }

            if (animatedShape)
            {
                text += "\n\tAnimated shape emission is enabled.";
            }
        }
 public void setupEmitter(ParticleSystemShapeType SystemShape, Vector3 SystemScale)
 {
     var shape = system.shape;
     shape.enabled = true;
     shape.shapeType = SystemShape;
     shape.scale = SystemScale;
     //sets up the emession burst at 0 seconds to add sparks to first particle emmission.
 }
        public static bool IsBoxAny(this ParticleSystemShapeType _this)
        {
            switch (_this)
            {
            case ParticleSystemShapeType.Box:
            case ParticleSystemShapeType.BoxEdge:
            case ParticleSystemShapeType.BoxShell:
                return(true);

            default:
                return(false);
            }
        }
 protected override void ReadFromImpl(object obj)
 {
     base.ReadFromImpl(obj);
     ParticleSystem.ShapeModule uo = (ParticleSystem.ShapeModule)obj;
     enabled                  = uo.enabled;
     shapeType                = uo.shapeType;
     randomDirectionAmount    = uo.randomDirectionAmount;
     sphericalDirectionAmount = uo.sphericalDirectionAmount;
     randomPositionAmount     = uo.randomPositionAmount;
     alignToDirection         = uo.alignToDirection;
     radius                = uo.radius;
     radiusMode            = uo.radiusMode;
     radiusSpread          = uo.radiusSpread;
     radiusSpeed           = uo.radiusSpeed;
     radiusSpeedMultiplier = uo.radiusSpeedMultiplier;
     radiusThickness       = uo.radiusThickness;
     angle                = uo.angle;
     length               = uo.length;
     boxThickness         = uo.boxThickness;
     meshShapeType        = uo.meshShapeType;
     mesh                 = ToID(uo.mesh);
     meshRenderer         = ToID(uo.meshRenderer);
     skinnedMeshRenderer  = ToID(uo.skinnedMeshRenderer);
     sprite               = ToID(uo.sprite);
     spriteRenderer       = ToID(uo.spriteRenderer);
     useMeshMaterialIndex = uo.useMeshMaterialIndex;
     meshMaterialIndex    = uo.meshMaterialIndex;
     useMeshColors        = uo.useMeshColors;
     normalOffset         = uo.normalOffset;
     arc                          = uo.arc;
     arcMode                      = uo.arcMode;
     arcSpread                    = uo.arcSpread;
     arcSpeed                     = uo.arcSpeed;
     arcSpeedMultiplier           = uo.arcSpeedMultiplier;
     donutRadius                  = uo.donutRadius;
     position                     = uo.position;
     rotation                     = uo.rotation;
     scale                        = uo.scale;
     texture                      = ToID(uo.texture);
     textureClipChannel           = uo.textureClipChannel;
     textureClipThreshold         = uo.textureClipThreshold;
     textureColorAffectsParticles = uo.textureColorAffectsParticles;
     textureAlphaAffectsParticles = uo.textureAlphaAffectsParticles;
     textureBilinearFiltering     = uo.textureBilinearFiltering;
     textureUVChannel             = uo.textureUVChannel;
     meshSpawnMode                = uo.meshSpawnMode;
     meshSpawnSpread              = uo.meshSpawnSpread;
     meshSpawnSpeed               = uo.meshSpawnSpeed;
     meshSpawnSpeedMultiplier     = uo.meshSpawnSpeedMultiplier;
 }
Example #6
0
 public static void ParticleShapeSettings(this ParticleSystem PS,
                                          bool enabled = true,
                                          ParticleSystemShapeType ShapeType            = ParticleSystemShapeType.Cone,
                                          ParticleSystemShapeMultiModeValue RadiusMode = ParticleSystemShapeMultiModeValue.Loop,
                                          bool AlignDirection = false,
                                          float Angle         = 0f,
                                          float Arc           = 0f,
                                          float Radius        = 0f)
 {
     ParticleSystem.ShapeModule shapeModule = PS.shape;
     // Shape settings
     shapeModule.shapeType        = ShapeType;
     shapeModule.arcMode          = ParticleSystemShapeMultiModeValue.Loop;
     shapeModule.radiusMode       = RadiusMode;
     shapeModule.alignToDirection = AlignDirection;
     shapeModule.angle            = Angle;
     shapeModule.arc    = Arc;
     shapeModule.radius = Radius;
 }
Example #7
0
    //Particle shape
    ParticleSystemShapeType ParticleShape(byte value)
    {
        ParticleSystemShapeType shape = ParticleSystemShapeType.Cone;

        switch (value)
        {
        case 1:
            shape = ParticleSystemShapeType.Rectangle;
            break;

        case 2:
            shape = ParticleSystemShapeType.Sphere;
            break;

        case 3:
            shape = ParticleSystemShapeType.Circle;
            break;
        }
        return(shape);
    }
Example #8
0
    void DrawLine(Vector3 start, Vector3 end, Color color, float duration = 0.2f)
    {
        // To synch with the particle system
        transform.position = end;



        GameObject ps = gameObject;

        foreach (Transform child in transform)
        {
            if (child.name == "Particle System")
            {
                ps = child.gameObject;
                Debug.Log("FOUND");
            }
        }

        float middlePoint_x = (start.x + end.x) / 2;
        float middlePoint_y = (start.y + end.y) / 2;
        float middlePoint_z = (start.z + end.z) / 2;

        Vector3 middlePoint = new Vector3(end.z - start.z, start.x - end.x, start.y - end.y);

        //ps.transform.position = middlePoint;



        sc = ps.GetComponent <ParticleSystem>();

        Vector3 base_x = new Vector3(1, 0, 0);
        Vector3 base_y = new Vector3(0, 1, 0);
        Vector3 base_z = new Vector3(0, 0, 1);

        Vector3 direction = (end - start);

        Vector3 temp    = new Vector3(0, direction.y, direction.z);
        float   angle_x = Vector3.Angle(base_z, temp);

        float sign = +1;

        if (direction.z < 0)
        {
            sign = -1;
        }

        temp = new Vector3(0, direction.y, sign * direction.z);
        float angle_y = sign * Vector3.Angle(temp, base_z);

        temp = new Vector3(direction.x, 0, sign * direction.z);
        float angle_z = sign * Vector3.Angle(temp, base_z);

        //Debug.Log ("angle_x is " + angle_x);
        Debug.Log("angle_y is " + angle_y);
        Debug.Log("angle_z is " + angle_z);

        ps.transform.localRotation = Quaternion.Euler(0, angle_y, -angle_z);


        // Particle system properties
        ParticleSystemShapeType shapeType = ParticleSystemShapeType.SingleSidedEdge;
        var shape = sc.shape;

        shape.shapeType = shapeType;
        shape.radius    = (end - start).magnitude;

        var emission = sc.emission;

        emission.rateOverTime = 0f;

        var main = sc.main;

        //main.startSpeed = 0.1f;
        main.startSize = 0.1f;
        //main.startLifetime = 1.0f;



        Debug.Log("before coro ps.transform.position.x is " + ps.transform.position.x);

        GameObject myLine = new GameObject();

        myLine.transform.SetParent(transform);

        StartCoroutine(PlacePoints(myLine, color, start, end));

        Debug.Log("after coro ps.transform.position.x is " + ps.transform.position.x);

        //GameObject.Destroy(myLine, duration);
    }
        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;
        }
        override public void OnInspectorGUI(InitialModuleUI initial)
        {
            EditorGUI.showMixedValue = m_Type.hasMultipleDifferentValues;
            int type  = m_Type.intValue;
            int index = m_TypeToGuiTypeIndex[type];

            EditorGUI.BeginChangeCheck();
            int  index2           = GUIPopup(s_Texts.shape, index, s_Texts.shapeTypes, m_Type);
            bool shapeTypeChanged = EditorGUI.EndChangeCheck();

            EditorGUI.showMixedValue = false;

            ParticleSystemShapeType guiType = m_GuiTypes[index2];

            if (index2 != index)
            {
                type = (int)guiType;
            }

            if (!m_Type.hasMultipleDifferentValues)
            {
                switch (guiType)
                {
                case ParticleSystemShapeType.Box:
                {
                    int emitFrom = ConvertBoxTypeToBoxEmitFrom((ParticleSystemShapeType)type);
                    emitFrom = GUIPopup(s_Texts.emitFrom, emitFrom, s_Texts.boxTypes, m_Type);
                    type     = (int)ConvertBoxEmitFromToBoxType(emitFrom);

                    if (type == (int)ParticleSystemShapeType.BoxShell || type == (int)ParticleSystemShapeType.BoxEdge)
                    {
                        GUIVector3Field(s_Texts.boxThickness, m_BoxThickness);
                    }
                }
                break;

                case ParticleSystemShapeType.Cone:
                {
                    GUIFloat(s_Texts.coneAngle, m_Angle);
                    GUIFloat(s_Texts.radius, m_Radius.m_Value);
                    GUIFloat(s_Texts.radiusThickness, m_RadiusThickness);

                    m_Arc.OnInspectorGUI(s_ArcTexts);

                    bool showLength = (type != (int)ParticleSystemShapeType.ConeVolume);
                    using (new EditorGUI.DisabledScope(showLength))
                    {
                        GUIFloat(s_Texts.coneLength, m_Length);
                    }

                    int emitFrom = ConvertConeTypeToConeEmitFrom((ParticleSystemShapeType)type);
                    emitFrom = GUIPopup(s_Texts.emitFrom, emitFrom, s_Texts.coneTypes, m_Type);
                    type     = (int)ConvertConeEmitFromToConeType(emitFrom);
                }
                break;

                case ParticleSystemShapeType.Donut:
                {
                    GUIFloat(s_Texts.radius, m_Radius.m_Value);
                    GUIFloat(s_Texts.donutRadius, m_DonutRadius);
                    GUIFloat(s_Texts.radiusThickness, m_RadiusThickness);

                    m_Arc.OnInspectorGUI(s_ArcTexts);
                }
                break;

                case ParticleSystemShapeType.Mesh:
                case ParticleSystemShapeType.MeshRenderer:
                case ParticleSystemShapeType.SkinnedMeshRenderer:
                {
                    GUIPopup(s_Texts.meshType, m_PlacementMode, s_Texts.meshTypes);

                    Material material = null;
                    Mesh     srcMesh  = null;
                    if (guiType == ParticleSystemShapeType.Mesh)
                    {
                        GUIObject(s_Texts.mesh, m_Mesh);
                        srcMesh = (Mesh)m_Mesh.objectReferenceValue;
                    }
                    else if (guiType == ParticleSystemShapeType.MeshRenderer)
                    {
                        GUIObject(s_Texts.meshRenderer, m_MeshRenderer);
                        MeshRenderer mesh = (MeshRenderer)m_MeshRenderer.objectReferenceValue;
                        if (mesh)
                        {
                            material = mesh.sharedMaterial;
                            if (mesh.GetComponent <MeshFilter>())
                            {
                                srcMesh = mesh.GetComponent <MeshFilter>().sharedMesh;
                            }
                        }
                    }
                    else
                    {
                        GUIObject(s_Texts.skinnedMeshRenderer, m_SkinnedMeshRenderer);
                        SkinnedMeshRenderer mesh = (SkinnedMeshRenderer)m_SkinnedMeshRenderer.objectReferenceValue;
                        if (mesh)
                        {
                            material = mesh.sharedMaterial;
                            srcMesh  = mesh.sharedMesh;
                        }
                    }

                    GUIToggleWithIntField(s_Texts.meshMaterialIndex, m_UseMeshMaterialIndex, m_MeshMaterialIndex, false);
                    bool useMeshColors = GUIToggle(s_Texts.useMeshColors, m_UseMeshColors);
                    if (useMeshColors)
                    {
                        if (material != null && srcMesh != null)
                        {
                            int colorName     = Shader.PropertyToID("_Color");
                            int tintColorName = Shader.PropertyToID("_TintColor");
                            if (!material.HasProperty(colorName) && !material.HasProperty(tintColorName) && !srcMesh.HasChannel(Mesh.InternalShaderChannel.Color))
                            {
                                GUIContent warning = EditorGUIUtility.TrTextContent("To use mesh colors, your source mesh must either provide vertex colors, or its shader must contain a color property named \"_Color\" or \"_TintColor\".");
                                EditorGUILayout.HelpBox(warning.text, MessageType.Warning, true);
                            }
                        }
                    }

                    GUIFloat(s_Texts.meshNormalOffset, m_MeshNormalOffset);
                }
                break;

                case ParticleSystemShapeType.Sprite:
                case ParticleSystemShapeType.SpriteRenderer:
                {
                    GUIPopup(s_Texts.meshType, m_PlacementMode, s_Texts.meshTypes);

                    if (guiType == ParticleSystemShapeType.Sprite)
                    {
                        GUIObject(s_Texts.sprite, m_Sprite);
                    }
                    else if (guiType == ParticleSystemShapeType.SpriteRenderer)
                    {
                        GUIObject(s_Texts.spriteRenderer, m_SpriteRenderer);
                    }

                    GUIFloat(s_Texts.meshNormalOffset, m_MeshNormalOffset);
                }
                break;

                case ParticleSystemShapeType.Sphere:
                case ParticleSystemShapeType.Hemisphere:
                {
                    GUIFloat(s_Texts.radius, m_Radius.m_Value);
                    GUIFloat(s_Texts.radiusThickness, m_RadiusThickness);
                }
                break;

                case ParticleSystemShapeType.Circle:
                {
                    GUIFloat(s_Texts.radius, m_Radius.m_Value);
                    GUIFloat(s_Texts.radiusThickness, m_RadiusThickness);

                    m_Arc.OnInspectorGUI(s_ArcTexts);
                }
                break;

                case ParticleSystemShapeType.SingleSidedEdge:
                {
                    m_Radius.OnInspectorGUI(s_RadiusTexts);
                }
                break;

                case ParticleSystemShapeType.Rectangle:
                    break;
                }
            }

            if (shapeTypeChanged || !m_Type.hasMultipleDifferentValues)
            {
                m_Type.intValue = type;
            }

            OnTextureInspectorGUI();
            OnTransformInspectorGUI();
            OnMiscInspectorGUI();
        }
 private int ConvertBoxTypeToBoxEmitFrom(ParticleSystemShapeType shapeType)
 {
     return(System.Array.IndexOf(boxShapes, shapeType));
 }
 private int ConvertConeTypeToConeEmitFrom(ParticleSystemShapeType shapeType)
 {
     return(System.Array.IndexOf(coneShapes, shapeType));
 }
Example #13
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;
        }
Example #14
0
        public override void OnInspectorGUI(InitialModuleUI initial)
        {
            EditorGUI.showMixedValue = this.m_Type.hasMultipleDifferentValues;
            int num  = this.m_Type.intValue;
            int num2 = this.m_TypeToGuiTypeIndex[num];

            EditorGUI.BeginChangeCheck();
            int  num3 = ModuleUI.GUIPopup(ShapeModuleUI.s_Texts.shape, num2, ShapeModuleUI.s_Texts.shapeTypes, this.m_Type, new GUILayoutOption[0]);
            bool flag = EditorGUI.EndChangeCheck();

            EditorGUI.showMixedValue = false;
            ParticleSystemShapeType particleSystemShapeType = this.m_GuiTypes[num3];

            if (num3 != num2)
            {
                num = (int)particleSystemShapeType;
            }
            if (!this.m_Type.hasMultipleDifferentValues)
            {
                switch (particleSystemShapeType)
                {
                case ParticleSystemShapeType.Sphere:
                case ParticleSystemShapeType.Hemisphere:
                    ModuleUI.GUIFloat(ShapeModuleUI.s_Texts.radius, this.m_Radius.m_Value, new GUILayoutOption[0]);
                    ModuleUI.GUIFloat(ShapeModuleUI.s_Texts.radiusThickness, this.m_RadiusThickness, new GUILayoutOption[0]);
                    break;

                case ParticleSystemShapeType.Cone:
                {
                    ModuleUI.GUIFloat(ShapeModuleUI.s_Texts.coneAngle, this.m_Angle, new GUILayoutOption[0]);
                    ModuleUI.GUIFloat(ShapeModuleUI.s_Texts.radius, this.m_Radius.m_Value, new GUILayoutOption[0]);
                    ModuleUI.GUIFloat(ShapeModuleUI.s_Texts.radiusThickness, this.m_RadiusThickness, new GUILayoutOption[0]);
                    this.m_Arc.OnInspectorGUI(ShapeModuleUI.s_ArcTexts);
                    bool disabled = num != 8;
                    using (new EditorGUI.DisabledScope(disabled))
                    {
                        ModuleUI.GUIFloat(ShapeModuleUI.s_Texts.coneLength, this.m_Length, new GUILayoutOption[0]);
                    }
                    int num4 = this.ConvertConeTypeToConeEmitFrom((ParticleSystemShapeType)num);
                    num4 = ModuleUI.GUIPopup(ShapeModuleUI.s_Texts.emitFrom, num4, ShapeModuleUI.s_Texts.coneTypes, this.m_Type, new GUILayoutOption[0]);
                    num  = (int)this.ConvertConeEmitFromToConeType(num4);
                    break;
                }

                case ParticleSystemShapeType.Box:
                {
                    int num5 = this.ConvertBoxTypeToBoxEmitFrom((ParticleSystemShapeType)num);
                    num5 = ModuleUI.GUIPopup(ShapeModuleUI.s_Texts.emitFrom, num5, ShapeModuleUI.s_Texts.boxTypes, this.m_Type, new GUILayoutOption[0]);
                    num  = (int)this.ConvertBoxEmitFromToBoxType(num5);
                    if (num == 15 || num == 16)
                    {
                        ModuleUI.GUIVector3Field(ShapeModuleUI.s_Texts.boxThickness, this.m_BoxThickness, new GUILayoutOption[0]);
                    }
                    break;
                }

                case ParticleSystemShapeType.Mesh:
                case ParticleSystemShapeType.MeshRenderer:
                case ParticleSystemShapeType.SkinnedMeshRenderer:
                {
                    ModuleUI.GUIPopup(ShapeModuleUI.s_Texts.meshType, this.m_PlacementMode, ShapeModuleUI.s_Texts.meshTypes, new GUILayoutOption[0]);
                    Material material = null;
                    Mesh     mesh     = null;
                    if (particleSystemShapeType == ParticleSystemShapeType.Mesh)
                    {
                        ModuleUI.GUIObject(ShapeModuleUI.s_Texts.mesh, this.m_Mesh, new GUILayoutOption[0]);
                        mesh = (Mesh)this.m_Mesh.objectReferenceValue;
                    }
                    else if (particleSystemShapeType == ParticleSystemShapeType.MeshRenderer)
                    {
                        ModuleUI.GUIObject(ShapeModuleUI.s_Texts.meshRenderer, this.m_MeshRenderer, new GUILayoutOption[0]);
                        MeshRenderer meshRenderer = (MeshRenderer)this.m_MeshRenderer.objectReferenceValue;
                        if (meshRenderer)
                        {
                            material = meshRenderer.sharedMaterial;
                            if (meshRenderer.GetComponent <MeshFilter>())
                            {
                                mesh = meshRenderer.GetComponent <MeshFilter>().sharedMesh;
                            }
                        }
                    }
                    else
                    {
                        ModuleUI.GUIObject(ShapeModuleUI.s_Texts.skinnedMeshRenderer, this.m_SkinnedMeshRenderer, new GUILayoutOption[0]);
                        SkinnedMeshRenderer skinnedMeshRenderer = (SkinnedMeshRenderer)this.m_SkinnedMeshRenderer.objectReferenceValue;
                        if (skinnedMeshRenderer)
                        {
                            material = skinnedMeshRenderer.sharedMaterial;
                            mesh     = skinnedMeshRenderer.sharedMesh;
                        }
                    }
                    ModuleUI.GUIToggleWithIntField(ShapeModuleUI.s_Texts.meshMaterialIndex, this.m_UseMeshMaterialIndex, this.m_MeshMaterialIndex, false, new GUILayoutOption[0]);
                    bool flag2 = ModuleUI.GUIToggle(ShapeModuleUI.s_Texts.useMeshColors, this.m_UseMeshColors, new GUILayoutOption[0]);
                    if (flag2)
                    {
                        if (material != null && mesh != null)
                        {
                            int name  = Shader.PropertyToID("_Color");
                            int name2 = Shader.PropertyToID("_TintColor");
                            if (!material.HasProperty(name) && !material.HasProperty(name2) && !mesh.HasChannel(Mesh.InternalShaderChannel.Color))
                            {
                                GUIContent gUIContent = EditorGUIUtility.TrTextContent("To use mesh colors, your source mesh must either provide vertex colors, or its shader must contain a color property named \"_Color\" or \"_TintColor\".", null, null);
                                EditorGUILayout.HelpBox(gUIContent.text, MessageType.Warning, true);
                            }
                        }
                    }
                    ModuleUI.GUIFloat(ShapeModuleUI.s_Texts.meshNormalOffset, this.m_MeshNormalOffset, new GUILayoutOption[0]);
                    break;
                }

                case ParticleSystemShapeType.Circle:
                    ModuleUI.GUIFloat(ShapeModuleUI.s_Texts.radius, this.m_Radius.m_Value, new GUILayoutOption[0]);
                    ModuleUI.GUIFloat(ShapeModuleUI.s_Texts.radiusThickness, this.m_RadiusThickness, new GUILayoutOption[0]);
                    this.m_Arc.OnInspectorGUI(ShapeModuleUI.s_ArcTexts);
                    break;

                case ParticleSystemShapeType.SingleSidedEdge:
                    this.m_Radius.OnInspectorGUI(ShapeModuleUI.s_RadiusTexts);
                    break;

                case ParticleSystemShapeType.Donut:
                    ModuleUI.GUIFloat(ShapeModuleUI.s_Texts.radius, this.m_Radius.m_Value, new GUILayoutOption[0]);
                    ModuleUI.GUIFloat(ShapeModuleUI.s_Texts.donutRadius, this.m_DonutRadius, new GUILayoutOption[0]);
                    ModuleUI.GUIFloat(ShapeModuleUI.s_Texts.radiusThickness, this.m_RadiusThickness, new GUILayoutOption[0]);
                    this.m_Arc.OnInspectorGUI(ShapeModuleUI.s_ArcTexts);
                    break;
                }
            }
            if (flag || !this.m_Type.hasMultipleDifferentValues)
            {
                this.m_Type.intValue = num;
            }
            this.OnTextureInspectorGUI();
            this.OnTransformInspectorGUI();
            this.OnMiscInspectorGUI();
        }
Example #15
0
 private int ConvertBoxTypeToBoxEmitFrom(ParticleSystemShapeType shapeType)
 {
     return(Array.IndexOf <ParticleSystemShapeType>(this.boxShapes, shapeType));
 }
Example #16
0
 private bool GetUsesShell(ParticleSystemShapeType shapeType)
 {
     return(Array.IndexOf <ParticleSystemShapeType>(this.shellShapes, shapeType) != -1);
 }
Example #17
0
    static string CheckCulling(ParticleSystem particleSystem)
    {
        string text = "";

        if (particleSystem.collision.enabled)
        {
            text += "\n勾选了 Collision";
        }

        if (particleSystem.emission.enabled)
        {
            if (particleSystem.emission.rateOverDistance.curveMultiplier != 0)
            {
                text += "\nEmission使用了Current(非线性运算)";
            }
        }

        if (particleSystem.externalForces.enabled)
        {
            text += "\n勾选了 External Forces";
        }

        if (particleSystem.forceOverLifetime.enabled)
        {
            if (GetIsRandomized(particleSystem.forceOverLifetime.x) ||
                GetIsRandomized(particleSystem.forceOverLifetime.y) ||
                GetIsRandomized(particleSystem.forceOverLifetime.z) ||
                particleSystem.forceOverLifetime.randomized)
            {
                text += "\nForce Over Lifetime使用了Current(非线性运算)";
            }
        }
        if (particleSystem.inheritVelocity.enabled)
        {
            if (GetIsRandomized(particleSystem.inheritVelocity.curve))
            {
                text += "\nInherit Velocity使用了Current(非线性运算)";
            }
        }
        if (particleSystem.noise.enabled)
        {
            text += "\n勾选了 Noise";
        }
        if (particleSystem.rotationBySpeed.enabled)
        {
            text += "\n勾选了 Rotation By Speed";
        }
        if (particleSystem.rotationOverLifetime.enabled)
        {
            if (GetIsRandomized(particleSystem.rotationOverLifetime.x) ||
                GetIsRandomized(particleSystem.rotationOverLifetime.y) ||
                GetIsRandomized(particleSystem.rotationOverLifetime.z))
            {
                text += "\nRotation Over Lifetime使用了Current(非线性运算)";
            }
        }
        if (particleSystem.shape.enabled)
        {
            ParticleSystemShapeType shapeType = (ParticleSystemShapeType)particleSystem.shape.shapeType;
            switch (shapeType)
            {
            case ParticleSystemShapeType.Cone:
            case ParticleSystemShapeType.ConeVolume:
#if UNITY_2017_1_OR_NEWER
            case ParticleSystemShapeType.Donut:
#endif
            case ParticleSystemShapeType.Circle:
                if (particleSystem.shape.arcMode != ParticleSystemShapeMultiModeValue.Random)
                {
                    text += "\nShape的Circle-Arc使用了Random模式";
                }
                break;

            case ParticleSystemShapeType.SingleSidedEdge:
                if (particleSystem.shape.radiusMode != ParticleSystemShapeMultiModeValue.Random)
                {
                    text += "\nShape的Edge-Radius使用了Random模式";
                }
                break;

            default:
                break;
            }
        }
        if (particleSystem.subEmitters.enabled)
        {
            text += "\n勾选了 SubEmitters";
        }
        if (particleSystem.trails.enabled)
        {
            text += "\n勾选了 Trails";
        }
        if (particleSystem.trigger.enabled)
        {
            text += "\n勾选了 Trigger";
        }
        if (particleSystem.velocityOverLifetime.enabled)
        {
            if (GetIsRandomized(particleSystem.velocityOverLifetime.x) ||
                GetIsRandomized(particleSystem.velocityOverLifetime.y) ||
                GetIsRandomized(particleSystem.velocityOverLifetime.z))
            {
                text += "\nVelocity Over Lifetime使用了Current(非线性运算)";
            }
        }
        if (particleSystem.limitVelocityOverLifetime.enabled)
        {
            text += "\n勾选了 Limit Velocity Over Lifetime";
        }
        if (particleSystem.main.simulationSpace != ParticleSystemSimulationSpace.Local)
        {
            text += "\nSimulationSpace 不等于 Local";
        }
        if (particleSystem.main.gravityModifierMultiplier != 0)
        {
            text += "\nGravityModifier 不等于0";
        }
        return(text);
    }
Example #18
0
        public override void OnInspectorGUI(InitialModuleUI initial)
        {
            if (ShapeModuleUI.s_Texts == null)
            {
                ShapeModuleUI.s_Texts = new ShapeModuleUI.Texts();
            }
            int  num       = this.m_Type.intValue;
            int  num2      = this.m_TypeToGuiTypeIndex[num];
            bool usesShell = this.GetUsesShell((ParticleSystemShapeType)num);

            EditorGUI.BeginChangeCheck();
            int  num3 = ModuleUI.GUIPopup(ShapeModuleUI.s_Texts.shape, num2, this.m_GuiNames, new GUILayoutOption[0]);
            bool flag = EditorGUI.EndChangeCheck();
            ParticleSystemShapeType particleSystemShapeType = this.m_GuiTypes[num3];

            if (num3 != num2)
            {
                num = (int)particleSystemShapeType;
            }
            switch (particleSystemShapeType)
            {
            case ParticleSystemShapeType.Sphere:
            {
                ModuleUI.GUIFloat(ShapeModuleUI.s_Texts.radius, this.m_Radius.m_Value, new GUILayoutOption[0]);
                bool flag2 = ModuleUI.GUIToggle(ShapeModuleUI.s_Texts.emitFromShell, usesShell, new GUILayoutOption[0]);
                num = ((!flag2) ? 0 : 1);
                break;
            }

            case ParticleSystemShapeType.Hemisphere:
            {
                ModuleUI.GUIFloat(ShapeModuleUI.s_Texts.radius, this.m_Radius.m_Value, new GUILayoutOption[0]);
                bool flag3 = ModuleUI.GUIToggle(ShapeModuleUI.s_Texts.emitFromShell, usesShell, new GUILayoutOption[0]);
                num = ((!flag3) ? 2 : 3);
                break;
            }

            case ParticleSystemShapeType.Cone:
            {
                ModuleUI.GUIFloat(ShapeModuleUI.s_Texts.coneAngle, this.m_Angle, new GUILayoutOption[0]);
                ModuleUI.GUIFloat(ShapeModuleUI.s_Texts.radius, this.m_Radius.m_Value, new GUILayoutOption[0]);
                this.m_Arc.OnInspectorGUI(ShapeModuleUI.s_ArcTexts);
                bool disabled = num != 8 && num != 9;
                using (new EditorGUI.DisabledScope(disabled))
                {
                    ModuleUI.GUIFloat(ShapeModuleUI.s_Texts.coneLength, this.m_Length, new GUILayoutOption[0]);
                }
                string[] options = new string[]
                {
                    "Base",
                    "Base Shell",
                    "Volume",
                    "Volume Shell"
                };
                int num4 = this.ConvertConeTypeToConeEmitFrom((ParticleSystemShapeType)num);
                num4 = ModuleUI.GUIPopup(ShapeModuleUI.s_Texts.emitFrom, num4, options, new GUILayoutOption[0]);
                num  = (int)this.ConvertConeEmitFromToConeType(num4);
                break;
            }

            case ParticleSystemShapeType.Box:
            {
                ModuleUI.GUIFloat(ShapeModuleUI.s_Texts.boxX, this.m_BoxX, new GUILayoutOption[0]);
                ModuleUI.GUIFloat(ShapeModuleUI.s_Texts.boxY, this.m_BoxY, new GUILayoutOption[0]);
                ModuleUI.GUIFloat(ShapeModuleUI.s_Texts.boxZ, this.m_BoxZ, new GUILayoutOption[0]);
                string[] options2 = new string[]
                {
                    "Volume",
                    "Shell",
                    "Edge"
                };
                int num5 = this.ConvertBoxTypeToConeEmitFrom((ParticleSystemShapeType)num);
                num5 = ModuleUI.GUIPopup(ShapeModuleUI.s_Texts.emitFrom, num5, options2, new GUILayoutOption[0]);
                num  = (int)this.ConvertBoxEmitFromToConeType(num5);
                break;
            }

            case ParticleSystemShapeType.Mesh:
            case ParticleSystemShapeType.MeshRenderer:
            case ParticleSystemShapeType.SkinnedMeshRenderer:
            {
                string[] options3 = new string[]
                {
                    "Vertex",
                    "Edge",
                    "Triangle"
                };
                ModuleUI.GUIPopup("", this.m_PlacementMode, options3, new GUILayoutOption[0]);
                Material material = null;
                Mesh     mesh     = null;
                if (particleSystemShapeType == ParticleSystemShapeType.Mesh)
                {
                    ModuleUI.GUIObject(ShapeModuleUI.s_Texts.mesh, this.m_Mesh, new GUILayoutOption[0]);
                }
                else if (particleSystemShapeType == ParticleSystemShapeType.MeshRenderer)
                {
                    ModuleUI.GUIObject(ShapeModuleUI.s_Texts.meshRenderer, this.m_MeshRenderer, new GUILayoutOption[0]);
                    MeshRenderer meshRenderer = (MeshRenderer)this.m_MeshRenderer.objectReferenceValue;
                    if (meshRenderer)
                    {
                        material = meshRenderer.sharedMaterial;
                        if (meshRenderer.GetComponent <MeshFilter>())
                        {
                            mesh = meshRenderer.GetComponent <MeshFilter>().sharedMesh;
                        }
                    }
                }
                else
                {
                    ModuleUI.GUIObject(ShapeModuleUI.s_Texts.skinnedMeshRenderer, this.m_SkinnedMeshRenderer, new GUILayoutOption[0]);
                    SkinnedMeshRenderer skinnedMeshRenderer = (SkinnedMeshRenderer)this.m_SkinnedMeshRenderer.objectReferenceValue;
                    if (skinnedMeshRenderer)
                    {
                        material = skinnedMeshRenderer.sharedMaterial;
                        mesh     = skinnedMeshRenderer.sharedMesh;
                    }
                }
                ModuleUI.GUIToggleWithIntField(ShapeModuleUI.s_Texts.meshMaterialIndex, this.m_UseMeshMaterialIndex, this.m_MeshMaterialIndex, false, new GUILayoutOption[0]);
                bool flag4 = ModuleUI.GUIToggle(ShapeModuleUI.s_Texts.useMeshColors, this.m_UseMeshColors, new GUILayoutOption[0]);
                if (flag4)
                {
                    if (material != null && mesh != null)
                    {
                        int nameID  = Shader.PropertyToID("_Color");
                        int nameID2 = Shader.PropertyToID("_TintColor");
                        if (!material.HasProperty(nameID) && !material.HasProperty(nameID2) && !mesh.HasChannel(Mesh.InternalShaderChannel.Color))
                        {
                            GUIContent gUIContent = EditorGUIUtility.TextContent("To use mesh colors, your source mesh must either provide vertex colors, or its shader must contain a color property named \"_Color\" or \"_TintColor\".");
                            EditorGUILayout.HelpBox(gUIContent.text, MessageType.Warning, true);
                        }
                    }
                }
                ModuleUI.GUIFloat(ShapeModuleUI.s_Texts.meshNormalOffset, this.m_MeshNormalOffset, new GUILayoutOption[0]);
                ModuleUI.GUIFloat(ShapeModuleUI.s_Texts.meshScale, this.m_MeshScale, new GUILayoutOption[0]);
                break;
            }

            case ParticleSystemShapeType.Circle:
            {
                ModuleUI.GUIFloat(ShapeModuleUI.s_Texts.radius, this.m_Radius.m_Value, new GUILayoutOption[0]);
                this.m_Arc.OnInspectorGUI(ShapeModuleUI.s_ArcTexts);
                bool flag5 = ModuleUI.GUIToggle(ShapeModuleUI.s_Texts.emitFromEdge, usesShell, new GUILayoutOption[0]);
                num = ((!flag5) ? 10 : 11);
                break;
            }

            case ParticleSystemShapeType.SingleSidedEdge:
                this.m_Radius.OnInspectorGUI(ShapeModuleUI.s_RadiusTexts);
                break;
            }
            if (flag || !this.m_Type.hasMultipleDifferentValues)
            {
                this.m_Type.intValue = num;
            }
            ModuleUI.GUIToggle(ShapeModuleUI.s_Texts.alignToDirection, this.m_AlignToDirection, new GUILayoutOption[0]);
            ModuleUI.GUIFloat(ShapeModuleUI.s_Texts.randomDirectionAmount, this.m_RandomDirectionAmount, new GUILayoutOption[0]);
            ModuleUI.GUIFloat(ShapeModuleUI.s_Texts.sphericalDirectionAmount, this.m_SphericalDirectionAmount, new GUILayoutOption[0]);
        }
Example #19
0
    public int SetProperty(string label, string value)    //returns true if it's a prefab
    {
        switch (label)
        {
        case "prefab":
            int.TryParse(value, out this.prefabId);
            if (this.prefabId > 0)
            {
                return(1);
            }
            return(0);

        case "behaviour":
            int.TryParse(value, out this.behaviourId);
            if (this.behaviourId > 0)
            {
                return(2);
            }
            return(0);

        case "type": this.type = value.ToEnum <FrEdLibrary.Type>(); return(0);

        case "x": float.TryParse(value, out this.pos.x); return(0);

        case "y": float.TryParse(value, out this.pos.y); return(0);

        case "pos": this.pos = this.GetVec2(value); return(0);

        case "xScale": float.TryParse(value, out this.scale.x); return(0);

        case "yScale": float.TryParse(value, out this.scale.y); return(0);

        case "scale": this.scale = this.GetVec2(value); return(0);

        case "tilt": float.TryParse(value, out this.tilt); return(0);

        case "destinationLevel": this.destinationLevel = value; return(0);

        case "destinationButt": this.destinationButt = value; return(0);

        case "noSound": bool.TryParse(value, out this.noSound); return(0);

        case "createLate": float.TryParse(value, out this.createLate); return(0);

        case "int1": int.TryParse(value, out this.int1); return(0);

        case "easing": int.TryParse(value, out this.easing); return(0);

        case "speed": float.TryParse(value, out this.speed); return(0);

        case "lifespan": float.TryParse(value, out this.lifespan); return(0);

        case "ammo": int.TryParse(value, out this.ammoId); return(0);

        case "firingDelay": float.TryParse(value, out this.firingDelay); return(0);

        case "turningSpeed": float.TryParse(value, out this.turningSpeed); return(0);

        case "cameraState": this.cameraState = value.ToEnum <StateBasedCamera.stateTypes>(); return(0);

        case "nodePosX": float.TryParse(value, out this.nodePos.x); return(0);

        case "nodePosY": float.TryParse(value, out this.nodePos.y); return(0);

        case "nodePos": this.nodePos = this.GetVec2(value); return(0);

        case "track": float.TryParse(value, out this.track); return(0);

        case "minX": float.TryParse(value, out this.min.x); return(0);

        case "minY": float.TryParse(value, out this.min.y); return(0);

        case "min": this.min = this.GetVec2(value); return(0);

        case "maxX": float.TryParse(value, out this.max.x); return(0);

        case "maxY": float.TryParse(value, out this.max.y); return(0);

        case "max": this.max = this.GetVec2(value); return(0);

        case "ani": int.TryParse(value, out this.aniId); return(0);

        case "frame": this.frames.Add(this.GetFFrame(value)); return(0);

        case "checkFloor": bool.TryParse(value, out this.checkFloor); return(0);

        case "mesh": this.mesh = value.ToEnum <FrEdLibrary.MeshType>(); return(0);

        case "emissionPerSecond": float.TryParse(value, out this.emissionPerSecond); return(0);

        case "speedMin": float.TryParse(value, out this.startSpeedMin); return(0);

        case "speedMax": float.TryParse(value, out this.startSpeedMax); return(0);

        case "startSizeMin": float.TryParse(value, out this.startSizeMin); return(0);

        case "startSizeMax": float.TryParse(value, out this.startSizeMax); return(0);

        case "lifespanMin": float.TryParse(value, out this.startLifespanMin); return(0);

        case "lifespanMax": float.TryParse(value, out this.startLifespanMax); return(0);

        case "shape": this.shape = value.ToEnum <ParticleSystemShapeType>(); return(0);

        case "shapeScaleX": float.TryParse(value, out this.shapeScale.x); return(0);

        case "shapeScaleY": float.TryParse(value, out this.shapeScale.y); return(0);

        case "shapeScaleZ": float.TryParse(value, out this.shapeScale.z); return(0);

        case "shapeScale": this.shapeScale = this.GetVec3(value); return(0);

        case "colour1": this.color1 = this.GetColor(value); return(0);

        case "colour2": this.color2 = this.GetColor(value); return(0);

        case "color1": this.color1 = this.GetColor(value); return(0);

        case "color2": this.color2 = this.GetColor(value); return(0);

        case "skyBands": int.TryParse(value, out this.skyBands); return(0);

        case "alpha1": float.TryParse(value, out this.alpha1); return(0);

        case "alpha2": float.TryParse(value, out this.alpha2); return(0);

        case "alpha3": float.TryParse(value, out this.alpha3); return(0);

        case "alpha4": float.TryParse(value, out this.alpha4); return(0);

        case "alpha5": float.TryParse(value, out this.alpha5); return(0);

        case "rotationMin": float.TryParse(value, out this.rotationMin); return(0);

        case "rotationMax": float.TryParse(value, out this.rotationMax); return(0);
        }

        return(0);
    }
Example #20
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;
        }
        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;
        }
Example #22
0
 private int ConvertConeTypeToConeEmitFrom(ParticleSystemShapeType shapeType)
 {
     return(Array.IndexOf <ParticleSystemShapeType>(this.coneShapes, shapeType));
 }