| | 1 | | using DG.Tweening; |
| | 2 | | using System; |
| | 3 | | using UnityEngine; |
| | 4 | | using UnityEngine.UI; |
| | 5 | |
|
| | 6 | | namespace DCLFeatures.ScreencaptureCamera.UI |
| | 7 | | { |
| | 8 | | [RequireComponent(typeof(Canvas))] [DisallowMultipleComponent] |
| | 9 | | public class ScreencaptureCameraHUDView : MonoBehaviour |
| | 10 | | { |
| | 11 | | [SerializeField] private Canvas rootCanvas; |
| | 12 | | [SerializeField] private GameObject noSpaceInfo; |
| | 13 | |
|
| | 14 | | [Header("BUTTONS")] |
| | 15 | | [SerializeField] private Button cameraReelButton; |
| | 16 | | [SerializeField] private Button takeScreenshotButton; |
| | 17 | | [SerializeField] private Button closeButton; |
| | 18 | | [SerializeField] private Button shortcutsInfoButton; |
| | 19 | |
|
| | 20 | | [Header("SHORTCUTS INFO PANEL")] |
| | 21 | | [SerializeField] private GameObject shortcutsInfoPanel; |
| | 22 | | [SerializeField] private Image openShortcutsIcon; |
| | 23 | | [SerializeField] private Image closeShortcutsIcon; |
| | 24 | |
|
| | 25 | | [Header("CAPTURE VFX")] |
| | 26 | | [SerializeField] private Image whiteSplashImage; |
| | 27 | | [SerializeField] private RectTransform cameraReelIcon; |
| | 28 | | [SerializeField] private Image animatedImage; |
| | 29 | |
|
| | 30 | | private Sequence currentVfxSequence; |
| | 31 | |
|
| 0 | 32 | | [field: SerializeField] public RectTransform RectTransform { get; private set; } |
| | 33 | |
|
| 0 | 34 | | public bool IsVisible => rootCanvas.enabled; |
| | 35 | |
|
| | 36 | | public event Action CloseButtonClicked; |
| | 37 | | public event Action ShortcutsInfoButtonClicked; |
| | 38 | | public event Action CameraReelButtonClicked; |
| | 39 | | public event Action TakeScreenshotButtonClicked; |
| | 40 | |
|
| | 41 | | private void OnEnable() |
| | 42 | | { |
| 0 | 43 | | cameraReelButton.onClick.AddListener(() => CameraReelButtonClicked?.Invoke()); |
| 0 | 44 | | takeScreenshotButton.onClick.AddListener(() => TakeScreenshotButtonClicked?.Invoke()); |
| 0 | 45 | | shortcutsInfoButton.onClick.AddListener(() => ShortcutsInfoButtonClicked?.Invoke()); |
| 0 | 46 | | closeButton.onClick.AddListener(() => CloseButtonClicked?.Invoke()); |
| 0 | 47 | | } |
| | 48 | |
|
| | 49 | | private void OnDisable() |
| | 50 | | { |
| 0 | 51 | | cameraReelButton.onClick.RemoveAllListeners(); |
| 0 | 52 | | takeScreenshotButton.onClick.RemoveAllListeners(); |
| 0 | 53 | | shortcutsInfoButton.onClick.RemoveAllListeners(); |
| 0 | 54 | | closeButton.onClick.RemoveAllListeners(); |
| 0 | 55 | | } |
| | 56 | |
|
| | 57 | | public virtual void SetVisibility(bool isVisible, bool hasStorageSpace) |
| | 58 | | { |
| 0 | 59 | | takeScreenshotButton.interactable = hasStorageSpace; |
| 0 | 60 | | noSpaceInfo.SetActive(!hasStorageSpace); |
| | 61 | |
|
| 0 | 62 | | if (rootCanvas.enabled != isVisible) |
| 0 | 63 | | rootCanvas.enabled = isVisible; |
| 0 | 64 | | } |
| | 65 | |
|
| | 66 | | public void ToggleShortcutsInfosHelpPanel() |
| | 67 | | { |
| 0 | 68 | | bool setEnabled = shortcutsInfoPanel.activeSelf == false; |
| | 69 | |
|
| 0 | 70 | | shortcutsInfoPanel.SetActive(setEnabled); |
| | 71 | |
|
| 0 | 72 | | openShortcutsIcon.enabled = !setEnabled; |
| 0 | 73 | | closeShortcutsIcon.enabled = setEnabled; |
| 0 | 74 | | } |
| | 75 | |
|
| | 76 | | public void ScreenshotCaptureAnimation(Texture2D screenshotImage, float splashDuration, float afterSplashPause, |
| | 77 | | { |
| 0 | 78 | | currentVfxSequence?.Complete(); |
| 0 | 79 | | currentVfxSequence?.Kill(); |
| | 80 | |
|
| 0 | 81 | | animatedImage.sprite = Sprite.Create(screenshotImage, new Rect(0, 0, screenshotImage.width, screenshotImage. |
| | 82 | |
|
| 0 | 83 | | animatedImage.enabled = true; |
| 0 | 84 | | whiteSplashImage.enabled = true; |
| | 85 | |
|
| 0 | 86 | | currentVfxSequence = CaptureVFXSequence(splashDuration, afterSplashPause, transitionDuration).Play(); |
| 0 | 87 | | } |
| | 88 | |
|
| | 89 | | private Sequence CaptureVFXSequence(float splashDuration, float afterSplashPause, float transitionDuration) |
| | 90 | | { |
| 0 | 91 | | Sequence sequence = DOTween.Sequence(); |
| | 92 | |
|
| 0 | 93 | | sequence.Append(AnimateSplash(splashDuration)); |
| 0 | 94 | | sequence.AppendInterval(afterSplashPause); // Delay between splash and transition |
| 0 | 95 | | sequence.Append(AnimateVFXImageTransition(transitionDuration)); |
| 0 | 96 | | sequence.Join(AnimateVFXImageScale(transitionDuration)); |
| 0 | 97 | | sequence.Join(AnimateVFXImageScale(transitionDuration)); |
| 0 | 98 | | sequence.OnComplete(() => animatedImage.enabled = false); |
| | 99 | |
|
| 0 | 100 | | return sequence; |
| | 101 | | } |
| | 102 | |
|
| | 103 | | private Tween AnimateVFXImageTransition(float duration) |
| | 104 | | { |
| 0 | 105 | | Vector3 cachedPosition = animatedImage.rectTransform.position; |
| | 106 | |
|
| 0 | 107 | | return animatedImage.rectTransform.DOMove(cameraReelIcon.position, duration) |
| | 108 | | .SetEase(Ease.InOutQuad) |
| 0 | 109 | | .OnComplete(() => { animatedImage.rectTransform.position = cachedPosition; }); |
| | 110 | | } |
| | 111 | |
|
| | 112 | | private Tween AnimateVFXImageScale(float duration) => |
| 0 | 113 | | animatedImage.rectTransform.DOScale(Vector2.zero, duration) |
| | 114 | | .SetEase(Ease.InOutQuad) |
| 0 | 115 | | .OnComplete(() => { animatedImage.rectTransform.localScale = Vector2.one; }); |
| | 116 | |
|
| | 117 | | private Tween AnimateSplash(float duration) |
| | 118 | | { |
| 0 | 119 | | return whiteSplashImage.DOFade(0f, duration) |
| | 120 | | .SetEase(Ease.InOutQuad) |
| | 121 | | .OnComplete(() => |
| | 122 | | { |
| 0 | 123 | | whiteSplashImage.enabled = false; |
| 0 | 124 | | whiteSplashImage.color = Color.white; |
| 0 | 125 | | }); |
| | 126 | | } |
| | 127 | | } |
| | 128 | | } |