using System; using System.Collections; using System.Collections.Generic; using Ichni.RhythmGame.Beatmap; using UniRx; using UnityEngine; namespace Ichni.RhythmGame { public partial class Trail : GameElement, IHaveTransformSubmodule, IHaveTrail { public TrailRenderer trailRenderer { get; set; } public Material renderMaterial; public float visibleTimeLength; public bool isAutoOrient; public float widthMultiplier; public AnimationCurve widthCurve; public Gradient gradient; public TransformSubmodule transformSubmodule { get; set; } public static Trail GenerateElement(string name, Guid id, List tags, bool isFirstGenerated, GameElement parentElement, float visibleTimeLength, bool isAutoOrient, float widthMultiplier, AnimationCurve widthCurve, Gradient gradient, Material material = null) { Trail trail = Instantiate(GameManager.instance.basePrefabs.trail, parentElement.transform).GetComponent(); trail.trailRenderer = trail.GetComponent(); trail.Initialize(name, id, tags, isFirstGenerated, parentElement); trail.renderMaterial = material == null ? GameManager.instance.basePrefabs.defaultTrailMaterial : material; trail.visibleTimeLength = visibleTimeLength; trail.isAutoOrient = isAutoOrient; trail.widthMultiplier = widthMultiplier; trail.widthCurve = widthCurve; trail.gradient = gradient; trail.trailRenderer.material = trail.renderMaterial; trail.trailRenderer.time = visibleTimeLength; trail.trailRenderer.alignment = isAutoOrient ? LineAlignment.View : LineAlignment.TransformZ; trail.trailRenderer.widthMultiplier = widthMultiplier; trail.trailRenderer.widthCurve = widthCurve; trail.trailRenderer.colorGradient = gradient; trail.trailRenderer.emitting = false; return trail; } public override void SetDefaultSubmodules() { transformSubmodule = new TransformSubmodule(this); } public override void WhenStart() { base.WhenStart(); trailRenderer.emitting = true; trailRenderer.Clear(); } } public partial class Trail { public override void SaveBM() { matchedBM = new Trail_BM(elementName, elementGuid, tags, parentElement.matchedBM as GameElement_BM, visibleTimeLength, isAutoOrient, widthMultiplier, widthCurve, renderMaterial, gradient); } } public interface IHaveTrail { TrailRenderer trailRenderer { get; set; } } namespace Beatmap { public class Trail_BM : GameElement_BM { public float visibleTimeLength; public string renderMaterialName; public bool isAutoOrient; public float widthMultiplier; public AnimationCurve widthCurve; public Gradient gradient; public Trail_BM() { } public Trail_BM(string elementName, Guid elementGuid, List tags, GameElement_BM attachedElement, float visibleTimeLength, bool isAutoOrient, float widthMultiplier, AnimationCurve widthCurve, Material renderMaterial, Gradient gradient) : base(elementName, elementGuid, tags, attachedElement) { this.visibleTimeLength = visibleTimeLength; this.renderMaterialName = renderMaterial.name; this.isAutoOrient = isAutoOrient; this.widthMultiplier = widthMultiplier; this.widthCurve = widthCurve; this.gradient = gradient; } public override void ExecuteBM() { matchedElement = Trail.GenerateElement(elementName, elementGuid, tags, false, GetElement(attachedElementGuid), visibleTimeLength, isAutoOrient, widthMultiplier, widthCurve, gradient); } } } }