Beispiel #1
0
        public override void OnInspectorGUI()
        {
            m_Object.Update();

            //emitter properties
            EditorGUILayout.LabelField("EMITTER STATS", EditorStyles.boldLabel);
            ++EditorGUI.indentLevel;
            {
                EditorGUILayout.LabelField("Particles number: ", m_numberOfParticles.intValue.ToString());
                if (m_MaxParticles.intValue > 0)
                {
                    ProgressBar((float)m_numberOfParticles.intValue / (float)m_MaxParticles.intValue, "Number of particles");
                }
                EditorGUILayout.LabelField("Emiter is active: " + m_isActive.boolValue.ToString());
                EditorGUILayout.LabelField("Emiter is playing: " + m_isPlaying.boolValue.ToString());

                //editor attributes
                if (!Application.isPlaying)
                {
//					EditorGUI.BeginChangeCheck ();
                    m_playOnEditor.boolValue = GUILayout.Toggle(m_playOnEditor.boolValue, "Play on editor", "Button");                     //, new GUIContent("Play on editor"));
                    if (GUI.changed)
                    {
                        if (m_playOnEditor.boolValue == false)
                        {
                            RemoveUpdateTarget(m_updateTargetIndex.intValue);
                            m_isPlayingOnEditor.boolValue = false;
                            myScript.StopEmitter();
                        }
                        else
                        {
                            AddUpdateTarget(m_updateTargetIndex.intValue);
                            m_isPlayingOnEditor.boolValue = true;
                        }
                    }
//					EditorGUI.EndChangeCheck ();

                    if (m_playOnEditor.boolValue == true)
                    {
                        m_playWhenSelected.boolValue = GUILayout.Toggle(m_playWhenSelected.boolValue, "Play only when selected", "Button");

                        if (m_Duration.floatValue > 0)
                        {
                            if (GUILayout.Button("Instant Play"))
                            {
                                myScript.StartEmitter();
                            }
                        }
                    }
                }
            }
            --EditorGUI.indentLevel;

            EditorGUILayout.Space();
            EditorGUILayout.Space();
            EditorGUILayout.PropertyField(m_playOnAwake);
            EditorGUILayout.PropertyField(m_EmitterRate);
            EditorGUILayout.PropertyField(m_ParticlesPerEmission);
            if (m_ParticlesPerEmission.intValue < 0)
            {
                m_ParticlesPerEmission.intValue = 0;
            }

            EditorGUILayout.PropertyField(m_MaxParticles);
            if (m_MaxParticles.intValue < 0)
            {
                m_MaxParticles.intValue = 0;
            }
            EditorGUILayout.PropertyField(m_Duration);
            if (m_Duration.floatValue < 0)
            {
                m_Duration.floatValue = 0;
            }
            EditorGUILayout.PropertyField(m_EmitOnce);
            if (m_Duration.floatValue > 0)
            {
                EditorGUILayout.PropertyField(m_AutoKill);
            }

            EditorGUILayout.PropertyField(m_EmitterShape);
            switch ((CanvasParticleEmitter.EmitterShapes)m_EmitterShape.enumValueIndex)
            {
            case CanvasParticleEmitter.EmitterShapes.Directional:
                EmitterDirectionalLayout();
                break;

            case CanvasParticleEmitter.EmitterShapes.Point:
                EmitterPointLayout();
                break;

            case CanvasParticleEmitter.EmitterShapes.RectEmitter:
                EmitterRectLayout();
                break;

            case CanvasParticleEmitter.EmitterShapes.CircleEmitter:
                EmitterCircleLayout();
                break;

            case CanvasParticleEmitter.EmitterShapes.LineEmitter:
                EmitterLineLayout();
                break;

            case CanvasParticleEmitter.EmitterShapes.PointList:
                EmitterPointListLayout();
                break;

            case CanvasParticleEmitter.EmitterShapes.Image:
                EmitterImageLayout();
                break;
            }


            FieldsFoldout = EditorGUI.Foldout(EditorGUILayout.GetControlRect(), FieldsFoldout, "Force Fields", true);
            if (FieldsFoldout == true)
            {
                ++EditorGUI.indentLevel;
                {
                    EditorGUILayout.PropertyField(m_Gravity);
                    EditorGUILayout.PropertyField(m_Wave, new GUIContent("Wave frequency"));
                    EditorGUILayout.PropertyField(m_WaveAmplitude, new GUIContent("Wave amplitude"));
                    EditorGUILayout.PropertyField(m_Turbulence, new GUIContent("Turbulence frequency"));
                    EditorGUILayout.PropertyField(m_TurbulenceAmplitude, new GUIContent("Turbulence amplitude"));
                }
                --EditorGUI.indentLevel;
            }

            EditorGUILayout.Space();
            EditorGUILayout.Space();
            EditorGUILayout.Space();
            EditorGUILayout.LabelField(" PARTICLE PROPERTIES ", EditorStyles.boldLabel);
            ++EditorGUI.indentLevel;
            {
                ParticleLifeSpanFoldout = EditorGUI.Foldout(EditorGUILayout.GetControlRect(), ParticleLifeSpanFoldout, "Particles Life Span", true);
                if (ParticleLifeSpanFoldout == true)
                {
                    ++EditorGUI.indentLevel;
                    {
                        EditorGUILayout.PropertyField(m_ParticleLife, new GUIContent("Life"));
                        if (m_ParticleLife.floatValue < 0)
                        {
                            m_ParticleLife.floatValue = 0;
                        }
                        EditorGUILayout.PropertyField(m_ParticleLifeRandMin, new GUIContent("Min Random Life"));
                        if (m_ParticleLifeRandMin.floatValue < 0)
                        {
                            m_ParticleLifeRandMin.floatValue = 0;
                        }
                        EditorGUILayout.PropertyField(m_ParticleLifeRandMax, new GUIContent("Max Random Life"));
                        if (m_ParticleLifeRandMax.floatValue < 0)
                        {
                            m_ParticleLifeRandMax.floatValue = 0;
                        }
                    }
                    --EditorGUI.indentLevel;
                }


                ParticleSizeFoldout = EditorGUI.Foldout(EditorGUILayout.GetControlRect(), ParticleSizeFoldout, "Particles Size", true);
                if (ParticleSizeFoldout == true)
                {
                    ++EditorGUI.indentLevel;
                    {
                        EditorGUILayout.PropertyField(m_particleSize, new GUIContent("Size"));
                        EditorGUILayout.LabelField("Life Size Multiplier");
                        EditorGUILayout.PropertyField(m_particleSizeCurve, new GUIContent(""));
                        EditorGUILayout.PropertyField(m_ParticleSizeRandomMax, new GUIContent("Random Size"));
                        EditorGUILayout.PropertyField(m_particleAspectRatio, new GUIContent("Aspect ratio"));
                        if (m_ParticleSizeRandomMax.floatValue < 0)
                        {
                            m_ParticleSizeRandomMax.floatValue = 0;
                        }
                    }
                    --EditorGUI.indentLevel;
                }

                ParticleSpeedFoldout = EditorGUI.Foldout(EditorGUILayout.GetControlRect(), ParticleSpeedFoldout, "Particles Speed", true);
                if (ParticleSpeedFoldout == true)
                {
                    ++EditorGUI.indentLevel;
                    {
                        EditorGUILayout.PropertyField(m_ParticleSpeed, new GUIContent("Speed"));
                        EditorGUILayout.PropertyField(m_ParticleSpeedRandMin, new GUIContent("Min Random Speed"));
                        EditorGUILayout.PropertyField(m_ParticleSpeedRandMax, new GUIContent("Max Random Speed"));
                    }
                    --EditorGUI.indentLevel;
                }


                ParticleOrientationFoldout = EditorGUI.Foldout(EditorGUILayout.GetControlRect(), ParticleOrientationFoldout, "Particles Orientation", true);
                if (ParticleOrientationFoldout == true)
                {
                    ++EditorGUI.indentLevel;
                    {
                        EditorGUILayout.PropertyField(m_AlignedRotation, new GUIContent("Aligned Rotation"));
                        if (m_AlignedRotation.boolValue == false)
                        {
                            EditorGUILayout.PropertyField(m_ParticleAngle, new GUIContent("Angle"));
                            EditorGUILayout.PropertyField(m_ParticleAngleRandMin, new GUIContent("Min Random Angle"));
                            EditorGUILayout.PropertyField(m_ParticleAngleRandMax, new GUIContent("Max Random Angle"));
                            EditorGUILayout.Space();
                            EditorGUILayout.PropertyField(m_ParticleSpinVel, new GUIContent("Spin Velocity"));
                            EditorGUILayout.PropertyField(m_ParticleSpinVelRandMin, new GUIContent("Min Random Spin"));
                            EditorGUILayout.PropertyField(m_ParticleSpinVelRandMax, new GUIContent("Max Random Spin"));
                        }
                        else
                        {
                            ++EditorGUI.indentLevel;
                            EditorGUILayout.PropertyField(m_Stretchable, new GUIContent("Stretchable"));
                            if (m_Stretchable.boolValue == true)
                            {
                                ++EditorGUI.indentLevel;
                                EditorGUILayout.PropertyField(m_StretchableMultiplier, new GUIContent("Multiplier"));
                                --EditorGUI.indentLevel;
                            }
                            --EditorGUI.indentLevel;
                        }
                    }
                    --EditorGUI.indentLevel;
                }

                ParticleColorFoldout = EditorGUI.Foldout(EditorGUILayout.GetControlRect(), ParticleColorFoldout, "Particles Color / Texture", true);
                if (ParticleColorFoldout == true)
                {
                    ++EditorGUI.indentLevel;
                    {
                        EditorGUI.BeginChangeCheck();
                        EditorGUILayout.LabelField("Particle Textures");
                        for (int i = 0; i < m_NumOfTextures.intValue; i++)
                        {
                            GUILayout.BeginVertical();
                            GUILayout.BeginHorizontal();
                            GUILayout.Label((i + 1).ToString(), GUILayout.Width(10));

                            SerializedProperty textureRef = m_TextureArray.GetArrayElementAtIndex(i);
                            textureRef.objectReferenceValue = EditorGUILayout.ObjectField(textureRef.objectReferenceValue, typeof(Texture), false);

                            bool objEnabled = GUI.enabled;
                            GUI.enabled &= CanMoveUp(i);
                            if (GUILayout.Button("-", GUILayout.Width(20)))
                            {
                                myScript.SwapTexture(i, i - 1);
                            }

                            GUI.enabled = objEnabled && CanMoveDown(i);
                            if (GUILayout.Button("+", GUILayout.Width(20)))
                            {
                                myScript.SwapTexture(i, i + 1);
                            }

                            GUI.enabled = objEnabled && m_TextureArray.arraySize > 1;
                            if (GUILayout.Button("X", GUILayout.Width(20)))
                            {
                                myScript.RemoveTexture(i);
                            }

                            GUI.enabled = objEnabled;
                            GUILayout.EndHorizontal();
                            GUILayout.EndVertical();
                        }

                        if (GUILayout.Button("Add Texture"))
                        {
                            myScript.AddTexture(m_TextureArray.GetArrayElementAtIndex(m_TextureArray.arraySize - 1).objectReferenceValue as Texture);
                        }
                        if (EditorGUI.EndChangeCheck())
                        {
                            m_Object.ApplyModifiedProperties();
                            myScript.CreateTextureAtlas();
                            m_Object.ApplyModifiedProperties();
                        }

                        EditorGUILayout.PropertyField(m_Material);


                        EditorGUILayout.PropertyField(m_particleTextureAspectRatio, new GUIContent("Use Texture Aspect Ratio"));

                        if (m_TextureArray.arraySize > 1)
                        {
                            EditorGUILayout.PropertyField(m_TextureAnimable, new GUIContent("Animated Texture"));
                        }

                        if (m_TextureAnimable.boolValue == true)
                        {
                            EditorGUILayout.PropertyField(m_TextureRandomStartFrame, new GUIContent("Random Start"));
                            EditorGUILayout.PropertyField(m_TextureFrameRate, new GUIContent("Frame Rate"));
                        }


                        EditorGUILayout.PropertyField(m_useLifeColor, new GUIContent("Use Life Color"));
                        if (m_useLifeColor.boolValue == true)
                        {
                            EditorGUILayout.LabelField("Life Color");
                            EditorGUILayout.PropertyField(m_ParticleColorRamp, new GUIContent(""));
                        }
                        else
                        {
                            EditorGUILayout.PropertyField(m_ParticleColor, new GUIContent("Color"));
                        }
                        EditorGUILayout.PropertyField(m_ParticleColorRandonR, new GUIContent("Random Red"));
                        EditorGUILayout.PropertyField(m_ParticleColorRandonG, new GUIContent("Random Green"));
                        EditorGUILayout.PropertyField(m_ParticleColorRandonB, new GUIContent("Random Blue"));
                        ArrayGUI(m_Object, m_ParticleColorArray, "Color Array");
                        EditorGUILayout.PropertyField(m_particleAlpha, new GUIContent("Opacity"));
                        EditorGUILayout.LabelField("Life Opacity Multiplier");
                        EditorGUILayout.PropertyField(m_particleAlphaCurve, new GUIContent(""));
                    }
                    --EditorGUI.indentLevel;
                }
                --EditorGUI.indentLevel;
            }
            m_Object.ApplyModifiedProperties();
        }
