レシピデータ構造変更

This commit is contained in:
kimura 2021-08-06 14:35:32 +09:00
parent 8c7b7c9990
commit 1477cde4b6
7 changed files with 220 additions and 84 deletions

View File

@ -588,12 +588,14 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 47bc31a2c7d14478bd4ebe3c32e41185, type: 3}
m_Name:
m_EditorClassIdentifier:
lockPanel: {fileID: 3261803197014340250}
detailButton: {fileID: 8320108874302735811}
flavorName: {fileID: 2929932626752093611}
flavorPrice: {fileID: 2929932627123125673}
cornAmountText: {fileID: 6296255899301773980}
flavor1AmountText: {fileID: 2929932625557648441}
flavor2AmountText: {fileID: 367551539734858426}
flavor2View: {fileID: 367551539495355422}
--- !u!1 &2997770120253274331
GameObject:
m_ObjectHideFlags: 0
@ -1313,6 +1315,12 @@ RectTransform:
type: 3}
m_PrefabInstance: {fileID: 2452498385069847742}
m_PrefabAsset: {fileID: 0}
--- !u!1 &367551539495355422 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 2814970099097301152, guid: e2818e79d8fc1f34388aff1b8969d340,
type: 3}
m_PrefabInstance: {fileID: 2452498385069847742}
m_PrefabAsset: {fileID: 0}
--- !u!1001 &8101979052737494168
PrefabInstance:
m_ObjectHideFlags: 0
@ -1473,6 +1481,12 @@ PrefabInstance:
m_RemovedComponents:
- {fileID: 2814970099097301159, guid: e2818e79d8fc1f34388aff1b8969d340, type: 3}
m_SourcePrefab: {fileID: 100100000, guid: e2818e79d8fc1f34388aff1b8969d340, type: 3}
--- !u!224 &6296255899524172857 stripped
RectTransform:
m_CorrespondingSourceObject: {fileID: 2814970099097301153, guid: e2818e79d8fc1f34388aff1b8969d340,
type: 3}
m_PrefabInstance: {fileID: 8101979052737494168}
m_PrefabAsset: {fileID: 0}
--- !u!114 &6296255899301773980 stripped
MonoBehaviour:
m_CorrespondingSourceObject: {fileID: 2814970099411582468, guid: e2818e79d8fc1f34388aff1b8969d340,
@ -1485,9 +1499,3 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 5f7201a12d95ffc409449d95f23cf332, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!224 &6296255899524172857 stripped
RectTransform:
m_CorrespondingSourceObject: {fileID: 2814970099097301153, guid: e2818e79d8fc1f34388aff1b8969d340,
type: 3}
m_PrefabInstance: {fileID: 8101979052737494168}
m_PrefabAsset: {fileID: 0}

View File

@ -1265,7 +1265,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 0
m_IsActive: 1
--- !u!224 &858120090
RectTransform:
m_ObjectHideFlags: 0
@ -1560,6 +1560,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 79171d1fad4a444cafc287590de884b7, type: 3}
m_Name:
m_EditorClassIdentifier:
backgroundAnimator: {fileID: 858120093}
cancelButton: {fileID: 843133640}
nextButton: {fileID: 1853630204}
flavorName: {fileID: 707887860}
@ -1568,6 +1569,7 @@ MonoBehaviour:
cornAmountText: {fileID: 4654596182167880407}
flavor1AmountText: {fileID: 5352886969301700758}
flavor2AmountText: {fileID: 1408233927}
flavor2View: {fileID: 1408233928}
--- !u!1 &1036314250
GameObject:
m_ObjectHideFlags: 0
@ -1735,7 +1737,7 @@ MonoBehaviour:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 0
m_RaycastTarget: 1
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
@ -1985,6 +1987,11 @@ PrefabInstance:
propertyPath: m_Name
value: NecessaryMaterial2
objectReference: {fileID: 0}
- target: {fileID: 5352886967997046946, guid: c84cc6844fe59ef4d8e52438b7bffa42,
type: 3}
propertyPath: m_IsActive
value: 1
objectReference: {fileID: 0}
- target: {fileID: 5352886967997046957, guid: c84cc6844fe59ef4d8e52438b7bffa42,
type: 3}
propertyPath: m_Pivot.x
@ -2110,6 +2117,12 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 5f7201a12d95ffc409449d95f23cf332, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1 &1408233928 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 5352886967997046946, guid: c84cc6844fe59ef4d8e52438b7bffa42,
type: 3}
m_PrefabInstance: {fileID: 1408233925}
m_PrefabAsset: {fileID: 0}
--- !u!1 &1484296443
GameObject:
m_ObjectHideFlags: 0

