Files
Convention-Unity-Demo/Assets/Scripts/MoreSpline/PointBaseRenderer/SplineTubeRenderer.cs

67 lines
1.9 KiB
C#
Raw Normal View History

2025-09-25 19:04:05 +08:00
using Convention;
2025-12-12 15:19:10 +08:00
using Demo.Attr;
2025-09-25 19:04:05 +08:00
using Dreamteck.Splines;
2025-12-12 15:19:10 +08:00
using System;
using System.Collections;
2025-09-25 19:04:05 +08:00
using UnityEngine;
namespace Demo.Game
{
2025-12-12 15:19:10 +08:00
[Scriptable]
2025-09-25 19:04:05 +08:00
public class SplineTubeRenderer : BasicSplineRenderer<TubeGenerator>
{
public static SplineTubeRenderer Make()
{
return new GameObject().AddComponent<SplineTubeRenderer>();
}
public const bool DefaultIsDoubleSide = true;
public const int DefaultSidesCount = 12;
[Content] public bool IsDoubleSide = DefaultIsDoubleSide;
[Content] public int SidesCount = DefaultSidesCount;
2025-09-25 19:04:05 +08:00
protected override IEnumerator DoSomethingDuringApplyScript()
2025-09-25 19:04:05 +08:00
{
if (MyDefaultMaterial == null)
MyDefaultMaterial = Resources.Load<Material>("Tube/Default");
yield return base.DoSomethingDuringApplyScript();
2025-09-25 19:04:05 +08:00
}
public override void SetupMeshGenerator(TubeGenerator meshGenerater)
{
base.SetupMeshGenerator(meshGenerater);
meshGenerater.doubleSided = IsDoubleSide;
meshGenerater.sides = SidesCount;
}
public override IEnumerator UnloadScript()
{
yield return base.UnloadScript();
// Reset
{
IsDoubleSide = DefaultIsDoubleSide;
SidesCount = DefaultSidesCount;
}
2025-09-25 19:04:05 +08:00
}
/// <summary>
/// 禁用双面渲染,用于优化性能
/// </summary>
[Convention.RScript.Variable.Attr.Method]
2025-09-25 19:04:05 +08:00
public void DisableDoubleSide()
{
IsDoubleSide = false;
}
/// <summary>
/// 设置面数,越高越圆润
/// </summary>
/// <param name="sides"></param>
[Convention.RScript.Variable.Attr.Method]
2025-09-25 19:04:05 +08:00
public void SetSides(int sides)
{
SidesCount = Mathf.Min(3, sides);
}
}
}