233 lines
6.6 KiB
C#
233 lines
6.6 KiB
C#
|
|
using UnityEngine;
|
|||
|
|
using UnityEngine.UIElements;
|
|||
|
|
|
|||
|
|
public class DataFlowUnit : MonoBehaviour
|
|||
|
|
{
|
|||
|
|
protected Transform _transform;
|
|||
|
|
protected Transform _rendererTransform;
|
|||
|
|
protected Transform _anchorPointTransform;
|
|||
|
|
|
|||
|
|
//<2F><>βλ<CEB2><CEBB>
|
|||
|
|
[SerializeField] private float _startPointXPos;
|
|||
|
|
[SerializeField] private float _startPointYPos;
|
|||
|
|
[SerializeField] private float _endPointXPos;
|
|||
|
|
[SerializeField] private float _endPointYPos;
|
|||
|
|
//<2F><>ʼʱ<CABC><CAB1>
|
|||
|
|
[SerializeField] private float _startTime;
|
|||
|
|
[SerializeField] private float _endTime;
|
|||
|
|
SongInformationContainer _songInformation;
|
|||
|
|
BPMGroup _BPMGroup;
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD>IJ<EFBFBD>ֵ
|
|||
|
|
/// </summary>
|
|||
|
|
private float currentTimeInterval
|
|||
|
|
{
|
|||
|
|
get
|
|||
|
|
{
|
|||
|
|
if(_endTime - _songInformation.SongCurrentTime >= 0)
|
|||
|
|
{
|
|||
|
|
return _endTime - _songInformation.SongCurrentTime;
|
|||
|
|
}
|
|||
|
|
else return -(_endTime -_songInformation.SongCurrentTime);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><>ʼʱ<CABC><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD>IJ<EFBFBD>ֵ
|
|||
|
|
/// </summary>
|
|||
|
|
private float timeInterval
|
|||
|
|
{
|
|||
|
|
get { return _endTime - _startTime; }
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <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>,
|
|||
|
|
if (_songInformation.SongCurrentTime < _endTime && _songInformation.SongCurrentTime >= _startTime)
|
|||
|
|
{
|
|||
|
|
return new(
|
|||
|
|
_endPointXPos - currentTimeInterval * (_endPointXPos - _startPointXPos) / timeInterval,
|
|||
|
|
_endPointYPos - currentTimeInterval * (_endPointYPos - _startPointYPos) / timeInterval,
|
|||
|
|
0
|
|||
|
|
);
|
|||
|
|
}
|
|||
|
|
//<2F><><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>غ<EFBFBD>
|
|||
|
|
if (_songInformation.SongCurrentTime >= _endTime)
|
|||
|
|
{
|
|||
|
|
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(
|
|||
|
|
_startPointXPos,
|
|||
|
|
_startPointYPos,
|
|||
|
|
_BPMGroup.CurrentNoteSpeed * (_startTime - _songInformation.SongCurrentTime)
|
|||
|
|
);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
private Vector3 _endPoint
|
|||
|
|
{
|
|||
|
|
get
|
|||
|
|
{
|
|||
|
|
return new(
|
|||
|
|
_endPointXPos,
|
|||
|
|
_endPointYPos,
|
|||
|
|
_BPMGroup.CurrentNoteSpeed * (_endTime - _songInformation.SongCurrentTime)
|
|||
|
|
);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
#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];
|
|||
|
|
private float _width = 0.4f;
|
|||
|
|
#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);
|
|||
|
|
|
|||
|
|
if (Input.GetKeyDown(KeyCode.A)&& _songInformation.SongCurrentTime>=_startTime)
|
|||
|
|
{
|
|||
|
|
Debug.Log(this.ToString());
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
public override string ToString()
|
|||
|
|
{
|
|||
|
|
return
|
|||
|
|
$"<22><>ʼʱ<CABC><CAB1>{_startTime}\n"+
|
|||
|
|
$"<22><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>{_endTime}\n"+
|
|||
|
|
$"Ŀǰ<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();
|
|||
|
|
_rendererMeshFilter.mesh = MeshEditor.DrawMeshByCoordinates(_rendererMeshFilter.mesh, _vertex, _triangles, _uvs, _startPoint, _endPoint, _width);
|
|||
|
|
|
|||
|
|
//<2F><><EFBFBD>ڲ<EFBFBD><DAB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɷ<EFBFBD>Χʱ,<2C><><EFBFBD><EFBFBD>Ϊ<EFBFBD>ر<EFBFBD>״̬<D7B4><CCAC><EFBFBD>ҷ<EFBFBD><D2B7><EFBFBD>
|
|||
|
|
if (currentTime > _endTime)
|
|||
|
|
{
|
|||
|
|
_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>
|
|||
|
|
if (currentTime < _startTime - _BPMGroup.InitializeOffset || currentTime > _endTime)
|
|||
|
|
{
|
|||
|
|
_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>
|
|||
|
|
_startPointXPos = startPoint.x;
|
|||
|
|
_startPointYPos = startPoint.y;
|
|||
|
|
_endPointXPos = endPoint.x;
|
|||
|
|
_endPointYPos = endPoint.y;
|
|||
|
|
|
|||
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>Ը<EFBFBD>ֵ
|
|||
|
|
_width = width;
|
|||
|
|
_songInformation = container;
|
|||
|
|
|
|||
|
|
//<2F><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
|||
|
|
_startTime = startTime;
|
|||
|
|
_endTime = endTime;
|
|||
|
|
|
|||
|
|
_anchorPointTransform.gameObject.SetActive(false);
|
|||
|
|
_BPMGroup = timing;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|