店舗レベル表示の条件ロジックを追加/ ハートメーターの挙動修正

This commit is contained in:
kimura 2021-10-14 17:43:00 +09:00
parent c32eb0bf7c
commit 04ff85725c
8 changed files with 118 additions and 26 deletions

View File

@ -94,6 +94,7 @@ GameObject:
- component: {fileID: 7740671670896384492}
- component: {fileID: 3756929251745663541}
- component: {fileID: 5400893423074421525}
- component: {fileID: 7906393928596777865}
m_Layer: 0
m_Name: DontDestroyObject
m_TagString: Untagged
@ -175,6 +176,18 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 77ded0026daa40d4b872efbaf2c1195c, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!114 &7906393928596777865
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3459593390050872226}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 6febd66062c34eb18c02d22a91eebab0, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1 &8739647597683206087
GameObject:
m_ObjectHideFlags: 0

View File

@ -49,6 +49,10 @@ public class BrotherConversation : MonoBehaviour
backgroundAnimator.SetTrigger(CloseTrigger);
this.CallWaitForSeconds(.25f, () =>
{
GameDataManager.GameData.ViewedShopLevel++;
GameDataManager.GameData.OrderConditionCount = 0;
GameDataManager.SaveGameData();
HeartMeter.Instance.SetShopLevel(GameDataManager.GameData.ViewedShopLevel, true);
TransitionManager.Instance.UnloadScene(GameScenes.Conversation);
});
}).AddTo(this);

View File

