Exemplo n.º 1
0
    void Start()
    {
        effectDataList.Clear();

        InitManager(this, MANAGER_ID.EFFECT);

        for (int createIndex = 0; createIndex < setEffectDBList.Count; createIndex++)
        {
            var db = setEffectDBList[createIndex];
            for (int i = 0; i < createNum; i++)
            {
                EffectData data = new EffectData();

                data.effectID = db.effectID;
                GameObject obj = Instantiate(db.prefab) as GameObject;
                obj.transform.SetParent(transform);
                obj.name = db.prefab.name + i.ToString("00");
                obj.transform.localPosition = Vector3.zero;
                obj.transform.localScale    = Vector3.zero;
                obj.transform.localRotation = Quaternion.identity;
                data.effectObject           = obj;
                data.effectMove             = obj.GetComponent <EffectMover>();

                ParticleSystemData particleData = data.particleSystemData;
                particleData.trans          = obj.transform.GetChild(0);
                particleData.particleSystem = particleData.trans.GetComponent <ParticleSystem>();
                particleData.particleSystem.Stop();

                data.effectObject.SetActive(false);
                data.isActive = false;

                effectDataList.Add(data);
            }
        }
    }
Exemplo n.º 2
0
        private void SynchronizeNested(List <ParticleSystemData> nestedData, ParticleSystem particleSystem)
        {
            // Render data is cached in ParticleSystem.RenderData.
            var renderData = particleSystem.RenderData as ParticleSystemData;

            if (renderData == null)
            {
                renderData = new ParticleSystemData(particleSystem);
                particleSystem.RenderData = renderData;
            }

            // Note: renderData.Frame is set in root particle system. It is not necessary
            // to check the frame number for nested particle systems.

            renderData.Update(particleSystem);
            nestedData.Add(renderData);

            // Synchronize nested particle systems.
            if (particleSystem.Children != null)
            {
                foreach (var child in particleSystem.Children)
                {
                    SynchronizeNested(nestedData, child);
                }
            }
        }
		/// <summary>
		/// Construct a particle system with data
		/// </summary>
		/// <param name="systemData"></param>
		/// <param name="update"></param>
		public ParticleSystem(ParticleSystemData systemData, UpdateManager update)
			: this()
		{
			if (update == null)
				throw new ArgumentNullException();

			Initalise(systemData, DefaultProcessorType);

			update.Add(this);
		}
Exemplo n.º 4
0
        public void SystemCanBeCreatedFromDataOfEmitterNames()
        {
            if (!IsMockResolver)
            {
                return;                 //ncrunch: no coverage start
            }
            var particleSystemData = new ParticleSystemData
            {
                emitterNames = new List <string>(new[] { "PointEmitter3D", "PointEmitter3D" })
            };
            var createdParticleSystem = new ParticleSystem(particleSystemData);

            Assert.AreEqual(particleSystemData.emitterNames.Count,
                            createdParticleSystem.AttachedEmitters.Count);
        }
Exemplo n.º 5
0
            internal override bool Reconstruct(BlamLib.Blam.CacheFile c)
            {
                bool result = true;

                if (ParticleSystemData.Count != 1)
                {
                    particle_system_lite_data_block data;
                    ParticleSystemData.Add(out data);

                    result = data.Reconstruct(GeometryBlockInfo.Value);
                }

                GeometryBlockInfo.Value.ClearPostReconstruction();

                return(result);
            }
Exemplo n.º 6
0
    public void ResetParticleSystemArray()
    {
        // We can't place into Awake method. Maybe data data has not been initialized.
        ParticleSystem[] pfxSystems = gameObject.GetComponentsInChildren <ParticleSystem>();
        particleSystemDataArray = new ParticleSystemData[pfxSystems.Length];

        for (int i = 0; i < pfxSystems.Length; i++)
        {
            particleSystemDataArray[i] = new ParticleSystemData().Create(pfxSystems[i]);

            //// Turn off the auto destroy caused by the data.
            //ParticleAnimator particleAnimator = (ParticleAnimator)data.gameObject.GetComponentInChildren(typeof(ParticleAnimator));
            //if (particleAnimator != null)
            //    particleAnimator.autodestruct = false;
        }
    }
