public CustomSpring(CustomParticleSystem particleSystem, CustomParticle particle1, CustomParticle particle2, float restLength, float strength, float damping) { if (particleSystem == null) { throw new System.ArgumentNullException("particleSystem", "Cannot supply null as ParticleSystem to CustomSpring"); } if (particle1 == null) { throw new System.ArgumentNullException("particle1", "Cannot supply null as Particle1 to CustomSpring"); } if (particle2 == null) { throw new System.ArgumentNullException("particle2", "Cannot supply null as Particle2 to CustomSpring"); } this.CustomParticleSystem = particleSystem; this.CustomParticleSystem.Springs.Add(this); this.Particle1 = particle1; this.Particle2 = particle2; this.RestLength = restLength; this.Strength = strength; this.Damping = damping; }
private void aggregateSpringsForces() { if (Springs.Count > 0) { foreach (CustomSpring spring in Springs) { CustomParticle particle1 = spring.Particle1; CustomParticle particle2 = spring.Particle2; Vector3 positionDelta = particle2.Position - particle1.Position; float positionDeltaNorm = positionDelta.magnitude; if (positionDeltaNorm < 1f) { positionDeltaNorm = 1f; } Vector3 positionDeltaUnit = positionDelta / positionDeltaNorm; Vector3 springForce = spring.Strength * positionDeltaUnit * (positionDeltaNorm - spring.RestLength); particle1.AddForce(springForce); particle2.AddForce(-springForce); Vector3 velocityDelta = particle2.Velocity - particle1.Velocity; Vector3 projectionVelocityDeltaOnPositionDelta = Vector3.Dot(positionDeltaUnit, velocityDelta) * positionDeltaUnit; Vector3 dampingForce = spring.Damping * projectionVelocityDeltaOnPositionDelta; particle1.AddForce(dampingForce); particle2.AddForce(-dampingForce); } } }
private void DrawDrainFX(SpriteBatch sb, Vector2 pos, Rectangle innerSrcRect, float animaPercentChangeRate) { //DebugLibraries.Print( "drain", "drain:" + (-animaPercentChangeRate * 1024f) ); if (Main.rand.NextFloat() >= (-animaPercentChangeRate * 1024f)) { return; } float tint = Main.playerInventory ? 0.5f : 1f; int duration = Main.rand.Next(15, 60); var newPos = pos + new Vector2( (float)innerSrcRect.Width * Main.rand.NextFloat(), innerSrcRect.Y ); CustomParticle.Create( isInWorld: false, pos: newPos, tickDuration: duration, color: Color.Gold * tint, scale: 2f, sprayAmt: 1f, hasGravity: true ); }
private void instantiateParticle(Vector3 position, Vector3 direction, float speed, Color color) { CustomParticle particle = EntityManager.instantiateParticle(); particle.transform.position = position; particle.init(speed, direction, color); }
//Particle Functions. public void PlayParticle(CustomParticle customParticle, Vector3 playPosition, Vector3 lookDirection) { GameObject newObject = Instantiate(customParticle.particlePrefab, playPosition, Quaternion.LookRotation(lookDirection)); HierarchyHelp.ChangeScaleOfParentAndChildren(newObject.transform, customParticle.defaultScaling); ParticleSystem particle = newObject.GetComponent <ParticleSystem>(); particle.Play(); StartCoroutine(DeleteFinishedParticle(particle)); }
private CustomParticle addNewParticle(CustomParticleSystem particleSystem, float mass, Vector3 position, Vector3 velocity, bool bFixed, float lifeSpan) { if (ParticlePrefab != null) { CustomParticle particle = (Instantiate(ParticlePrefab) as GameObject).GetComponent <CustomParticle>(); particle.Initialize(particleSystem, mass, position, velocity, bFixed, lifeSpan); return(particle); } else { throw new System.NullReferenceException("ERROR: No particle prefab set on GameController!"); } }
void Awake() { if (m_Audio == null) { m_Audio = Camera.main.GetComponent <AudioPlayer>(); } if (m_CameraShake == null) { m_CameraShake = Camera.main.GetComponent <CameraShake>(); } CustomParticle.UpdateEffectorList(); }
//// public override void ModifyInterfaceLayers(List <GameInterfaceLayer> layers) { int barsIdx = layers.FindIndex(layer => layer.Name.Equals("Vanilla: Resource Bars")); if (barsIdx == -1) { return; } int npcChatIdx = layers.FindIndex(layer => layer.Name.Equals("Vanilla: NPC / Sign Dialog")); if (npcChatIdx == -1) { return; } int topIdx = layers.FindIndex(layer => layer.Name.Equals("Vanilla: Mouse Over")); if (topIdx == -1) { return; } // var particleLayer = new LegacyGameInterfaceLayer( "Necrotis: UI Particles", () => { CustomParticle.DrawParticles(Main.spriteBatch, false); return(true); }, InterfaceScaleType.UI ); /*var hoverLayer = new LegacyGameInterfaceLayer( * "Necrotis: Ankh Hover Tooltip", * drawAnkhHoverTip, * InterfaceScaleType.UI * );*/ GameInterfaceLayer npcButtonWDLayer = this.GetInterfaceLayer_NpcChatButton_WitchDoctor_HealNecrotis(); // layers.Add(particleLayer); //barsIdx + 1 //layers.Insert( topIdx + 1, hoverLayer ); layers.Insert(npcChatIdx + 1, npcButtonWDLayer); }
/* Phase Space State */ private void setPhaseSpaceState(List <CustomPhaseSpaceState> phaseSpaceState) { int particleCount = this.Particles.Count; if (particleCount > 0) { for (int i = 0; i < particleCount; i++) { CustomParticle particle = this.Particles[i]; particle.Position += new Vector3(phaseSpaceState[i].x, phaseSpaceState[i].y, phaseSpaceState[i].z); particle.Velocity = new Vector3(phaseSpaceState[i].xd, phaseSpaceState[i].yd, phaseSpaceState[i].zd); } } }
public CustomAttraction(CustomParticleSystem particleSystem, CustomParticle particle1, CustomParticle particle2, float strength, float minimumDistance) { if (particleSystem == null) throw new System.ArgumentNullException("particleSystem", "Cannot supply null as ParticleSystem to CustomAttraction"); if (particle1 == null) throw new System.ArgumentNullException("particle1", "Cannot supply null as Particle1 to CustomAttraction"); if (particle2 == null) throw new System.ArgumentNullException("particle2", "Cannot supply null as Particle2 to CustomAttraction"); this.CustomParticleSystem = particleSystem; this.CustomParticleSystem.Attractions.Add(this); this.Particle1 = particle1; this.Particle2 = particle2; this.Strength = strength; this.MinimumDistance = minimumDistance; }
public void KillParticle(CustomParticle particle) { if (Particles.Contains(particle)) { List <CustomAttraction> attractionsToBeKilled = new List <CustomAttraction>(); foreach (CustomAttraction attract in Attractions) { if (particle == attract.Particle1 || particle == attract.Particle2) { attractionsToBeKilled.Add(attract); } } while (attractionsToBeKilled.Count > 0) { KillAttraction(attractionsToBeKilled[0]); attractionsToBeKilled.RemoveAt(0); } List <CustomSpring> springsToBeKilled = new List <CustomSpring>(); foreach (CustomSpring spring in Springs) { if (particle == spring.Particle1 || particle == spring.Particle2) { springsToBeKilled.Add(spring); } } while (springsToBeKilled.Count > 0) { KillSpring(springsToBeKilled[0]); springsToBeKilled.RemoveAt(0); } particle.Delete(); Particles.Remove(particle); } else { Debug.LogWarning("KillParticle supplied particle parameter is invalid: " + particle.ToString()); } }
private void SwitchEmitters() { if (_currentEmitor != -1) { particleEmitters [_currentEmitor].SetActive(false); } _currentEmitor = (_currentEmitor + 1) % particleEmitters.Length; particleEmitters [_currentEmitor].SetActive(true); if (emitterText) { emitterText.text = preEmitterString + particleEmitters [_currentEmitor].name + postEmitterString; } if (updateEffectorsOnChange) { CustomParticle.UpdateEffectorList(); } }
public CustomSpring(CustomParticleSystem particleSystem, CustomParticle particle1, CustomParticle particle2, float restLength, float strength, float damping) { if (particleSystem == null) throw new System.ArgumentNullException("particleSystem", "Cannot supply null as ParticleSystem to CustomSpring"); if (particle1 == null) throw new System.ArgumentNullException("particle1", "Cannot supply null as Particle1 to CustomSpring"); if (particle2 == null) throw new System.ArgumentNullException("particle2", "Cannot supply null as Particle2 to CustomSpring"); this.CustomParticleSystem = particleSystem; this.CustomParticleSystem.Springs.Add(this); this.Particle1 = particle1; this.Particle2 = particle2; this.RestLength = restLength; this.Strength = strength; this.Damping = damping; }
//////////////// public override void PreUpdate() { if (this.player.whoAmI == Main.myPlayer) { if (Main.netMode != NetmodeID.Server) { if (Main.netMode == NetmodeID.MultiplayerClient) { DillutedEctoplasmItem.CanPickupAny(this); } CustomParticle.UpdateParticles(); } } if (!this.player.dead) { this.UpdateAnimaState(); this.UpdateAnimaBehaviors(); //DebugLibraries.Print( "necrotis", "necrotis%: "+this.AnimaPercent.ToString("N2") ); } }
private void DrawAnkh(SpriteBatch sb, float animaPercent, float animaChangeRate) { Vector2 pos = this.GetHUDComputedPosition(true); int necScroll = (int)(animaPercent * (float)this.AnkhFgTex.Height); var statSrcRect = new Rectangle( x: 0, y: this.AnkhFgTex.Height - necScroll, width: this.AnkhFgTex.Width, height: necScroll ); if (this.WasInventory != Main.playerInventory) { this.WasInventory = Main.playerInventory; CustomParticle.ClearAll(); } this.DrawAnkhMain(sb, pos, statSrcRect, animaPercent, animaChangeRate); this.DrawAnkhFx(sb, pos, statSrcRect, animaChangeRate); }
public CustomAttraction(CustomParticleSystem particleSystem, CustomParticle particle1, CustomParticle particle2, float strength, float minimumDistance) { if (particleSystem == null) { throw new System.ArgumentNullException("particleSystem", "Cannot supply null as ParticleSystem to CustomAttraction"); } if (particle1 == null) { throw new System.ArgumentNullException("particle1", "Cannot supply null as Particle1 to CustomAttraction"); } if (particle2 == null) { throw new System.ArgumentNullException("particle2", "Cannot supply null as Particle2 to CustomAttraction"); } this.CustomParticleSystem = particleSystem; this.CustomParticleSystem.Attractions.Add(this); this.Particle1 = particle1; this.Particle2 = particle2; this.Strength = strength; this.MinimumDistance = minimumDistance; }
private void aggregateAttractionsForces() { if (Attractions.Count > 0) { foreach (CustomAttraction attract in Attractions) { CustomParticle particle1 = attract.Particle1; CustomParticle particle2 = attract.Particle2; Vector3 positionDelta = particle2.Position - particle1.Position; float positionDeltaNorm = positionDelta.magnitude; if (positionDeltaNorm < attract.MinimumDistance) { positionDeltaNorm = attract.MinimumDistance; } Vector3 attractionForce = attract.Strength * particle1.Mass * particle2.Mass * positionDelta / positionDeltaNorm / positionDeltaNorm / positionDeltaNorm; particle1.AddForce(attractionForce); particle2.AddForce(-attractionForce); } } }
private void addNewBeamSystem() { Vector3 gravity = playerRef.transform.forward.normalized; float drag = 0.1f; int particleCount = 30; float particleMass = 10f, particleLifeSpan = 60f; float samplingRate = 10f; // 10 ms float springRestLength = 3f, springStrength = 3f, springDamping = 0.75f; CustomParticleSystem beamSystem = addNewParticleSystem(gravity, drag, playerRef.transform.position, samplingRate); beamSystem.name = "BEAM SYSTEM"; CustomParticle leaderParticle = addNewParticle(beamSystem, particleMass, beamSystem.Position + new Vector3(0f, 1f, 0f), Vector3.zero, true, particleLifeSpan); leaderParticle.name = "Leader Particle"; leaderParticle.transform.rotation = playerRef.transform.rotation; List <CustomParticle> stream1 = new List <CustomParticle>(), stream2 = new List <CustomParticle>(), stream3 = new List <CustomParticle>(), stream4 = new List <CustomParticle>(); for (int i = 0; i < Mathf.RoundToInt(particleCount / 4f); i++) { Vector3 pos = beamSystem.Position - playerRef.transform.forward.normalized * (float)(i + 1); CustomParticle particle = addNewParticle(beamSystem, particleMass, pos, Vector3.zero, false, particleLifeSpan); particle.name = "Stream_1-" + i.ToString(); stream1.Add(particle); CustomParticle particle2 = addNewParticle(beamSystem, particleMass, pos, Vector3.zero, false, particleLifeSpan); particle2.name = "Stream_2-" + i.ToString(); stream2.Add(particle2); CustomParticle particle3 = addNewParticle(beamSystem, particleMass, pos, Vector3.zero, false, particleLifeSpan); particle3.name = "Stream_3-" + i.ToString(); stream3.Add(particle3); CustomParticle particle4 = addNewParticle(beamSystem, particleMass, pos, Vector3.zero, false, particleLifeSpan); particle4.name = "Stream_4-" + i.ToString(); stream4.Add(particle4); if (i > 0) { addNewSpring(beamSystem, stream1[i], stream1[i - 1], springRestLength, springStrength, springDamping); addNewSpring(beamSystem, stream2[i], stream2[i - 1], springRestLength, springStrength, springDamping); addNewSpring(beamSystem, stream3[i], stream3[i - 1], springRestLength, springStrength, springDamping); addNewSpring(beamSystem, stream4[i], stream4[i - 1], springRestLength, springStrength, springDamping); } else { addNewSpring(beamSystem, leaderParticle, particle, springRestLength, springStrength * 1.5f, springDamping); addNewSpring(beamSystem, leaderParticle, particle2, springRestLength, springStrength * 1.5f, springDamping); addNewSpring(beamSystem, leaderParticle, particle3, springRestLength, springStrength * 1.5f, springDamping); addNewSpring(beamSystem, leaderParticle, particle4, springRestLength, springStrength * 1.5f, springDamping); } } }
private CustomSpring addNewSpring(CustomParticleSystem particleSystem, CustomParticle particle1, CustomParticle particle2, float restLength, float strength, float damping) { return(new CustomSpring(particleSystem, particle1, particle2, restLength, strength, damping)); }
private CustomAttraction addNewAttraction(CustomParticleSystem particleSystem, CustomParticle particle1, CustomParticle particle2, float strength, float minimumDistance) { return(new CustomAttraction(particleSystem, particle1, particle2, strength, minimumDistance)); }
void Update() { if (Input.GetKeyDown(KeyCode.B)) { addNewBeamSystem(); } if (Input.GetKeyDown(KeyCode.Delete) || Input.GetKeyDown(KeyCode.Backspace)) { if (this.ParticleSystems.Count > 0) { Destroy(ParticleSystems[0].gameObject, 1f); this.ParticleSystems.RemoveAt(0); Debug.Log("DELETED 0th particle system in list"); } } if (ParticleSystems.Count > 0) { foreach (CustomParticleSystem beamSystem in ParticleSystems) { if (beamSystem.Particles.Count > 0) { for (int i = 0; i < beamSystem.Particles.Count; i++) { CustomParticle particle = beamSystem.Particles[i]; if (!particle.Fixed) { particle.Velocity += Random.insideUnitSphere; } else { if (!particle.bProhibitMovement) { particle.transform.position += particle.transform.forward.normalized / 4f; } } } } } CustomParticleSystem lastBeam = ParticleSystems[ParticleSystems.Count - 1]; if (lastBeam != null && lastBeam.Particles.Count > 0) { CustomParticle leaderParticle = lastBeam.Particles[0]; if (leaderParticle != null) { Vector3 leaderPos = leaderParticle.Position; if (lastBeam.GetComponentInChildren <Camera>() == null) { beamCamera = (Instantiate(Resources.Load("BeamCamera")) as GameObject).GetComponent <Camera>(); beamCamera.transform.parent = lastBeam.transform; beamCamera.transform.localPosition = leaderPos + new Vector3(5f, 20f, 0f); beamCamera.transform.LookAt(leaderParticle.transform.position); beamCamera.transform.localPosition += new Vector3(0f, 0f, 20f); } else { beamCamera.transform.localPosition = leaderPos + new Vector3(5f, 20f, 0f); beamCamera.transform.LookAt(leaderParticle.transform.position); beamCamera.transform.localPosition += new Vector3(0f, 0f, 20f); } } } } }
public void KillParticle(CustomParticle particle) { if (Particles.Contains(particle)) { List<CustomAttraction> attractionsToBeKilled = new List<CustomAttraction>(); foreach (CustomAttraction attract in Attractions) { if (particle == attract.Particle1 || particle == attract.Particle2) { attractionsToBeKilled.Add(attract); } } while (attractionsToBeKilled.Count > 0) { KillAttraction(attractionsToBeKilled[0]); attractionsToBeKilled.RemoveAt(0); } List<CustomSpring> springsToBeKilled = new List<CustomSpring>(); foreach (CustomSpring spring in Springs) { if (particle == spring.Particle1 || particle == spring.Particle2) { springsToBeKilled.Add(spring); } } while (springsToBeKilled.Count > 0) { KillSpring(springsToBeKilled[0]); springsToBeKilled.RemoveAt(0); } particle.Delete(); Particles.Remove(particle); } else { Debug.LogWarning("KillParticle supplied particle parameter is invalid: " + particle.ToString()); } }
private void DrawGainFX(SpriteBatch sb, Vector2 pos, Rectangle innerSrcRect, float animaPercentChangeRate) { var srcPos = pos; srcPos.X += innerSrcRect.Width / 2; var origin = new Vector2(this.AnkhDripSource.Width / 2, this.AnkhDripSource.Height / 2); float tint = Main.playerInventory ? 0.5f : 1f; float flicker = 1f - (float)Math.Pow(Main.rand.NextFloat(), animaPercentChangeRate * 8192); sb.Draw( texture: this.AnkhDripSource, position: srcPos, sourceRectangle: null, color: Color.White * tint, rotation: 0f, origin: origin, scale: 0.5f, effects: SpriteEffects.None, layerDepth: 0f ); sb.Draw( texture: this.AnkhDripSource, position: srcPos, sourceRectangle: null, color: Color.White * (0.25f + (0.5f * flicker)) * tint, rotation: 0f, origin: origin, scale: 1f, effects: SpriteEffects.None, layerDepth: 0f ); sb.Draw( texture: this.AnkhDripSource, position: srcPos, sourceRectangle: null, color: Color.White * flicker * tint, rotation: 0f, origin: origin, scale: 2f, effects: SpriteEffects.None, layerDepth: 0f ); //DebugLibraries.Print( "gain", "gain:" + (-animaPercentChangeRate * 1024f) ); if (Main.rand.NextFloat() >= (animaPercentChangeRate * 1024f)) { return; } var dripPos = srcPos; dripPos.X += Main.rand.Next(8) - 4; CustomParticle.Create( isInWorld: false, pos: dripPos, tickDuration: 60 * 4, color: Color.Gold * tint, scale: 2f, sprayAmt: 0f, hasGravity: true ); }
private CustomSpring addNewSpring(CustomParticleSystem particleSystem, CustomParticle particle1, CustomParticle particle2, float restLength, float strength, float damping) { return new CustomSpring(particleSystem, particle1, particle2, restLength, strength, damping); }
private CustomAttraction addNewAttraction(CustomParticleSystem particleSystem, CustomParticle particle1, CustomParticle particle2, float strength, float minimumDistance) { return new CustomAttraction(particleSystem, particle1, particle2, strength, minimumDistance); }
//////////////// public override void PostDrawTiles() { CustomParticle.DrawParticles(Main.spriteBatch, true); }