从旧版中移植,Prefab未确认
This commit is contained in:
196
Convention/[Art]/Line/DreamTeckSplinePointBuilder.cs
Normal file
196
Convention/[Art]/Line/DreamTeckSplinePointBuilder.cs
Normal file
@@ -0,0 +1,196 @@
|
||||
#if DREAMTECK_SPLINES
|
||||
using System.Collections.Generic;
|
||||
using Convention.WindowsUI.Variant;
|
||||
using Dreamteck.Splines;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Convention.VFX
|
||||
{
|
||||
public class DreamTeckSplinePointBuilder : MonoAnyBehaviour, ILoadedInHierarchy
|
||||
{
|
||||
public enum InjectType
|
||||
{
|
||||
None = -1,
|
||||
SmoothMirrored = SplinePoint.Type.SmoothMirrored,
|
||||
Broken = SplinePoint.Type.Broken,
|
||||
SmoothFree = SplinePoint.Type.SmoothFree
|
||||
};
|
||||
[Setting, InspectorDraw] public PerformanceIndicator.PerformanceMode performanceMode = PerformanceIndicator.PerformanceMode.Speed;
|
||||
[Content] public List<LinePoint> childPoints = new();
|
||||
|
||||
[Resources, SerializeField, HopeNotNull, InspectorDraw] private SplineComputer m_splineComputer;
|
||||
[Setting, InspectorDraw] public InjectType PointType = InjectType.None;
|
||||
[Resources, SerializeField, HopeNotNull, InspectorDraw] private SplineRenderer m_splineRenderer;
|
||||
public SplineComputer MainSpline => m_splineComputer;
|
||||
[Content] public List<SplinePoint> knots = new();
|
||||
|
||||
[InspectorDraw]
|
||||
public Vector2 Range
|
||||
{
|
||||
get => new((float)m_splineRenderer.clipFrom, (float)m_splineRenderer.clipTo);
|
||||
set
|
||||
{
|
||||
m_splineRenderer.SetClipRange(value.x, value.y);
|
||||
}
|
||||
}
|
||||
[Percentage(0, 1), InspectorDraw]
|
||||
public float Head
|
||||
{
|
||||
get => (float)m_splineRenderer.clipFrom;
|
||||
set => m_splineRenderer.clipFrom = value;
|
||||
}
|
||||
[Percentage(0, 1), InspectorDraw]
|
||||
public float Tail
|
||||
{
|
||||
get => (float)m_splineRenderer.clipTo;
|
||||
set => m_splineRenderer.clipTo = value;
|
||||
}
|
||||
[Percentage(0, 1), InspectorDraw]
|
||||
public float Duration
|
||||
{
|
||||
get => (float)(m_splineRenderer.clipTo - m_splineRenderer.clipFrom);
|
||||
set => m_splineRenderer.clipTo = m_splineRenderer.clipFrom + value;
|
||||
}
|
||||
public float Distance
|
||||
{
|
||||
get => m_splineRenderer.CalculateLength(Head, Tail);
|
||||
set
|
||||
{
|
||||
var t = value / m_splineRenderer.CalculateLength(Head, Tail);
|
||||
Duration = t;
|
||||
}
|
||||
}
|
||||
public float GetDistanceBetweenHeadAndBegin()
|
||||
{
|
||||
return m_splineRenderer.CalculateLength(0, Head);
|
||||
}
|
||||
public float GetDistanceBetweenHeadAndTail()
|
||||
{
|
||||
return m_splineRenderer.CalculateLength(Head, Tail);
|
||||
}
|
||||
public float GetDistanceBetweenTailAndBegin()
|
||||
{
|
||||
return m_splineRenderer.CalculateLength(0, Tail);
|
||||
}
|
||||
public float GetDistanceBetweenEndAndTail()
|
||||
{
|
||||
return m_splineRenderer.CalculateLength(Tail, 1);
|
||||
}
|
||||
public float GetDistanceBetweenEndAndHead()
|
||||
{
|
||||
return m_splineRenderer.CalculateLength(Head,1);
|
||||
}
|
||||
public float GetTotalDistance()
|
||||
{
|
||||
return m_splineRenderer.CalculateLength(0, 1);
|
||||
}
|
||||
|
||||
|
||||
private void Reset()
|
||||
{
|
||||
m_splineComputer = GetComponent<SplineComputer>();
|
||||
m_splineRenderer = GetComponent<SplineRenderer>();
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
if (m_splineComputer == null)
|
||||
m_splineComputer = GetComponent<SplineComputer>();
|
||||
if (m_splineRenderer == null)
|
||||
m_splineRenderer = GetComponent<SplineRenderer>();
|
||||
}
|
||||
|
||||
private void LateUpdate()
|
||||
{
|
||||
if ((int)performanceMode >= (int)PerformanceIndicator.PerformanceMode.L6)
|
||||
{
|
||||
RebuildAll();
|
||||
m_splineRenderer.Rebuild();
|
||||
}
|
||||
else if ((int)performanceMode >= (int)PerformanceIndicator.PerformanceMode.L6)
|
||||
{
|
||||
if (childPoints.Count != knots.Count)
|
||||
RebuildAll();
|
||||
else
|
||||
ResetPoints();
|
||||
m_splineRenderer.Rebuild();
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetKnot([In, ArgPackage] ref SplinePoint point, [In, ArgPackage] LinePoint linePoint)
|
||||
{
|
||||
point.position = linePoint.transform.localPosition;
|
||||
point.normal = linePoint.Forward;
|
||||
point.size = linePoint.Scale;
|
||||
point.color = linePoint.PointColor;
|
||||
}
|
||||
|
||||
[Content]
|
||||
public void RebuildAll()
|
||||
{
|
||||
if (knots.Count != childPoints.Count)
|
||||
{
|
||||
for (int i = knots.Count, e = childPoints.Count; i != e; i++)
|
||||
knots.Add(new());
|
||||
}
|
||||
if (knots.Count != childPoints.Count)
|
||||
{
|
||||
knots.RemoveRange(childPoints.Count, knots.Count - childPoints.Count);
|
||||
}
|
||||
MainSpline.SetPoints(knots.ToArray());
|
||||
|
||||
// 更新所有点的位置和类型
|
||||
for (int i = 0; i < childPoints.Count; i++)
|
||||
{
|
||||
var point = knots[i];
|
||||
SetKnot(ref point, childPoints[i]);
|
||||
if (PointType != InjectType.None)
|
||||
point.type = (SplinePoint.Type)PointType;
|
||||
MainSpline.SetPoint(i, knots[i] = point, SplineComputer.Space.Local);
|
||||
}
|
||||
}
|
||||
[Content]
|
||||
public void ResetPoints()
|
||||
{
|
||||
if (knots.Count == 0)
|
||||
return;
|
||||
for (int i = 0; i < childPoints.Count; i++)
|
||||
{
|
||||
var point = knots[i];
|
||||
SetKnot(ref point, childPoints[i]);
|
||||
if (PointType != InjectType.None)
|
||||
point.type = (SplinePoint.Type)PointType;
|
||||
MainSpline.SetPoint(i, knots[i] = point);
|
||||
}
|
||||
for (int i = childPoints.Count, e = knots.Count; i < e; i++)
|
||||
{
|
||||
var point = knots[i];
|
||||
SetKnot(ref point, childPoints[i]);
|
||||
if (PointType != InjectType.None)
|
||||
point.type = (SplinePoint.Type)PointType;
|
||||
MainSpline.SetPoint(i, knots[i] = point);
|
||||
}
|
||||
}
|
||||
[Content]
|
||||
[return: ReturnNotNull]
|
||||
public LinePoint AddChild()
|
||||
{
|
||||
var trans = new GameObject("Point").AddComponent<LinePoint>();
|
||||
if (childPoints.Count > 0)
|
||||
{
|
||||
trans.transform.SetParent(childPoints[^1].transform.parent);
|
||||
trans.transform.position = childPoints[^1].transform.position;
|
||||
}
|
||||
childPoints.Add(trans);
|
||||
if (HierarchyWindow.instance && HierarchyWindow.instance.ContainsReference(this))
|
||||
{
|
||||
var item = HierarchyWindow.instance.GetReferenceItem(this)
|
||||
.CreateSubPropertyItemWithBinders(trans.gameObject)[0];
|
||||
item.ref_value.GetComponent<HierarchyItem>().title = trans.gameObject.name;
|
||||
}
|
||||
RebuildAll();
|
||||
return trans;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
11
Convention/[Art]/Line/DreamTeckSplinePointBuilder.cs.meta
Normal file
11
Convention/[Art]/Line/DreamTeckSplinePointBuilder.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9dcad3baf738c3d479d5507841c3c218
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
19
Convention/[Art]/Line/LinePoint.cs
Normal file
19
Convention/[Art]/Line/LinePoint.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Convention.VFX
|
||||
{
|
||||
public class LinePoint : MonoBehaviour, ILoadedInHierarchy
|
||||
{
|
||||
public float Scale { get; private set; }
|
||||
public float ScaleOne = new Vector3(1, 1, 1).magnitude;
|
||||
public Vector3 Forward { get; private set; }
|
||||
public Color PointColor = Color.white;
|
||||
public float PointWeight = 1;
|
||||
|
||||
private void Update()
|
||||
{
|
||||
Scale = transform.localScale.magnitude / ScaleOne;
|
||||
Forward = transform.forward;
|
||||
}
|
||||
}
|
||||
}
|
11
Convention/[Art]/Line/LinePoint.cs.meta
Normal file
11
Convention/[Art]/Line/LinePoint.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 634e0418c9478104ca8cf43ef250841d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
27
Convention/[Art]/Line/LinePointContainer.cs
Normal file
27
Convention/[Art]/Line/LinePointContainer.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Convention.VFX
|
||||
{
|
||||
[RequireComponent(typeof(LineRenderer))]
|
||||
public class LinePointContainer : MonoBehaviour
|
||||
{
|
||||
[Resources, HopeNotNull, SerializeField] private LineRenderer lineRenderer;
|
||||
private void Reset()
|
||||
{
|
||||
lineRenderer = GetComponent<LineRenderer>();
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
if (lineRenderer == null)
|
||||
lineRenderer = GetComponent<LineRenderer>();
|
||||
}
|
||||
|
||||
public void Rebuild()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
11
Convention/[Art]/Line/LinePointContainer.cs.meta
Normal file
11
Convention/[Art]/Line/LinePointContainer.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d9caa8670fe1a0046b08e71bd7509e05
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
137
Convention/[Art]/Line/SplinePointBuilder.cs
Normal file
137
Convention/[Art]/Line/SplinePointBuilder.cs
Normal file
@@ -0,0 +1,137 @@
|
||||
#if UNITY_SPLINE
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Convention.WindowsUI.Variant;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Splines;
|
||||
|
||||
namespace Convention.VFX
|
||||
{
|
||||
public class SplinePointBuilder : MonoAnyBehaviour, ILoadedInHierarchy
|
||||
{
|
||||
[Setting, InspectorDraw] public PerformanceIndicator.PerformanceMode performanceMode = PerformanceIndicator.PerformanceMode.Speed;
|
||||
[Content] public List<LinePoint> childPoints = new();
|
||||
|
||||
[Resources, SerializeField, HopeNotNull, InspectorDraw] private SplineContainer m_splineContainer;
|
||||
public Spline MainSpline => m_splineContainer.Spline;
|
||||
[Resources, SerializeField, HopeNotNull, InspectorDraw] private SplineExtrude m_splineExtrude;
|
||||
[Content] public List<BezierKnot> knots = new List<BezierKnot>();
|
||||
|
||||
[InspectorDraw]
|
||||
public Vector2 Range
|
||||
{
|
||||
get => m_splineExtrude.Range;
|
||||
set => m_splineExtrude.Range = value;
|
||||
}
|
||||
[Percentage(0, 1), InspectorDraw]
|
||||
public float Head
|
||||
{
|
||||
get => Range.x;
|
||||
set => Range = new(value, Range.y);
|
||||
}
|
||||
[Percentage(0, 1), InspectorDraw]
|
||||
public float Tail
|
||||
{
|
||||
get => Range.y;
|
||||
set => Range = new(Range.x, value);
|
||||
}
|
||||
[Percentage(0, 1), InspectorDraw]
|
||||
public float Duration
|
||||
{
|
||||
get => Range.y - Range.x;
|
||||
set => Tail = Head + value;
|
||||
}
|
||||
|
||||
|
||||
private void Reset()
|
||||
{
|
||||
m_splineExtrude = GetComponent<SplineExtrude>();
|
||||
m_splineContainer = GetComponent<SplineContainer>();
|
||||
if (m_splineExtrude != null)
|
||||
m_splineExtrude.Container = m_splineContainer;
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
if (m_splineExtrude == null)
|
||||
m_splineExtrude = GetComponent<SplineExtrude>();
|
||||
if (m_splineContainer == null)
|
||||
{
|
||||
m_splineContainer = GetComponent<SplineContainer>();
|
||||
m_splineExtrude.Container = m_splineContainer;
|
||||
}
|
||||
}
|
||||
|
||||
private void LateUpdate()
|
||||
{
|
||||
if ((int)performanceMode >= (int)PerformanceIndicator.PerformanceMode.L8)
|
||||
{
|
||||
if (childPoints.Count != knots.Count)
|
||||
RebuildAll();
|
||||
else
|
||||
ResetPoints();
|
||||
m_splineExtrude.Rebuild();
|
||||
}
|
||||
}
|
||||
|
||||
[Content]
|
||||
public void RebuildAll()
|
||||
{
|
||||
int lastcount = knots.Count;
|
||||
if (knots.Count < childPoints.Count)
|
||||
{
|
||||
knots.AddRange(new BezierKnot[childPoints.Count - knots.Count]);
|
||||
}
|
||||
else if (knots.Count == childPoints.Count)
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
knots = new BezierKnot[childPoints.Count].ToList();
|
||||
}
|
||||
MainSpline.Knots = knots;
|
||||
for (int i = 0, e = childPoints.Count; i < e; i++)
|
||||
{
|
||||
MainSpline.SetKnot(i, new BezierKnot(childPoints[i].transform.localPosition));
|
||||
}
|
||||
for (int i = childPoints.Count, e = lastcount; i < e; i++)
|
||||
{
|
||||
MainSpline.RemoveAt(i);
|
||||
}
|
||||
}
|
||||
[Content]
|
||||
public void ResetPoints()
|
||||
{
|
||||
for (int i = 0, e = childPoints.Count; i < e; i++)
|
||||
{
|
||||
MainSpline.SetKnot(i, knots[i] = new BezierKnot(childPoints[i].transform.localPosition));
|
||||
}
|
||||
}
|
||||
[Content]
|
||||
[return: ReturnNotNull]
|
||||
public LinePoint AddChild()
|
||||
{
|
||||
var trans = new GameObject("Point").AddComponent<LinePoint>();
|
||||
if (childPoints.Count > 0)
|
||||
{
|
||||
trans.transform.SetParent(childPoints[^1].transform.parent);
|
||||
trans.transform.position = childPoints[^1].transform.position;
|
||||
}
|
||||
childPoints.Add(trans);
|
||||
if (HierarchyWindow.instance && HierarchyWindow.instance.ContainsReference(this))
|
||||
{
|
||||
var item = HierarchyWindow.instance.GetReferenceItem(this)
|
||||
.CreateSubPropertyItemWithBinders(trans.gameObject)[0];
|
||||
item.ref_value.GetComponent<HierarchyItem>().title = trans.gameObject.name;
|
||||
}
|
||||
RebuildAll();
|
||||
return trans;
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
|
||||
|
||||
#endif
|
11
Convention/[Art]/Line/SplinePointBuilder.cs.meta
Normal file
11
Convention/[Art]/Line/SplinePointBuilder.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c2e1401c85b3d1746a4547fe717962d5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user