From dc0abb20ff05611328086a4fd865fe76016445b4 Mon Sep 17 00:00:00 2001 From: kimura Date: Fri, 24 Sep 2021 11:04:49 +0900 Subject: [PATCH 1/2] =?UTF-8?q?=E3=82=BF=E3=83=B3=E3=82=AF=E4=B8=8D?= =?UTF-8?q?=E8=B6=B3=E8=A1=A8=E7=A4=BA=E5=AF=BE=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MyGame/Scenes/recipe/RecipeChoice.unity | 2 + .../Scenes/recipe/Scripts/RecipeDetailView.cs | 99 ++++++++----------- 2 files changed, 44 insertions(+), 57 deletions(-) diff --git a/popcorn/Assets/MyGame/Scenes/recipe/RecipeChoice.unity b/popcorn/Assets/MyGame/Scenes/recipe/RecipeChoice.unity index 47c6d078..bb8c03a9 100644 --- a/popcorn/Assets/MyGame/Scenes/recipe/RecipeChoice.unity +++ b/popcorn/Assets/MyGame/Scenes/recipe/RecipeChoice.unity @@ -1867,6 +1867,8 @@ MonoBehaviour: cancelButton: {fileID: 843133640} nextButton: {fileID: 1853630204} disabledNextButton: {fileID: 1037294270} + tankCaution: {fileID: 1464412873} + panSelector: {fileID: 1160535648} flavorName: {fileID: 707887860} flavorPrice: {fileID: 498799267} flavorStock: {fileID: 1109202679} diff --git a/popcorn/Assets/MyGame/Scenes/recipe/Scripts/RecipeDetailView.cs b/popcorn/Assets/MyGame/Scenes/recipe/Scripts/RecipeDetailView.cs index a39a37c5..3ad373a7 100644 --- a/popcorn/Assets/MyGame/Scenes/recipe/Scripts/RecipeDetailView.cs +++ b/popcorn/Assets/MyGame/Scenes/recipe/Scripts/RecipeDetailView.cs @@ -8,12 +8,16 @@ public class RecipeDetailView : MonoBehaviour { private static readonly int OpenTrigger = Animator.StringToHash("OpenTrigger"); private static readonly int CloseTrigger = Animator.StringToHash("CloseTrigger"); - + private static readonly string flavorStockFormat = "所持数 :{0}"; + private static readonly string cornAmountFormat = "{0}/{1}"; + private static readonly string flavorAmountFormat = "{0} / {1}"; [SerializeField] private Animator backgroundAnimator; [SerializeField] private Button cancelButton; [SerializeField] private Button nextButton; [SerializeField] private GameObject disabledNextButton; + [SerializeField] private GameObject tankCaution; + [SerializeField] private PanSelector panSelector; [SerializeField] private Text flavorName; [SerializeField] private Text flavorPrice; [SerializeField] private Text flavorStock; @@ -21,9 +25,6 @@ public class RecipeDetailView : MonoBehaviour [SerializeField] private Text flavor1AmountText; [SerializeField] private Text flavor2AmountText; [SerializeField] private GameObject flavor2View; - private static readonly string flavorStockFormat = "所持数 :{0}"; - private static readonly string cornAmountFormat = "{0}/{1}"; - private static readonly string flavorAmountFormat = "{0} / {1}"; private void Start() { @@ -38,36 +39,34 @@ public class RecipeDetailView : MonoBehaviour TransitionManager.Instance.UnloadScene(GameScenes.RecipeChoice); }); }).AddTo(this); + + nextButton.OnClickAsObservable().Subscribe(_ => + { + var gameData = GameDataManager.GameData; + gameData.cornSeed -= data.CornAmount; + var flavorIndex1 = gameData.Material.FindIndex(x => x.Id == data.Flavors[0].id); + var stockMaterial1 = gameData.Material[flavorIndex1]; + stockMaterial1.Amount -= data.Flavors[0].amount; + gameData.Material[flavorIndex1] = stockMaterial1; + if (data.Flavors.Count == 2) + { + var flavorIndex2 = gameData.Material.FindIndex(x => x.Id == data.Flavors[1].id); + var stockMaterial2 = gameData.Material[flavorIndex2]; + stockMaterial2.Amount -= data.Flavors[1].amount; + gameData.Material[flavorIndex2] = stockMaterial2; + } + + GameDataManager.SaveGameData(); + TransitionManager.Instance.LoadScene(GameScenes.Cooking); + }).AddTo(this); SetRecipe(data); - if (CheckAmount(data)) - { - disabledNextButton.SetActive(false); - nextButton.OnClickAsObservable().Subscribe(_ => - { - var gameData = GameDataManager.GameData; - gameData.cornSeed -= data.CornAmount; - var flavorIndex1 = gameData.Material.FindIndex(x => x.Id == data.Flavors[0].id); - var stockMaterial1 = gameData.Material[flavorIndex1]; - stockMaterial1.Amount -= data.Flavors[0].amount; - gameData.Material[flavorIndex1] = stockMaterial1; - if (data.Flavors.Count == 2) - { - var flavorIndex2 = gameData.Material.FindIndex(x => x.Id == data.Flavors[1].id); - var stockMaterial2 = gameData.Material[flavorIndex2]; - stockMaterial2.Amount -= data.Flavors[1].amount; - gameData.Material[flavorIndex2] = stockMaterial2; - } - - GameDataManager.SaveGameData(); - TransitionManager.Instance.LoadScene(GameScenes.Cooking); - }).AddTo(this); - } - else - { - nextButton.interactable = false; - disabledNextButton.SetActive(true); - } + var isPassedAmount = CheckAmount(data); + var isPassedTank = CheckTank(data); + nextButton.interactable = isPassedAmount && isPassedTank; + panSelector.gameObject.SetActive(isPassedTank); + disabledNextButton.SetActive(!isPassedAmount || !isPassedTank); + tankCaution.SetActive(!isPassedTank); } public void SetRecipe(RecipeData data) @@ -132,35 +131,21 @@ public class RecipeDetailView : MonoBehaviour flavor2AmountText.color = Color.red; } } + return flag; + } - if (!flag) - { - return false; - } - - // 店頭の空きがない - // 店頭の空きに追加 - if (Market.ShopStockCount >= gameData.ShopStock.Count + data.Volume) + private bool CheckTank(RecipeData data) + { + var gameData = GameDataManager.GameData; + // 店頭の空き確認 + if (data.Volume <= Market.ShopStockCount - gameData.ShopStock.Count) { return true; } - // 空のタンクに追加 - if (gameData.StorageTanks.FindIndex(x => x.Stock == 0) != -1) - { - return true; - } - // 同じフレーバーのタンクを確認 - var index = gameData.StorageTanks.FindIndex(x => x.FlavorId == data.RecipeId); - if (index != -1) - { - // 同じフレーバーのタンクの空きに追加 - var tank = gameData.StorageTanks[index]; - if (tank.Capacity >= tank.Stock + data.Volume) - { - return true; - } - } - return false; + // 空のタンク、同じフレーバーのタンク空き確認 + return gameData.StorageTanks + .Where(tank => tank.IsEmpty || tank.FlavorId == data.RecipeId && !tank.IsFull) + .Any(tank => data.Volume <= tank.Capacity - tank.Stock); } } \ No newline at end of file From 4cfbf674153fb12c38360f7975162d198bb23f59 Mon Sep 17 00:00:00 2001 From: kimura Date: Fri, 24 Sep 2021 11:16:50 +0900 Subject: [PATCH 2/2] =?UTF-8?q?=E3=83=AC=E3=82=B7=E3=83=94=E3=82=B9?= =?UTF-8?q?=E3=82=AF=E3=83=AD=E3=83=BC=E3=83=AB=E3=83=90=E3=83=BC=E6=94=B9?= =?UTF-8?q?=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../recipe/Scripts/RecipeSelectDialog.cs | 5 ++- .../Assets/MyGame/Scenes/recipe/recipe.unity | 33 ++++++++++++++----- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/popcorn/Assets/MyGame/Scenes/recipe/Scripts/RecipeSelectDialog.cs b/popcorn/Assets/MyGame/Scenes/recipe/Scripts/RecipeSelectDialog.cs index 7e105c48..5825c9d1 100644 --- a/popcorn/Assets/MyGame/Scenes/recipe/Scripts/RecipeSelectDialog.cs +++ b/popcorn/Assets/MyGame/Scenes/recipe/Scripts/RecipeSelectDialog.cs @@ -7,7 +7,7 @@ using UnityEngine.UI; public class RecipeSelectDialog : MonoBehaviour { - [SerializeField] private GameObject content; + [SerializeField] private ScrollRect scrollRect; [SerializeField] private RecipeView recipePrefab; [SerializeField] private Button closeButton; // Start is called before the first frame update @@ -19,6 +19,7 @@ public class RecipeSelectDialog : MonoBehaviour }).AddTo(this); // レシピ一覧生成 + var content = scrollRect.content; content.transform.DestroyAllChildrens(); foreach (var recipeData in RecipeData.GetAllRecipe()) { @@ -39,5 +40,7 @@ public class RecipeSelectDialog : MonoBehaviour view.SetLockPanel(true); } } + LayoutRebuilder.ForceRebuildLayoutImmediate(content); + scrollRect.verticalNormalizedPosition = 1; } } diff --git a/popcorn/Assets/MyGame/Scenes/recipe/recipe.unity b/popcorn/Assets/MyGame/Scenes/recipe/recipe.unity index dba8adba..2f7efb26 100644 --- a/popcorn/Assets/MyGame/Scenes/recipe/recipe.unity +++ b/popcorn/Assets/MyGame/Scenes/recipe/recipe.unity @@ -654,6 +654,7 @@ GameObject: - component: {fileID: 203586001} - component: {fileID: 203586000} - component: {fileID: 203585999} + - component: {fileID: 203586002} m_Layer: 0 m_Name: Scroll View m_TagString: Untagged @@ -704,7 +705,7 @@ MonoBehaviour: m_ScrollSensitivity: 1 m_Viewport: {fileID: 25421135} m_HorizontalScrollbar: {fileID: 0} - m_VerticalScrollbar: {fileID: 409545283} + m_VerticalScrollbar: {fileID: 0} m_HorizontalScrollbarVisibility: 2 m_VerticalScrollbarVisibility: 0 m_HorizontalScrollbarSpacing: -3 @@ -749,6 +750,20 @@ CanvasRenderer: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 203585997} m_CullTransparentMesh: 0 +--- !u!114 &203586002 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 203585997} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 4c7fb96966974f86a04af9747989d1f9, type: 3} + m_Name: + m_EditorClassIdentifier: + scrollRect: {fileID: 203585999} + verticalSlider: {fileID: 409545283} --- !u!1 &277152052 GameObject: m_ObjectHideFlags: 0 @@ -914,7 +929,7 @@ MonoBehaviour: m_GameObject: {fileID: 409545281} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 2a4db7a114972834c8e4117be1d82ba3, type: 3} + m_Script: {fileID: 11500000, guid: 67db9e8f0e2ae9c40bc1e2b64352a6b4, type: 3} m_Name: m_EditorClassIdentifier: m_Navigation: @@ -944,12 +959,14 @@ MonoBehaviour: m_SelectedTrigger: Selected m_DisabledTrigger: Disabled m_Interactable: 1 - m_TargetGraphic: {fileID: 2120123254} + m_TargetGraphic: {fileID: 409545284} + m_FillRect: {fileID: 0} m_HandleRect: {fileID: 2120123253} m_Direction: 2 - m_Value: 1 - m_Size: 1 - m_NumberOfSteps: 0 + m_MinValue: 0 + m_MaxValue: 1 + m_WholeNumbers: 0 + m_Value: 0 m_OnValueChanged: m_PersistentCalls: m_Calls: [] @@ -2821,7 +2838,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 2154205f893c042a390e4b410b5b5ea5, type: 3} m_Name: m_EditorClassIdentifier: - content: {fileID: 28991871} + scrollRect: {fileID: 203585999} recipePrefab: {fileID: 5490177795204899762, guid: 2beb2d436ad55734186e797d315796b3, type: 3} closeButton: {fileID: 968322477} @@ -3652,7 +3669,7 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 0} m_AnchorMax: {x: 0, y: 0} - m_AnchoredPosition: {x: 0, y: 127.75} + m_AnchoredPosition: {x: 0, y: 0} m_SizeDelta: {x: 52, y: 52} m_Pivot: {x: 0.5, y: 0.5} --- !u!114 &2120123254