2025-10-17 16:58:04 +08:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
using UnityEngine.UIElements;
|
|
|
|
|
|
|
2025-11-06 20:06:29 +08:00
|
|
|
|
public class DataFlowUnit : DataFlowController
|
2025-10-17 16:58:04 +08:00
|
|
|
|
{
|
2025-11-06 20:06:29 +08:00
|
|
|
|
//protected Transform _transform;
|
|
|
|
|
|
//protected Transform _rendererTransform;
|
|
|
|
|
|
//protected Transform _anchorPointTransform;
|
2025-10-17 16:58:04 +08:00
|
|
|
|
|
|
|
|
|
|
//<2F><>βλ<CEB2><CEBB>
|
2025-11-06 20:06:29 +08:00
|
|
|
|
private float _UnitStartPointXPos;
|
|
|
|
|
|
private float _UnitStartPointYPos;
|
|
|
|
|
|
private float _UnitEndPointXPos;
|
|
|
|
|
|
private float _UnitEndPointYPos;
|
2025-10-17 16:58:04 +08:00
|
|
|
|
//<2F><>ʼʱ<CABC><CAB1>
|
2025-11-06 20:06:29 +08:00
|
|
|
|
private float _UnitStartTime;
|
|
|
|
|
|
private float _UnitEndTime;
|
|
|
|
|
|
//SongInformationContainer _songInformation;
|
|
|
|
|
|
//BPMGroup _BPMGroup;
|
2025-10-17 16:58:04 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// <20><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD>IJ<EFBFBD>ֵ
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private float currentTimeInterval
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
2025-11-06 20:06:29 +08:00
|
|
|
|
if(_UnitEndTime - _songInformation.SongCurrentTime >= 0)
|
2025-10-17 16:58:04 +08:00
|
|
|
|
{
|
2025-11-06 20:06:29 +08:00
|
|
|
|
return _UnitEndTime - _songInformation.SongCurrentTime;
|
2025-10-17 16:58:04 +08:00
|
|
|
|
}
|
2025-11-06 20:06:29 +08:00
|
|
|
|
else return -(_UnitEndTime -_songInformation.SongCurrentTime);
|
2025-10-17 16:58:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// <20><>ʼʱ<CABC><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD>IJ<EFBFBD>ֵ
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private float timeInterval
|
|
|
|
|
|
{
|
2025-11-06 20:06:29 +08:00
|
|
|
|
get { return _UnitEndTime - _UnitStartTime; }
|
2025-10-17 16:58:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// ʹ<><CAB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԭ<EFBFBD><D4AD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֮<EFBFBD><D6AE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Բ<EFBFBD>ֵ
|
|
|
|
|
|
///
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public Vector3 _startPoint
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
//Ŀǰʱ<C7B0>䴦<EFBFBD><E4B4A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>м<EFBFBD>,
|
2025-11-06 20:06:29 +08:00
|
|
|
|
if (_songInformation.SongCurrentTime < _UnitEndTime && _songInformation.SongCurrentTime >= _UnitStartTime)
|
2025-10-17 16:58:04 +08:00
|
|
|
|
{
|
|
|
|
|
|
return new(
|
2025-11-06 20:06:29 +08:00
|
|
|
|
_UnitEndPointXPos - currentTimeInterval * (_UnitEndPointXPos - _UnitStartPointXPos) / timeInterval,
|
|
|
|
|
|
_UnitEndPointYPos - currentTimeInterval * (_UnitEndPointYPos - _UnitStartPointYPos) / timeInterval,
|
2025-10-17 16:58:04 +08:00
|
|
|
|
0
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>غ<EFBFBD>
|
2025-11-06 20:06:29 +08:00
|
|
|
|
if (_songInformation.SongCurrentTime >= _UnitEndTime)
|
2025-10-17 16:58:04 +08:00
|
|
|
|
{
|
|
|
|
|
|
return _endPoint;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
//<2F>ڿ<EFBFBD>ʼʱ<CABC>仹<EFBFBD><E4BBB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
return new(
|
2025-11-06 20:06:29 +08:00
|
|
|
|
_UnitStartPointXPos,
|
|
|
|
|
|
_UnitStartPointYPos,
|
|
|
|
|
|
_BPMGroup.CurrentNoteSpeed * (_UnitStartTime - _songInformation.SongCurrentTime)
|
2025-10-17 16:58:04 +08:00
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
private Vector3 _endPoint
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return new(
|
2025-11-06 20:06:29 +08:00
|
|
|
|
_UnitEndPointXPos,
|
|
|
|
|
|
_UnitEndPointYPos,
|
|
|
|
|
|
_BPMGroup.CurrentNoteSpeed * (_UnitEndTime - _songInformation.SongCurrentTime)
|
2025-10-17 16:58:04 +08:00
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
#region Mesh<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֶ<EFBFBD>
|
|
|
|
|
|
private MeshFilter _rendererMeshFilter;
|
|
|
|
|
|
private int[] _triangles = new int[]
|
|
|
|
|
|
{
|
|
|
|
|
|
//front
|
|
|
|
|
|
2,1,0,
|
|
|
|
|
|
0,3,2,
|
|
|
|
|
|
//left
|
|
|
|
|
|
4,5,6,
|
|
|
|
|
|
4,6,7,
|
|
|
|
|
|
//back
|
|
|
|
|
|
9,11,8,
|
|
|
|
|
|
9,10,11,
|
|
|
|
|
|
//right
|
|
|
|
|
|
12,13,14,
|
|
|
|
|
|
12,14,15,
|
|
|
|
|
|
//up
|
|
|
|
|
|
16,17,18,
|
|
|
|
|
|
16,18,19,
|
|
|
|
|
|
//buttom
|
|
|
|
|
|
21,23,22,
|
|
|
|
|
|
21,20,23,
|
|
|
|
|
|
};
|
|
|
|
|
|
private Vector2[] _uvs = new Vector2[]
|
|
|
|
|
|
{
|
|
|
|
|
|
// Front
|
|
|
|
|
|
new Vector2(1.0f, 0.0f),
|
|
|
|
|
|
new Vector2(1.0f, 1.0f),
|
|
|
|
|
|
new Vector2(1.0f, 0.0f),
|
|
|
|
|
|
new Vector2(0.0f, 0.0f),
|
|
|
|
|
|
// Left
|
|
|
|
|
|
new Vector2(1.0f, 1.0f),
|
|
|
|
|
|
new Vector2(0.0f, 1.0f),
|
|
|
|
|
|
new Vector2(0.0f, 0.0f),
|
|
|
|
|
|
new Vector2(1.0f, 0.0f),
|
|
|
|
|
|
// Back
|
|
|
|
|
|
new Vector2(1.0f, 0.0f),
|
|
|
|
|
|
new Vector2(1.0f, 1.0f),
|
|
|
|
|
|
new Vector2(1.0f, 0.0f),
|
|
|
|
|
|
new Vector2(0.0f, 0.0f),
|
|
|
|
|
|
// Right
|
|
|
|
|
|
new Vector2(1.0f, 1.0f),
|
|
|
|
|
|
new Vector2(0.0f, 1.0f),
|
|
|
|
|
|
new Vector2(0.0f, 0.0f),
|
|
|
|
|
|
new Vector2(1.0f, 0.0f),
|
|
|
|
|
|
//// Top
|
|
|
|
|
|
new Vector2(0.0f, 0.0f),
|
|
|
|
|
|
new Vector2(1.0f, 0.0f),
|
|
|
|
|
|
new Vector2(1.0f, 1.0f),
|
|
|
|
|
|
new Vector2(0.0f, 1.0f),
|
|
|
|
|
|
// Bottom
|
|
|
|
|
|
new Vector2(0.0f, 0.0f),
|
|
|
|
|
|
new Vector2(1.0f, 0.0f),
|
|
|
|
|
|
new Vector2(1.0f, 1.0f),
|
|
|
|
|
|
new Vector2(0.0f, 1.0f),
|
|
|
|
|
|
};
|
|
|
|
|
|
private Vector3[] _vertex = new Vector3[24];
|
2025-11-06 20:06:29 +08:00
|
|
|
|
private float _unitWidth = 0.4f;
|
2025-10-17 16:58:04 +08:00
|
|
|
|
#endregion
|
|
|
|
|
|
void Awake()
|
|
|
|
|
|
{
|
|
|
|
|
|
_transform = gameObject.GetComponent<Transform>();
|
|
|
|
|
|
_rendererMeshFilter = _transform.Find("Renderer").GetComponent<MeshFilter>();
|
|
|
|
|
|
_rendererTransform = _transform.Find("Renderer").GetComponent<Transform>();
|
|
|
|
|
|
_anchorPointTransform = _transform.Find("HeadAnchorPoint").GetComponent<Transform>();
|
|
|
|
|
|
//<2F><>mesh<73><68><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>̬
|
|
|
|
|
|
_rendererMeshFilter.mesh.MarkDynamic();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Update()
|
|
|
|
|
|
{
|
|
|
|
|
|
//<2F><>Ⱦ<EFBFBD><C8BE><EFBFBD>ĸ<EFBFBD><C4B8><EFBFBD>,<2C><><EFBFBD><EFBFBD>Mesh<73>Լ<EFBFBD><D4BC>ж<EFBFBD><D0B6><EFBFBD>
|
|
|
|
|
|
UpdateRenderer(_songInformation.SongCurrentTime);
|
|
|
|
|
|
UpdateAnchorPoint(_songInformation.SongCurrentTime);
|
|
|
|
|
|
|
2025-11-06 20:06:29 +08:00
|
|
|
|
if (Input.GetKeyDown(KeyCode.A)&& _songInformation.SongCurrentTime>=_UnitStartTime)
|
2025-10-17 16:58:04 +08:00
|
|
|
|
{
|
|
|
|
|
|
Debug.Log(this.ToString());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
public override string ToString()
|
|
|
|
|
|
{
|
|
|
|
|
|
return
|
2025-11-06 20:06:29 +08:00
|
|
|
|
$"<22><>ʼʱ<CABC><CAB1>{_UnitStartTime}\n"+
|
|
|
|
|
|
$"<22><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>{_UnitEndTime}\n"+
|
2025-10-17 16:58:04 +08:00
|
|
|
|
$"Ŀǰ<C4BF><C7B0>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>{_startPoint}\n" +
|
|
|
|
|
|
$"Ŀǰ<C4BF><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>{_endPoint}";
|
|
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// <20><><EFBFBD>ڸ<EFBFBD><DAB8><EFBFBD><EFBFBD><EFBFBD>Ⱦ<EFBFBD><C8BE>
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
void UpdateRenderer(float currentTime)
|
|
|
|
|
|
{
|
|
|
|
|
|
_rendererMeshFilter.mesh.Clear();
|
2025-11-06 20:06:29 +08:00
|
|
|
|
_rendererMeshFilter.mesh = MeshEditor.DrawMeshByCoordinates(_rendererMeshFilter.mesh, _vertex, _triangles, _uvs, _startPoint, _endPoint, _unitWidth);
|
2025-10-17 16:58:04 +08:00
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD>ڲ<EFBFBD><DAB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɷ<EFBFBD>Χʱ,<2C><><EFBFBD><EFBFBD>Ϊ<EFBFBD>ر<EFBFBD>״̬<D7B4><CCAC><EFBFBD>ҷ<EFBFBD><D2B7><EFBFBD>
|
2025-11-06 20:06:29 +08:00
|
|
|
|
if (currentTime > _UnitEndTime)
|
2025-10-17 16:58:04 +08:00
|
|
|
|
{
|
|
|
|
|
|
_rendererTransform.gameObject.SetActive(false);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_rendererTransform.gameObject.SetActive(true);
|
|
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// <20><><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD>λ<EFBFBD><CEBB><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
void UpdateAnchorPoint(float currentTime)
|
|
|
|
|
|
{
|
|
|
|
|
|
_anchorPointTransform.position = new Vector3(_startPoint.x, _startPoint.y, 0);
|
|
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD>ڲ<EFBFBD><DAB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɷ<EFBFBD>Χʱ,<2C><><EFBFBD><EFBFBD>Ϊ<EFBFBD>ر<EFBFBD>״̬<D7B4><CCAC><EFBFBD>ҷ<EFBFBD><D2B7><EFBFBD>
|
2025-11-06 20:06:29 +08:00
|
|
|
|
if (currentTime < _UnitStartTime - _BPMGroup.InitializeOffset || currentTime > _UnitEndTime)
|
2025-10-17 16:58:04 +08:00
|
|
|
|
{
|
|
|
|
|
|
_anchorPointTransform.gameObject.SetActive(false);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>Լ<EFBFBD><D4BC>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD>ʱ,<2C><><EFBFBD><EFBFBD>
|
|
|
|
|
|
if (_anchorPointTransform.gameObject.activeSelf == true)
|
|
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_anchorPointTransform.gameObject.SetActive(true);
|
|
|
|
|
|
}
|
|
|
|
|
|
public void Init(Vector2 startPoint, Vector2 endPoint, float startTime, float endTime, float width, SongInformationContainer container, BPMGroup timing)
|
|
|
|
|
|
{
|
|
|
|
|
|
//<2F><>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD>
|
2025-11-06 20:06:29 +08:00
|
|
|
|
_UnitStartPointXPos = startPoint.x;
|
|
|
|
|
|
_UnitStartPointYPos = startPoint.y;
|
|
|
|
|
|
_UnitEndPointXPos = endPoint.x;
|
|
|
|
|
|
_UnitEndPointYPos = endPoint.y;
|
2025-10-17 16:58:04 +08:00
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>Ը<EFBFBD>ֵ
|
2025-11-06 20:06:29 +08:00
|
|
|
|
_unitWidth = width;
|
2025-10-17 16:58:04 +08:00
|
|
|
|
_songInformation = container;
|
|
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
2025-11-06 20:06:29 +08:00
|
|
|
|
_UnitStartTime = startTime;
|
|
|
|
|
|
_UnitEndTime = endTime;
|
2025-10-17 16:58:04 +08:00
|
|
|
|
|
|
|
|
|
|
_anchorPointTransform.gameObject.SetActive(false);
|
|
|
|
|
|
_BPMGroup = timing;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|