各种优化,movable采音器完善
This commit is contained in:
@@ -85,7 +85,7 @@ namespace Ichni.RhythmGame
|
||||
new FlexibleFloat(), new FlexibleFloat(), new FlexibleFloat()));
|
||||
var scaleButton = inspector.GenerateButton(this, generateAnimation, "Scale", () =>
|
||||
{
|
||||
Swirl.GenerateElement("New Scale", Guid.NewGuid(), new List<string>(), true, this,
|
||||
Scale.GenerateElement("New Scale", Guid.NewGuid(), new List<string>(), true, this,
|
||||
new FlexibleFloat(), new FlexibleFloat(), new FlexibleFloat());
|
||||
}); //缩放
|
||||
}
|
||||
@@ -109,7 +109,7 @@ namespace Ichni.RhythmGame
|
||||
{
|
||||
Debug.Log(note.GetType() + " " + note.elementName + " " + note.exactJudgeTime);
|
||||
}
|
||||
|
||||
|
||||
return notes;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -177,7 +177,7 @@ namespace Ichni.RhythmGame
|
||||
}); //旋转
|
||||
var scaleButton = inspector.GenerateButton(this, animationSubcontainer, "Scale", () =>
|
||||
{
|
||||
Swirl.GenerateElement("New Scale", Guid.NewGuid(), new List<string>(), true, this,
|
||||
Scale.GenerateElement("New Scale", Guid.NewGuid(), new List<string>(), true, this,
|
||||
new FlexibleFloat(), new FlexibleFloat(), new FlexibleFloat());
|
||||
}); //缩放
|
||||
if (trackPathSubmodule != null)
|
||||
|
||||
@@ -24,6 +24,7 @@ public class EventPoint : MonoBehaviour
|
||||
public RawImage CurveCanvas;
|
||||
|
||||
public FlexibleFloatTab FatherTab;
|
||||
public TMP_Text ViewText;
|
||||
|
||||
public int BeatDeviver => FatherTab.BeatDeviver;
|
||||
public void Initialize(AnimatedFloat animatedFloat)
|
||||
@@ -122,11 +123,15 @@ public class EventPoint : MonoBehaviour
|
||||
|
||||
selectButton.transform.localPosition = EvDrawimage.transform.localPosition;
|
||||
selectButton.GetComponent<RectTransform>().sizeDelta = EvDrawimage.rectTransform.sizeDelta;
|
||||
ViewText.text = animatedFloat.startTime.ToString("0.00") + "s" + "\n" +
|
||||
animatedFloat.startValue.ToString("0.0") + "\n" + animatedFloat.endValue.ToString("0.0") + "\n" + animatedFloat.endTime.ToString("0.00") + "s" + "\n" +
|
||||
animatedFloat.animationCurveType.ToString();
|
||||
ViewText.color = new Color(1, 1, 1, EvDrawimage.rectTransform.sizeDelta.x < 100 ? 0 : 1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void SelectButtonClick()
|
||||
public void SelectButtonClick()//unity内:当按钮按下时
|
||||
{
|
||||
if (Keyboard.current.leftShiftKey.isPressed)
|
||||
{
|
||||
@@ -134,6 +139,7 @@ public class EventPoint : MonoBehaviour
|
||||
{
|
||||
FatherTab.FatherWindow.ClipBoard[FatherTab.Title].Remove(animatedFloat);
|
||||
LeftSide.sizeDelta = new Vector2(15, EvDrawimage.rectTransform.sizeDelta.y);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -142,6 +148,7 @@ public class EventPoint : MonoBehaviour
|
||||
LeftSide.sizeDelta = EvDrawimage.rectTransform.sizeDelta;
|
||||
|
||||
}
|
||||
FatherTab.FatherWindow.updateClipBoardMuM();
|
||||
}
|
||||
else UpLoad();
|
||||
}
|
||||
@@ -166,6 +173,10 @@ public class EventPoint : MonoBehaviour
|
||||
// 如果有已连接点,则重置其颜色
|
||||
if (FatherTab.FatherWindow.ConnectedPoint != null)
|
||||
{
|
||||
FatherTab.TabButton.onClick.RemoveAllListeners();
|
||||
FatherTab.TabButton.onClick.AddListener(FatherTab.AddEvent);
|
||||
FatherTab.FatherWindow.EvEndpointChangeButton.GetComponent<Image>().color = new Color(1f, 1f, 1f, 1);
|
||||
|
||||
FatherTab.FatherWindow.ConnectedPoint.EvDrawimage.color = new Color(
|
||||
FatherTab.FatherWindow.ConnectedPoint.EvDrawimage.color.r,
|
||||
0.3019607843137255f,
|
||||
@@ -193,4 +204,79 @@ public class EventPoint : MonoBehaviour
|
||||
|
||||
FatherTab.FatherWindow.animationCurveTypeDropdown.onValueChanged.AddListener(value => FatherTab.FatherWindow.ChangeValue());
|
||||
}
|
||||
|
||||
// 添加静态方法:查找插入索引
|
||||
public static int FindInsertIndex(List<EventPoint> eventPoints, 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;
|
||||
}
|
||||
|
||||
// 添加实例方法:连接事件点
|
||||
public void LinkEventPoints(List<EventPoint> eventPoints, int index)
|
||||
{
|
||||
if (index - 1 >= 0)
|
||||
{
|
||||
LastEventPoint = eventPoints[index - 1];
|
||||
LastEventPoint.NextEventPoint = this;
|
||||
}
|
||||
else
|
||||
{
|
||||
LastEventPoint = null;
|
||||
}
|
||||
if (index == eventPoints.Count - 1)
|
||||
{
|
||||
NextEventPoint = null;
|
||||
}
|
||||
}
|
||||
|
||||
// 添加实例方法:连接新事件点
|
||||
public void LinkNewEventPoint(List<EventPoint> eventPoints, bool link, float scalevalue)
|
||||
{
|
||||
int index = eventPoints.IndexOf(this);
|
||||
if (index - 1 >= 0)
|
||||
{
|
||||
LastEventPoint = eventPoints[index - 1];
|
||||
LastEventPoint.NextEventPoint = this;
|
||||
LastEventPoint.ReDraw(scalevalue);
|
||||
}
|
||||
if (index + 1 < eventPoints.Count)
|
||||
{
|
||||
NextEventPoint = eventPoints[index + 1];
|
||||
if (link) animatedFloat.endTime = NextEventPoint.animatedFloat.startTime;
|
||||
Initialize(animatedFloat);
|
||||
NextEventPoint.LastEventPoint = this;
|
||||
}
|
||||
}
|
||||
|
||||
// 添加静态方法:克隆 AnimatedFloat 并应用时间偏移
|
||||
/// <summary>
|
||||
/// 克隆一个 AnimatedFloat 对象,并根据偏移量调整其开始和结束时间。
|
||||
/// </summary>
|
||||
/// <param name="animatedFloat">要克隆的 AnimatedFloat 对象。</param>
|
||||
/// <param name="offset">时间偏移量。</param>
|
||||
/// <returns>克隆后的 AnimatedFloat 对象。</returns>
|
||||
public static AnimatedFloat CloneWithOffset(AnimatedFloat animatedFloat, float offset)
|
||||
{
|
||||
return new AnimatedFloat(
|
||||
animatedFloat.startTime + offset,
|
||||
animatedFloat.endTime + offset,
|
||||
animatedFloat.startValue,
|
||||
animatedFloat.endValue,
|
||||
animatedFloat.animationCurveType
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ using Ichni.RhythmGame;
|
||||
using Unity.VisualScripting;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class FlexibleFloatTab : MonoBehaviour
|
||||
{
|
||||
@@ -18,8 +19,8 @@ public class FlexibleFloatTab : MonoBehaviour
|
||||
public RectTransform XBeatArea;
|
||||
public EventPoint eventPoint;
|
||||
public GameObject BeatLine;
|
||||
public Button TabButton;
|
||||
public string Title;
|
||||
public GameObject FirstBeatLine;
|
||||
public FlexibleFloat connectFloat;
|
||||
public int BeatDeviver => FatherWindow.BeatDeviver;
|
||||
public int BeatNextDeviver => FatherWindow.BeatNextDeviver;
|
||||
@@ -34,8 +35,8 @@ public class FlexibleFloatTab : MonoBehaviour
|
||||
connectFloat = flexibleFloat;
|
||||
CreateBeatLines();
|
||||
CreateEventPoints();
|
||||
RedrawEventPoints();
|
||||
Area.localPosition = new Vector3(FatherWindow.songBeat * BeatDeviver, 0, 0);
|
||||
TabButton.onClick.AddListener(AddEvent);
|
||||
}
|
||||
|
||||
// 清除子节点
|
||||
@@ -54,7 +55,6 @@ public class FlexibleFloatTab : MonoBehaviour
|
||||
{
|
||||
GameObject u = Instantiate(BeatLine, BeatArea);
|
||||
u.transform.localPosition = new Vector3(BeatDeviver * i, 0, 0);
|
||||
if (i == 1) FirstBeatLine = u;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,29 +70,6 @@ public class FlexibleFloatTab : MonoBehaviour
|
||||
eventPoints.Add(eventPoint);
|
||||
LinkEventPoints(i, eventPoint);
|
||||
}
|
||||
}
|
||||
|
||||
// 连接事件点
|
||||
private void LinkEventPoints(int index, EventPoint eventPoint)
|
||||
{
|
||||
if (index - 1 >= 0)
|
||||
{
|
||||
eventPoint.LastEventPoint = eventPoints[index - 1];
|
||||
eventPoint.LastEventPoint.NextEventPoint = eventPoint;
|
||||
}
|
||||
else
|
||||
{
|
||||
eventPoint.LastEventPoint = null;
|
||||
}
|
||||
if (index == connectFloat.animations.Count - 1)
|
||||
{
|
||||
eventPoint.NextEventPoint = null;
|
||||
}
|
||||
}
|
||||
|
||||
// 重绘事件点
|
||||
private void RedrawEventPoints()
|
||||
{
|
||||
foreach (var i in eventPoints)
|
||||
{
|
||||
i.ReDraw(scalevalue);
|
||||
@@ -141,57 +118,40 @@ public class FlexibleFloatTab : MonoBehaviour
|
||||
connectFloat.Add(eventPoint.animatedFloat);
|
||||
connectFloat.Sort();
|
||||
}
|
||||
// 连接新事件点
|
||||
private void LinkNewEventPoint(EventPoint eventPoint, bool link = false)
|
||||
|
||||
// 添加调用 EventPoint 类的接口
|
||||
public void LinkEventPoints(int index, EventPoint eventPoint)
|
||||
{
|
||||
int index = eventPoints.IndexOf(eventPoint);
|
||||
if (index - 1 >= 0)
|
||||
{
|
||||
eventPoint.LastEventPoint = eventPoints[index - 1];
|
||||
eventPoint.LastEventPoint.NextEventPoint = eventPoint;
|
||||
eventPoint.LastEventPoint.ReDraw(scalevalue);
|
||||
}
|
||||
if (index + 1 < eventPoints.Count)
|
||||
{
|
||||
eventPoint.NextEventPoint = eventPoints[index + 1];
|
||||
if (link) eventPoint.animatedFloat.endTime = eventPoint.NextEventPoint.animatedFloat.startTime;
|
||||
eventPoint.Initialize(eventPoint.animatedFloat);
|
||||
eventPoint.NextEventPoint.LastEventPoint = eventPoint;
|
||||
}
|
||||
eventPoint.LinkEventPoints(eventPoints, index);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void LinkNewEventPoint(EventPoint eventPoint, bool link = false)
|
||||
{
|
||||
eventPoint.LinkNewEventPoint(eventPoints, link, scalevalue);
|
||||
}
|
||||
|
||||
// 查找插入索引
|
||||
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;
|
||||
return EventPoint.FindInsertIndex(eventPoints, startTime);
|
||||
}
|
||||
|
||||
// 获取节拍
|
||||
public float GetBeat()
|
||||
{
|
||||
float mouseInputX = Mouse.current.position.ReadValue().x;
|
||||
float far = BeatArea.transform.position.x;
|
||||
float Beat = 0;
|
||||
while (far < mouseInputX)
|
||||
// 获取鼠标在 BeatArea 中的相对位置
|
||||
Vector2 localMousePosition = BeatArea.InverseTransformPoint(Mouse.current.position.ReadValue());
|
||||
//Debug.Log(localMousePosition);
|
||||
|
||||
float mouseBeat = localMousePosition.x / BeatDeviver;
|
||||
float far = 0f;
|
||||
while (far < mouseBeat)
|
||||
{
|
||||
far += (FirstBeatLine.transform.position.x - BeatArea.transform.position.x) / BeatNextDeviver;
|
||||
Beat += 1f / BeatNextDeviver;
|
||||
far += 1f / BeatNextDeviver;
|
||||
}
|
||||
return FatherWindow.timePerBeat * (Beat - (1f / BeatNextDeviver));
|
||||
far -= 1f / BeatNextDeviver;
|
||||
return far * FatherWindow.timePerBeat;
|
||||
}
|
||||
|
||||
public float scalevalue => FatherWindow.scalevalue;
|
||||
@@ -233,4 +193,35 @@ public class FlexibleFloatTab : MonoBehaviour
|
||||
connectFloat.animations.Remove(a);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从事件点列表中移除指定的事件点,并更新其前后连接关系。
|
||||
/// </summary>
|
||||
/// <param name="eventPoint">要移除的事件点。</param>
|
||||
public void RemoveEventPoint(EventPoint eventPoint)
|
||||
{
|
||||
if (eventPoints.Contains(eventPoint))
|
||||
{
|
||||
// 更新前后事件点的连接关系
|
||||
if (eventPoint.LastEventPoint != null)
|
||||
{
|
||||
eventPoint.LastEventPoint.NextEventPoint = eventPoint.NextEventPoint;
|
||||
eventPoint.LastEventPoint.ReDraw(scalevalue);
|
||||
}
|
||||
if (eventPoint.NextEventPoint != null)
|
||||
{
|
||||
eventPoint.NextEventPoint.LastEventPoint = eventPoint.LastEventPoint;
|
||||
eventPoint.NextEventPoint.ReDraw(scalevalue);
|
||||
}
|
||||
|
||||
// 从列表中移除事件点
|
||||
eventPoints.Remove(eventPoint);
|
||||
|
||||
// 从连接的动画中移除
|
||||
connectFloat.animations.Remove(eventPoint.animatedFloat);
|
||||
|
||||
// 销毁事件点对象
|
||||
Destroy(eventPoint.gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,6 +57,7 @@ public partial class GraphicalFlexibleFloatWindow : MovableWindow
|
||||
|
||||
};
|
||||
XDeviverScale("1");
|
||||
EvEndpointChangeButton.onClick.AddListener(EvEndpointStartChange);
|
||||
}
|
||||
public void AddUnit(FlexibleFloat flexibleFloat, string Subtitle)
|
||||
{
|
||||
@@ -123,36 +124,23 @@ public partial class GraphicalFlexibleFloatWindow
|
||||
public GameObject VisibleArea;
|
||||
|
||||
|
||||
public void Removed()
|
||||
/// <summary>
|
||||
/// 移除当前连接的事件点,并更新 UI。
|
||||
/// </summary>
|
||||
public void RemoveConnectedPoint()
|
||||
{
|
||||
if (ConnectedPoint != null)
|
||||
{
|
||||
ConnectedPoint.FatherTab.remoceAnim(ConnectedPoint.animatedFloat);
|
||||
ConnectedPoint.FatherTab.eventPoints.Remove(ConnectedPoint);
|
||||
if (ConnectedPoint.LastEventPoint != null)
|
||||
{
|
||||
ConnectedPoint.LastEventPoint.NextEventPoint = ConnectedPoint.NextEventPoint;
|
||||
if (ConnectedPoint.LastEventPoint.NextEventPoint != null) ConnectedPoint.LastEventPoint.NextEventPoint.ReDraw(scalevalue);
|
||||
ConnectedPoint.LastEventPoint.ReDraw(scalevalue);
|
||||
}
|
||||
|
||||
if (ConnectedPoint.NextEventPoint != null)
|
||||
{
|
||||
ConnectedPoint.NextEventPoint.LastEventPoint = ConnectedPoint.LastEventPoint;
|
||||
if (ConnectedPoint.NextEventPoint.LastEventPoint != null) ConnectedPoint.NextEventPoint.LastEventPoint.ReDraw(scalevalue);
|
||||
}
|
||||
|
||||
//Destroy(ConnectedPoint.animatedFloat);
|
||||
// 调用 FlexibleFloatTab 的 RemoveEventPoint 方法
|
||||
ConnectedPoint.FatherTab.RemoveEventPoint(ConnectedPoint);
|
||||
|
||||
// 清空连接点并隐藏可见区域
|
||||
ConnectedPoint = null;
|
||||
VisibleArea.SetActive(false);
|
||||
|
||||
Destroy(ConnectedPoint.gameObject);
|
||||
ApplyParameters();
|
||||
}
|
||||
}
|
||||
|
||||
public void ChangeValue()
|
||||
|
||||
|
||||
{
|
||||
if (ConnectedPoint != null)
|
||||
{
|
||||
@@ -170,45 +158,75 @@ public partial class GraphicalFlexibleFloatWindow
|
||||
ConnectedPoint.ReDraw(scalevalue);
|
||||
}
|
||||
}
|
||||
public Button EvEndpointChangeButton;
|
||||
public void EvEndpointStartChange()
|
||||
{
|
||||
if (ConnectedPoint != null)
|
||||
{
|
||||
EndText.text = (ConnectedPoint.animatedFloat.startTime + 0.01).ToString();
|
||||
ChangeValue();
|
||||
EvEndpointChangeButton.GetComponent<Image>().color = new Color(1f, 0.5f, 0.5f, 1);
|
||||
ConnectedPoint.FatherTab.TabButton.onClick.RemoveAllListeners();
|
||||
ConnectedPoint.FatherTab.TabButton.onClick.AddListener(EvEndpointEndChange);
|
||||
|
||||
}
|
||||
}
|
||||
public void EvEndpointEndChange()
|
||||
{
|
||||
if (ConnectedPoint != null)
|
||||
{
|
||||
EvEndpointChangeButton.GetComponent<Image>().color = new Color(1f, 1f, 1f, 1);
|
||||
|
||||
float newendtime = ConnectedPoint.FatherTab.GetBeat();
|
||||
if (newendtime > ConnectedPoint.animatedFloat.startTime)
|
||||
{
|
||||
if (ConnectedPoint.NextEventPoint != null && newendtime > ConnectedPoint.NextEventPoint.animatedFloat.startTime)
|
||||
EndText.text = ConnectedPoint.NextEventPoint.animatedFloat.startTime.ToString();
|
||||
else EndText.text = newendtime.ToString();
|
||||
ChangeValue();
|
||||
}
|
||||
|
||||
ConnectedPoint.FatherTab.TabButton.onClick.RemoveAllListeners();
|
||||
ConnectedPoint.FatherTab.TabButton.onClick.AddListener(ConnectedPoint.FatherTab.AddEvent);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public Dictionary<string, List<AnimatedFloat>> ClipBoard = new();
|
||||
public float MinCopyTime = 0f;
|
||||
|
||||
public void Update()
|
||||
{
|
||||
if (Keyboard.current.deleteKey.isPressed && ConnectedPoint != null)
|
||||
{
|
||||
Removed();
|
||||
RemoveConnectedPoint();
|
||||
}
|
||||
|
||||
if (Keyboard.current.shiftKey.isPressed && Keyboard.current.vKey.wasPressedThisFrame)
|
||||
{
|
||||
Paste();
|
||||
PasteClipboard();
|
||||
}
|
||||
}
|
||||
public void Paste()
|
||||
{
|
||||
float time = unitList[0].GetBeat();
|
||||
print(time);
|
||||
FindMinStartTime();
|
||||
foreach (KeyValuePair<string, List<AnimatedFloat>> i in ClipBoard)
|
||||
if (Keyboard.current.escapeKey.wasPressedThisFrame)
|
||||
{
|
||||
foreach (AnimatedFloat j in i.Value)
|
||||
foreach (var key in ClipBoard.Keys.ToList())
|
||||
{
|
||||
AnimatedFloat newone = new AnimatedFloat(j.startTime, j.endTime, j.startValue, j.endValue, j.animationCurveType)
|
||||
ClipBoard[key] = new List<AnimatedFloat>();
|
||||
}
|
||||
foreach (FlexibleFloatTab i in unitList)
|
||||
{
|
||||
foreach (EventPoint j in i.eventPoints)
|
||||
{
|
||||
startTime = j.startTime - MinCopyTime + time,
|
||||
endTime = j.endTime - MinCopyTime + time
|
||||
};
|
||||
|
||||
unitList.Find(x => x.Title == i.Key).SpawnEvent(newone);
|
||||
j.LeftSide.sizeDelta = new Vector2(15, j.EvDrawimage.rectTransform.sizeDelta.y);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void FindMinStartTime()
|
||||
public void PasteClipboard()
|
||||
{
|
||||
MinCopyTime = float.MaxValue;
|
||||
// 获取当前时间线的节拍位置
|
||||
float time = unitList[0].GetBeat();
|
||||
float MinCopyTime = float.MaxValue;
|
||||
// 遍历剪贴板中的所有动画数据MinCopyTime = float.MaxValue;
|
||||
foreach (var list in ClipBoard.Values)
|
||||
{
|
||||
foreach (var animatedFloat in list)
|
||||
@@ -219,5 +237,30 @@ public partial class GraphicalFlexibleFloatWindow
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach (var key in ClipBoard.Keys)
|
||||
{
|
||||
foreach (var animatedFloat in ClipBoard[key])
|
||||
{
|
||||
// 克隆动画数据并应用时间偏移
|
||||
AnimatedFloat newFloat = EventPoint.CloneWithOffset(animatedFloat, time - MinCopyTime);
|
||||
|
||||
// 在对应的 FlexibleFloatTab 中生成事件点
|
||||
unitList.Find(x => x.Title == key).SpawnEvent(newFloat);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
public partial class GraphicalFlexibleFloatWindow
|
||||
{//以后显示类写这里,别在叠大粪了
|
||||
public TMP_Text ClipBoardMuM;
|
||||
public void updateClipBoardMuM()
|
||||
{
|
||||
int mum = 0;
|
||||
foreach (var key in ClipBoard.Keys)
|
||||
{
|
||||
mum += ClipBoard[key].Count();
|
||||
}
|
||||
ClipBoardMuM.text = "ClipBoard: " + mum.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
16
Assets/Scripts/Sample Assiant/NotefabContoler.cs
Normal file
16
Assets/Scripts/Sample Assiant/NotefabContoler.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Ichni;
|
||||
using Ichni.RhythmGame;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class NotefabContoler : MonoBehaviour
|
||||
{
|
||||
public NoteBase noteBase;
|
||||
public RawImage ifHold;
|
||||
public void Onclick()
|
||||
{
|
||||
EditorManager.instance.uiManager.hierarchy.FindTab(noteBase);
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Sample Assiant/NotefabContoler.cs.meta
Normal file
11
Assets/Scripts/Sample Assiant/NotefabContoler.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ae19b314bbfece546a1a8d74d38387ac
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
280
Assets/Scripts/Sample Assiant/SampleWindow.cs
Normal file
280
Assets/Scripts/Sample Assiant/SampleWindow.cs
Normal file
@@ -0,0 +1,280 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using Dreamteck.Splines;
|
||||
using Ichni;
|
||||
using Ichni.Editor;
|
||||
using Ichni.RhythmGame;
|
||||
using TMPro;
|
||||
using Unity.VisualScripting;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class SampleWindow : MovableWindow//该window高度为300,横的要在100和500之间切换
|
||||
{
|
||||
public static List<SampleWindow> instances = new List<SampleWindow>();
|
||||
public TMP_InputField DeviverInputField;
|
||||
public TMP_InputField verticalInputField;
|
||||
public TMP_InputField horizontalInputField;
|
||||
public RectTransform LineMovepoint;
|
||||
public RectTransform NoteMovepoint;
|
||||
|
||||
public List<NoteBase> noteBases;
|
||||
public bool isFocus = false;
|
||||
public bool isExpand = false;
|
||||
public int beatDeviver = 100;
|
||||
public int Xdevide = 1;
|
||||
public float realDevider;
|
||||
public GameObject beatLinePrefabv;
|
||||
public GameObject beatLinePrefabh;
|
||||
public GameObject NotePrefab;
|
||||
public RectTransform secBeatLineh;//用于定位屏幕位置
|
||||
float songTime => EditorManager.instance.songInformation.songTime;
|
||||
float songBeat => EditorManager.instance.songInformation.songBeat;
|
||||
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(() =>
|
||||
{
|
||||
instances.Remove(this);
|
||||
});
|
||||
if (instances.Where(i => i.gameElement == qgameElement).Count() != 0)
|
||||
{
|
||||
Destroy(this.gameObject);
|
||||
foreach (SampleWindow i in instances)
|
||||
{
|
||||
i.StartCoroutine(WindowAnim.Shake(instances.Where(i => i.gameElement == qgameElement).First().windowRect.gameObject));
|
||||
|
||||
}
|
||||
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);
|
||||
|
||||
|
||||
//
|
||||
SpawnBeatline();
|
||||
OnceSpawnNote();
|
||||
instances.Add(this);
|
||||
}
|
||||
public void SpawnBeatline()//添加优化措施
|
||||
|
||||
{
|
||||
for (int i = LineMovepoint.childCount - 1; i >= 0; i--)
|
||||
{
|
||||
Destroy(LineMovepoint.GetChild(i).gameObject);
|
||||
}
|
||||
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(0, 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)
|
||||
{
|
||||
secBeatLineh = u.GetComponent<RectTransform>();
|
||||
realDevider = secBeatLineh.position.y - LineMovepoint.position.y;
|
||||
Debug.Log(realDevider);
|
||||
}
|
||||
if (u.transform.localPosition.y > 600)
|
||||
{
|
||||
Destroy(u);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void OnceSpawnNote()
|
||||
{
|
||||
if (gameElement is Track track) noteBases = track.GetAllNotes();
|
||||
else if (gameElement is ElementFolder elementFolder) noteBases = elementFolder.GetAllNotes();
|
||||
for (int i = NoteMovepoint.childCount - 1; i >= 0; i--)
|
||||
{
|
||||
Destroy(NoteMovepoint.GetChild(i).gameObject);
|
||||
}
|
||||
foreach (var i in noteBases)
|
||||
{
|
||||
SpawnNote(i);
|
||||
}
|
||||
}
|
||||
private void SpawnNote(NoteBase i, float posx = 0)
|
||||
{
|
||||
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:
|
||||
color.color = new Color(0, 1, 0, 1);
|
||||
RawImage a = u.GetComponent<NotefabContoler>().ifHold;
|
||||
a.transform.localPosition = new Vector3(0, (hold.holdEndTime - hold.exactJudgeTime) / timePerBeat * beatDeviver / 2, 0);
|
||||
a.GetComponent<RectTransform>().sizeDelta = new Vector2(a.GetComponent<RectTransform>().sizeDelta.x, (hold.holdEndTime - hold.exactJudgeTime) / timePerBeat * beatDeviver);
|
||||
a.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;
|
||||
}//服了,之后整合到controler里头去
|
||||
}
|
||||
|
||||
public GameObject selectedGameObject = EventSystem.current.currentSelectedGameObject;
|
||||
void Update()
|
||||
{
|
||||
selectedGameObject = EventSystem.current.currentSelectedGameObject;
|
||||
LineMovepoint.localPosition = new(0, -beatDeviver * (songBeat - (int)songBeat), 0);
|
||||
NoteMovepoint.localPosition = new(0, -beatDeviver * songBeat, 0);
|
||||
if (isFocus && gameElement is Track track)
|
||||
{
|
||||
if (track.trackTimeSubmodule is TrackTimeSubmoduleMovable trackTimeSubmoduleMovable)
|
||||
{
|
||||
trackPositioner.SetPercent(track.trackTimeSubmodule.headPercent);
|
||||
windowRect.GetComponent<CanvasGroup>().alpha = (songTime >= trackTimeSubmoduleMovable.trackStartTime && songTime <= trackTimeSubmoduleMovable.trackEndTime) ? 1f : 0.2f;
|
||||
|
||||
}
|
||||
else if (track.trackTimeSubmodule is TrackTimeSubmoduleStatic)
|
||||
{
|
||||
trackPositioner.SetPercent(0f);
|
||||
}
|
||||
TransformChanged();
|
||||
windowRect.GetComponent<CanvasGroup>().alpha = track.timeDurationSubmodule.CheckTimeInDuration(songTime) ? 1f : 0.2f;
|
||||
}
|
||||
if (selectedGameObject == null && RectTransformUtility.RectangleContainsScreenPoint(windowRect, Mouse.current.position.ReadValue()))
|
||||
{
|
||||
DetectNote();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
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)
|
||||
{
|
||||
beatDeviver = int.Parse(devide);
|
||||
SpawnBeatline();
|
||||
OnceSpawnNote();
|
||||
}
|
||||
public void ChangeExpand()
|
||||
{
|
||||
if (isExpand)
|
||||
{
|
||||
isExpand = false;
|
||||
windowRect.sizeDelta = new Vector2(100, windowRect.sizeDelta.y);
|
||||
}
|
||||
else
|
||||
{
|
||||
isExpand = true;
|
||||
windowRect.sizeDelta = new Vector2(500, windowRect.sizeDelta.y);
|
||||
}
|
||||
}
|
||||
public void DetectNote()
|
||||
{
|
||||
if (Keyboard.current.digit1Key.wasPressedThisFrame)
|
||||
AddNote(0);
|
||||
else if (Keyboard.current.digit2Key.wasPressedThisFrame)
|
||||
AddNote(1);
|
||||
else if (Keyboard.current.digit3Key.wasPressedThisFrame)
|
||||
AddNote(2);
|
||||
else if (Keyboard.current.digit4Key.wasPressedThisFrame)
|
||||
AddNote(3);
|
||||
}
|
||||
public void AddNote(int NoteCode)
|
||||
{
|
||||
// 获取鼠标在 NoteMovepoint 中的相对位置
|
||||
Vector2 localMousePosition = NoteMovepoint.InverseTransformPoint(Mouse.current.position.ReadValue());
|
||||
Debug.Log(localMousePosition);
|
||||
float mouseBeat = localMousePosition.y / beatDeviver;
|
||||
float far = 0f;
|
||||
while (far < mouseBeat)
|
||||
{
|
||||
far += 1f / Xdevide;
|
||||
}
|
||||
far -= 1f / Xdevide;
|
||||
float time = far * timePerBeat;
|
||||
|
||||
|
||||
if (!isExpand)//movable
|
||||
{
|
||||
switch (NoteCode)
|
||||
{
|
||||
case 0:
|
||||
Tap a = Tap.GenerateElement("New Tap", Guid.NewGuid(), new List<string>(), true, gameElement, time);
|
||||
noteBases.Add(a);
|
||||
SpawnNote(a);
|
||||
break;
|
||||
case 3:
|
||||
Hold b = Hold.GenerateElement("New Hold", Guid.NewGuid(), new List<string>(), true, gameElement, time, time + 0.5f);
|
||||
noteBases.Add(b);
|
||||
SpawnNote(b);
|
||||
break;
|
||||
case 1:
|
||||
Stay c = Stay.GenerateElement("New Stay", Guid.NewGuid(), new List<string>(), true, gameElement, time);
|
||||
noteBases.Add(c);
|
||||
SpawnNote(c);
|
||||
break;
|
||||
case 2:
|
||||
Flick d = Flick.GenerateElement("New Flick", Guid.NewGuid(), new List<string>(), true, gameElement, time, new List<Vector2>());
|
||||
noteBases.Add(d);
|
||||
SpawnNote(d);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Sample Assiant/SampleWindow.cs.meta
Normal file
11
Assets/Scripts/Sample Assiant/SampleWindow.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a48a638548bdb6645bfa74867dc72087
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user