Exemplo n.º 7
0
    private void Awake()
    {
        var particleSystems = GetComponentsInChildren <ParticleSystem>();

        particleData = new ParticleSystemData[particleSystems.Length];
        if (particleSystems.Length > 0)
        {
            for (int i = 0; i < particleData.Length; i++)
            {
                particleData[i] = new ParticleSystemData(particleSystems[i]);
            }
        }
        else
        {
            Debug.LogError(string.Format("物体{0}的粒子缩放器无法找到粒子系统", gameObject.name));
        }
    }
Exemplo n.º 8
0
    // ParticleSystemDataCircle psdci { get { return psd as ParticleSystemDataCircle; } }
    // ParticleSystemDataCone psdco { get { return psd as ParticleSystemDataCone; } }
    // ParticleSystemDataDonut psddo { get { return psd as ParticleSystemDataDonut; } }
    // ParticleSystemDataEdge psded { get { return psd as ParticleSystemDataEdge; } }

    // Use this for initialization

    static ParticleSystemShapeMultiModeValue                SetPSShape(ParticleSystemData psd)
    {
        if (psd.mode == ParticleEmissionMode.Loop)
        {
            // Debug.Log("loop");
            return(ParticleSystemShapeMultiModeValue.Loop);
        }
        if (psd.mode == ParticleEmissionMode.PingPong)
        {
            // Debug.Log("ping");
            return(ParticleSystemShapeMultiModeValue.PingPong);
        }
        if (psd.mode == ParticleEmissionMode.BurstSpread)
        {
            // Debug.Log("burst");
            return(ParticleSystemShapeMultiModeValue.BurstSpread);
        }
        return(ParticleSystemShapeMultiModeValue.Random);
    }
Exemplo n.º 9
0
 public override void TransformAnimation(float time, MeshRenderer myRenderer, Transform myTransform)
 {
     if (list == null || list.Length == 0)
     {
         return;
     }
     for (int i = 0; i < list.Length; i++)
     {
         ParticleSystemData data = list[i];
         if (time >= data.startTime && time <= data.endTime)
         {
             if (!IsParticleSystemActive(data.particle))
             {
                 SetParticleSystemActive(data.particle, true);
             }
         }
         else if (IsParticleSystemActive(data.particle))
         {
             SetParticleSystemActive(data.particle, false);
         }
     }
 }
		//creates the particle system storage classes (store all particle life data)
		private void Initalise(ParticleSystemData systemData, Type processorType)
		{
			if (systemData == null)
				throw new ArgumentNullException();

			this.systemData = systemData;
			this.enabled = true;

			//build the triggers
			this.triggers = new ParticleSystemTrigger[systemData.SystemLogicData.Triggers.Length];
			for (int i = 0; i < this.triggers.Length; i++)
				this.triggers[i] = new ParticleSystemTrigger(this, i);

			this.toggles = new ParticleSystemToggleTrigger[systemData.SystemLogicData.ToggleTriggers.Length];
			for (int i = 0; i < this.toggles.Length; i++)
				this.toggles[i] = new ParticleSystemToggleTrigger(this, i);


			this.systemLogic = systemData.SystemLogicData;

			//create the storage for the particle instances
			if (processorType == null)
				this.particleStore = systemData.CreateParticleProfilerStore();
			else
				this.particleStore = systemData.CreateParticleStore(processorType);

			this.particleStoreSortedDrawOrder = new List<ParticleStore>[4];
			//fill with a few empty entires
			for (int i = 0; i < particleStoreSortedDrawOrder.Length; i++)
				particleStoreSortedDrawOrder[i] = new List<ParticleStore>(particleStore.Length);

			typeDependancyList = new int[this.particleStore.Length * 2];


			activeSpawnDetails = this.userSpawnDetails;

			//run the 'once' emitter
			if (this.systemLogic.OnceEmitter != null)
				this.systemLogic.OnceEmitter.Run(this, 0);
		}
		//a profiler is used to compute how much memory the particle system will use
		internal static ParticleSystem CreateProfiler(ParticleSystemData systemData)
		{
			return new ParticleSystem(systemData, (Type)null);
		}
