81 lines
3.0 KiB
C#
81 lines
3.0 KiB
C#
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, float posX)
|
|
{
|
|
noteBase = note;
|
|
Image color = GetComponent<Image>();
|
|
transform.localPosition = new Vector3(posX, note.exactJudgeTime / timePerBeat * beatDeviver, 0);
|
|
switch (note)
|
|
{
|
|
case Hold hold:
|
|
color.color = new Color(0, 1, 0, 1);
|
|
if (ifHold != null)
|
|
{
|
|
ifHold.transform.localPosition = new Vector3(0, (hold.holdEndTime - hold.exactJudgeTime) / timePerBeat * beatDeviver / 2, 0);
|
|
var rect = ifHold.GetComponent<RectTransform>();
|
|
rect.sizeDelta = new Vector2(rect.sizeDelta.x, (hold.holdEndTime - hold.exactJudgeTime) / timePerBeat * beatDeviver);
|
|
ifHold.color = new Color(0, 1, 0, 1);
|
|
}
|
|
break;
|
|
case Tap:
|
|
color.color = new Color(0, 1, 1, 1);
|
|
break;
|
|
case Stay:
|
|
color.color = new Color(1, 1, 0, 1);
|
|
break;
|
|
case Flick:
|
|
color.color = new Color(1, 0.2f, 0, 1);
|
|
break;
|
|
}
|
|
|
|
}
|
|
public void Update()
|
|
{
|
|
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;
|
|
}
|
|
|
|
}
|