Beispiel #2
0
        protected override void OnEnable()
        {
            base.OnEnable();

            m_Object = new SerializedObject(target);
            myScript = (CanvasParticleEmitter)target;

            //read only
            m_numberOfParticles = m_Object.FindProperty("m_numberOfParticles");
            m_isPlaying         = m_Object.FindProperty("m_isPlaying");
            m_isActive          = m_Object.FindProperty("m_isActive");

            //emitter base
            m_playOnAwake          = m_Object.FindProperty("m_playOnAwake");
            m_AutoKill             = m_Object.FindProperty("m_AutoKill");
            m_EmitOnce             = m_Object.FindProperty("m_EmitOnce");
            m_EmitterRate          = m_Object.FindProperty("m_EmitterRate");
            m_Duration             = m_Object.FindProperty("m_Duration");
            m_MaxParticles         = m_Object.FindProperty("m_MaxParticles");
            m_ParticlesPerEmission = m_Object.FindProperty("m_ParticlesPerEmission");


            //emitter shape
            m_EmitterShape = m_Object.FindProperty("m_EmitterShape");

            //directional emitter
            m_EmitterSpread    = m_Object.FindProperty("m_EmitterSpread");
            m_EmitterDirection = m_Object.FindProperty("m_EmitterDirection");

            //rect emitter
            m_EmitterRectType      = m_Object.FindProperty("m_EmitterShapeRectType");
            m_EmitterRect          = m_Object.FindProperty("m_EmitterShapeRect");
            m_EmitterRectTransform = m_Object.FindProperty("m_EmitterShapeRectTransform");

            //circle emitter
            m_EmitterCircleType     = m_Object.FindProperty("m_EmitterShapeCircleType");
            m_EmitterCircleRadius   = m_Object.FindProperty("m_EmitterShapeCircleRadius");
            m_EmitterCircleSegments = m_Object.FindProperty("m_EmitterShapeCircleSegments");

            //line emitter
            m_EmitterLinePointA = m_Object.FindProperty("m_EmitterShapeLinePointA");
            m_EmitterLinePointB = m_Object.FindProperty("m_EmitterShapeLinePointB");

            // point list emitter m_EmitterShapePointListPoints
            m_EmitterShapePointListPoints = m_Object.FindProperty("m_EmitterShapePointListPoints");

            //image emitter
            m_EmitterShapeImage = m_Object.FindProperty("m_EmitterShapeImage");
            //m_EmitterImagePixels = m_Object.FindProperty ("m_EmitterImagePixels");


            //forces
            m_Gravity             = m_Object.FindProperty("m_Gravity");
            m_Wave                = m_Object.FindProperty("m_Wave");
            m_WaveAmplitude       = m_Object.FindProperty("m_WaveAmplitude");
            m_Turbulence          = m_Object.FindProperty("m_Turbulence");
            m_TurbulenceAmplitude = m_Object.FindProperty("m_TurbulenceAmplitude");


            //particle size and shape
            m_particleSize          = m_Object.FindProperty("m_particleSize");
            m_particleSizeCurve     = m_Object.FindProperty("m_particleSizeCurve");
            m_ParticleSizeRandomMax = m_Object.FindProperty("m_ParticleSizeRandomMax");
            m_particleAspectRatio   = m_Object.FindProperty("m_particleAspectRatio");

            //particle behavior
            m_ParticleLife        = m_Object.FindProperty("m_ParticleLife");
            m_ParticleLifeRandMin = m_Object.FindProperty("m_ParticleLifeRandMin");
            m_ParticleLifeRandMax = m_Object.FindProperty("m_ParticleLifeRandMax");

            m_ParticleSpeed        = m_Object.FindProperty("m_ParticleSpeed");
            m_ParticleSpeedRandMin = m_Object.FindProperty("m_ParticleSpeedRandMin");
            m_ParticleSpeedRandMax = m_Object.FindProperty("m_ParticleSpeedRandMax");

            m_AlignedRotation       = m_Object.FindProperty("m_AlignedRotation");
            m_ParticleAngle         = m_Object.FindProperty("m_ParticleAngle");
            m_ParticleAngleRandMin  = m_Object.FindProperty("m_ParticleAngleRandMin");
            m_ParticleAngleRandMax  = m_Object.FindProperty("m_ParticleAngleRandMax");
            m_Stretchable           = m_Object.FindProperty("m_Stretchable");
            m_StretchableMultiplier = m_Object.FindProperty("m_StretchableMultiplier");


            m_ParticleSpinVel        = m_Object.FindProperty("m_ParticleSpinVel");
            m_ParticleSpinVelRandMin = m_Object.FindProperty("m_ParticleSpinVelRandMin");
            m_ParticleSpinVelRandMax = m_Object.FindProperty("m_ParticleSpinVelRandMax");

            //particle color and tranparency
            m_useLifeColor               = m_Object.FindProperty("m_useLifeColor");
            m_ParticleColor              = m_Object.FindProperty("m_ParticleColor");
            m_ParticleColorRamp          = m_Object.FindProperty("m_ParticleColorRamp");
            m_ParticleColorArray         = m_Object.FindProperty("m_ParticleColorArray");
            m_ParticleColorRandonR       = m_Object.FindProperty("m_ParticleColorRandonR");
            m_ParticleColorRandonG       = m_Object.FindProperty("m_ParticleColorRandonG");
            m_ParticleColorRandonB       = m_Object.FindProperty("m_ParticleColorRandonB");
            m_particleAlpha              = m_Object.FindProperty("m_ParticleAlpha");
            m_particleAlphaCurve         = m_Object.FindProperty("m_particleAlphaCurve");
            m_TextureArray               = m_Object.FindProperty("m_TextureArray");
            m_TextureAnimable            = m_Object.FindProperty("m_isAnimated");
            m_TextureFrameRate           = m_Object.FindProperty("m_ParticleFrameRate");
            m_TextureRandomStartFrame    = m_Object.FindProperty("m_isRandomStartFrame");
            m_particleTextureAspectRatio = m_Object.FindProperty("m_particleTextureAspectRatio");
            m_NumOfTextures              = m_Object.FindProperty(ARRAY_SIZE);
            //m_ParticleColliders = m_Object.FindProperty("m_ParticleColliders");
            m_Material = m_Object.FindProperty("m_Material");

            //editor update
            m_playOnEditor      = m_Object.FindProperty("m_playOnEditor");
            m_playWhenSelected  = m_Object.FindProperty("m_playWhenSelected");
            m_isPlayingOnEditor = m_Object.FindProperty("m_isPlayingOnEditor");
            m_updateTargetIndex = m_Object.FindProperty("m_updateTargetIndex");


            if (m_TextureArray.arraySize > 1)
            {
                myScript.CreateTextureAtlas();
            }

            if (!Application.isPlaying)
            {
                if (m_playOnEditor.boolValue == false)
                {
                    RemoveUpdateTarget(m_updateTargetIndex.intValue);
                    m_isPlayingOnEditor.boolValue = false;
                    m_playWhenSelected.boolValue  = false;
                }

                if (m_playOnEditor.boolValue == true && m_playWhenSelected.boolValue == true)
                {
                    AddUpdateTarget(m_updateTargetIndex.intValue);
                    m_isPlayingOnEditor.boolValue = true;
                }
            }
        }