//any time this define is used, the code is only needed to build the 
//particle system data, or for hotloading
#if DEBUG && !XBOX360

		//used by the hotloader
		internal void SetParticleSystemHotloadedData(ParticleSystemData data)
		{
			//hackity hack
			Dispose();
			this.disposed = false;

			Initalise(data, DefaultProcessorType);
		}
			public LocalContentLoader(ParticleSystemData system)
			{
				this.system = system;
			}
		//internal
		private ParticleSystem(ParticleSystemData systemData, Type processorType)
			: this()
		{
			Initalise(systemData, processorType);
		}
Exemplo n.º 15
0
        /// <summary>
        /// Synchronizes the graphics data with the particle system data. (Needs to be called once per
        /// frame!)
        /// </summary>
        /// <param name="graphicsService">The graphics service.</param>
        /// <remarks>
        /// This method needs to be called once per frame to synchronize the graphics service with the
        /// particle system service. It creates a snapshot of the particle system and converts the
        /// particles to render data.
        /// </remarks>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="graphicsService"/> is <see langword="null"/>.
        /// </exception>
        public void Synchronize(IGraphicsService graphicsService)
        {
            if (graphicsService == null)
            {
                throw new ArgumentNullException("graphicsService");
            }

            int frame = graphicsService.Frame + 1;

            SynchronizeShape();

            // ----- Synchronize pose.
            if (ParticleSystem.ReferenceFrame == ParticleReferenceFrame.World)
            {
                PoseWorld = ParticleSystem.Pose;

                // Note: Scale is ignored and not copied. Because we cannot simply set ScaleWorld.
                // ParticleSystems with reference frame World should not use a scale.
            }

            // If the ReferenceFrame is Local, then ParticleSystem.Pose is irrelevant.
            // (The particle system can be instanced. Particles are relative to the scene
            // node.)

            // ----- Synchronize render data.
            // Render data is cached in ParticleSystem.RenderData.
            var renderData = ParticleSystem.RenderData as ParticleSystemData;

            if (renderData == null)
            {
                renderData = new ParticleSystemData(ParticleSystem);
                ParticleSystem.RenderData = renderData;
            }
            else if (renderData.Frame == frame)
            {
                // Render data is up-to-date.
                return;
            }
            else if (!ParticleSystem.Enabled && renderData.Frame == frame - 1)
            {
                // The particle system was updated in the last frame and the particles haven't
                // changed since. (The particle system is disabled.)
                renderData.Frame = frame;
                return;
            }

            // Synchronize render data of root particle system.
            renderData.Update(ParticleSystem);

            // Synchronize render data of nested particle systems.
            if (ParticleSystem.Children != null && ParticleSystem.Children.Count > 0)
            {
                if (renderData.NestedRenderData == null)
                {
                    renderData.NestedRenderData = new List <ParticleSystemData>();
                }
                else
                {
                    renderData.NestedRenderData.Clear();
                }

                foreach (var childParticleSystem in ParticleSystem.Children)
                {
                    SynchronizeNested(renderData.NestedRenderData, childParticleSystem);
                }
            }
            else
            {
                // Clear nested render data.
                renderData.NestedRenderData = null;
            }

            renderData.Frame = frame;
        }
