From e1b0ca09903caca8955b2499eb3e660ca1807b22 Mon Sep 17 00:00:00 2001 From: kimura Date: Wed, 13 Apr 2022 14:26:06 +0900 Subject: [PATCH] =?UTF-8?q?autocookProgress=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Main/AutomaticCookingConfirmation.unity | 19 +++-- .../Main/Scripts/AutoCookProgressView.cs | 77 +++++++++++++++++++ .../Main/Scripts/AutoCookProgressView.cs.meta | 3 + 3 files changed, 92 insertions(+), 7 deletions(-) create mode 100644 popcorn/Assets/MyGame/Scenes/Main/Scripts/AutoCookProgressView.cs create mode 100644 popcorn/Assets/MyGame/Scenes/Main/Scripts/AutoCookProgressView.cs.meta diff --git a/popcorn/Assets/MyGame/Scenes/Main/AutomaticCookingConfirmation.unity b/popcorn/Assets/MyGame/Scenes/Main/AutomaticCookingConfirmation.unity index c0c9c334..f5579daf 100644 --- a/popcorn/Assets/MyGame/Scenes/Main/AutomaticCookingConfirmation.unity +++ b/popcorn/Assets/MyGame/Scenes/Main/AutomaticCookingConfirmation.unity @@ -1380,7 +1380,7 @@ GameObject: serializedVersion: 6 m_Component: - component: {fileID: 534902213} - - component: {fileID: 534902214} + - component: {fileID: 534902215} m_Layer: 5 m_Name: Window m_TagString: Untagged @@ -1408,7 +1408,7 @@ RectTransform: m_AnchoredPosition: {x: 0, y: 200} m_SizeDelta: {x: 800, y: 570} m_Pivot: {x: 0.5, y: 0.5} ---- !u!114 &534902214 +--- !u!114 &534902215 MonoBehaviour: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} @@ -1417,11 +1417,16 @@ MonoBehaviour: m_GameObject: {fileID: 534902212} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 7ac380b2956543a6a6b17c6150b154c0, type: 3} + m_Script: {fileID: 11500000, guid: 3e8c4262dcaf40dcb5ece1963e468cdd, type: 3} m_Name: m_EditorClassIdentifier: backgroundAnimator: {fileID: 1090969545} closeButton: {fileID: 288409570} + progressText: {fileID: 1546017217} + cookAnimator: {fileID: 156549606} + progressImage: {fileID: 662005411} + minProgressYPos: -56 + maxProgressYPos: 9.5 --- !u!1 &582907704 GameObject: m_ObjectHideFlags: 0 @@ -1440,7 +1445,7 @@ GameObject: m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 0 + m_IsActive: 1 --- !u!224 &582907705 RectTransform: m_ObjectHideFlags: 0 @@ -1473,7 +1478,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 31a19414c41e5ae4aae2af33fee712f6, type: 3} m_Name: m_EditorClassIdentifier: - m_ShowMaskGraphic: 1 + m_ShowMaskGraphic: 0 --- !u!114 &582907707 MonoBehaviour: m_ObjectHideFlags: 0 @@ -1487,7 +1492,7 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: m_Material: {fileID: 0} - m_Color: {r: 1, g: 1, b: 1, a: 0.003921569} + m_Color: {r: 1, g: 1, b: 1, a: 1} m_RaycastTarget: 1 m_Maskable: 1 m_OnCullStateChanged: @@ -1804,7 +1809,7 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0.5, y: 0.5} m_AnchorMax: {x: 0.5, y: 0.5} - m_AnchoredPosition: {x: 0, y: 9.5} + m_AnchoredPosition: {x: 0, y: 6.2} m_SizeDelta: {x: 734, y: 608} m_Pivot: {x: 0.5, y: 0.5} --- !u!114 &662005412 diff --git a/popcorn/Assets/MyGame/Scenes/Main/Scripts/AutoCookProgressView.cs b/popcorn/Assets/MyGame/Scenes/Main/Scripts/AutoCookProgressView.cs new file mode 100644 index 00000000..399a079c --- /dev/null +++ b/popcorn/Assets/MyGame/Scenes/Main/Scripts/AutoCookProgressView.cs @@ -0,0 +1,77 @@ +using System; +using UniRx; +using UnityEngine; +using UnityEngine.UI; + +namespace MyGame.Scenes.Main.Scripts +{ + public class AutoCookProgressView : MonoBehaviour + { + private static readonly string CallbackTag = "AutoCoolProgressCallback"; + private static readonly int OpenTrigger = Animator.StringToHash("OpenTrigger"); + private static readonly int CloseTrigger = Animator.StringToHash("CloseTrigger"); + + [SerializeField] private Animator backgroundAnimator; + [SerializeField] private Button closeButton; + + [SerializeField] private Text progressText; + [SerializeField] private Animator cookAnimator; + [SerializeField] private Transform progressImage; + [SerializeField] private float minProgressYPos; + [SerializeField] private float maxProgressYPos; + + private IDisposable timerDisposable; + + private void Start() + { + closeButton.OnClickAsObservable().Take(1).Subscribe(_ => + { + LocalCacheManager.Load(CallbackTag, null)?.Invoke(); + LocalCacheManager.Remove(CallbackTag); + transform.parent.SetLocalScale(0); + backgroundAnimator.SetTrigger(CloseTrigger); + this.CallWaitForSeconds(.25f, () => + { + TransitionManager.Instance.UnloadScene(GameScenes.AutomaticCookingConfirmation); + }); + }).AddTo(this); + + var remainigTime = 0; + ResetTimer((int) DateTime.FromBinary(remainigTime).Subtract(DateTime.UtcNow).TotalSeconds); + } + + private void SetProgressImage(float value) + { + var yPos = Mathf.Lerp(minProgressYPos, maxProgressYPos, value); + progressImage.localPosition = progressImage.localPosition.SetY(yPos); + } + + private void SetTime(int seconds) + { + progressText.text = $"残り時間:{TimeSpan.FromSeconds(seconds):g}"; + } + + public void ResetTimer(int time) + { + // タイマーの更新処理 + timerDisposable?.Dispose(); + SetTime(time); + timerDisposable = Observable.Timer(TimeSpan.Zero, TimeSpan.FromSeconds(1f)) + .Select(x => (int)(time - x)) + .TakeWhile(x => x > 0) + .Subscribe(x => + { + SetTime(x); + SetProgressImage(1f - (float)x/time); + }, () => + { + cookAnimator.enabled = false; + }).AddTo(this); + } + + public static void ShowDialog(Action onClose = null){ + LocalCacheManager.Save(CallbackTag, onClose); + TransitionManager.Instance.LoadSceneAdditive(GameScenes.AutomaticCookingConfirmation); + } + } +} \ No newline at end of file diff --git a/popcorn/Assets/MyGame/Scenes/Main/Scripts/AutoCookProgressView.cs.meta b/popcorn/Assets/MyGame/Scenes/Main/Scripts/AutoCookProgressView.cs.meta new file mode 100644 index 00000000..2bcb4d11 --- /dev/null +++ b/popcorn/Assets/MyGame/Scenes/Main/Scripts/AutoCookProgressView.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 3e8c4262dcaf40dcb5ece1963e468cdd +timeCreated: 1649824003 \ No newline at end of file