// random void SetSpriteInParticleSystem(int _mid = -1, int _gameMidsIndex = -1) { Debug.Log("SetRandomSpriteInParticleSystem() mid =" + mid); // choose random if (_mid < 1) { // sprites to choose from totalSprites = MonsterIndex.Instance.monstersFromSheetsDistinct.Length; // make sure its divisible by 3 spriteIndex = (int)Random.Range(0, totalSprites); while (spriteIndex % 3 != 0) { spriteIndex = (int)Random.Range(0, totalSprites); } } else { spriteIndex = _gameMidsIndex * 3; } // access particle system's TextureSheetAnimationModule ParticleSystem ps = GetComponent <ParticleSystem> (); ParticleSystem.TextureSheetAnimationModule tsam = ps.textureSheetAnimation; // SetSprite on the three tsam.SetSprite(0, MonsterIndex.Instance.monstersFromSheetsDistinct [spriteIndex + 0]); tsam.SetSprite(1, MonsterIndex.Instance.monstersFromSheetsDistinct [spriteIndex + 1]); tsam.SetSprite(2, MonsterIndex.Instance.monstersFromSheetsDistinct [spriteIndex + 2]); }
public void Destroy(bool particle = true) { if (particle) { ParticleSystem explosion = Instantiate(this.explosionParticle, this.transform.position, this.explosionParticle.transform.rotation); ParticleSystem.TextureSheetAnimationModule sheetAnimation = explosion.textureSheetAnimation; sheetAnimation.SetSprite(0, this.spriteRenderer.sprite); GameManager.Instance.PlaySound(this.explosionSound, 0.1f); } SpawnerManager.Instance.DestroyMeteor(this); }
private void CopyParticle(ParticleSystem part, ParticleSystem newPart) { ParticleSystem.MainModule main = part.main; main.duration = newPart.main.duration; main.startLifetime = newPart.main.startLifetime; main.startSpeed = newPart.main.startSpeed; main.startSize = newPart.main.startSize; main.startColor = newPart.main.startColor; ParticleSystem.EmissionModule emis = part.emission; emis.rateOverTime = newPart.emission.rateOverTime; emis.rateOverDistance = newPart.emission.rateOverDistance; emis.burstCount = newPart.emission.burstCount; emis.SetBurst(0, newPart.emission.GetBurst(0)); ParticleSystem.ShapeModule shape = part.shape; shape.shapeType = newPart.shape.shapeType; shape.radius = newPart.shape.radius; shape.radiusThickness = newPart.shape.radiusThickness; shape.arc = newPart.shape.arc; shape.arcMode = newPart.shape.arcMode; shape.arcSpeed = newPart.shape.arcSpeed; shape.position = newPart.shape.position; shape.rotation = newPart.shape.rotation; ParticleSystem.RotationOverLifetimeModule rot = part.rotationOverLifetime; rot.enabled = newPart.rotationOverLifetime.enabled; rot.z = newPart.rotationOverLifetime.z; ParticleSystem.TextureSheetAnimationModule tex = part.textureSheetAnimation; tex.enabled = newPart.textureSheetAnimation.enabled; if (tex.enabled) { tex.mode = newPart.textureSheetAnimation.mode; tex.SetSprite(0, newPart.textureSheetAnimation.GetSprite(0)); } ParticleSystem.SubEmittersModule sub = part.subEmitters; sub.enabled = newPart.subEmitters.enabled; if (sub.enabled) { sub.AddSubEmitter(newPart.subEmitters.GetSubEmitterSystem(0), newPart.subEmitters.GetSubEmitterType(0), newPart.subEmitters.GetSubEmitterProperties(0)); } }
public bool Spawn() { if (active) { return(false); } int mining_level = Manager_Main.Instance.GetMiningLevel(); int max_gem_level = Manager_Main.Instance.GetGemColors().Length - 1; int gem_level = mining_level / mining_level_upgrade; gem_level = (gem_level > max_gem_level) ? max_gem_level : gem_level; gem_tier = 0; gem_type = 0; int val; bool found; // Choose a material to spawn int total_gem_chances = Manager_Main.Instance.GetTotalGemChances(gem_level); val = (int)(Random.value * total_gem_chances); val = (val >= total_gem_chances) ? (total_gem_chances - 1) : val; found = false; for (int i = 0; i <= gem_level && !found; ++i) { if (val < Manager_Main.Instance.GetTotalGemChances(i)) { gem_tier = i; found = true; } } // Choose a type to spawn val = (int)(Random.value * total_type_chances); val = (val >= total_type_chances) ? (total_type_chances - 1) : val; found = false; int total = 0; for (int i = 0; i < script_node_types.Length && !found; ++i) { total += script_node_types[i].GetSpawnChance(); if (val < total) { gem_type = i; found = true; } } max_durability = Manager_Main.Instance.GetGemHealths()[gem_tier] * script_node_types[gem_type].GetDurabilityMultiplier(); current_durability = max_durability; script_durability_meter.SetValue(current_durability / max_durability); script_node_types[gem_type].gameObject.SetActive(true); script_durability_meter.gameObject.SetActive(true); Color c = Manager_Main.Instance.GetGemColors()[gem_tier]; SpriteRenderer node_sprite_renderer = script_node_types[gem_type].GetComponentInChildren <SpriteRenderer>(); node_sprite_renderer.color = c; current_amount = script_node_types[gem_type].GetSpawnAmount(); // Set particles MM_mining.startColor = c; MM_finished.startColor = c; TAM_finished.SetSprite(0, node_sprite_renderer.sprite); // Set variables active = true; mining_residue = 0.5f; // Solves rounding issues mining_particle_play_next = mining_particle_thresh; return(true); }
/// <summary> /// Generates the particle effect when a demolision occurs /// </summary> /// <param name="tile"></param> /// <returns></returns> IEnumerator GenerateDestructionParticles(MapTile tile) { GameObject copyOfGameObject = GameObject.Instantiate(tile.Structure.GameObject); copyOfGameObject.name = "CopyStructures"; copyOfGameObject.transform.SetParent(tile.Structure.GameObject.transform.parent.gameObject.transform); GameObject customParticleSystem = new GameObject("CustomDemolishParticle"); customParticleSystem.transform.SetParent(copyOfGameObject.transform.parent, false); customParticleSystem.transform.position = copyOfGameObject.transform.position; ParticleSystem particles = customParticleSystem.AddComponent <ParticleSystem>(); Particles.InitParticleSystem(particles); particles.Stop(); copyOfGameObject.AddComponent <ShakerBehaviour>(); ParticleSystem.MainModule mainModule = particles.main; mainModule.startColor = Color.white; mainModule.startLifetime = 1; mainModule.startSize = new ParticleSystem.MinMaxCurve(0.3f, 0.5f); mainModule.startSpeed = 0.6f; mainModule.maxParticles = 100; mainModule.loop = false; mainModule.duration = 1; ParticleSystem.ShapeModule shapeModule = particles.shape; shapeModule.shapeType = ParticleSystemShapeType.Sphere; shapeModule.angle = 25; shapeModule.radius = 0.8f; shapeModule.scale = new Vector3(0.3f, 0.1f, 1); shapeModule.position = new Vector3(0, -0.4f, 0); var emission = particles.emission; emission.rateOverTime = 30; emission.enabled = true; var colorOverLifetime = particles.colorOverLifetime; Gradient gradientLifetime = new Gradient(); GradientColorKey[] colorKeys = new GradientColorKey[2]; colorKeys[0].color = Color.white; colorKeys[0].time = 0.0f; colorKeys[1].color = Color.white; colorKeys[1].time = 1.0f; GradientAlphaKey[] alphaKeys = new GradientAlphaKey[2]; alphaKeys[0].alpha = 1; alphaKeys[0].time = 0.5f; alphaKeys[1].alpha = 0; alphaKeys[1].time = 1.0f; gradientLifetime.SetKeys(colorKeys, alphaKeys); colorOverLifetime.color = gradientLifetime; colorOverLifetime.enabled = true; var sizeOverLifetime = particles.sizeOverLifetime; sizeOverLifetime.size = new ParticleSystem.MinMaxCurve(1, new AnimationCurve(new Keyframe(0.0f, 0.0f), new Keyframe(0.5f, 1.0f, 0, 0))); sizeOverLifetime.enabled = true; var limit = particles.limitVelocityOverLifetime; limit.separateAxes = true; limit.limitX = 1; limit.limitY = 0; limit.limitZ = 0; limit.dampen = 1; limit.enabled = true; ParticleSystem.TextureSheetAnimationModule textureSheetAnimationModule = particles.textureSheetAnimation; textureSheetAnimationModule.enabled = true; textureSheetAnimationModule.mode = ParticleSystemAnimationMode.Sprites; textureSheetAnimationModule.SetSprite(0, Resources.Load <Sprite>("Textures/CloudParticle")); Renderer renderer = particles.GetComponent <Renderer>(); renderer.sortingLayerName = "Structure"; renderer.sortingOrder = 100; particles.Play(); var existingSmoker = tile.Structure.GameObject.GetComponentInChildren <ParticleSystem>(); if (existingSmoker != null) { var position = existingSmoker.transform.localPosition; var scale = existingSmoker.transform.localScale; // Wait until structure does its unrendering. yield return(new WaitForEndOfFrame()); // Copy over existing smoker and make them stay at their place relative to the world even when the building is falling. existingSmoker.transform.SetParent(copyOfGameObject.transform); existingSmoker.transform.localScale = scale; existingSmoker.transform.localPosition = position; // Stop any existing smokers. Let their trail stay though. foreach (var smoker in copyOfGameObject.GetComponentsInChildren <ParticleSystem>()) { smoker.Stop(); } } yield return(new WaitForSeconds(10)); GameObject.Destroy(copyOfGameObject); GameObject.Destroy(customParticleSystem); }