Signed-off-by: TRAfoer <lhf190@outlook.com>
This commit is contained in:
@@ -2,18 +2,21 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Ichni;
|
||||
using Ichni.RhythmGame;
|
||||
using Michsky.MUIP;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class NotefabContoler : MonoBehaviour
|
||||
{
|
||||
public SampleWindow sampleWindow;
|
||||
public NoteBase noteBase;
|
||||
public RawImage ifHold;
|
||||
public void Initialize(NoteBase note, float timePerBeat, int beatDeviver)
|
||||
public void Initialize(NoteBase note, float timePerBeat, int beatDeviver, float posX)
|
||||
{
|
||||
noteBase = note;
|
||||
Image color = GetComponent<Image>();
|
||||
transform.localPosition = new Vector3(0, note.exactJudgeTime / timePerBeat * beatDeviver, 0);
|
||||
transform.localPosition = new Vector3(posX, note.exactJudgeTime / timePerBeat * beatDeviver, 0);
|
||||
switch (note)
|
||||
{
|
||||
case Hold hold:
|
||||
@@ -36,9 +39,42 @@ public class NotefabContoler : MonoBehaviour
|
||||
color.color = new Color(1, 0.2f, 0, 1);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
public void Onclick()
|
||||
public void Update()
|
||||
{
|
||||
EditorManager.instance.uiManager.hierarchy.FindTab(noteBase);
|
||||
if (RectTransformUtility.RectangleContainsScreenPoint(this.GetComponent<RectTransform>(), Mouse.current.position.ReadValue()))
|
||||
{
|
||||
if (Mouse.current.leftButton.wasPressedThisFrame)
|
||||
{
|
||||
StartCoroutine(Moving());
|
||||
if (EditorManager.instance.uiManager.inspector.connectedGameElement != noteBase) EditorManager.instance.uiManager.hierarchy.FindTab(noteBase);
|
||||
}
|
||||
}
|
||||
}
|
||||
public IEnumerator Moving()
|
||||
{
|
||||
sampleWindow.GetComponent<WindowDragger>().Lock = true;
|
||||
float startX = transform.localPosition.x;
|
||||
while (Mouse.current.leftButton.isPressed)
|
||||
{
|
||||
Vector2 localMousePosition = GetComponent<RectTransform>().InverseTransformPoint(Mouse.current.position.ReadValue());
|
||||
// if (Mathf.Abs(localMousePosition.x - startX) > GetComponent<RectTransform>().sizeDelta.x / 2)
|
||||
{
|
||||
transform.localPosition += new Vector3(Mouse.current.delta.ReadValue().x, 0, 0);
|
||||
|
||||
}
|
||||
|
||||
yield return null;
|
||||
}
|
||||
noteBase.noteVisual.transformSubmodule.originalPosition = new Vector3(
|
||||
transform.localPosition.x / sampleWindow.XWidth,
|
||||
noteBase.noteVisual.transformSubmodule.originalPosition.y,
|
||||
noteBase.noteVisual.transformSubmodule.originalPosition.z
|
||||
);
|
||||
noteBase.noteVisual.transformSubmodule.Refresh();
|
||||
|
||||
sampleWindow.GetComponent<WindowDragger>().Lock = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ using UnityEngine.EventSystems;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class SampleWindow : MovableWindow//该window高度为300,横的要在100和500之间切换
|
||||
public class SampleWindow : MovableWindow//该window高度为300,横的要XWidth0和500之间切换
|
||||
{
|
||||
public static List<SampleWindow> instances = new List<SampleWindow>();
|
||||
public TMP_InputField DeviverInputField;
|
||||
@@ -27,6 +27,7 @@ public class SampleWindow : MovableWindow//该window高度为300,横的要在1
|
||||
public bool isFocus = false;
|
||||
public bool isExpand = false;
|
||||
public int beatDeviver = 100;
|
||||
public int XWidth = 10;
|
||||
public int Xdevide = 1;
|
||||
public float realDevider;
|
||||
public GameObject beatLinePrefabv;
|
||||
@@ -88,7 +89,7 @@ public class SampleWindow : MovableWindow//该window高度为300,横的要在1
|
||||
v.transform.localPosition = new Vector3(0, i * beatDeviver + (beatDeviver / Xdevide * j), 0);
|
||||
RawImage g = v.GetComponent<RawImage>();
|
||||
g.color = new Color(0, g.color.g, g.color.b, 0.2f);
|
||||
if (v.transform.localPosition.y > 600)
|
||||
if (v.transform.localPosition.y > 1200)
|
||||
{
|
||||
Destroy(v);
|
||||
break;
|
||||
@@ -117,13 +118,14 @@ public class SampleWindow : MovableWindow//该window高度为300,横的要在1
|
||||
}
|
||||
foreach (var i in noteBases)
|
||||
{
|
||||
SpawnNote(i);
|
||||
SpawnNote(i, i.noteVisual.transformSubmodule.originalPosition.x * XWidth);
|
||||
}
|
||||
}
|
||||
private void SpawnNote(NoteBase i, float posx = 0)
|
||||
{
|
||||
GameObject u = Instantiate(NotePrefab, NoteMovepoint);
|
||||
u.GetComponent<NotefabContoler>().Initialize(i, timePerBeat, beatDeviver);
|
||||
u.GetComponent<NotefabContoler>().Initialize(i, timePerBeat, beatDeviver, posx);
|
||||
u.GetComponent<NotefabContoler>().sampleWindow = this;
|
||||
}
|
||||
|
||||
public GameObject selectedGameObject;
|
||||
@@ -132,6 +134,16 @@ public class SampleWindow : MovableWindow//该window高度为300,横的要在1
|
||||
selectedGameObject = EventSystem.current.currentSelectedGameObject;
|
||||
LineMovepoint.localPosition = new(0, -beatDeviver * (songBeat - (int)songBeat), 0);
|
||||
NoteMovepoint.localPosition = new(0, -beatDeviver * songBeat, 0);
|
||||
|
||||
if (RectTransformUtility.RectangleContainsScreenPoint(windowRect, Mouse.current.position.ReadValue()))
|
||||
{
|
||||
DetectNote();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
void LateUpdate()
|
||||
{
|
||||
if (isFocus && gameElement is Track track)
|
||||
{
|
||||
if (track.trackTimeSubmodule is TrackTimeSubmoduleMovable trackTimeSubmoduleMovable)
|
||||
@@ -147,12 +159,6 @@ public class SampleWindow : MovableWindow//该window高度为300,横的要在1
|
||||
TransformChanged();
|
||||
windowRect.GetComponent<CanvasGroup>().alpha = track.timeDurationSubmodule.CheckTimeInDuration(songTime) ? 1f : 0.2f;
|
||||
}
|
||||
if (RectTransformUtility.RectangleContainsScreenPoint(windowRect, Mouse.current.position.ReadValue()))
|
||||
{
|
||||
DetectNote();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
void TransformChanged()
|
||||
{
|
||||
@@ -193,6 +199,11 @@ public class SampleWindow : MovableWindow//该window高度为300,横的要在1
|
||||
windowRect.sizeDelta = new Vector2(500, windowRect.sizeDelta.y);
|
||||
}
|
||||
}
|
||||
public void ChangeXWidth(string change)
|
||||
{
|
||||
XWidth = int.Parse(change);
|
||||
OnceSpawnNote();
|
||||
}
|
||||
public void DetectNote()
|
||||
{
|
||||
if (Keyboard.current.digit1Key.wasPressedThisFrame)
|
||||
@@ -206,6 +217,11 @@ public class SampleWindow : MovableWindow//该window高度为300,横的要在1
|
||||
}
|
||||
public void AddNote(int NoteCode)
|
||||
{
|
||||
if (!EditorManager.instance.useNotePrefab)
|
||||
{
|
||||
LogWindow.Log("Please enable \"Note Prefab\" in EditorManager", Color.red);
|
||||
return;
|
||||
}
|
||||
// 获取鼠标在 NoteMovepoint 中的相对位置
|
||||
Vector2 localMousePosition = NoteMovepoint.InverseTransformPoint(Mouse.current.position.ReadValue());
|
||||
Debug.Log(localMousePosition);
|
||||
@@ -218,32 +234,41 @@ public class SampleWindow : MovableWindow//该window高度为300,横的要在1
|
||||
far -= 1f / Xdevide;
|
||||
float time = far * timePerBeat;
|
||||
|
||||
if (!isExpand)//movable
|
||||
;
|
||||
switch (NoteCode)
|
||||
{
|
||||
switch (NoteCode)
|
||||
{
|
||||
case 0:
|
||||
Tap a = Tap.GenerateElement("New Tap", Guid.NewGuid(), new List<string>(), false, gameElement, time);
|
||||
noteBases.Add(a);
|
||||
SpawnNote(a);
|
||||
break;
|
||||
case 3:
|
||||
Hold b = Hold.GenerateElement("New Hold", Guid.NewGuid(), new List<string>(), false, gameElement, time, time + 0.5f);
|
||||
noteBases.Add(b);
|
||||
SpawnNote(b);
|
||||
break;
|
||||
case 1:
|
||||
Stay c = Stay.GenerateElement("New Stay", Guid.NewGuid(), new List<string>(), false, gameElement, time);
|
||||
noteBases.Add(c);
|
||||
SpawnNote(c);
|
||||
break;
|
||||
case 2:
|
||||
Flick d = Flick.GenerateElement("New Flick", Guid.NewGuid(), new List<string>(), false, gameElement, time, new List<Vector2>());
|
||||
noteBases.Add(d);
|
||||
SpawnNote(d);
|
||||
break;
|
||||
}
|
||||
|
||||
case 0:
|
||||
Tap a = Tap.GenerateElement("New Tap", Guid.NewGuid(), new List<string>(), true, gameElement, time);
|
||||
noteBases.Add(a);
|
||||
a.noteVisual.transformSubmodule.originalPosition = new Vector3(localMousePosition.x / XWidth, 0f, 0f);
|
||||
a.noteVisual.transformSubmodule.Refresh();
|
||||
SpawnNote(a, isExpand ? localMousePosition.x : 0f);
|
||||
break;
|
||||
case 3:
|
||||
Hold b = Hold.GenerateElement("New Hold", Guid.NewGuid(), new List<string>(), true, gameElement, time, time + 0.5f);
|
||||
noteBases.Add(b);
|
||||
b.noteVisual.transformSubmodule.originalPosition = new Vector3(localMousePosition.x / XWidth, 0f, 0f);
|
||||
b.noteVisual.transformSubmodule.Refresh();
|
||||
SpawnNote(b, isExpand ? localMousePosition.x : 0f);
|
||||
break;
|
||||
case 1:
|
||||
Stay c = Stay.GenerateElement("New Stay", Guid.NewGuid(), new List<string>(), true, gameElement, time);
|
||||
noteBases.Add(c);
|
||||
c.noteVisual.transformSubmodule.originalPosition = new Vector3(localMousePosition.x / XWidth, 0f, 0f);
|
||||
c.noteVisual.transformSubmodule.Refresh();
|
||||
SpawnNote(c, isExpand ? localMousePosition.x : 0f);
|
||||
break;
|
||||
case 2:
|
||||
Flick d = Flick.GenerateElement("New Flick", Guid.NewGuid(), new List<string>(), true, gameElement, time, new List<Vector2>());
|
||||
noteBases.Add(d);
|
||||
d.noteVisual.transformSubmodule.originalPosition = new Vector3(localMousePosition.x / XWidth, 0f, 0f);
|
||||
d.noteVisual.transformSubmodule.Refresh();
|
||||
SpawnNote(d, isExpand ? localMousePosition.x : 0f);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user