175 lines
5.1 KiB
C#
175 lines
5.1 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using Ichni;
|
|
using Ichni.Editor;
|
|
using Ichni.RhythmGame;
|
|
using Unity.VisualScripting;
|
|
using UnityEngine;
|
|
using UnityEngine.InputSystem;
|
|
|
|
|
|
public class FlexibleFloatTab : MonoBehaviour
|
|
{
|
|
public FlexibleFloat flexibleFloat;
|
|
|
|
public GraphicalFlexibleFloatWindow FatherWindow;
|
|
|
|
public List<EventPoint> eventPoints;
|
|
|
|
public RectTransform Area;
|
|
public RectTransform BeatArea;
|
|
|
|
public EventPoint eventPoint;
|
|
public GameObject BeatLine;
|
|
|
|
public FlexibleFloat connectFloat;
|
|
public int BeatDeviver => FatherWindow.BeatDeviver;
|
|
public void Initialize(FlexibleFloat flexibleFloat, string Title)
|
|
{
|
|
connectFloat = flexibleFloat;
|
|
for (int i = 0; i < (int)EditorManager.instance.songInformation.song.length / FatherWindow.timePerBeat; i++)
|
|
{
|
|
GameObject u = Instantiate(BeatLine, BeatArea);
|
|
u.transform.localPosition = new Vector3(BeatDeviver * i, 0, 0);
|
|
}
|
|
for (int i = 0; i <= flexibleFloat.animations.Count - 1; i++)
|
|
{
|
|
AnimatedFloat animatedFloat = flexibleFloat.animations[i];
|
|
EventPoint eventPoint = Instantiate(this.eventPoint, Area);
|
|
eventPoint.FatherTab = this;
|
|
eventPoint.Initialize(animatedFloat);
|
|
eventPoints.Add(eventPoint);
|
|
if (i - 1 >= 0)
|
|
{
|
|
eventPoint.LastEventPoint = eventPoints[i - 1];
|
|
eventPoint.LastEventPoint.NextEventPoint = eventPoint;
|
|
}
|
|
else eventPoint.LastEventPoint = null;
|
|
if (i == flexibleFloat.animations.Count - 1) eventPoint.NextEventPoint = null;
|
|
|
|
|
|
|
|
}
|
|
foreach (var i in eventPoints)
|
|
{
|
|
i.ReDraw(scalevalue);
|
|
}
|
|
Area.localPosition = new Vector3(FatherWindow.songBeat * BeatDeviver, 0, 0);
|
|
}
|
|
public void Update()
|
|
{
|
|
|
|
Area.localPosition = new Vector3(-FatherWindow.songBeat * BeatDeviver, 0, 0);
|
|
BeatArea.localPosition = Area.localPosition;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void AddEvent()
|
|
{
|
|
if (Keyboard.current.ctrlKey.isPressed)
|
|
{
|
|
EventPoint eventPoint = Instantiate(this.eventPoint, Area);
|
|
eventPoint.FatherTab = this;
|
|
eventPoint.Initialize(new AnimatedFloat(GetBeat(), GetBeat() + 1f, 0, 0, AnimationCurveType.Linear));
|
|
eventPoints.Insert(FindInsertIndex(eventPoint.animatedFloat.startTime), eventPoint);
|
|
if (eventPoints.IndexOf(eventPoint) - 1 >= 0)
|
|
{
|
|
eventPoint.LastEventPoint = eventPoints[eventPoints.IndexOf(eventPoint) - 1];
|
|
eventPoint.LastEventPoint.NextEventPoint = eventPoint;
|
|
}
|
|
|
|
if (eventPoints.IndexOf(eventPoint) + 1 < eventPoints.Count)
|
|
{
|
|
eventPoint.NextEventPoint = eventPoints[eventPoints.IndexOf(eventPoint) + 1];
|
|
eventPoint.animatedFloat.endTime = eventPoint.NextEventPoint.animatedFloat.startTime;
|
|
}
|
|
eventPoint.ReDraw(scalevalue);
|
|
//print(1);
|
|
}
|
|
|
|
}
|
|
|
|
public int FindInsertIndex(float startTime)
|
|
{
|
|
int low = 0;
|
|
int high = eventPoints.Count - 1;
|
|
|
|
while (low <= high)
|
|
{
|
|
int mid = (low + high) / 2;
|
|
if (eventPoints[mid].animatedFloat.startTime < startTime)
|
|
{
|
|
low = mid + 1;
|
|
}
|
|
else
|
|
{
|
|
high = mid - 1;
|
|
}
|
|
}
|
|
|
|
return low;
|
|
}
|
|
|
|
float GetBeat()//这里出现问题:转换坐标
|
|
{
|
|
Vector2 mouseLocalPos = MousePosition2Local();
|
|
float far = BeatArea.transform.localPosition.x;
|
|
int Beat = 0;
|
|
|
|
while (far < mouseLocalPos.x)
|
|
{
|
|
far += BeatDeviver;
|
|
Beat++;
|
|
}
|
|
|
|
return FatherWindow.timePerBeat * Beat;
|
|
}
|
|
|
|
Vector2 MousePosition2Local()
|
|
{
|
|
Vector2 mousePosition = Mouse.current.position.ReadValue(); // 获取屏幕坐标
|
|
Debug.Log($"Screen Position: {mousePosition}");
|
|
Camera mainCamera;
|
|
if (EditorManager.instance.cameraManager.isSceneCameraActive)
|
|
{
|
|
mainCamera = EditorManager.instance.cameraManager.sceneCamera.sceneCamera;
|
|
}
|
|
else
|
|
{
|
|
mainCamera = EditorManager.instance.cameraManager.gameCamera.camera;
|
|
}
|
|
|
|
|
|
|
|
Vector2 mouseWorldPos = mainCamera.ScreenToWorldPoint(mousePosition); // 屏幕坐标转世界坐标
|
|
Debug.Log($"World Position: {mouseWorldPos}");
|
|
|
|
Vector2 mouseLocalPos = transform.parent.transform.InverseTransformPoint(mouseWorldPos); // 世界坐标转本地坐标
|
|
Debug.Log($"Local Position: {mouseLocalPos}");
|
|
|
|
return mouseLocalPos;
|
|
}
|
|
|
|
public float scalevalue => FatherWindow.scalevalue;
|
|
public void CurveScale(float value)
|
|
{
|
|
foreach (EventPoint i in eventPoints)
|
|
{
|
|
i.ReDraw(value);
|
|
}
|
|
}
|
|
public void remoceAnim(AnimatedFloat a)
|
|
{
|
|
|
|
if (connectFloat.animations.Contains(a))
|
|
{
|
|
|
|
connectFloat.animations.Remove(a);
|
|
}
|
|
}
|
|
}
|