using System; using System.Collections; using System.Collections.Generic; using Dreamteck.Splines; using Ichni.RhythmGame.Beatmap; using UnityEngine; using UnityEngine.Serialization; namespace Ichni.RhythmGame { public partial class ParticleTracker : GameElement, IHaveParticles, IHaveColorSubmodule { public Track track; public ParticleController particleController; public ParticleSystem particle { get; set; } public ColorSubmodule colorSubmodule { get; set; } public bool haveBaseColor => true; public bool haveEmissionColor => true; public string themeBundleName; public string materialName; public bool prewarm; public float playTime; public float stopTime; public bool is3D; public float width; public Vector3 extendDirection; public float density; public float lifeTime; public bool isAutoOrient; public Vector3 particleRotation; public static ParticleTracker GenerateElement(string elementName, Guid id, List tags, bool isFirstGenerated, Track track, string themeBundleName, string materialName, bool prewarm, float playTime, float stopTime, bool is3D, float width, Vector3 extendDirection, float density, float lifeTime, bool isAutoOrient, Vector3 particleRotation) { ParticleTracker particleTracker = Instantiate(GameManager.instance.basePrefabs.particleTracker, track.transform) .GetComponent(); particleTracker.particle = particleTracker.GetComponent(); particleTracker.Initialize(elementName, id, tags, isFirstGenerated, track); particleTracker.track = track; particleTracker.particleController.spline = track.trackPathSubmodule.path; particleTracker.playTime = playTime; particleTracker.stopTime = stopTime; particleTracker.themeBundleName = themeBundleName; particleTracker.materialName = materialName; (particleTracker as IHaveParticles).SetParticleMaterial(themeBundleName, materialName); particleTracker.SetParticleSettings(prewarm, is3D, width, extendDirection, density, lifeTime, isAutoOrient, particleRotation); return particleTracker; } public override void SetDefaultSubmodules() { colorSubmodule = new ColorSubmodule(this, Color.white, true, Color.white, 0); } public void SetParticleSettings(bool prewarm, bool is3D, float width, Vector3 extendDirection, float density, float lifeTime, bool isAutoOrient, Vector3 particleRotation) { this.prewarm = prewarm; this.is3D = is3D; this.width = width; this.extendDirection = extendDirection; this.density = density; this.lifeTime = lifeTime; this.prewarm = prewarm; this.isAutoOrient = isAutoOrient; this.particleRotation = particleRotation; (this as IHaveParticles).SetParticleSettings(prewarm, ParticleSystemSimulationSpace.Local, density, lifeTime, 0, 1, isAutoOrient, particleRotation); SetShape(); } } public partial class ParticleTracker { private void Update() { float songTime = GameManager.instance.songTime; if (playTime > songTime || stopTime < songTime) { particle.Stop(); } else { if (!particle.isPlaying) { particle.Play(); } } } public override void SaveBM() { matchedBM = new ParticleTracker_BM(elementName, elementGuid, tags, parentElement.matchedBM as GameElement_BM, prewarm, playTime, stopTime, is3D, width, extendDirection, density, lifeTime, isAutoOrient, particleRotation, themeBundleName, materialName); } } public partial class ParticleTracker { private void SetShape() { particleController.is3D = is3D; particleController.width = width; particleController.extendDirection = extendDirection; particleController.Rebuild(); } public override void Refresh() { base.Refresh(); ParticleSystemRenderer particleSystemRenderer = particle.GetComponent(); particleSystemRenderer.material.SetColor("_BaseColor", colorSubmodule.currentBaseColor); if (colorSubmodule.emissionEnabled) { particleSystemRenderer.material.EnableKeyword("_EMISSION_ON"); particleSystemRenderer.material.SetColor("_EmissionColor", colorSubmodule.GetCurrentEmissionColor()); } else { particleSystemRenderer.material.DisableKeyword("_EMISSION_ON"); } } } namespace Beatmap { public class ParticleTracker_BM : GameElement_BM { public bool prewarm = false; public float playTime = 0f; public float stopTime = 1f; public bool is3D = false; public float width = 10f; public Vector3 extendDirection = Vector3.right; public float density = 10; public float lifeTime = 5; public bool isAutoOrient = true; public Vector3 particleRotation = Vector3.zero; public string materialThemeBundleName = string.Empty; public string materialName = string.Empty; public ParticleTracker_BM() { } public ParticleTracker_BM(string elementName, Guid elementGuid, List tags, GameElement_BM attachedElement, bool prewarm, float playTime, float stopTime, bool is3D, float width, Vector3 extendDirection, float density, float lifeTime, bool isAutoOrient, Vector3 particleRotation, string materialThemeBundleName, string materialName) : base(elementName, elementGuid, tags, attachedElement) { this.prewarm = prewarm; this.playTime = playTime; this.stopTime = stopTime; this.width = width; this.density = density; this.is3D = is3D; this.extendDirection = extendDirection; this.lifeTime = lifeTime; this.isAutoOrient = isAutoOrient; this.particleRotation = particleRotation; this.materialThemeBundleName = materialThemeBundleName; this.materialName = materialName; } public override void ExecuteBM() { matchedElement = ParticleTracker.GenerateElement( elementName, elementGuid, tags, false, GetElement(attachedElementGuid) as Track, materialThemeBundleName, materialName, prewarm, playTime, stopTime, is3D, width, extendDirection, density, lifeTime, isAutoOrient, particleRotation); } } } }