112 lines
3.7 KiB
C#
112 lines
3.7 KiB
C#
using Convention;
|
|
using Convention.WindowsUI;
|
|
using UnityEngine;
|
|
using UnityEngine.Events;
|
|
|
|
namespace Demo.Editor.UI
|
|
{
|
|
public class TimelineItem : WindowUIModule, ITitle, IText, IActionInvoke
|
|
{
|
|
[Resources] public UnityEngine.UI.Button RawButton;
|
|
private RectTransform RawRect;
|
|
[Resources] public Text MyTitle;
|
|
|
|
private void Start()
|
|
{
|
|
RawRect = RawButton.GetComponent<RectTransform>();
|
|
}
|
|
|
|
public string title { get => ((ITitle)this.MyTitle).title; set => ((ITitle)this.MyTitle).title = value; }
|
|
public string text { get => ((IText)this.MyTitle).text; set => ((IText)this.MyTitle).text = value; }
|
|
public bool interactable { get => throw new System.NotImplementedException(); set => throw new System.NotImplementedException(); }
|
|
|
|
public IActionInvoke AddListener(params UnityAction[] action)
|
|
{
|
|
foreach (var item in action)
|
|
{
|
|
RawButton.onClick.AddListener(item);
|
|
}
|
|
return this;
|
|
}
|
|
|
|
public IActionInvoke RemoveAllListeners()
|
|
{
|
|
RawButton.onClick.RemoveAllListeners();
|
|
return this;
|
|
}
|
|
|
|
public IActionInvoke RemoveListener(params UnityAction[] action)
|
|
{
|
|
foreach (var item in action)
|
|
{
|
|
RawButton.onClick.RemoveListener(item);
|
|
}
|
|
return this;
|
|
}
|
|
|
|
public Vector2 duration;
|
|
public bool IsSetup = false;
|
|
[Content] public static Vector2 clip = new(0, 1);
|
|
|
|
public void SetupDuration(Vector2 duration, Color color)
|
|
{
|
|
this.duration = duration;
|
|
RawButton.image.color = new(color.r, color.g, color.b, RawButton.image.color.a);
|
|
IsSetup = true;
|
|
}
|
|
|
|
public void SetupDuration(Vector2 duration) => SetupDuration(duration, Color.white);
|
|
|
|
public void ResizeOnTimeline()
|
|
{
|
|
if (IsSetup == false)
|
|
{
|
|
gameObject.SetActive(false);
|
|
return;
|
|
}
|
|
// 可见性
|
|
{
|
|
var DragObjectInternal = transform as RectTransform;
|
|
var DragAreaInternal = transform.parent as RectTransform;
|
|
|
|
Vector3 minPosition = DragAreaInternal.rect.min - DragObjectInternal.rect.min;
|
|
Vector3 maxPosition = DragAreaInternal.rect.max - DragObjectInternal.rect.max;
|
|
|
|
if (DragObjectInternal.localPosition.y < minPosition.y || DragObjectInternal.localPosition.y > maxPosition.y)
|
|
{
|
|
RawButton.gameObject.SetActive(false);
|
|
return;
|
|
}
|
|
}
|
|
// 变量
|
|
float left2rightDuration = clip.y - clip.x;
|
|
float from;
|
|
float to;
|
|
// 设定
|
|
float durationX = duration.x;
|
|
float durationY = duration.y;
|
|
if (Mathf.Approximately(durationX, durationY))
|
|
{
|
|
from = (durationX - clip.x) / left2rightDuration;
|
|
to = Mathf.Max(from + 0.1f, (EditorController.instance.SongOffset - clip.x) / left2rightDuration);
|
|
}
|
|
else
|
|
{
|
|
from = (durationX - clip.x) / left2rightDuration;
|
|
to = (durationY - clip.x) / left2rightDuration;
|
|
}
|
|
// 检定
|
|
if (from > 1 || to < 0)
|
|
{
|
|
gameObject.SetActive(false);
|
|
}
|
|
else
|
|
{
|
|
gameObject.SetActive(true);
|
|
RawRect.anchorMin = new(Mathf.Clamp01(from), 0);
|
|
RawRect.anchorMax = new(Mathf.Clamp01(to), 1);
|
|
}
|
|
}
|
|
}
|
|
}
|