Oh yessss Movable Track Sampler
This commit is contained in:
@@ -2,6 +2,7 @@ using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Dreamteck.Splines;
|
||||
using Ichni;
|
||||
using Ichni.Editor;
|
||||
using Ichni.RhythmGame;
|
||||
@@ -11,7 +12,7 @@ using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class SampleWindow : MovableWindow//该window高度为300,横的要在200和500之间切换
|
||||
public class SampleWindow : MovableWindow//该window高度为300,横的要在100和500之间切换
|
||||
{
|
||||
public static List<SampleWindow> instances = new List<SampleWindow>();
|
||||
public TMP_InputField DeviverInputField;
|
||||
@@ -35,6 +36,8 @@ public class SampleWindow : MovableWindow//该window高度为300,横的要在2
|
||||
float beatmapStartTime => -EditorManager.instance.songInformation.delay;
|
||||
float timePerBeat => 60f / EditorManager.instance.songInformation.bpm;
|
||||
public GameElement gameElement;
|
||||
public SplinePositioner trackPositioner = null;
|
||||
public GameObject trackHead;
|
||||
public void Initialize(GameElement qgameElement, string title)
|
||||
{
|
||||
closeButton.onClick.AddListener(() =>
|
||||
@@ -52,6 +55,13 @@ public class SampleWindow : MovableWindow//该window高度为300,横的要在2
|
||||
return;
|
||||
}
|
||||
this.gameElement = qgameElement;
|
||||
if (qgameElement is Track track)
|
||||
{
|
||||
trackPositioner = this.gameObject.AddComponent<SplinePositioner>();
|
||||
trackPositioner.spline = track.trackPathSubmodule.path;
|
||||
trackPositioner.enabled = isFocus;
|
||||
trackPositioner.targetObject = trackHead;
|
||||
}
|
||||
InitializeWindow(title);
|
||||
|
||||
|
||||
@@ -70,6 +80,21 @@ public class SampleWindow : MovableWindow//该window高度为300,横的要在2
|
||||
for (int i = 0; i < (int)EditorManager.instance.songInformation.song.length / timePerBeat; i++)
|
||||
{
|
||||
|
||||
|
||||
for (int j = 1; j < Xdevide; j++)
|
||||
{
|
||||
GameObject v = Instantiate(beatLinePrefabh, LineMovepoint);
|
||||
v.transform.localPosition = new Vector3(0, i * beatDeviver + (beatDeviver / Xdevide * j), 0);
|
||||
RawImage g = v.GetComponent<RawImage>();
|
||||
g.color = new Color(g.color.r, g.color.g, g.color.b, 0.2f);
|
||||
if (v.transform.localPosition.y > 600)
|
||||
{
|
||||
Destroy(v);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
GameObject u = Instantiate(beatLinePrefabh, LineMovepoint);
|
||||
u.transform.localPosition = new Vector3(0, i * beatDeviver, 0);
|
||||
if (i == 1)
|
||||
@@ -78,7 +103,7 @@ public class SampleWindow : MovableWindow//该window高度为300,横的要在2
|
||||
realDevider = secBeatLineh.position.y - LineMovepoint.position.y;
|
||||
Debug.Log(realDevider);
|
||||
}
|
||||
if (u.transform.localPosition.y > 300)
|
||||
if (u.transform.localPosition.y > 600)
|
||||
{
|
||||
Destroy(u);
|
||||
break;
|
||||
@@ -103,28 +128,29 @@ public class SampleWindow : MovableWindow//该window高度为300,横的要在2
|
||||
{
|
||||
GameObject u = Instantiate(NotePrefab, NoteMovepoint);
|
||||
u.transform.localPosition = new Vector3(0, i.exactJudgeTime / timePerBeat * beatDeviver, 0);
|
||||
|
||||
Image color = u.GetComponent<Image>();
|
||||
u.GetComponent<NotefabContoler>().noteBase = i;
|
||||
switch (i)
|
||||
{
|
||||
case Hold hold:
|
||||
u.GetComponent<Image>().color = new Color(0, 1, 0, 1);
|
||||
color.color = new Color(0, 1, 0, 1);
|
||||
RawImage a = u.GetComponent<RawImage>();
|
||||
a.transform.localPosition = new Vector3(0, (hold.holdEndTime - hold.exactJudgeTime) / timePerBeat * beatDeviver / 2, 0);
|
||||
a.GetComponent<RectTransform>().sizeDelta = new Vector2(0, (hold.holdEndTime - hold.exactJudgeTime) / timePerBeat * beatDeviver);
|
||||
break;
|
||||
|
||||
case Tap:
|
||||
u.GetComponent<Image>().color = new Color(0, 1, 1, 1);
|
||||
color.color = new Color(0, 1, 1, 1);
|
||||
break;
|
||||
|
||||
case Stay:
|
||||
u.GetComponent<Image>().color = new Color(1, 1, 0, 1);
|
||||
color.color = new Color(1, 1, 0, 1);
|
||||
break;
|
||||
|
||||
case Flick:
|
||||
u.GetComponent<Image>().color = new Color(1, 0.2f, 0, 1);
|
||||
color.color = new Color(1, 0.2f, 0, 1);
|
||||
break;
|
||||
}
|
||||
}//服了,之后整合到controler里头去
|
||||
}
|
||||
void Update()
|
||||
|
||||
@@ -134,18 +160,38 @@ public class SampleWindow : MovableWindow//该window高度为300,横的要在2
|
||||
NoteMovepoint.localPosition = new(0, -beatDeviver * songBeat, 0);
|
||||
if (isFocus && gameElement is Track track)
|
||||
{
|
||||
if (track.submoduleList.Where(i => i is TrackTimeSubmoduleMovable).Count() != 0)
|
||||
{
|
||||
trackPositioner.SetPercent(track.trackTimeSubmodule.headPercent);
|
||||
}
|
||||
else if (track.submoduleList.Where(i => i is TrackTimeSubmoduleStatic).Count() != 0)
|
||||
{
|
||||
trackPositioner.SetPercent(0f);
|
||||
}
|
||||
TransformChanged();
|
||||
windowRect.GetComponent<CanvasGroup>().alpha = track.timeDurationSubmodule.CheckTimeInDuration(songTime) ? 1f : 0.2f;
|
||||
}
|
||||
|
||||
}
|
||||
void TransformChanged()
|
||||
{
|
||||
RectTransform canvasRect = EditorManager.instance.inspectorCanvas.GetComponent<RectTransform>();
|
||||
Vector2 ScreenPosition = EditorManager.instance.cameraManager.currentCamera.WorldToScreenPoint(trackHead.transform.position);
|
||||
|
||||
if (RectTransformUtility.ScreenPointToLocalPointInRectangle(canvasRect, ScreenPosition, null, out Vector2 uiPosition))
|
||||
{
|
||||
windowRect.anchoredPosition = new Vector2(uiPosition.x, uiPosition.y + 150f);
|
||||
}
|
||||
}
|
||||
public void ChangeFocus()
|
||||
{
|
||||
isFocus = !isFocus;
|
||||
|
||||
if (trackPositioner != null) trackPositioner.enabled = isFocus;
|
||||
}
|
||||
public void ChangeXdevide(string devide)
|
||||
{
|
||||
Xdevide = int.Parse(devide);
|
||||
SpawnBeatline();
|
||||
}
|
||||
public void ChangeBeatdevide(string devide)
|
||||
{
|
||||
@@ -158,7 +204,7 @@ public class SampleWindow : MovableWindow//该window高度为300,横的要在2
|
||||
if (isExpand)
|
||||
{
|
||||
isExpand = false;
|
||||
windowRect.sizeDelta = new Vector2(200, windowRect.sizeDelta.y);
|
||||
windowRect.sizeDelta = new Vector2(100, windowRect.sizeDelta.y);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -171,7 +217,8 @@ public class SampleWindow : MovableWindow//该window高度为300,横的要在2
|
||||
// 获取鼠标在 NoteMovepoint 中的相对位置
|
||||
Vector2 localMousePosition = NoteMovepoint.InverseTransformPoint(Mouse.current.position.ReadValue());
|
||||
Debug.Log(localMousePosition);
|
||||
// 使用 realDevider 进行整数倍舍入
|
||||
|
||||
|
||||
float mouseBeat = localMousePosition.y / beatDeviver;
|
||||
float far = 0f;
|
||||
while (far < mouseBeat)
|
||||
@@ -179,15 +226,13 @@ public class SampleWindow : MovableWindow//该window高度为300,横的要在2
|
||||
far += 1f / Xdevide;
|
||||
}
|
||||
far -= 1f / Xdevide;
|
||||
float time = (far * timePerBeat);//idk
|
||||
//Debug.Log($"Rounded Position Y: {time}");
|
||||
float time = far * timePerBeat;
|
||||
|
||||
if (!isExpand)
|
||||
if (!isExpand)//movable
|
||||
{
|
||||
Tap a = Tap.GenerateElement("New Tap", Guid.NewGuid(), new List<string>(), true, gameElement, time);
|
||||
noteBases.Add(a);
|
||||
SpawnNote(a);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user