@ -7,6 +7,7 @@ using UnityEngine.UI;
public class ShopLevelUp : MonoBehaviour
{
public static readonly string DataTag = "ShopLevelUpData";
private static readonly int OpenTrigger = Animator.StringToHash("OpenTrigger");
private static readonly int CloseTrigger = Animator.StringToHash("CloseTrigger");
@ -19,12 +20,9 @@ public class ShopLevelUp : MonoBehaviour
private void Start()
{
// レベルからスクリプト読み込み
var shopLevel = 5;
var shopLevel = LocalCacheManager.Load<int>(DataTag);
var scriptList = SpreadsheetDataManager.Instance.GetBaseDataList<BrotherScriptData>(Const.ScriptDataSheet);
var targetScriptList = scriptList.Where(data => data.id == shopLevel).ToList();
LocalCacheManager.Save(BrotherConversation.ScriptDataTag, targetScriptList);
closeButton.OnClickAsObservable().Subscribe(_ =>
{
transform.SetLocalScale(0);
@ -32,7 +30,17 @@ public class ShopLevelUp : MonoBehaviour
this.CallWaitForSeconds(.25f, () =>
{
TransitionManager.Instance.UnloadScene(GameScenes.StoreLevel);
TransitionManager.Instance.LoadSceneAdditive(GameScenes.Conversation);
if (targetScriptList.Count > 0)
{
LocalCacheManager.Save(BrotherConversation.ScriptDataTag, targetScriptList);
TransitionManager.Instance.LoadSceneAdditive(GameScenes.Conversation);
}
else
{
GameDataManager.GameData.ViewedShopLevel++;
GameDataManager.SaveGameData();
HeartMeter.Instance.SetShopLevel(GameDataManager.GameData.ViewedShopLevel, true);
}
});
}).AddTo(this);

View File

@ -23,7 +23,6 @@ public class Shopping : MonoBehaviour
var shopDataList = SpreadsheetDataManager.Instance.GetBaseDataList<ShopData>(Const.ShopDataSheet);
foreach (var shopData in shopDataList)
{
Debug.Log($"{shopData.name}, {shopData.Category}");
if (shopData.Category == ItemCategory.Special)
{
continue;

View File

@ -91,8 +91,8 @@ public sealed class GameData {
public int Heart = 0;
[DataMember(Name = "Data22")]
public int[] Pans;
// [DataMember(Name = "Data23")]
[DataMember(Name = "Data23")]
public int ViewedShopLevel;
[DataMember(Name = "Data24")]
public ProductRefillMode RefillMode;
[DataMember(Name = "Data25")]

View File

@ -0,0 +1,56 @@
using System;
using System.Linq;
using UniRx;
using UnityEngine;
public class GameDataObserver : SingletonMonoBehaviour<GameDataObserver>
{
[SerializeField] private FloatReactiveProperty checkInterval = new FloatReactiveProperty(.1f);
private IObservable<int> heartObserver;
public IObservable<int> Heart => heartObserver;
private IObservable<int> sceneCounter;
public IObservable<int> SceneCounter => sceneCounter;
public IObservable<bool> ShopLevelUpdate;
private void Start()
{
checkInterval.AddTo(this);
var gameData = GameDataManager.GameData;
var levelList = SpreadsheetDataManager.Instance.GetBaseDataList<ShopLevelData>(Const.ShopLevelDataSheet);
heartObserver = checkInterval
.Select(x =>
Observable.Interval(TimeSpan.FromSeconds(x))
.Select(_ => gameData.Heart)
.DistinctUntilChanged())
.Switch();
var shopLevelObserver = checkInterval
.Select(x =>
Observable.Interval(TimeSpan.FromSeconds(x))
.Select(_ => gameData.ViewedShopLevel)
.DistinctUntilChanged())
.Switch();
sceneCounter = checkInterval
.Select(x =>
Observable.Interval(TimeSpan.FromSeconds(x))
.Select(_ => UnityEngine.SceneManagement.SceneManager.sceneCount)
.DistinctUntilChanged()
// .Do(c => { Debug.Log($"sceneCount:{c}");})
)
.Switch();
ShopLevelUpdate = Observable.CombineLatest(heartObserver, shopLevelObserver, sceneCounter,
(heart, level, sceneCount) =>
{
var currentLevel = levelList.LastOrDefault(data => data.heart <= heart)?.shopLevel ?? 1;
return currentLevel > level && sceneCount == 1;
})
.DistinctUntilChanged()
.Publish(false)
.RefCount();
ShopLevelUpdate.Subscribe(x => { Debug.Log($"change:{x}"); });
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 6febd66062c34eb18c02d22a91eebab0
timeCreated: 1634180079

View File

@ -12,12 +12,15 @@ public class HeartMeter : SingletonMonoBehaviour<HeartMeter>
[SerializeField] private TextMeshProUGUI heartLevel;
private Coroutine coroutine;
private List<int> levelList = new List<int>();
private List<ShopLevelData> shopLevelList = new List<ShopLevelData>();
private int currentHeartCount;
private readonly ReactiveProperty<float> viewHeartCount = new ReactiveProperty<float>();
public IReadOnlyReactiveProperty<int> ShopLevel => shopLevel;
private readonly ReactiveProperty<int> shopLevel = new ReactiveProperty<int>();
private CompositeDisposable compositeDisposable = new CompositeDisposable();
private float minHeart;
private float maxHeart;
private void Awake()
{
@ -31,30 +34,24 @@ public class HeartMeter : SingletonMonoBehaviour<HeartMeter>
compositeDisposable.AddTo(this);
}
public void Initialize()
public void Initialize(int newShopLevel = 0, int newHeartCount = 0)
{
levelList = SpreadsheetDataManager.Instance.GetBaseDataList<ShopLevelData>(Const.ShopLevelDataSheet).Select(shopLevelData => shopLevelData.heart).ToList();
compositeDisposable.Clear();
shopLevel.Subscribe(x =>
{
heartLevel.text = $"{x}";
}).AddTo(compositeDisposable);
shopLevelList = SpreadsheetDataManager.Instance.GetBaseDataList<ShopLevelData>(Const.ShopLevelDataSheet);
viewHeartCount.SkipLatestValueOnSubscribe().Subscribe(heartCount =>
{
if (levelList.Empty())
{
return;
}
shopLevel.Value = GetShopLevel(Mathf.FloorToInt(heartCount)) + 1;
if (levelList.Count == shopLevel.Value)
if (shopLevelList.Count == shopLevel.Value)
{
slider.value = 1;
}
else
{
slider.value = (heartCount - levelList[shopLevel.Value - 1]) / (levelList[shopLevel.Value] - levelList[shopLevel.Value - 1]);
slider.value = Mathf.InverseLerp(minHeart, maxHeart, heartCount);
}
}).AddTo(compositeDisposable);
SetHeart(newHeartCount);
SetShopLevel(newShopLevel);
}
public void SetHeart(int heartCount)
@ -63,11 +60,23 @@ public class HeartMeter : SingletonMonoBehaviour<HeartMeter>
viewHeartCount.SetValueAndForceNotify(heartCount);
}
private int GetShopLevel(int heartCount)
public void SetShopLevel(int newShopLevel, bool animate = false)
{
return levelList.FindLastIndex(x => x <= heartCount);
shopLevel.Value = newShopLevel;
heartLevel.text = $"{newShopLevel}";
minHeart = shopLevelList.FirstOrDefault(data => data.shopLevel == newShopLevel)?.heart ?? 0;
maxHeart = shopLevelList.FirstOrDefault(data => data.shopLevel == newShopLevel + 1)?.heart ?? 0;
if (animate)
{
var tmpCount = currentHeartCount - (int)minHeart;
SetHeart((int)minHeart);
AddHeart(tmpCount);
}
else
{
viewHeartCount.SetValueAndForceNotify(currentHeartCount);
}
}
public void AddHeart(int value)
{
this.SafeStopCoroutine(coroutine);
@ -78,7 +87,7 @@ public class HeartMeter : SingletonMonoBehaviour<HeartMeter>
});
this.CallLerp(1f, f =>
{
viewHeartCount.Value = Mathf.Min(currentHeartCount, viewHeartCount.Value + value * Time.deltaTime);
viewHeartCount.Value = Mathf.Min(currentHeartCount, viewHeartCount.Value + value * f);
});
}
}