93 lines
2.8 KiB
C#
93 lines
2.8 KiB
C#
using Convention;
|
|
using Demo.Game.Attr;
|
|
using Dreamteck.Splines;
|
|
using System;
|
|
using System.Collections;
|
|
using System.IO;
|
|
using UnityEngine;
|
|
|
|
namespace Demo.Game
|
|
{
|
|
namespace ConfigType
|
|
{
|
|
public class SplineTubeRendererConfig : BasicSplineJustFollowConfig
|
|
{
|
|
public const bool DefaultIsDoubleSide = true;
|
|
public const int DefaultSidesCount = 12;
|
|
public bool IsDoubleSide = DefaultIsDoubleSide;
|
|
public int SidesCount = DefaultSidesCount;
|
|
|
|
public override void Deserialize(BinaryReader reader)
|
|
{
|
|
IsDoubleSide = BinarySerializeUtility.ReadBool(reader);
|
|
SidesCount = BinarySerializeUtility.ReadInt(reader);
|
|
base.Deserialize(reader);
|
|
}
|
|
|
|
public override void Serialize(BinaryWriter writer)
|
|
{
|
|
BinarySerializeUtility.WriteBool(writer, IsDoubleSide);
|
|
BinarySerializeUtility.WriteInt(writer, SidesCount);
|
|
base.Serialize(writer);
|
|
}
|
|
}
|
|
}
|
|
|
|
[Scriptable]
|
|
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;
|
|
|
|
protected override IEnumerator DoSomethingDuringApplyScript()
|
|
{
|
|
if (MyDefaultMaterial == null)
|
|
MyDefaultMaterial = Resources.Load<Material>("Tube/Default");
|
|
yield return base.DoSomethingDuringApplyScript();
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 禁用双面渲染,用于优化性能
|
|
/// </summary>
|
|
[Convention.RScript.Variable.Attr.Method]
|
|
public void DisableDoubleSide()
|
|
{
|
|
IsDoubleSide = false;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 设置面数,越高越圆润
|
|
/// </summary>
|
|
/// <param name="sides"></param>
|
|
[Convention.RScript.Variable.Attr.Method]
|
|
public void SetSides(int sides)
|
|
{
|
|
SidesCount = Mathf.Min(3, sides);
|
|
}
|
|
}
|
|
}
|