Beispiel #1
0
        // Create single dust particle system
        public void CreateDust(Transform host, RayfireDust scr, MeshFilter emitMeshFilter, int emitMatIndex, ParticleSystem ps)
        {
            // Set main module
            RFParticles.SetMain(ps.main, scr.emission.lifeMin, scr.emission.lifeMax, scr.emission.sizeMin, scr.emission.sizeMax,
                                scr.dynamic.gravityMin, scr.dynamic.gravityMax, scr.dynamic.speedMin, scr.dynamic.speedMax,
                                0f, scr.limitations.maxParticles, scr.emission.duration);

            // Emission over distance
            RFParticles.SetEmission(ps.emission, scr.emission.distanceRate, (short)scr.amountFinal);

            // Emission from mesh or from impact point
            if (emitMeshFilter != null)
            {
                RFParticles.SetShapeMesh(ps.shape, emitMeshFilter.sharedMesh, emitMatIndex, emitMeshFilter.transform.localScale);
            }
            else
            {
                RFParticles.SetShapeObject(ps.shape);
            }

            // Collision
            RFParticles.SetCollisionDust(ps.collision, scr.collision);

            // Color over life time
            RFParticles.SetColorOverLife(ps.colorOverLifetime, scr.opacity);

            // Noise
            RFParticles.SetNoise(ps.noise, scr.noise);

            // Renderer
            SetParticleRendererDust(ps.GetComponent <ParticleSystemRenderer>(), scr.dustMaterial, scr.rendering.castShadows, scr.rendering.receiveShadows);

            // Start playing
            ps.Play();
        }
Beispiel #2
0
        // Copy debris and dust
        public static void CopyParticles(RayfireRigid source, RayfireRigid target)
        {
            // Copy debris
            if (source.HasDebris == true)
            {
                for (int i = 0; i < source.debrisList.Count; i++)
                {
                    RayfireDebris targetDebris = target.gameObject.AddComponent <RayfireDebris>();
                    targetDebris.CopyFrom(source.debrisList[i]);

                    if (source.debrisList[i].children == null)
                    {
                        source.debrisList[i].children = new List <RayfireDebris>();
                    }
                    source.debrisList[i].children.Add(targetDebris);
                }
            }

            // Copy dust
            if (source.HasDust == true)
            {
                for (int i = 0; i < source.dustList.Count; i++)
                {
                    RayfireDust targetDust = target.gameObject.AddComponent <RayfireDust>();
                    targetDust.CopyFrom(source.dustList[i]);

                    if (source.dustList[i].children == null)
                    {
                        source.dustList[i].children = new List <RayfireDust>();
                    }
                    source.dustList[i].children.Add(targetDust);
                }
            }
        }
        public override void OnInspectorGUI()
        {
            // Get target
            dust = target as RayfireDust;
            if (dust == null)
            {
                return;
            }

            // Space
            GUILayout.Space(8);

            if (Application.isPlaying == true)
            {
                if (GUILayout.Button("Emit", GUILayout.Height(25)))
                {
                    foreach (var targ in targets)
                    {
                        if (targ as RayfireDust != null)
                        {
                            (targ as RayfireDust).Emit();
                        }
                    }
                }
            }

            // Draw script UI
            DrawDefaultInspector();
        }
Beispiel #4
0
        // Create single debris particle system
        public static void CreateDustImpact(RayfireDust dust, Vector3 impactPos, Vector3 impactNormal)
        {
            // Particle system
            ParticleSystem ps = dust.CreateParticleSystem(dust);

            // Align over impact
            dust.hostTm.position = impactPos;
            dust.hostTm.LookAt(impactPos + impactNormal);

            // Set amount
            dust.amountFinal = dust.emission.burstAmount;

            // Create debris
            dust.CreateDust(dust.rigid.transForm, dust, null, -1, ps);
        }
Beispiel #5
0
        // Create single dust particle system
        public static void CreateDustRigid(RayfireDust target)
        {
            // No particles
            if (target.amountFinal < target.limitations.minParticles && target.emission.distanceRate == 0)
            {
                return;
            }

            // Particle system
            ParticleSystem ps = target.CreateParticleSystem(target);

            // Get emit material index
            int emitMatIndex = GetEmissionMatIndex(target.rigid.meshRenderer, target.emissionMaterial);

            // Create debris
            target.CreateDust(target.rigid.transForm, target, target.rigid.meshFilter, emitMatIndex, ps);
        }
