2022-10-01 13:43:28 +03:00
|
|
|
using UnityEngine;
|
|
|
|
|
using TMPro;
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
public class FrameEditor : MonoBehaviour
|
|
|
|
|
{
|
2022-10-01 15:40:51 +03:00
|
|
|
[SerializeField] private CharacterEditor _characterEditor = default;
|
2022-10-01 13:43:28 +03:00
|
|
|
[SerializeField] private Image _frameImage = default;
|
2022-10-02 12:58:34 +03:00
|
|
|
[SerializeField] private Image _frameSelectedImage = default;
|
2022-10-01 15:40:51 +03:00
|
|
|
[SerializeField] private Button _frameButton = default;
|
2022-10-01 13:43:28 +03:00
|
|
|
[SerializeField] private TMP_InputField _durationInputField = default;
|
2022-10-02 12:58:34 +03:00
|
|
|
private static FrameEditor previousFrameEditor;
|
2022-10-01 13:43:28 +03:00
|
|
|
|
|
|
|
|
|
2022-10-01 15:40:51 +03:00
|
|
|
void Awake()
|
|
|
|
|
{
|
|
|
|
|
_durationInputField.onEndEdit.AddListener(UpdateFrameDuration);
|
|
|
|
|
_frameButton.onClick.AddListener(ClickFrame);
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-01 13:43:28 +03:00
|
|
|
public void SetDuration(int value)
|
|
|
|
|
{
|
|
|
|
|
_durationInputField.text = value.ToString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetImage(Color color)
|
|
|
|
|
{
|
|
|
|
|
_frameImage.color = color;
|
|
|
|
|
}
|
2022-10-01 15:40:51 +03:00
|
|
|
|
|
|
|
|
private void UpdateFrameDuration(string value)
|
|
|
|
|
{
|
|
|
|
|
int duration;
|
|
|
|
|
if (!int.TryParse(value, out duration))
|
|
|
|
|
{
|
|
|
|
|
duration = 1;
|
|
|
|
|
}
|
|
|
|
|
_characterEditor.SetFrameDuration(transform.GetSiblingIndex(), duration);
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-02 12:58:34 +03:00
|
|
|
public void EnableFrameSelected()
|
|
|
|
|
{
|
|
|
|
|
if (previousFrameEditor != null)
|
|
|
|
|
{
|
|
|
|
|
previousFrameEditor.DisableFrameSelected();
|
|
|
|
|
}
|
|
|
|
|
previousFrameEditor = this;
|
|
|
|
|
_frameSelectedImage.enabled = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void DisableFrameSelected()
|
|
|
|
|
{
|
|
|
|
|
_frameSelectedImage.enabled = false;
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-01 15:40:51 +03:00
|
|
|
private void ClickFrame()
|
|
|
|
|
{
|
2022-10-01 18:02:11 +03:00
|
|
|
if (Input.GetKey(KeyCode.LeftControl))
|
|
|
|
|
{
|
|
|
|
|
_characterEditor.DeleteFrame(transform.GetSiblingIndex());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_characterEditor.GoToFrame(transform.GetSiblingIndex());
|
|
|
|
|
}
|
2022-10-01 15:40:51 +03:00
|
|
|
}
|
2022-10-01 13:43:28 +03:00
|
|
|
}
|