制作点击添加组件然后出现bug
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
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;
|
||||
@@ -22,9 +24,11 @@ public class FlexibleFloatTab : MonoBehaviour
|
||||
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);
|
||||
@@ -47,6 +51,10 @@ public class FlexibleFloatTab : MonoBehaviour
|
||||
|
||||
|
||||
|
||||
}
|
||||
foreach (var i in eventPoints)
|
||||
{
|
||||
i.ReDraw(scalevalue);
|
||||
}
|
||||
Area.localPosition = new Vector3(FatherWindow.songBeat * BeatDeviver, 0, 0);
|
||||
}
|
||||
@@ -55,23 +63,96 @@ public class FlexibleFloatTab : MonoBehaviour
|
||||
|
||||
Area.localPosition = new Vector3(-FatherWindow.songBeat * BeatDeviver, 0, 0);
|
||||
BeatArea.localPosition = Area.localPosition;
|
||||
CheckForAddEvent();
|
||||
|
||||
}
|
||||
|
||||
private void CheckForAddEvent()
|
||||
|
||||
|
||||
public void AddEvent()
|
||||
{
|
||||
if (Keyboard.current.rKey.wasPressedThisFrame && RectTransformUtility.RectangleContainsScreenPoint(Area, Mouse.current.position.ReadValue()))
|
||||
if (Keyboard.current.ctrlKey.isPressed)
|
||||
{
|
||||
AddEvent();
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void AddEvent()
|
||||
public int FindInsertIndex(float startTime)
|
||||
{
|
||||
print(1);
|
||||
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.camera;
|
||||
}
|
||||
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)
|
||||
@@ -81,5 +162,13 @@ public class FlexibleFloatTab : MonoBehaviour
|
||||
i.ReDraw(value);
|
||||
}
|
||||
}
|
||||
public void remoceAnim(AnimatedFloat a)
|
||||
{
|
||||
|
||||
if (connectFloat.animations.Contains(a))
|
||||
{
|
||||
|
||||
connectFloat.animations.Remove(a);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user