View File

@ -1,9 +1,68 @@
using System.Collections.Generic;
public class RecipeData
{
public int RecipeId;
public string Name;
public int Price;
// public string IconSprite;
public int Volume;
public int CornAmount;
public int Flavor1Amount;
public int Flavor2Amount;
public List<(int id, int amount)> Flavors;
public static List<RecipeData> GetAllRecipe()
{
return new List<RecipeData>
{
new RecipeData
{
RecipeId = 1,
Name = "塩コケコーン",
Price = 5,
Volume = 10,
CornAmount = 150,
Flavors = new List<(int id, int amount)>
{
(1, 1)
}
},
new RecipeData
{
RecipeId = 2,
Name = "キャラメルコケコーン",
Price = 15,
Volume = 10,
CornAmount = 150,
Flavors = new List<(int id, int amount)>
{
(6, 1)
}
},
new RecipeData
{
RecipeId = 3,
Name = "ブラックペッパーコケコーン",
Price = 9,
Volume = 10,
CornAmount = 150,
Flavors = new List<(int id, int amount)>
{
(2, 1)
}
},
new RecipeData
{
RecipeId = 13,
Name = "塩キャラメルコケコーン",
Price = 19,
Volume = 10,
CornAmount = 150,
Flavors = new List<(int id, int amount)>
{
(1, 1),
(6, 1),
}
},
};
}
}

View File

@ -19,12 +19,15 @@ public class RecipeDetailView : MonoBehaviour
[SerializeField] private Text cornAmountText;
[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()
{
var data = LocalCacheManager.Load<RecipeData>(DetailRecipeTag);
cancelButton.OnClickAsObservable().Subscribe(_ =>
{
backgroundAnimator.SetTrigger(CloseTrigger);
@ -33,12 +36,20 @@ public class RecipeDetailView : MonoBehaviour
TransitionManager.Instance.UnloadScene(GameScenes.RecipeChoice);
});
}).AddTo(this);
nextButton.OnClickAsObservable().Subscribe(_ =>
{
TransitionManager.Instance.LoadScene(GameScenes.Cooking);
}).AddTo(this);
var data = LocalCacheManager.Load<RecipeData>(DetailRecipeTag);
SetRecipe(data);
if (CheckAmount(data))
{
nextButton.OnClickAsObservable().Subscribe(_ =>
{
TransitionManager.Instance.LoadScene(GameScenes.Cooking);
}).AddTo(this);
}
else
{
nextButton.interactable = false;
}
}
public void SetRecipe(RecipeData data)
@ -48,7 +59,37 @@ public class RecipeDetailView : MonoBehaviour
flavorName.text = data.Name;
flavorPrice.text = data.Price.ToString();
cornAmountText.text = string.Format(cornAmountFormat, gameData.cornSeed, data.CornAmount);
flavor1AmountText.text = string.Format(flavorAmountFormat, 999, data.Flavor1Amount);
flavor2AmountText.text = string.Format(flavorAmountFormat, 999, data.Flavor2Amount);
flavor1AmountText.text = string.Format(flavorAmountFormat, 999, data.Flavors[0].amount);
if (data.Flavors.Count == 2)
{
flavor2View.SetActive(true);
flavor2AmountText.text = string.Format(flavorAmountFormat, 0, data.Flavors[1].amount);
}
else
{
flavor2View.SetActive(false);
}
}
private bool CheckAmount(RecipeData data)
{
var flag = true;
var gameData = GameDataManager.GameData;
if (gameData.cornSeed < data.CornAmount)
{
flag = false;
cornAmountText.color = Color.red;
}
if (999 < data.Flavors[0].amount)
{
flag = false;
flavor1AmountText.color = Color.red;
}
if (data.Flavors.Count == 2 && 0 < data.Flavors[1].amount)
{
flag = false;
flavor2AmountText.color = Color.red;
}
return flag;
}
}

View File

