データ保存対応

This commit is contained in:
kimura 2021-08-06 17:49:05 +09:00
parent ad05a2081a
commit 0afa505a56
5 changed files with 99 additions and 14 deletions

View File

@ -1,6 +1,7 @@
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using UniRx; using UniRx;
using UnityEngine; using UnityEngine;
using UnityEngine.UI; using UnityEngine.UI;
@ -11,13 +12,76 @@ public class KitchenManager : MonoBehaviour
// Start is called before the first frame update // Start is called before the first frame update
void Start() void Start()
{ {
// レシピの表示
cookingButton.OnClickAsObservable().Subscribe(_ => cookingButton.OnClickAsObservable().Subscribe(_ =>
{ {
// TransitionManager.Instance.LoadScene(GameScenes.Cooking); // TransitionManager.Instance.LoadScene(GameScenes.Cooking);
TransitionManager.Instance.LoadSceneAdditive(GameScenes.Recipe); TransitionManager.Instance.LoadSceneAdditive(GameScenes.Recipe);
}); });
// スプレッドシート対応
// レシピIDが一覧で入っている
// データ
var gameData = GameDataManager.GameData; var gameData = GameDataManager.GameData;
CoinManager.Instance.ChangeCoin(gameData.coin); CoinManager.Instance.ChangeCoin(gameData.coin);
// 所持レシピ
gameData.MyRecipes = new[]
{
1,
2,
13,
};
// 所持素材
if (gameData.Material == null)
{
gameData.Material = new List<(int id, int amount)>
{
(1, 10),
(2, 10),
(6, 10),
};
}
// 素材の補充
var materialStockIndex = gameData.Material.FindIndex(x => x.amount == 0);
if (materialStockIndex != -1)
{
var temp = gameData.Material[materialStockIndex];
temp.amount += 10;
gameData.Material[materialStockIndex] = temp;
}
// 店頭ストック
if (gameData.ShopStock == null)
{
gameData.ShopStock = new List<int>();
}
// 保存タンク
if (gameData.StorageTanks == null || gameData.StorageTanks.Count == 0)
{
gameData.StorageTanks = new List<StorageTank>
{
new StorageTank
{
Id = 1,
Capacity = 50,
FlavorId = -1,
Stock = 0,
BonusRate = 0
}
};
}
GameDataManager.SaveGameData();
var shopStockString = "";
foreach (var data in RecipeData.GetAllRecipe())
{
var shopStockCount = gameData.ShopStock.FindAll(x => x == data.RecipeId).Count;
var tank = gameData.StorageTanks.FindAll(x => x.FlavorId == data.RecipeId).Sum(x => x.Stock);
shopStockString += $"{data.Name} shop:{shopStockCount} stock:{tank}\n";
}
Debug.Log(shopStockString);
} }
} }

View File

@ -0,0 +1,11 @@
using UnityEngine.Internal.VR;
public class StorageTank
{
// タンクID, タンク内のフレーバーID, フレーバーの個数
public int Id;
public int Capacity;
public int FlavorId;
public int Stock;
public int BonusRate;
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: a842565a93614828bf8e8062120550f7
timeCreated: 1628142406

View File

@ -18,24 +18,14 @@ public class RecipeSelectDialog : MonoBehaviour
TransitionManager.Instance.UnloadScene(GameScenes.Recipe); TransitionManager.Instance.UnloadScene(GameScenes.Recipe);
}).AddTo(this); }).AddTo(this);
// 所持レシピ取得
var myRecipes = new[]
{
1,
2,
13,
};
// 全レシピ
var allRecipe = RecipeData.GetAllRecipe();
// レシピ一覧生成 // レシピ一覧生成
content.transform.DestroyAllChildrens(); content.transform.DestroyAllChildrens();
foreach (var recipeData in allRecipe) foreach (var recipeData in RecipeData.GetAllRecipe())
{ {
var view = Instantiate(recipePrefab, content.transform); var view = Instantiate(recipePrefab, content.transform);
view.SetRecipe(recipeData); view.SetRecipe(recipeData);
if (myRecipes.Contains(recipeData.RecipeId)) // 所持レシピ確認
if (GameDataManager.GameData.MyRecipes.Contains(recipeData.RecipeId))
{ {
view.SetLockPanel(false); view.SetLockPanel(false);
view.RecipeClickObservable.Subscribe(_ => view.RecipeClickObservable.Subscribe(_ =>

View File

@ -51,6 +51,7 @@ public sealed class GameData {
// public List<int> newAvatarIdList; // public List<int> newAvatarIdList;
// [DataMember(Name = "Data11")] // [DataMember(Name = "Data11")]
// public bool isRandomAvatar; // public bool isRandomAvatar;
// CornField
[DataMember(Name = "Data12")] [DataMember(Name = "Data12")]
public List<(PlantLineType type, CornFieldRank level)> PlantLineTypes; public List<(PlantLineType type, CornFieldRank level)> PlantLineTypes;
[DataMember(Name = "Data13")] [DataMember(Name = "Data13")]
@ -59,7 +60,23 @@ public sealed class GameData {
public int MachineLevel = 1; public int MachineLevel = 1;
[DataMember(Name = "Data15")] [DataMember(Name = "Data15")]
public List<SeedlingProgressData> SeedlingDataList = new List<SeedlingProgressData>(); public List<SeedlingProgressData> SeedlingDataList = new List<SeedlingProgressData>();
[DataMember(Name = "Data16")] public int cornSeed; [DataMember(Name = "Data16")]
public int cornSeed;
// Main
// 所持レシピ
[DataMember(Name = "Data17")]
public int[] MyRecipes;
// 所持素材
[DataMember(Name = "Data18")]
public List<(int id, int amount)> Material = new List<(int id, int amount)>();
// 店頭ポップコーン在庫
[DataMember(Name = "Data19")]
public List<int> ShopStock;
// タンクポップコーン在庫
[DataMember(Name = "Data20")]
public List<StorageTank> StorageTanks;
// public void ChangeAvatar(AvatarData avatarData){ // public void ChangeAvatar(AvatarData avatarData){
// newAvatarIdList.Remove(avatarData.id); // newAvatarIdList.Remove(avatarData.id);