Beispiel #6
0
        // Copy from
        public void CopyFrom(RayfireDust source)
        {
            onDemolition = source.onDemolition;
            onActivation = source.onActivation;
            onImpact     = source.onImpact;

            dustMaterial     = source.dustMaterial;
            opacity          = source.opacity;
            emissionMaterial = source.emissionMaterial;

            emission.CopyFrom(source.emission);
            dynamic.CopyFrom(source.dynamic);
            noise.CopyFrom(source.noise);
            collision.CopyFrom(source.collision);
            limitations.CopyFrom(source.limitations);
            rendering.CopyFrom(source.rendering);

            initialized = source.initialized;
        }
Beispiel #7
0
        /// /////////////////////////////////////////////////////////
        /// Create common
        /// /////////////////////////////////////////////////////////

        // Create host and particle system
        public ParticleSystem CreateParticleSystem(RayfireDust scr)
        {
            // Create root
            GameObject host = new GameObject(scr.name + "_dust");

            host.transform.position   = scr.transform.position;
            host.transform.rotation   = scr.transform.rotation;
            host.transform.parent     = scr.transform;
            host.transform.localScale = Vector3.one;

            // Particle system
            ParticleSystem ps = host.AddComponent <ParticleSystem>();

            scr.pSystem = ps;
            scr.hostTm  = host.transform;

            // Destroy after all particles death
            Destroy(host, scr.emission.lifeMax + ps.main.duration);

            // Stop for further properties set
            ps.Stop();

            return(ps);
        }
Beispiel #8
0
        // Copy debris and dust
        public static void CopyRootMeshParticles(RayfireRigid source, List <RayfireRigid> targets)
        {
            // Copy debris. only initialized debris in this list
            if (source.HasDebris == true)
            {
                for (int d = 0; d < source.debrisList.Count; d++)
                {
                    // Set max amount
                    int maxAmount = targets.Count;
                    if (source.debrisList[d].limitations.percentage < 100)
                    {
                        maxAmount = targets.Count * source.debrisList[d].limitations.percentage / 100;
                    }

                    // Copy component
                    for (int i = 0; i < targets.Count; i++)
                    {
                        // Max amount reached
                        if (maxAmount <= 0)
                        {
                            break;
                        }

                        // TODO consider size threshold

                        // Filter by percentage
                        if (Random.Range(0, 100) > source.debrisList[d].limitations.percentage)
                        {
                            continue;
                        }

                        // Copy
                        RayfireDebris targetDebris = targets[i].gameObject.AddComponent <RayfireDebris>();
                        targetDebris.CopyFrom(source.debrisList[d]);
                        targetDebris.rigid = targets[i];

                        // Collect debris for Rigid
                        if (targets[i].debrisList == null)
                        {
                            targets[i].debrisList = new List <RayfireDebris>();
                        }
                        targets[i].debrisList.Add(targetDebris);

                        // Collect debris for parent debris
                        if (source.debrisList[d].children == null)
                        {
                            source.debrisList[d].children = new List <RayfireDebris>();
                        }
                        source.debrisList[d].children.Add(targetDebris);

                        maxAmount--;
                    }

                    // Get amount list
                    SetDebrisFinalAmount(source.debrisList[d].children, source.debrisList[d].emission.burstType, source.debrisList[d].emission.burstAmount);
                }
            }

            // Copy dust
            if (source.HasDust == true)
            {
                for (int d = 0; d < source.dustList.Count; d++)
                {
                    // Set max amount
                    int maxAmount = targets.Count;
                    if (source.dustList[d].limitations.percentage < 100)
                    {
                        maxAmount = targets.Count * source.dustList[d].limitations.percentage / 100;
                    }

                    for (int i = 0; i < targets.Count; i++)
                    {
                        // Max amount reached
                        if (maxAmount <= 0)
                        {
                            break;
                        }

                        // Filter by percentage
                        if (Random.Range(0, 100) > source.dustList[d].limitations.percentage)
                        {
                            continue;
                        }

                        // Copy
                        RayfireDust targetDust = targets[i].gameObject.AddComponent <RayfireDust>();
                        targetDust.CopyFrom(source.dustList[d]);
                        targetDust.rigid = targets[i];

                        // Collect debris for Rigid
                        if (targets[i].dustList == null)
                        {
                            targets[i].dustList = new List <RayfireDust>();
                        }
                        targets[i].dustList.Add(targetDust);

                        // Collect debris for parent debris
                        if (source.dustList[d].children == null)
                        {
                            source.dustList[d].children = new List <RayfireDust>();
                        }
                        source.dustList[d].children.Add(targetDust);

                        maxAmount--;
                    }

                    // Get amount list
                    SetDustFinalAmount(source.dustList[d].children, source.dustList[d].emission.burstType, source.dustList[d].emission.burstAmount);
                }
            }
        }