@ -1,5 +1,6 @@
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UniRx;
using UnityEngine;
using UnityEngine.UI;
@ -18,46 +19,35 @@ public class RecipeSelectDialog : MonoBehaviour
}).AddTo(this);
// 所持レシピ取得
var recipes = new[]
var myRecipes = new[]
{
new RecipeData
{
RecipeId = 0,
Name = "塩コケコーン",
Price = 5,
CornAmount = 60,
Flavor1Amount = 1,
Flavor2Amount = 1
},
new RecipeData
{
RecipeId = 0,
Name = "キャラメルコケコーン",
Price = 15,
CornAmount = 60,
Flavor1Amount = 1,
Flavor2Amount = 1
},
new RecipeData
{
RecipeId = 0,
Name = "ブラックペッパーコケコーン",
Price = 9,
CornAmount = 60,
Flavor1Amount = 1,
Flavor2Amount = 1
},
1,
2,
13,
};
// 全レシピ
var allRecipe = RecipeData.GetAllRecipe();
// レシピ一覧生成
foreach (var recipeData in recipes)
content.transform.DestroyAllChildrens();
foreach (var recipeData in allRecipe)
{
var view = Instantiate(recipePrefab, content.transform);
view.SetRecipe(recipeData);
view.RecipeClickObservable.Subscribe(_ =>
if (myRecipes.Contains(recipeData.RecipeId))
{
LocalCacheManager.Save(RecipeDetailView.DetailRecipeTag, recipeData);
TransitionManager.Instance.LoadSceneAdditive(GameScenes.RecipeChoice);
}).AddTo(this);
view.SetLockPanel(false);
view.RecipeClickObservable.Subscribe(_ =>
{
LocalCacheManager.Save(RecipeDetailView.DetailRecipeTag, recipeData);
TransitionManager.Instance.LoadSceneAdditive(GameScenes.RecipeChoice);
}).AddTo(this);
}
else
{
view.SetLockPanel(true);
}
}
}
}

View File

@ -5,12 +5,14 @@ using UnityEngine.UI;
public class RecipeView : MonoBehaviour
{
[SerializeField] private GameObject lockPanel;
[SerializeField] private Button detailButton;
[SerializeField] private Text flavorName;
[SerializeField] private Text flavorPrice;
[SerializeField] private Text cornAmountText;
[SerializeField] private Text flavor1AmountText;
[SerializeField] private Text flavor2AmountText;
[SerializeField] private GameObject flavor2View;
private static readonly string amountFormat = "x{0}";
public IObservable<Unit> RecipeClickObservable => detailButton.OnClickAsObservable().TakeUntilDestroy(this);
@ -23,7 +25,20 @@ public class RecipeView : MonoBehaviour
flavorName.text = data.Name;
flavorPrice.text = data.Price.ToString();
cornAmountText.text = string.Format(amountFormat, data.CornAmount);
flavor1AmountText.text = string.Format(amountFormat, data.Flavor1Amount);
flavor2AmountText.text = string.Format(amountFormat, data.Flavor2Amount);
flavor1AmountText.text = string.Format(amountFormat, data.Flavors[0].amount);
if (data.Flavors.Count == 2)
{
flavor2View.SetActive(true);
flavor2AmountText.text = string.Format(amountFormat, data.Flavors[1].amount);
}
else
{
flavor2View.SetActive(false);
}
}
public void SetLockPanel(bool hasRecipe)
{
lockPanel.SetActive(hasRecipe);
}
}

View File