Exemplo n.º 16
0
        private void CheckChanged(Application application)
        {
            //has the file changed?
            DateTime modifiedTime = File.GetLastWriteTime(this.filename);

            ParticleSystem system = this.system.Target as ParticleSystem;

            if (system == null)
            {
                //particle system is no longer
                return;
            }

            if (sourceFileModifiedDate < modifiedTime)
            {
                sourceFileModifiedDate = modifiedTime;
                //particle system source has changed...

                //attempt to reload

                ParticleSystemData previousData = loadedSystemData;


                try
                {
                    XmlDocument doc = new XmlDocument();
                    doc.Load(this.filename);
                    XmlElement root = doc.SelectSingleNode("particlesystem") as XmlElement;
                    if (root == null)
                    {
                        throw new ArgumentException("Missing XML root element \'particlesystem\'");
                    }

                    loadedSystemData = new ParticleSystemData(this.filename, root, TargetPlatform.Windows, false, null);

                    LocalContentLoader content = new LocalContentLoader(loadedSystemData);
                    application.Content.Add(content);

                    system.SetParticleSystemHotloadedData(loadedSystemData);

                    if (previousData != null)
                    {
                        //previous hot load has existing data still hanging around
                        foreach (ParticleSystemTypeData typeData in previousData.ParticleTypeData)
                        {
                            //this is nasty
                            //eeek! this texture was loaded with FromFile()....
                            if (typeData.Texture != null)
                            {
                                typeData.Texture.Dispose();
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    loadedSystemData = null;

                    try
                    {
                        //show a message
                        //the difficult way...
                        string assembly = @"System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

                        Type type = System.Reflection.Assembly.Load(assembly).GetType("System.Windows.Forms.MessageBox");

                        System.Reflection.MethodInfo method = type.GetMethod("Show", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static, null, new Type[] { typeof(string), typeof(string) }, null);

                        method.Invoke(null, new string[] { ex.ToString(), "Error importing updated particle system" });
                    }
                    catch
                    {
                        throw ex;
                    }
                }
            }
        }
Exemplo n.º 17
0
 public LocalContentLoader(ParticleSystemData system)
 {
     this.system = system;
 }
            /// <summary>
            /// filters out the active (in use) ParticleSystems
            /// </summary>
            protected override JobHandle OnUpdate(JobHandle inputDeps)
            {
                i = particleSystemRequestQuery.CalculateEntityCount();
                if (i == 0 && particleSystemRemoveRequestQuery.CalculateEntityCount() == 0)
                {
                    return(inputDeps);
                }
                NativeArray <Entity> particleSystemEntityEntities = particleSystemEntityQuery.ToEntityArray(Allocator.TempJob);
                NativeArray <ParticleSystemEntity> pses           = particleSystemEntityQuery.ToComponentDataArray <ParticleSystemEntity>(Allocator.TempJob);

                //test if any one needs new particles
                if (i > 0)
                {
                    if (haveParticlePrefab)
                    {
                        NativeArray <Entity> particleSystemRequestEntities = particleSystemRequestQuery.ToEntityArray(Allocator.TempJob);
                        j = getActiveParticleSystems(pses);
                        requiresNewParticleSystems = j + particleSystemRequestEntities.Length > particleSystemEntityEntities.Length;
                        Debug.Log("detected " + j + " active particleSystems. current max: " + particleSystemEntityEntities.Length + " current requested: " + particleSystemRequestEntities.Length + " require new spawns = " + requiresNewParticleSystems);
                        //test to see if we need to make new particle systems
                        if (requiresNewParticleSystems)
                        {
                            //			Debug.Log("Detected a request in new entities!");
                            for (i = 0; i < j + particleSystemRequestEntities.Length - particleSystemEntityEntities.Length; i++)
                            {
                                createParticleSystemGameObject("ParticleSystem" + (i + particleSystemEntityEntities.Length), new float3(), new float4());
                            }
                            particleSystemEntityEntities.Dispose();
                            pses.Dispose();
                            particleSystemEntityEntities = particleSystemEntityQuery.ToEntityArray(Allocator.TempJob);
                            pses = particleSystemEntityQuery.ToComponentDataArray <ParticleSystemEntity>(Allocator.TempJob);
                        }
                        Debug.Log("Filling in Requests...");
                        //now we fill the requests
                        for (i = 0; i < particleSystemRequestEntities.Length; i++)
                        {
                            for (j = 0; j < pses.Length; j++)
                            {
                                if (!pses[j].isActive)
                                {
                                    pses[j] = new ParticleSystemEntity
                                    {
                                        id       = pses[j].id,
                                        isActive = true
                                    };
                                    Debug.Log("setting particle system " + pses[j].id + " to a entity");
                                    //assumes the eneity already has the ParticleSystemData
                                    EntityManager.RemoveComponent <ParticleSystemRequest>(particleSystemRequestEntities[i]);
                                    ParticleSystem ps = EntityManager.GetComponentObject <ParticleSystem>(particleSystemEntityEntities[j]) as ParticleSystem;
                                    if (ps == null)
                                    {
                                        Debug.LogError("FAILED TO GET PARTICLE SYSTEM");
                                    }
                                    //			else Debug.Log("particle position = "+ps.transform.position);
                                    if (EntityManager.HasComponent <ParticleSystemSpawnData>(particleSystemRequestEntities[i]))
                                    {
                                        ParticleSystemSpawnData pssd = EntityManager.GetComponentData <ParticleSystemSpawnData>(particleSystemRequestEntities[i]);
                                        if (pssd.paticleSystemName.A != 0)
                                        {
                                            GameObject temp = Resources.Load("Pokemon/PokemonMoves/" + (pssd.paticleSystemName) + "/" + (pssd.paticleSystemName) + "ParticleSystem") as GameObject;
                                            if (temp != null)
                                            {
                                                ps = temp.GetComponent <ParticleSystem>();
                                            }
                                            else
                                            {
                                                Debug.LogWarning("Failed to load ParticleSystem Preset: invalid ParticleSystem, got \"Pokemon/PokemonMoves/" + (pssd.paticleSystemName) + "ParticleSystem\"");
                                            }
                                        }
                                        else
                                        {
                                            Debug.LogWarning("Failed to load ParticleSystem Preset: invalid Name");
                                        }
                                        if (pssd.particleSystemSpawnDataShape.isValid)
                                        {
                                            var shape = ps.shape;
                                            shape.position = pssd.particleSystemSpawnDataShape.offsetPostiion;
                                            shape.rotation = pssd.particleSystemSpawnDataShape.offsetRotation;
                                            shape.scale    = pssd.particleSystemSpawnDataShape.offsetScale;
                                        }
                                    }
                                    else
                                    {
                                        Debug.LogWarning("No ParticleSystemDataSpawnData found, setting some defaults." + EntityManager.GetName(particleSystemRequestEntities[i]));
                                        var shape = ps.shape;
                                        shape.position = new float3();
                                        shape.rotation = new float3();
                                        shape.scale    = new float3(1f, 1f, 1f);
                                    }
                                    ps.Play();
                                    EntityManager.AddComponentObject(particleSystemRequestEntities[i], ps);
                                    EntityManager.SetComponentData(particleSystemRequestEntities[i],
                                                                   new ParticleSystemData
                                    {
                                        isFinished           = false,
                                        particleSystemEntity = pses[j]
                                    }
                                                                   );

                                    EntityManager.SetComponentData <ParticleSystemEntity>(particleSystemEntityEntities[j], pses[j]);
                                    break;
                                }
                            }
                        }
                        particleSystemRequestEntities.Dispose();
                    }
                    else
                    {
                        Debug.LogError("Cannot create new prefabs becuase we failed to laod thr original");
                    }
                }
                //test for any removal request
                if (particleSystemRemoveRequestQuery.CalculateEntityCount() > 0)
                {
                    //				Debug.Log("Detected "+ particleSystemRemoveRequestQuery.CalculateEntityCount()+" remove requests");
                    //now we test if there are any particlesystems that are finished being used
                    NativeArray <Entity> psds = particleSystemRemoveRequestQuery.ToEntityArray(Allocator.TempJob);
                    for (i = 0; i < psds.Length; i++)
                    {
                        ParticleSystemData psd = EntityManager.GetComponentData <ParticleSystemData>(psds[i]);
                        for (j = 0; j < pses.Length; j++)
                        {
                            //				Debug.Log("testing "+pses[j].id +" with "+ psd.particleSystemEntity.id);
                            if (pses[j].id == psd.particleSystemEntity.id)
                            {
                                //					Debug.Log("Preforming remove request on id " + pses[j].id);
                                EntityManager.SetComponentData(psds[i], new ParticleSystemData {
                                });
                                EntityManager.RemoveComponent <ParticleSystemRemoveRequest>(psds[i]);
                                EntityManager.SetComponentData(particleSystemEntityEntities[j], new ParticleSystemEntity
                                {
                                    id       = pses[j].id,
                                    isActive = false
                                });
                                break;
                            }
                        }
                    }
                    psds.Dispose();
                }
                pses.Dispose();
                particleSystemEntityEntities.Dispose();
                return(inputDeps);
            }
		private void CheckChanged(Application application)
		{

			//has the file changed?
			DateTime modifiedTime = File.GetLastWriteTime(this.filename);

			ParticleSystem system = this.system.Target as ParticleSystem;

			if (system == null)
			{
				//particle system is no longer
				return;
			}

			if (sourceFileModifiedDate < modifiedTime)
			{
				sourceFileModifiedDate = modifiedTime;
				//particle system source has changed...

				//attempt to reload

				ParticleSystemData previousData = loadedSystemData;


				try
				{
					XmlDocument doc = new XmlDocument();
					doc.Load(this.filename);
					XmlElement root = doc.SelectSingleNode("particlesystem") as XmlElement;
					if (root == null)
						throw new ArgumentException("Missing XML root element \'particlesystem\'");

					loadedSystemData = new ParticleSystemData(this.filename, root, ContentTargetPlatform.Windows, false, null, pathToShaderSystem);

					LocalContentLoader content = new LocalContentLoader(loadedSystemData);
					application.Content.Add(content);

					system.SetParticleSystemHotloadedData(loadedSystemData);

					if (previousData != null)
					{
						//previous hot load has existing data still hanging around
						foreach (ParticleSystemTypeData typeData in previousData.ParticleTypeData)
						{
							//this is nasty
							//eeek! this texture was loaded with FromFile()....
							if (typeData.Texture != null)
								typeData.Texture.Dispose();
						}
					}
				}
				catch (Exception ex)
				{
					loadedSystemData = null;

					try
					{
						//show a message
						//the difficult way...
						string assembly = @"System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

						Type type = System.Reflection.Assembly.Load(assembly).GetType("System.Windows.Forms.MessageBox");

						System.Reflection.MethodInfo method = type.GetMethod("Show", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static, null, new Type[] { typeof(string), typeof(string) }, null);

						method.Invoke(null, new string[] { ex.ToString(), "Error importing updated particle system" });
					}
					catch
					{
						throw ex;
					}
				}
			}
		}
Exemplo n.º 20
0
 public void SystemCanBeCreatedFromDataOfEmitterNames()
 {
     var particleSystemData = new ParticleSystemData
     {
         emitterNames = new List<string>(new[] { "PointEmitter3D", "PointEmitter3D" })
     };
     var createdParticleSystem = new ParticleSystem(particleSystemData);
     Assert.AreEqual(particleSystemData.emitterNames.Count,
         createdParticleSystem.AttachedEmitters.Count);
 }
		/// <summary>
		/// Dispose this particle system, unloading resources created by it's processor and storage children
		/// </summary>
		public void Dispose()
		{
			if (disposed)
				return;


			disposed = true;
			this.threadWaitCallback.WaitForCompletion();

			this.timeStep = 0;
			this.renderStepCount = 0;

			this.systemData = null;
			this.systemLogic = null;

			for (int i = 0; i < this.particleStore.Length; i++)
			{
				this.particleStore[i].Dispose();
				this.particleStore[i] = null;
			}
			for (int i = 0; i < this.triggers.Length; i++)
			{
				this.triggers[i] = null;
			}
			for (int i = 0; i < this.toggles.Length; i++)
			{
				this.toggles[i] = null;
			}
			for (int i = 0; i < particleStoreSortedDrawOrder.Length; i++)
			{
				if (particleStoreSortedDrawOrder[i] != null)
					particleStoreSortedDrawOrder[i].Clear();
			}
			particleStoreSortedDrawOrder = null;
		}
    ApplyLerp(Component targetComponent, ComponentData rightData, float factor)
    {
        ParticleSystem     target = (ParticleSystem)targetComponent;
        ParticleSystemData right  = (ParticleSystemData)rightData;

        //determine time
        float loopTime  = target.main.duration;
        float deltaTime = FrameData.frameInterval;
        float lerpTime;

        if (IsLoopingType(target))
        {
            lerpTime = GUC.Math.Repeat(this.time + FrameData.timeToLeft, loopTime);
        }
        else if (this.time > 0f)
        {
            lerpTime = Mathf.Clamp(this.time + FrameData.timeToLeft, 0f, loopTime);
        }
        else if (right.time > 0f)
        {
            lerpTime = Mathf.Clamp(right.time - FrameData.timeToRight, 0f, loopTime);
        }
        else
        {
            lerpTime = 0f;
        }

        //check if lerp is caught between a loop reset
        if (deltaTime < 0f)
        {
            lerpTime   = Mathf.Lerp(this.time, right.time + loopTime, factor) % loopTime;
            deltaTime += loopTime;
        }

        //List out all particles, left and right
        List <ParticleData> leftParticles = new List <ParticleData>();

        for (int i = 0; i < this.size; i++)
        {
            leftParticles.Add(new ParticleData(this.particles[i]));
        }
        List <ParticleData> rightParticles = new List <ParticleData>();

        for (int i = 0; i < right.size; i++)
        {
            rightParticles.Add(new ParticleData(right.particles[i]));
        }

        //match them up as well as possible
        int matched = 0;
        List <ParticleData> matchedParticles = new List <ParticleData>();

        while (leftParticles.Count > 0)
        {
            int sourceI = leftParticles.Count - 1;
            int matchI  = FindMatch(leftParticles[sourceI], rightParticles, deltaTime);

            if (matchI >= 0)
            {
                //if there is a match, add a lerped particle
                ParticleData lerpedParticle =
                    new ParticleData(leftParticles[sourceI], rightParticles[matchI], factor);
                matchedParticles.Add(lerpedParticle);
                leftParticles.RemoveAt(sourceI);
                rightParticles.RemoveAt(matchI);
                matched++;
            }
            else
            {
                //if there is no match, add unlerped particle if its not expired by now.
                if (!leftParticles[sourceI].IsExpired(factor * deltaTime))
                {
                    matchedParticles.Add(leftParticles[sourceI]);
                }
                leftParticles.RemoveAt(sourceI);
            }
        }

        //add any remaining particles at right hand side, if they had already spawned
        for (int i = 0; i < rightParticles.Count; i++)
        {
            if (!rightParticles[i].IsUnborn(loopTime, (1f - factor) * deltaTime))
            {
                matchedParticles.Add(rightParticles[i]);
            }
        }

        //apply Data's and apply particles
        int lerpSize = matchedParticles.Count;

        ParticleSystem.Particle[] systemParticles = Refresh(target, lerpSize);
        if (lerpSize > systemParticles.Length)
        {
            Debug.LogWarning("Too many particles recorded for system " + targetComponent.transform.name);
            lerpSize = systemParticles.Length;
        }
        for (int i = 0; i < lerpSize; i++)
        {
            systemParticles[i] = matchedParticles[i].Generate(systemParticles[i]);
        }
        target.SetParticles(systemParticles, size);

        if (playing && right.playing)
        {
            Kick(target, lerpTime);
        }
        if (IsLoopingType(target))
        {
            SetEmission(target, false);
        }
        else
        {
            target.Stop();
        }
    }
Exemplo n.º 23
0
 static public void    SetPSHromData(GameObject psHolder, ParticleSystemData psd)
 {
     ps = psHolder.GetComponent <ParticleSystem>();
     SetPSFromData(ps, psd);
 }
Exemplo n.º 24
0
		public void SystemCanBeCreatedFromDataOfEmitterNames()
		{
			if (!IsMockResolver)
				return; //ncrunch: no coverage start
			var particleSystemData = new ParticleSystemData
			{
				emitterNames = new List<string>(new[] { "PointEmitter3D", "PointEmitter3D" })
			};
			var createdParticleSystem = new ParticleSystem(particleSystemData);
			Assert.AreEqual(particleSystemData.emitterNames.Count,
				createdParticleSystem.AttachedEmitters.Count);
		}
Exemplo n.º 25
0
    public static void SetPSFromData(ParticleSystem ps, ParticleSystemData psd)
    {
        var main = ps.main;

        // ps.Stop();
        // main.duration = psd.duration;
        if (playeditorparticle == true)
        {
            ps.Stop();
            main.duration = psd.duration;
            ps.Play();
            playeditorparticle = false;
        }
        //ps.Stop();
        main.maxParticles    = 20000;
        main.simulationSpace = ParticleSystemSimulationSpace.World;
        main.startDelay      = psd.startDelay;
        main.loop            = false;
        // main.duration = psd.duration;
        main.startLifetime = psd.lifetime;
        main.startSpeed    = psd.speed;
        main.startSize     = psd.size;

        var em = ps.emission;

        if (psd.isBurst == true)
        {
            em.rateOverTime = 0;
            em.SetBursts(new ParticleSystem.Burst[] { new ParticleSystem.Burst(0f, psd.burstCount, psd.burstCount, psd.burstCycles, psd.burstinterval) });
        }
        else
        {
            em.SetBursts(new ParticleSystem.Burst[] { new ParticleSystem.Burst(0, 0, 0) });
            em.rateOverTime = psd.rate;
        }

        var sh = ps.shape;

        if (psd.shape == ParticleEmissionShape.Cone)
        {
            sh.shapeType             = ParticleSystemShapeType.Cone;
            sh.arcMode               = SetPSShape(psd);
            sh.angle                 = psd.angle;
            sh.radius                = psd.radius;
            sh.arc                   = psd.arc;
            sh.arcSpeed              = psd.rotspeed;
            sh.rotation              = new Vector3(90f, 0, 0);
            sh.scale                 = new Vector3(psd.xscale, 0, psd.zscale);
            ps.transform.eulerAngles = new Vector3(0, 0, psd.zrot);
            ps.transform.Rotate(0, 0, psd.zrotGameObject);
        }
        else if (psd.shape == ParticleEmissionShape.Donut)
        {
            sh.shapeType   = ParticleSystemShapeType.Donut;
            sh.arcMode     = SetPSShape(psd);
            sh.donutRadius = psd.donutRadius;
            sh.radius      = psd.radius;
            sh.arc         = psd.arc;
            sh.arcSpeed    = psd.rotspeed;
            sh.rotation    = new Vector3(0, 0, psd.zrot);
            sh.scale       = new Vector3(psd.xscale, psd.yscale, 0);
            ps.transform.Rotate(0, 0, psd.zrotGameObject);
        }
        else if (psd.shape == ParticleEmissionShape.Edge)
        {
            sh.shapeType = ParticleSystemShapeType.SingleSidedEdge;
            sh.arcMode   = SetPSShape(psd);
            sh.radius    = psd.radius;
            sh.arc       = psd.arc;
            sh.arcSpeed  = psd.rotspeed;
            sh.rotation  = new Vector3(0, 0, psd.zrot);
            sh.scale     = new Vector3(1, 1, 1);
            ps.transform.Rotate(0, 0, psd.zrotGameObject);
        }
        else if (psd.shape == ParticleEmissionShape.Circle)
        {
            sh.shapeType = ParticleSystemShapeType.Circle;
            sh.arcMode   = SetPSShape(psd);
            sh.radius    = psd.radius;
            sh.arc       = psd.arc;
            sh.arcSpeed  = psd.rotspeed;
            sh.rotation  = new Vector3(0, 0, psd.zrot);
            sh.scale     = new Vector3(psd.xscale, psd.yscale, 0);
            ps.transform.Rotate(0, 0, psd.zrotGameObject);
        }
        var FOL = ps.forceOverLifetime;

        FOL.enabled = true;
        FOL.x       = psd.xforce;
        FOL.y       = psd.yforce;

        var VOL = ps.velocityOverLifetime;

        VOL.x = psd.xvel;
        VOL.y = psd.yvel;

        //ps.Play();
    }
Exemplo n.º 26
0
 void OnEnable()
 {
     psd = ConfigPatterns.GetCurrentParticleSystemData();
 }