/// <summary> /// Initializes the LineRenderer's that are the lasers and /// the muzzle flash emitter pool. /// </summary> protected override void SetupWeapon() { leftLaser = left.gameObject.AddComponent <LineRenderer>(); leftLaser.material = laserMaterial; leftLaser.shadowCastingMode = ShadowCastingMode.Off; leftLaser.receiveShadows = false; leftLaser.alignment = LineAlignment.View; leftLaser.startWidth = thickness; leftLaser.endWidth = thickness; leftLaser.enabled = false; rightLaser = right.gameObject.AddComponent <LineRenderer>(); rightLaser.material = laserMaterial; rightLaser.shadowCastingMode = ShadowCastingMode.Off; rightLaser.receiveShadows = false; rightLaser.alignment = LineAlignment.View; rightLaser.startWidth = thickness; rightLaser.endWidth = thickness; rightLaser.enabled = false; muzzleFlashEmitters = new ParticleSystems[Mathf.FloorToInt(fireRate * 2.5f)]; muzzleFlashIndex = 0; for (int i = 0; i < muzzleFlashEmitters.Length; ++i) { GameObject muzzleFlash = Instantiate(muzzleFlashEmitter, transform); ParticleSystems muzzleFlashSystem = muzzleFlash.GetComponent <ParticleSystems>(); muzzleFlashSystem.stop(); muzzleFlashSystem.clear(); muzzleFlashEmitters[i] = muzzleFlashSystem; } }
void Awake() { ourSystem = GetComponentInParent <ParticleSystems>(); ScreamFollowObject.ScreamObjectMoving += SetObjectWereFollowing; PromptPlayerHit.PlayerFailed += ScreamSucceeded; PromptPlayerHit.PlayerParried += StopFollowing; }
public void InstantiateParticlePrefab(Vector2 mousePosition, float maxDistance) { if (this.spawnedPrefabs != null && !this.disableSpawn) { Vector3 position = mousePosition; position.z = maxDistance; Vector3 vector = Camera.main.ScreenToWorldPoint(position); Vector3 direction = vector - Camera.main.transform.position; RaycastHit raycastHit; Physics.Raycast(Camera.main.transform.position + Camera.main.transform.forward * 0.01f, direction, out raycastHit, maxDistance); Vector3 position2; if (raycastHit.collider) { position2 = raycastHit.point; } else { position2 = vector; } ParticleSystems particleSystems = this.particlePrefabs[this.currentParticlePrefabIndex]; ParticleSystems particleSystems2 = UnityEngine.Object.Instantiate <ParticleSystems>(particleSystems, position2, particleSystems.transform.rotation); particleSystems2.gameObject.SetActive(true); particleSystems2.transform.parent = base.transform; this.spawnedPrefabs.Add(particleSystems2); } }
/// <summary> /// Initializes the LineRenderer's for the minigun tracers and /// the muzzle flash emitter pool. /// </summary> protected override void SetupWeapon() { foreach (Renderer r in barrelRenderers) { r.material.SetColor("_overheatColor", overheatBarrelColor); r.material.SetFloat("_overheatPercent", 0.0f); } for (int i = 0; i < left.Length; ++i) { InitLineRenderer(left[i]); InitLineRenderer(right[i]); } muzzleFlashEmitters = new ParticleSystems[Mathf.FloorToInt(fireRate * 2.5f)]; muzzleFlashIndex = 0; for (int i = 0; i < muzzleFlashEmitters.Length; ++i) { GameObject muzzleFlash = Instantiate(muzzleFlashEmitter, transform); ParticleSystems muzzleFlashSystem = muzzleFlash.GetComponent <ParticleSystems>(); muzzleFlashSystem.stop(); muzzleFlashSystem.clear(); muzzleFlashEmitters[i] = muzzleFlashSystem; } }
/// <summary> /// Shoots the miniguns. Alternates between left and right, shooting from a random barrel /// for aesthetic purposes. Spawns the muzzle flash emitter and plays the firing sound. /// </summary> /// <param name="position"> The position of the shot </param> private IEnumerator Shoot(Vector3 position) { canShoot = false; if (!isOverheating) { isCooling = false; if (overheatDecreaseDelayCoroutine != null) { StopCoroutine(overheatDecreaseDelayCoroutine); overheatDecreaseDelayCoroutine = null; } overheatDecreaseDelayCoroutine = StartCoroutine(OverheatDecreaseDelay()); } else { Debug.LogError(GetType().Name + " - Shot while overheating."); } if (overheatTickCoroutine != null) { StopCoroutine(overheatTickCoroutine); } AddOverheat(); GameObject barrel = isLeftFire ? left[Random.Range(0, left.Length)] : right[Random.Range(0, right.Length)]; ParticleSystems muzzleFlash = muzzleFlashEmitters[muzzleFlashIndex++]; muzzleFlash.gameObject.transform.position = barrel.transform.position; muzzleFlash.gameObject.transform.rotation = barrel.transform.rotation; muzzleFlash.play(); if (muzzleFlashIndex >= muzzleFlashEmitters.Length) { muzzleFlashIndex = 0; } StartCoroutine(FlashTracer(barrel, position, barrel.GetComponent <LineRenderer>())); source.PlayOneShot(minigunShootSound); reference.statistics.IsFiring(); reference.statistics.WeaponFired("Minigun", 1); reference.playerIdleTimer.SetIsIdle(false); yield return(new WaitForSeconds(1.0f / fireRate)); isLeftFire = !isLeftFire; canShoot = true; reference.statistics.IsNotFiring(); reference.playerIdleTimer.SetIsIdle(true); }
/// <summary> /// Blocks the gun from shooting based on fire rate, updates LineRenderers, plays a muzzle /// flash emitter, plays the gun sound and starts the FlashLaser coroutine. /// </summary> /// <param name="position"> The position of the target being shot </param> private IEnumerator Shoot(Vector3 position) { canShoot = false; GameObject laser; if (isLeftFire) { leftLaser.endWidth = thickness * Mathf.Max( Vector3.Magnitude(left.transform.position - position), 1.0f); leftLaser.SetPosition(0, left.transform.position); leftLaser.SetPosition(1, position); laser = left; } else { rightLaser.endWidth = thickness * Mathf.Max( Vector3.Magnitude(right.transform.position - position), 1.0f); rightLaser.SetPosition(0, right.transform.position); rightLaser.SetPosition(1, position); laser = right; } ParticleSystems muzzleFlash = muzzleFlashEmitters[muzzleFlashIndex++]; muzzleFlash.gameObject.transform.position = laser.transform.position; muzzleFlash.gameObject.transform.rotation = laser.transform.rotation; muzzleFlash.play(); if (muzzleFlashIndex >= muzzleFlashEmitters.Length) { muzzleFlashIndex = 0; } StartCoroutine(FlashLaser(isLeftFire)); source.PlayOneShot(laserShootSound); reference.statistics.IsFiring(); reference.statistics.WeaponFired("Laser Gun", 1); reference.playerIdleTimer.SetIsIdle(false); yield return(new WaitForSeconds(1.0f / fireRate)); isLeftFire = !isLeftFire; canShoot = true; reference.statistics.IsNotFiring(); reference.playerIdleTimer.SetIsIdle(true); }
public static ParticleSystem GetParticleSystem(string vid) { if (!ParticleSystems.ContainsKey(vid)) { ParticleSystem s = new ParticleSystem(vid); League.Engine.Components.Add(s); ParticleSystems.Add(vid, s); return(s); } return(ParticleSystems[vid]); }
/// <summary> /// Initialize reference manager reference and system /// </summary> protected override void Awake() { base.Awake(); system = GetComponent <ParticleSystems>(); if (system != null) { system.onParticleSystemsDeadEvent += OnParticleSystemsDead; } }
void OnEnable() { titleContent = new GUIContent("Particle Generator"); if (babylonParticles == null && Selection.activeObject is ParticleSystems) { babylonParticles = Selection.activeObject as ParticleSystems; } if (shurikenParticles == null && Selection.activeObject is ParticleSystem) { shurikenParticles = Selection.activeObject as ParticleSystem; } }
// ... public void InstantiateParticlePrefab(Vector2 mousePosition, float maxDistance) { if (spawnedPrefabs != null) { if (!disableSpawn) { Vector3 position = mousePosition; position.z = maxDistance; Vector3 worldMousePosition = Camera.main.ScreenToWorldPoint(position); Vector3 directionToWorldMouse = worldMousePosition - Camera.main.transform.position; RaycastHit rayHit; // Start the raycast a little bit ahead of the camera because the camera starts right where a cube's edge is // and that causes the raycast to hit... spawning a prefab right at the camera position. It's fixed by moving the camera, // or I can just add this forward to prevent it from happening at all. Physics.Raycast(Camera.main.transform.position + Camera.main.transform.forward * 0.01f, directionToWorldMouse, out rayHit, maxDistance); Vector3 spawnPosition; if (rayHit.collider) { spawnPosition = rayHit.point; } else { spawnPosition = worldMousePosition; } ParticleSystems prefab = particlePrefabs[currentParticlePrefabIndex]; ParticleSystems newParticlePrefab = Instantiate( prefab, spawnPosition, prefab.transform.rotation) as ParticleSystems; newParticlePrefab.gameObject.SetActive(true); // Parent to spawner. newParticlePrefab.transform.parent = transform; spawnedPrefabs.Add(newParticlePrefab); } } }
// ... public void instantiateParticlePrefab(Vector3 mousePosition) { if (!disableSpawn) { mousePosition.z = -Camera.main.transform.localPosition.z; Vector3 spawnPosition = Camera.main.ScreenToWorldPoint(mousePosition); ParticleSystems newParticlePrefab = Instantiate( particlePrefabs[currentParticlePrefab], spawnPosition, Quaternion.identity) as ParticleSystems; newParticlePrefab.gameObject.SetActive(true); // Parent to spawner. newParticlePrefab.transform.parent = transform; spawnedPrefabs.Add(newParticlePrefab); } }
// ... public void instantiateParticlePrefab(Vector2 mousePosition, float maxDistance) { if (spawnedPrefabs != null) { if (!disableSpawn) { Vector3 position = mousePosition; position.z = maxDistance; Vector3 worldMousePosition = Camera.main.ScreenToWorldPoint(position); Vector3 directionToWorldMouse = worldMousePosition - Camera.main.transform.position; RaycastHit rayHit; Physics.Raycast(Camera.main.transform.position, directionToWorldMouse, out rayHit, maxDistance); Vector3 spawnPosition; if (rayHit.collider) { spawnPosition = rayHit.point; } else { spawnPosition = worldMousePosition; } ParticleSystems prefab = particlePrefabs[currentParticlePrefab]; ParticleSystems newParticlePrefab = Instantiate( prefab, spawnPosition, prefab.transform.rotation) as ParticleSystems; newParticlePrefab.gameObject.SetActive(true); // Parent to spawner. newParticlePrefab.transform.parent = transform; spawnedPrefabs.Add(newParticlePrefab); } } }
public void OnGUI() { EditorGUILayout.Space(); babylonParticles = EditorGUILayout.ObjectField("Babylon Particle System:", babylonParticles, typeof(ParticleSystems), true) as ParticleSystems; EditorGUILayout.Space(); shurikenParticles = EditorGUILayout.ObjectField("Shuriken Particle System:", shurikenParticles, typeof(ParticleSystem), true) as ParticleSystem; EditorGUILayout.Space(); defaultColor = EditorGUILayout.ColorField("Default Particle Color:", defaultColor); EditorGUILayout.Space(); updateSpeedModifier = (float)EditorGUILayout.Slider("Start Speed Modifier:", updateSpeedModifier, 0.0f, 1.0f); EditorGUILayout.Space(); emitRateModifier = (float)EditorGUILayout.Slider("Emit Rate Modifier:", emitRateModifier, 0.0f, 100.0f); EditorGUILayout.Space(); convertCurveValues = (BabylonCurveValues)EditorGUILayout.EnumPopup("Convert Curve Values:", convertCurveValues, GUILayout.ExpandWidth(true)); EditorGUILayout.Space(); exportShurikenData = EditorGUILayout.Toggle("Custom Shuriken Data:", exportShurikenData); EditorGUILayout.Space(); keepGeneratorOpen = EditorGUILayout.Toggle("Keep Generator Open:", keepGeneratorOpen); EditorGUILayout.Space(); EditorGUILayout.Space(); if (GUILayout.Button("Parse Shuriken Particle System")) { if (shurikenParticles && babylonParticles) { Parse(); } if (!shurikenParticles) { ExporterWindow.ShowMessage("You must select a shuriken particle system"); } else if (!babylonParticles) { ExporterWindow.ShowMessage("You must select a babylon particle system"); } } }
public void unparentObjects() { Transform targetParent = unparentSelectObjectsToBulletParent ? transform.parent : objectsToUnparentTarget; for (int i = 0; i < objectsToUnparentOnDestroy.Count; i++) { // In the case of DestroyOnParticlesDead, the object may not exist any more. if (objectsToUnparentOnDestroy[i]) { ParticleSystems particleSystems = objectsToUnparentOnDestroy[i].GetComponent <ParticleSystems>(); if (particleSystems) { particleSystems.stop(); particleSystems.setLoop(false); } objectsToUnparentOnDestroy[i].parent = targetParent; } } }
public virtual void Remove(ParticleSystems.Particle value) { List.Remove(value); }
public virtual void Add(ParticleSystems.Particle value) { List.Add(value); }