@ -947,7 +947,7 @@ MonoBehaviour:
m_TargetGraphic: {fileID: 2120123254}
m_HandleRect: {fileID: 2120123253}
m_Direction: 2
m_Value: 0
m_Value: 1
m_Size: 1
m_NumberOfSteps: 0
m_OnValueChanged:
@ -1020,7 +1020,7 @@ PrefabInstance:
- target: {fileID: 2929932627350163026, guid: 2beb2d436ad55734186e797d315796b3,
type: 3}
propertyPath: m_AnchorMax.y
value: 1
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2929932627350163026, guid: 2beb2d436ad55734186e797d315796b3,
type: 3}
@ -1030,17 +1030,17 @@ PrefabInstance:
- target: {fileID: 2929932627350163026, guid: 2beb2d436ad55734186e797d315796b3,
type: 3}
propertyPath: m_AnchorMin.y
value: 1
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2929932627350163026, guid: 2beb2d436ad55734186e797d315796b3,
type: 3}
propertyPath: m_SizeDelta.x
value: 490
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2929932627350163026, guid: 2beb2d436ad55734186e797d315796b3,
type: 3}
propertyPath: m_SizeDelta.y
value: 300
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2929932627350163026, guid: 2beb2d436ad55734186e797d315796b3,
type: 3}
@ -1080,12 +1080,12 @@ PrefabInstance:
- target: {fileID: 2929932627350163026, guid: 2beb2d436ad55734186e797d315796b3,
type: 3}
propertyPath: m_AnchoredPosition.x
value: 715
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2929932627350163026, guid: 2beb2d436ad55734186e797d315796b3,
type: 3}
propertyPath: m_AnchoredPosition.y
value: -369.5
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2929932627350163026, guid: 2beb2d436ad55734186e797d315796b3,
type: 3}
@ -1110,7 +1110,7 @@ PrefabInstance:
- target: {fileID: 2929932627350163027, guid: 2beb2d436ad55734186e797d315796b3,
type: 3}
propertyPath: m_IsActive
value: 0
value: 1
objectReference: {fileID: 0}
- target: {fileID: 2969128505512012149, guid: 2beb2d436ad55734186e797d315796b3,
type: 3}
@ -1132,6 +1132,11 @@ PrefabInstance:
propertyPath: m_AnchoredPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3261803197014340250, guid: 2beb2d436ad55734186e797d315796b3,
type: 3}
propertyPath: m_IsActive
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8440980752897465212, guid: 2beb2d436ad55734186e797d315796b3,
type: 3}
propertyPath: m_AnchorMax.y
@ -1145,17 +1150,17 @@ PrefabInstance:
- target: {fileID: 8440980752897465212, guid: 2beb2d436ad55734186e797d315796b3,
type: 3}
propertyPath: m_SizeDelta.x
value: 0
value: 126.50001
objectReference: {fileID: 0}
- target: {fileID: 8440980752897465212, guid: 2beb2d436ad55734186e797d315796b3,
type: 3}
propertyPath: m_AnchoredPosition.x
value: 0
value: 107.25
objectReference: {fileID: 0}
- target: {fileID: 9097260142390357153, guid: 2beb2d436ad55734186e797d315796b3,
type: 3}
propertyPath: m_SizeDelta.x
value: 0
value: 170.5
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 2beb2d436ad55734186e797d315796b3, type: 3}
@ -1382,7 +1387,7 @@ PrefabInstance:
- target: {fileID: 2929932627350163026, guid: 2beb2d436ad55734186e797d315796b3,
type: 3}
propertyPath: m_AnchorMax.y
value: 1
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2929932627350163026, guid: 2beb2d436ad55734186e797d315796b3,
type: 3}
@ -1392,17 +1397,17 @@ PrefabInstance:
- target: {fileID: 2929932627350163026, guid: 2beb2d436ad55734186e797d315796b3,
type: 3}
propertyPath: m_AnchorMin.y
value: 1
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2929932627350163026, guid: 2beb2d436ad55734186e797d315796b3,
type: 3}
propertyPath: m_SizeDelta.x
value: 490
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2929932627350163026, guid: 2beb2d436ad55734186e797d315796b3,
type: 3}
propertyPath: m_SizeDelta.y
value: 300
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2929932627350163026, guid: 2beb2d436ad55734186e797d315796b3,
type: 3}
@ -1442,12 +1447,12 @@ PrefabInstance:
- target: {fileID: 2929932627350163026, guid: 2beb2d436ad55734186e797d315796b3,
type: 3}
propertyPath: m_AnchoredPosition.x
value: 245
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2929932627350163026, guid: 2beb2d436ad55734186e797d315796b3,
type: 3}
propertyPath: m_AnchoredPosition.y
value: -369.5
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2929932627350163026, guid: 2beb2d436ad55734186e797d315796b3,
type: 3}
@ -1472,7 +1477,7 @@ PrefabInstance:
- target: {fileID: 2929932627350163027, guid: 2beb2d436ad55734186e797d315796b3,
type: 3}
propertyPath: m_IsActive
value: 0
value: 1
objectReference: {fileID: 0}
- target: {fileID: 2969128505512012149, guid: 2beb2d436ad55734186e797d315796b3,
type: 3}
@ -2531,7 +2536,7 @@ PrefabInstance:
- target: {fileID: 2929932627350163026, guid: 2beb2d436ad55734186e797d315796b3,
type: 3}
propertyPath: m_AnchorMax.y
value: 1
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2929932627350163026, guid: 2beb2d436ad55734186e797d315796b3,
type: 3}
@ -2541,17 +2546,17 @@ PrefabInstance:
- target: {fileID: 2929932627350163026, guid: 2beb2d436ad55734186e797d315796b3,
type: 3}
propertyPath: m_AnchorMin.y
value: 1
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2929932627350163026, guid: 2beb2d436ad55734186e797d315796b3,
type: 3}
propertyPath: m_SizeDelta.x
value: 490
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2929932627350163026, guid: 2beb2d436ad55734186e797d315796b3,
type: 3}
propertyPath: m_SizeDelta.y
value: 300
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2929932627350163026, guid: 2beb2d436ad55734186e797d315796b3,
type: 3}
@ -2591,12 +2596,12 @@ PrefabInstance:
- target: {fileID: 2929932627350163026, guid: 2beb2d436ad55734186e797d315796b3,
type: 3}
propertyPath: m_AnchoredPosition.x
value: 715
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2929932627350163026, guid: 2beb2d436ad55734186e797d315796b3,
type: 3}
propertyPath: m_AnchoredPosition.y
value: -150
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2929932627350163026, guid: 2beb2d436ad55734186e797d315796b3,
type: 3}
@ -2621,7 +2626,7 @@ PrefabInstance:
- target: {fileID: 2929932627350163027, guid: 2beb2d436ad55734186e797d315796b3,
type: 3}
propertyPath: m_IsActive
value: 0
value: 1
objectReference: {fileID: 0}
- target: {fileID: 2969128505512012149, guid: 2beb2d436ad55734186e797d315796b3,
type: 3}
@ -3107,7 +3112,7 @@ PrefabInstance:
- target: {fileID: 2929932627350163026, guid: 2beb2d436ad55734186e797d315796b3,
type: 3}
propertyPath: m_AnchorMax.y
value: 1
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2929932627350163026, guid: 2beb2d436ad55734186e797d315796b3,
type: 3}
@ -3117,17 +3122,17 @@ PrefabInstance:
- target: {fileID: 2929932627350163026, guid: 2beb2d436ad55734186e797d315796b3,
type: 3}
propertyPath: m_AnchorMin.y
value: 1
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2929932627350163026, guid: 2beb2d436ad55734186e797d315796b3,
type: 3}
propertyPath: m_SizeDelta.x
value: 490
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2929932627350163026, guid: 2beb2d436ad55734186e797d315796b3,
type: 3}
propertyPath: m_SizeDelta.y
value: 300
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2929932627350163026, guid: 2beb2d436ad55734186e797d315796b3,
type: 3}
@ -3167,12 +3172,12 @@ PrefabInstance:
- target: {fileID: 2929932627350163026, guid: 2beb2d436ad55734186e797d315796b3,
type: 3}
propertyPath: m_AnchoredPosition.x
value: 245
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2929932627350163026, guid: 2beb2d436ad55734186e797d315796b3,
type: 3}
propertyPath: m_AnchoredPosition.y
value: -589
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2929932627350163026, guid: 2beb2d436ad55734186e797d315796b3,
type: 3}
@ -3197,7 +3202,7 @@ PrefabInstance:
- target: {fileID: 2929932627350163027, guid: 2beb2d436ad55734186e797d315796b3,
type: 3}
propertyPath: m_IsActive
value: 0
value: 1
objectReference: {fileID: 0}
- target: {fileID: 2969128505512012149, guid: 2beb2d436ad55734186e797d315796b3,
type: 3}
@ -3219,6 +3224,11 @@ PrefabInstance:
propertyPath: m_AnchoredPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3261803197014340250, guid: 2beb2d436ad55734186e797d315796b3,
type: 3}
propertyPath: m_IsActive
value: 1
objectReference: {fileID: 0}
- target: {fileID: 8440980752897465212, guid: 2beb2d436ad55734186e797d315796b3,
type: 3}
propertyPath: m_AnchorMax.y