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 { #region [暴露属性字段] Essential Configs public Material renderMaterial; public float visibleTimeLength; public bool isAutoOrient; public float widthMultiplier; public AnimationCurve widthCurve; public Gradient gradient; #endregion #region [子模块接口] Submodules public TrailRenderer trailRenderer { get; set; } public TransformSubmodule transformSubmodule { get; set; } #endregion #region [生命周期] Lifecycle & Factory 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(); } #endregion } #region [接口定义] Interfaces public interface IHaveTrail { TrailRenderer trailRenderer { get; set; } } #endregion }