GraphicEditor基本完成
不过还有优化空间 TODO: 用整个的Rawimage贴图替换beatline
This commit is contained in:
@@ -5,6 +5,7 @@ using Ichni;
|
||||
using Ichni.RhythmGame;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class EventPoint : MonoBehaviour
|
||||
@@ -21,7 +22,7 @@ public class EventPoint : MonoBehaviour
|
||||
public RectTransform RightSide;
|
||||
public Button selectButton;
|
||||
public RawImage CurveCanvas;
|
||||
public RawImage CurveCanvas2;
|
||||
|
||||
public FlexibleFloatTab FatherTab;
|
||||
|
||||
public int BeatDeviver => FatherTab.BeatDeviver;
|
||||
@@ -37,8 +38,8 @@ public class EventPoint : MonoBehaviour
|
||||
EvDrawimage.rectTransform.sizeDelta = new Vector2(RightSide.localPosition.x - LeftSide.localPosition.x, EvDrawimage.rectTransform.sizeDelta.y);
|
||||
EvDrawimage.transform.localPosition = new Vector3(EvDrawimage.rectTransform.sizeDelta.x / 2, 0, 0);
|
||||
OvDrawimage.transform.localPosition = RightSide.localPosition;
|
||||
CurveCanvas.transform.localPosition = EvDrawimage.transform.localPosition;
|
||||
CurveCanvas.rectTransform.sizeDelta = new Vector2(EvDrawimage.rectTransform.sizeDelta.x, EvDrawimage.rectTransform.sizeDelta.y + 50);
|
||||
|
||||
CurveCanvas.rectTransform.sizeDelta = new Vector2(EvDrawimage.rectTransform.sizeDelta.x, EvDrawimage.rectTransform.sizeDelta.y);
|
||||
|
||||
|
||||
|
||||
@@ -51,6 +52,7 @@ public class EventPoint : MonoBehaviour
|
||||
public float value => FatherTab.scalevalue;
|
||||
public void ReDraw(float value)
|
||||
{
|
||||
|
||||
Texture2D Texture = new Texture2D((int)CurveCanvas.rectTransform.sizeDelta.x / 5, (int)CurveCanvas.rectTransform.sizeDelta.y / 5);
|
||||
for (int i = 0; i < Texture.width; i++)
|
||||
{
|
||||
@@ -60,6 +62,9 @@ public class EventPoint : MonoBehaviour
|
||||
}
|
||||
}
|
||||
Texture.Apply();
|
||||
|
||||
|
||||
int LastEventPointY = 0;
|
||||
for (int i = 0; i < Texture.width; i++)
|
||||
{
|
||||
float t = (float)i / Texture.width;
|
||||
@@ -67,26 +72,46 @@ public class EventPoint : MonoBehaviour
|
||||
(Texture.height / 2) + (animatedFloat.startValue * value + ((animatedFloat.endValue - animatedFloat.startValue)
|
||||
* AnimationCurveEvaluator.Evaluate(animatedFloat.animationCurveType, t) * value))
|
||||
);
|
||||
if (f < Texture.height) Texture.SetPixel(i, f, Color.green);//丑陋
|
||||
|
||||
|
||||
//不是哥们
|
||||
for (int j = LastEventPointY; j < f; j++)
|
||||
{
|
||||
if (j < Texture.height) Texture.SetPixel(i, j, Color.green);
|
||||
else Texture.SetPixel(i, j, Color.red);
|
||||
}
|
||||
for (int j = LastEventPointY; j > f; j--)
|
||||
{
|
||||
if (j > 0) Texture.SetPixel(i, j, Color.green);
|
||||
else Texture.SetPixel(i, j, Color.red);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
if (f < Texture.height && f > 0) Texture.SetPixel(i, f, Color.green);//丑陋
|
||||
else Texture.SetPixel(i, f, Color.red);
|
||||
LastEventPointY = f;
|
||||
}
|
||||
Texture.Apply();
|
||||
CurveCanvas.texture = Texture;
|
||||
if (NextEventPoint != null)
|
||||
{
|
||||
OvDrawimage.transform.localPosition = new Vector3(RightSide.transform.localPosition.x, animatedFloat.endValue * value * 5, 0);
|
||||
OvDrawimage.rectTransform.sizeDelta = new Vector2((NextEventPoint.animatedFloat.startTime - animatedFloat.endTime) / EditorManager.instance.uiManager.timeline.timePerBeat * FatherTab.BeatDeviver, OvDrawimage.rectTransform.sizeDelta.y);
|
||||
OvDrawimage.transform.localPosition = new Vector3(RightSide.transform.localPosition.x,
|
||||
animatedFloat.endValue * value * 5, 0);
|
||||
OvDrawimage.rectTransform.sizeDelta = new Vector2((NextEventPoint.animatedFloat.startTime - animatedFloat.endTime) / EditorManager.instance.uiManager.timeline.timePerBeat * FatherTab.BeatDeviver,
|
||||
OvDrawimage.rectTransform.sizeDelta.y);
|
||||
|
||||
OvDrawimage.color = new Color(0, 1, 0, 1);
|
||||
while (OvDrawimage.transform.localPosition.y > 130)
|
||||
while (OvDrawimage.transform.localPosition.y > 100)
|
||||
{
|
||||
OvDrawimage.color = new Color(1, 0, 0, 0.3f);
|
||||
OvDrawimage.transform.localPosition = new Vector3(OvDrawimage.transform.localPosition.x, OvDrawimage.transform.localPosition.y - 260, OvDrawimage.transform.localPosition.z);
|
||||
OvDrawimage.transform.localPosition = new Vector3(OvDrawimage.transform.localPosition.x, OvDrawimage.transform.localPosition.y - 200, OvDrawimage.transform.localPosition.z);
|
||||
}
|
||||
while (OvDrawimage.transform.localPosition.y < -130)
|
||||
while (OvDrawimage.transform.localPosition.y < -100)
|
||||
{
|
||||
OvDrawimage.color = new Color(1, 0, 0, 0.3f);
|
||||
OvDrawimage.transform.localPosition = new Vector3(OvDrawimage.transform.localPosition.x, OvDrawimage.transform.localPosition.y + 260, OvDrawimage.transform.localPosition.z);
|
||||
OvDrawimage.transform.localPosition = new Vector3(OvDrawimage.transform.localPosition.x, OvDrawimage.transform.localPosition.y + 200, OvDrawimage.transform.localPosition.z);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -99,46 +124,73 @@ public class EventPoint : MonoBehaviour
|
||||
selectButton.GetComponent<RectTransform>().sizeDelta = EvDrawimage.rectTransform.sizeDelta;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void SelectButtonClick()
|
||||
{
|
||||
if (Keyboard.current.leftShiftKey.isPressed)
|
||||
{
|
||||
if (FatherTab.FatherWindow.ClipBoard[FatherTab.Title].Contains(animatedFloat))
|
||||
{
|
||||
FatherTab.FatherWindow.ClipBoard[FatherTab.Title].Remove(animatedFloat);
|
||||
LeftSide.sizeDelta = new Vector2(15, EvDrawimage.rectTransform.sizeDelta.y);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
FatherTab.FatherWindow.ClipBoard[FatherTab.Title].Add(animatedFloat);
|
||||
LeftSide.sizeDelta = EvDrawimage.rectTransform.sizeDelta;
|
||||
|
||||
}
|
||||
}
|
||||
else UpLoad();
|
||||
}
|
||||
public void UpLoad()
|
||||
{
|
||||
FatherTab.FatherWindow.animationCurveTypeDropdown.onValueChanged.RemoveAllListeners();
|
||||
|
||||
|
||||
// 如果当前点是已连接点,则取消连接并隐藏可见区域
|
||||
if (FatherTab.FatherWindow.ConnectedPoint == this)
|
||||
{
|
||||
FatherTab.FatherWindow.VisibleArea.SetActive(false);
|
||||
FatherTab.FatherWindow.ConnectedPoint = null;
|
||||
EvDrawimage.color = new Color(
|
||||
EvDrawimage.color.r,
|
||||
0.3019607843137255f,
|
||||
EvDrawimage.color.b, 0.5f
|
||||
);
|
||||
EvDrawimage.color = new Color(EvDrawimage.color.r, 0.3019607843137255f, EvDrawimage.color.b, 0.5f);
|
||||
FatherTab.FatherWindow.StartText.text = "";
|
||||
FatherTab.FatherWindow.EndText.text = "";
|
||||
FatherTab.FatherWindow.StartValueText.text = "";
|
||||
FatherTab.FatherWindow.EndValueText.text = "";
|
||||
return;
|
||||
}
|
||||
|
||||
// 如果有已连接点,则重置其颜色
|
||||
if (FatherTab.FatherWindow.ConnectedPoint != null)
|
||||
{
|
||||
|
||||
FatherTab.FatherWindow.ConnectedPoint.EvDrawimage.color = new Color(
|
||||
FatherTab.FatherWindow.ConnectedPoint.EvDrawimage.color.r,
|
||||
0.3019607843137255f,
|
||||
FatherTab.FatherWindow.ConnectedPoint.EvDrawimage.color.b, 0.5f)
|
||||
;
|
||||
FatherTab.FatherWindow.ConnectedPoint.EvDrawimage.color.r,
|
||||
0.3019607843137255f,
|
||||
FatherTab.FatherWindow.ConnectedPoint.EvDrawimage.color.b, 0.5f
|
||||
);
|
||||
}
|
||||
|
||||
// 设置新的连接点并更新UI
|
||||
FatherTab.FatherWindow.ConnectedPoint = this;
|
||||
EvDrawimage.color = new Color(EvDrawimage.color.r, 0.75f, EvDrawimage.color.b, 1f);
|
||||
|
||||
// 更新下拉选项
|
||||
FatherTab.FatherWindow.animationCurveTypeDropdown.ClearOptions();
|
||||
List<string> enumNameList = System.Enum.GetNames(typeof(AnimationCurveType)).ToList();
|
||||
FatherTab.FatherWindow.VisibleArea.SetActive(true);
|
||||
FatherTab.FatherWindow.animationCurveTypeDropdown.ClearOptions();
|
||||
FatherTab.FatherWindow.animationCurveTypeDropdown.AddOptions(enumNameList);
|
||||
FatherTab.FatherWindow.animationCurveTypeDropdown.value = (int)animatedFloat.animationCurveType;
|
||||
FatherTab.FatherWindow.ConnectedPoint = this;
|
||||
EvDrawimage.color = new Color(
|
||||
EvDrawimage.color.r,
|
||||
0.75f,
|
||||
EvDrawimage.color.b,
|
||||
1f);
|
||||
|
||||
|
||||
// 更新文本
|
||||
FatherTab.FatherWindow.StartText.text = animatedFloat.startTime.ToString();
|
||||
FatherTab.FatherWindow.EndText.text = animatedFloat.endTime.ToString();
|
||||
FatherTab.FatherWindow.StartValueText.text = animatedFloat.startValue.ToString();
|
||||
FatherTab.FatherWindow.EndValueText.text = animatedFloat.endValue.ToString();
|
||||
|
||||
FatherTab.FatherWindow.animationCurveTypeDropdown.onValueChanged.AddListener(value => FatherTab.FatherWindow.ChangeValue());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,65 +9,106 @@ using Unity.VisualScripting;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
|
||||
public class FlexibleFloatTab : MonoBehaviour
|
||||
{
|
||||
public FlexibleFloat flexibleFloat;
|
||||
|
||||
public GraphicalFlexibleFloatWindow FatherWindow;
|
||||
|
||||
public List<EventPoint> eventPoints;
|
||||
|
||||
public RectTransform Area;
|
||||
public RectTransform BeatArea;
|
||||
|
||||
public RectTransform XBeatArea;
|
||||
public EventPoint eventPoint;
|
||||
public GameObject BeatLine;
|
||||
|
||||
public string Title;
|
||||
public GameObject FirstBeatLine;
|
||||
public FlexibleFloat connectFloat;
|
||||
public int BeatDeviver => FatherWindow.BeatDeviver;
|
||||
public void Initialize(FlexibleFloat flexibleFloat, string Title)
|
||||
public int BeatNextDeviver => FatherWindow.BeatNextDeviver;
|
||||
|
||||
// 初始化函数
|
||||
public void Initialize(FlexibleFloat flexibleFloat, string title)
|
||||
{
|
||||
Title = title;
|
||||
ClearChildren(Area);
|
||||
ClearChildren(BeatArea);
|
||||
eventPoints = new List<EventPoint>();
|
||||
connectFloat = flexibleFloat;
|
||||
CreateBeatLines();
|
||||
CreateEventPoints();
|
||||
RedrawEventPoints();
|
||||
Area.localPosition = new Vector3(FatherWindow.songBeat * BeatDeviver, 0, 0);
|
||||
}
|
||||
|
||||
// 清除子节点
|
||||
private void ClearChildren(RectTransform parent)
|
||||
{
|
||||
for (int i = 0; i < parent.childCount; i++)
|
||||
{
|
||||
Destroy(parent.GetChild(i).gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
// 创建节拍线
|
||||
private void CreateBeatLines()
|
||||
{
|
||||
for (int i = 0; i < (int)EditorManager.instance.songInformation.song.length / FatherWindow.timePerBeat; i++)
|
||||
{
|
||||
GameObject u = Instantiate(BeatLine, BeatArea);
|
||||
u.transform.localPosition = new Vector3(BeatDeviver * i, 0, 0);
|
||||
if (i == 1) FirstBeatLine = u;
|
||||
}
|
||||
for (int i = 0; i <= flexibleFloat.animations.Count - 1; i++)
|
||||
}
|
||||
|
||||
// 创建事件点
|
||||
private void CreateEventPoints()
|
||||
{
|
||||
for (int i = 0; i <= connectFloat.animations.Count - 1; i++)
|
||||
{
|
||||
AnimatedFloat animatedFloat = flexibleFloat.animations[i];
|
||||
AnimatedFloat animatedFloat = connectFloat.animations[i];
|
||||
EventPoint eventPoint = Instantiate(this.eventPoint, Area);
|
||||
eventPoint.FatherTab = this;
|
||||
eventPoint.Initialize(animatedFloat);
|
||||
eventPoints.Add(eventPoint);
|
||||
if (i - 1 >= 0)
|
||||
{
|
||||
eventPoint.LastEventPoint = eventPoints[i - 1];
|
||||
eventPoint.LastEventPoint.NextEventPoint = eventPoint;
|
||||
}
|
||||
else eventPoint.LastEventPoint = null;
|
||||
if (i == flexibleFloat.animations.Count - 1) eventPoint.NextEventPoint = null;
|
||||
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
Area.localPosition = new Vector3(FatherWindow.songBeat * BeatDeviver, 0, 0);
|
||||
}
|
||||
|
||||
// 更新函数
|
||||
public void Update()
|
||||
{
|
||||
|
||||
Area.localPosition = new Vector3(-FatherWindow.songBeat * BeatDeviver, 0, 0);
|
||||
BeatArea.localPosition = Area.localPosition;
|
||||
|
||||
Vector3 newPosition = new Vector3(-FatherWindow.songBeat * BeatDeviver, 0, 0);
|
||||
Area.localPosition = newPosition;
|
||||
BeatArea.localPosition = newPosition;
|
||||
XBeatArea.localPosition = newPosition;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 添加事件
|
||||
public void AddEvent()
|
||||
{
|
||||
if (Keyboard.current.ctrlKey.isPressed)
|
||||
@@ -76,28 +117,53 @@ public class FlexibleFloatTab : MonoBehaviour
|
||||
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;
|
||||
}
|
||||
LinkNewEventPoint(eventPoint);
|
||||
eventPoint.ReDraw(scalevalue);
|
||||
//print(1);
|
||||
eventPoint.selectButton.onClick.Invoke();
|
||||
FatherWindow.ChangeValue();
|
||||
connectFloat.Add(eventPoint.animatedFloat);
|
||||
connectFloat.Sort();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (FatherWindow.ConnectedPoint != null) FatherWindow.ConnectedPoint.UpLoad();
|
||||
}
|
||||
}
|
||||
public void SpawnEvent(AnimatedFloat animatedFloat)
|
||||
{
|
||||
EventPoint eventPoint = Instantiate(this.eventPoint, Area);
|
||||
eventPoint.FatherTab = this;
|
||||
eventPoint.Initialize(animatedFloat);
|
||||
eventPoints.Insert(FindInsertIndex(eventPoint.animatedFloat.startTime), eventPoint);
|
||||
LinkNewEventPoint(eventPoint);
|
||||
eventPoint.ReDraw(scalevalue);
|
||||
connectFloat.Add(eventPoint.animatedFloat);
|
||||
connectFloat.Sort();
|
||||
}
|
||||
// 连接新事件点
|
||||
private void LinkNewEventPoint(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];
|
||||
eventPoint.animatedFloat.endTime = eventPoint.NextEventPoint.animatedFloat.startTime;
|
||||
eventPoint.Initialize(eventPoint.animatedFloat);
|
||||
eventPoint.NextEventPoint.LastEventPoint = eventPoint;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 查找插入索引
|
||||
public int FindInsertIndex(float startTime)
|
||||
{
|
||||
int low = 0;
|
||||
int high = eventPoints.Count - 1;
|
||||
|
||||
while (low <= high)
|
||||
{
|
||||
int mid = (low + high) / 2;
|
||||
@@ -110,51 +176,26 @@ public class FlexibleFloatTab : MonoBehaviour
|
||||
high = mid - 1;
|
||||
}
|
||||
}
|
||||
|
||||
return low;
|
||||
}
|
||||
|
||||
float GetBeat()//这里出现问题:转换坐标
|
||||
// 获取节拍
|
||||
public float GetBeat()
|
||||
{
|
||||
Vector2 mouseLocalPos = MousePosition2Local();
|
||||
float far = BeatArea.transform.localPosition.x;
|
||||
int Beat = 0;
|
||||
|
||||
while (far < mouseLocalPos.x)
|
||||
float mouseInputX = Mouse.current.position.ReadValue().x;
|
||||
float far = BeatArea.transform.position.x;
|
||||
float Beat = 0;
|
||||
while (far < mouseInputX)
|
||||
{
|
||||
far += BeatDeviver;
|
||||
Beat++;
|
||||
far += (FirstBeatLine.transform.position.x - BeatArea.transform.position.x) / BeatNextDeviver;
|
||||
Beat += 1f / BeatNextDeviver;
|
||||
}
|
||||
|
||||
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.sceneCamera;
|
||||
}
|
||||
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;
|
||||
return FatherWindow.timePerBeat * (Beat - (1f / BeatNextDeviver));
|
||||
}
|
||||
|
||||
public float scalevalue => FatherWindow.scalevalue;
|
||||
|
||||
// 曲线缩放
|
||||
public void CurveScale(float value)
|
||||
{
|
||||
foreach (EventPoint i in eventPoints)
|
||||
@@ -162,12 +203,32 @@ public class FlexibleFloatTab : MonoBehaviour
|
||||
i.ReDraw(value);
|
||||
}
|
||||
}
|
||||
|
||||
// 改变X轴节拍
|
||||
public void XbeatCnange(int num)
|
||||
{
|
||||
ClearChildren(XBeatArea);
|
||||
for (int i = 1; i < num; i++)
|
||||
{
|
||||
foreach (Transform child in BeatArea)
|
||||
{
|
||||
GameObject newChild = Instantiate(child.gameObject, XBeatArea);
|
||||
CanvasGroup canvasGroup = newChild.GetComponent<CanvasGroup>();
|
||||
newChild.transform.localPosition = new Vector3(child.localPosition.x + ((float)BeatDeviver) / num * i, child.localPosition.y, child.localPosition.z);
|
||||
if (canvasGroup == null)
|
||||
{
|
||||
canvasGroup = newChild.AddComponent<CanvasGroup>();
|
||||
}
|
||||
canvasGroup.alpha = 0.1f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 移除动画
|
||||
public void remoceAnim(AnimatedFloat a)
|
||||
{
|
||||
|
||||
if (connectFloat.animations.Contains(a))
|
||||
{
|
||||
|
||||
connectFloat.animations.Remove(a);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,18 +6,20 @@ using Ichni;
|
||||
using Ichni.Editor;
|
||||
using Ichni.RhythmGame;
|
||||
using Sirenix.OdinInspector;
|
||||
using Sirenix.Utilities;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public partial class GraphicalFlexibleFloatWindow : MovableWindow
|
||||
{
|
||||
public Button addNewUnitButton;
|
||||
|
||||
public FlexibleFloatTab unitPrefab;
|
||||
public IBaseElement connectedBaseElement;
|
||||
public List<FlexibleFloatTab> unitList;
|
||||
public string parameterName;
|
||||
|
||||
public UnityAction ApplyParameters;
|
||||
|
||||
|
||||
@@ -27,31 +29,34 @@ public partial class GraphicalFlexibleFloatWindow : MovableWindow
|
||||
public float timePerBeat => 60f / EditorManager.instance.songInformation.bpm;
|
||||
|
||||
public int BeatDeviver = 100;
|
||||
public int BeatNextDeviver = 1;
|
||||
public void Initialize(IBaseElement baseElement, string title, FlexibleFloat[] FlexibleFloats, string[] Subtitles)
|
||||
{
|
||||
|
||||
scalevalue = 5;
|
||||
transform.localScale = Vector3.zero;
|
||||
this.connectedBaseElement = baseElement;
|
||||
this.title.text = title;
|
||||
unitList = new List<FlexibleFloatTab>();
|
||||
for (int i = 0; i <= FlexibleFloats.Length - 1; i++)
|
||||
{
|
||||
AddUnit(FlexibleFloats[i], Subtitles[i]);
|
||||
}
|
||||
|
||||
|
||||
closeButton.onClick.AddListener(Quit);
|
||||
StartCoroutine(WindowAnim.ShowPanelOnScale(gameObject));
|
||||
for (int i = 0; i <= FlexibleFloats.Length - 1; i++)
|
||||
{
|
||||
ClipBoard.Add(Subtitles[i], new List<AnimatedFloat>());
|
||||
AddUnit(FlexibleFloats[i], Subtitles[i]);
|
||||
}
|
||||
|
||||
ApplyParameters = () =>
|
||||
{
|
||||
|
||||
|
||||
for (int i = 0; i <= unitList.Count - 1; i++)
|
||||
{
|
||||
unitList[i].flexibleFloat.Sort();
|
||||
unitList[i].connectFloat.Sort();
|
||||
}
|
||||
//Dangered
|
||||
//connectedBaseElement.SetParameter(parameterName, unitList.Select(unit => unit.flexibleFloat).ToArray());
|
||||
|
||||
};
|
||||
XDeviverScale("1");
|
||||
}
|
||||
public void AddUnit(FlexibleFloat flexibleFloat, string Subtitle)
|
||||
{
|
||||
@@ -82,6 +87,26 @@ public partial class GraphicalFlexibleFloatWindow : MovableWindow
|
||||
i.CurveScale(value);
|
||||
}
|
||||
}
|
||||
public void DeviverScale(string Rawvalue)
|
||||
{
|
||||
if (ConnectedPoint != null) ConnectedPoint.UpLoad();
|
||||
BeatDeviver = int.Parse(Rawvalue);
|
||||
ChangeValue();
|
||||
for (int i = unitList.Count - 1; i >= 0; i--)
|
||||
{
|
||||
unitList[i].Initialize(unitList[i].connectFloat, unitList[i].Title);
|
||||
}
|
||||
XDeviverScale(BeatNextDeviver.ToString());
|
||||
|
||||
}
|
||||
public void XDeviverScale(string Rawvalue)
|
||||
{
|
||||
BeatNextDeviver = int.Parse(Rawvalue);
|
||||
foreach (FlexibleFloatTab i in unitList)
|
||||
{
|
||||
i.XbeatCnange(BeatNextDeviver);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public partial class GraphicalFlexibleFloatWindow
|
||||
@@ -106,6 +131,7 @@ public partial class GraphicalFlexibleFloatWindow
|
||||
{
|
||||
ConnectedPoint.LastEventPoint.NextEventPoint = ConnectedPoint.NextEventPoint;
|
||||
if (ConnectedPoint.LastEventPoint.NextEventPoint != null) ConnectedPoint.LastEventPoint.NextEventPoint.ReDraw(scalevalue);
|
||||
ConnectedPoint.LastEventPoint.ReDraw(scalevalue);
|
||||
}
|
||||
|
||||
if (ConnectedPoint.NextEventPoint != null)
|
||||
@@ -123,6 +149,8 @@ public partial class GraphicalFlexibleFloatWindow
|
||||
}
|
||||
}
|
||||
public void ChangeValue()
|
||||
|
||||
|
||||
{
|
||||
if (ConnectedPoint != null)
|
||||
{
|
||||
@@ -140,4 +168,49 @@ public partial class GraphicalFlexibleFloatWindow
|
||||
ConnectedPoint.ReDraw(scalevalue);
|
||||
}
|
||||
}
|
||||
|
||||
public Dictionary<string, List<AnimatedFloat>> ClipBoard = new();
|
||||
public float MinCopyTime = 0f;
|
||||
|
||||
public void Update()
|
||||
{
|
||||
if (Keyboard.current.shiftKey.isPressed && Keyboard.current.vKey.wasPressedThisFrame)
|
||||
{
|
||||
Paste();
|
||||
}
|
||||
}
|
||||
public void Paste()
|
||||
{
|
||||
float time = unitList[0].GetBeat();
|
||||
print(time);
|
||||
FindMinStartTime();
|
||||
foreach (KeyValuePair<string, List<AnimatedFloat>> i in ClipBoard)
|
||||
{
|
||||
foreach (AnimatedFloat j in i.Value)
|
||||
{
|
||||
AnimatedFloat newone = new AnimatedFloat(j.startTime, j.endTime, j.startValue, j.endValue, j.animationCurveType)
|
||||
{
|
||||
startTime = j.startTime - MinCopyTime + time,
|
||||
endTime = j.endTime - MinCopyTime + time
|
||||
};
|
||||
|
||||
unitList.Find(x => x.Title == i.Key).SpawnEvent(newone);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void FindMinStartTime()
|
||||
{
|
||||
MinCopyTime = float.MaxValue;
|
||||
foreach (var list in ClipBoard.Values)
|
||||
{
|
||||
foreach (var animatedFloat in list)
|
||||
{
|
||||
if (animatedFloat.startTime < MinCopyTime)
|
||||
{
|
||||
MinCopyTime = animatedFloat.startTime;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user