仕入れに広告視聴回数でレシピ開放機能を追加
This commit is contained in:
		
							parent
							
								
									f73c00a420
								
							
						
					
					
						commit
						7e28d48528
					
				|  | @ -416,7 +416,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: -1, y: -18} | ||||
|   m_AnchoredPosition: {x: -1, y: -22} | ||||
|   m_SizeDelta: {x: 150, y: 150} | ||||
|   m_Pivot: {x: 0.5, y: 0.5} | ||||
| --- !u!1 &594261736 | ||||
|  | @ -1232,14 +1232,13 @@ MonoBehaviour: | |||
|   m_GameObject: {fileID: 1684918699} | ||||
|   m_Enabled: 1 | ||||
|   m_EditorHideFlags: 0 | ||||
|   m_Script: {fileID: 11500000, guid: 5f2a9cddac65495987f3657236411f7a, type: 3} | ||||
|   m_Script: {fileID: 11500000, guid: 145ec1a447b54867a4992cca4a0a5803, type: 3} | ||||
|   m_Name:  | ||||
|   m_EditorClassIdentifier:  | ||||
|   backgroundAnimator: {fileID: 418527617} | ||||
|   normalMissionObject: {fileID: 0} | ||||
|   dailyMissionObject: {fileID: 1193390268} | ||||
|   name: {fileID: 1264740260} | ||||
|   iconTarget: {fileID: 497670574} | ||||
|   closeButton: {fileID: 1115920389} | ||||
|   coinText: {fileID: 1264740260} | ||||
| --- !u!1001 &1803163400 | ||||
| PrefabInstance: | ||||
|   m_ObjectHideFlags: 0 | ||||
|  | @ -1350,7 +1349,7 @@ PrefabInstance: | |||
|     - target: {fileID: 3719207458405043424, guid: 9a2aaf7985e538d42b6167af79daf316, | ||||
|         type: 3} | ||||
|       propertyPath: m_AnchoredPosition.y | ||||
|       value: -4 | ||||
|       value: 0 | ||||
|       objectReference: {fileID: 0} | ||||
|     - target: {fileID: 3719207458405043424, guid: 9a2aaf7985e538d42b6167af79daf316, | ||||
|         type: 3} | ||||
|  |  | |||
|  | @ -1618,6 +1618,14 @@ MonoBehaviour: | |||
|   itemName: {fileID: 8536603424255746891} | ||||
|   price: {fileID: 8536603424463105953} | ||||
|   stockCount: {fileID: 8536603422883751234} | ||||
|   purchaseObject: {fileID: 1724054491481647808} | ||||
|   exchangeObject: {fileID: 5433729606380246405} | ||||
|   progressBar: {fileID: 7490815301205721763} | ||||
|   progressText: {fileID: 5831242374484716135} | ||||
|   onObject: {fileID: 8599340879278054956} | ||||
|   offObject: {fileID: 1852637203793855555} | ||||
|   soldOutObject: {fileID: 6377311622786111752} | ||||
|   exchangeButton: {fileID: 1139534594415698666} | ||||
| --- !u!1 &8536603423534268947 | ||||
| GameObject: | ||||
|   m_ObjectHideFlags: 0 | ||||
|  |  | |||
|  | @ -0,0 +1,50 @@ | |||
| using System; | ||||
| using MyGame.Scripts; | ||||
| using UniRx; | ||||
| using UnityEngine; | ||||
| using UnityEngine.UI; | ||||
| 
 | ||||
| public class ShopItemExchangeView : MonoBehaviour | ||||
| { | ||||
|     private static readonly string ShopDataTag = "ShopItemExchangeViewShopData"; | ||||
|     private static readonly string CloseCallbackTag = "ShopItemExchangeViewCloseCallbackTag"; | ||||
|     private static readonly int OpenTrigger = Animator.StringToHash("OpenTrigger"); | ||||
|     private static readonly int CloseTrigger = Animator.StringToHash("CloseTrigger"); | ||||
|      | ||||
|     [SerializeField] private Animator backgroundAnimator; | ||||
|     [SerializeField] private Text name; | ||||
|     [SerializeField] private Transform iconTarget; | ||||
|     [SerializeField] private Button closeButton; | ||||
| 
 | ||||
|     private void Start() | ||||
|     { | ||||
|         // 表示データを受け取る | ||||
|         var shopData = LocalCacheManager.Load<ShopData>(ShopDataTag); | ||||
|         LocalCacheManager.Remove(ShopDataTag); | ||||
|         SetData(shopData); | ||||
|         closeButton.OnClickAsObservable().Take(1).Subscribe(_ => | ||||
|         { | ||||
|             LocalCacheManager.Load<Action>(CloseCallbackTag, null)?.Invoke(); | ||||
|             transform.SetLocalScale(0); | ||||
|             backgroundAnimator.SetTrigger(CloseTrigger); | ||||
|             this.CallWaitForSeconds(.25f, () => | ||||
|             { | ||||
|                 TransitionManager.Instance.UnloadScene(GameScenes.ExchangeAchievement); | ||||
|             }); | ||||
|         }).AddTo(this); | ||||
|     } | ||||
| 
 | ||||
|     private void SetData(ShopData shopData) | ||||
|     { | ||||
|         name.text = shopData.name; | ||||
|         iconTarget.DestroyAllChildrens(); | ||||
|         Instantiate(shopData.GetPrefab(), iconTarget); | ||||
|     } | ||||
| 
 | ||||
|     public static void ShowDialog(ShopData shopData, Action onClose = null) | ||||
|     { | ||||
|         LocalCacheManager.Save(ShopDataTag, shopData); | ||||
|         LocalCacheManager.Save(CloseCallbackTag, onClose); | ||||
|         TransitionManager.Instance.LoadSceneAdditive(GameScenes.ExchangeAchievement); | ||||
|     } | ||||
| } | ||||
|  | @ -0,0 +1,3 @@ | |||
| fileFormatVersion: 2 | ||||
| guid: 145ec1a447b54867a4992cca4a0a5803 | ||||
| timeCreated: 1639119851 | ||||
|  | @ -1,4 +1,5 @@ | |||
| using System; | ||||
| using TMPro; | ||||
| using UniRx; | ||||
| using UnityEngine; | ||||
| using UnityEngine.UI; | ||||
|  | @ -11,9 +12,20 @@ public class ShopItemView : MonoBehaviour | |||
|     [SerializeField] private Text itemName; | ||||
|     [SerializeField] private Text price; | ||||
|     [SerializeField] private Text stockCount; | ||||
|     [SerializeField] private GameObject purchaseObject; | ||||
|     [SerializeField] private GameObject exchangeObject; | ||||
| 
 | ||||
|     private static readonly string ProgressFormat = "{0} / {1}"; | ||||
|     [SerializeField] private Slider progressBar; | ||||
|     [SerializeField] private TextMeshProUGUI progressText; | ||||
|     [SerializeField] private GameObject onObject; | ||||
|     [SerializeField] private GameObject offObject; | ||||
|     [SerializeField] private GameObject soldOutObject; | ||||
|     [SerializeField] private Button exchangeButton; | ||||
| 
 | ||||
|     public IObservable<Unit> DetailButtonObservable => detailButton.OnClickAsObservable().TakeUntilDestroy(this); | ||||
|     public IObservable<Unit> PurchaseButtonObservable => purchaseButton.ClickObservable.TakeUntilDestroy(this); | ||||
|     public IObservable<Unit> PurchaseButtonObservable => purchaseButton.ClickObservable; | ||||
|     public IObservable<Unit> ExchangeButtonObservable => exchangeButton.OnClickAsObservable().TakeUntilDestroy(this); | ||||
| 
 | ||||
|     public void SetData(ShopData shopData) | ||||
|     { | ||||
|  | @ -26,12 +38,29 @@ public class ShopItemView : MonoBehaviour | |||
|         iconTarget.DestroyAllChildrens(); | ||||
|         Instantiate(shopData.GetPrefab(), iconTarget); | ||||
|         purchaseButton.SetItemType(shopData.Category, shopData.ConsumeType); | ||||
|          | ||||
|         /* | ||||
|          * レシピは広告視聴回数で開放 | ||||
|          * 別途フラグで切替も検討 | ||||
|          */ | ||||
|         purchaseObject.SetActive(shopData.Category != ItemCategory.Recipe); | ||||
|         exchangeObject.SetActive(shopData.Category == ItemCategory.Recipe); | ||||
|         progressBar.value = Mathf.InverseLerp(0, shopData.price, GameDataManager.GameData.adCount); | ||||
|         progressText.text = string.Format(ProgressFormat, GameDataManager.GameData.adCount, shopData.price); | ||||
|         onObject.SetActive(shopData.price <= GameDataManager.GameData.adCount); | ||||
|         offObject.SetActive(!onObject.activeSelf); | ||||
|     } | ||||
| 
 | ||||
|     public void SetStockCount(int stock) | ||||
|     { | ||||
|         stockCount.text = $"{stock}"; | ||||
|         purchaseButton.SetItemPurchased(stock > 0); | ||||
|         soldOutObject.SetActive(stock > 0); | ||||
|         if (soldOutObject.activeSelf) | ||||
|         { | ||||
|             onObject.SetActive(false); | ||||
|             offObject.SetActive(false); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     public void SetItemActive(bool active) | ||||
|  |  | |||
|  | @ -90,6 +90,21 @@ public class Shopping : MonoBehaviour | |||
|                         } | ||||
|                     }); | ||||
|                 }).AddTo(itemView); | ||||
|              | ||||
|             // 広告視聴獲得 | ||||
|             itemView.ExchangeButtonObservable | ||||
|                 .ThrottleFirst(TimeSpan.FromSeconds(.3f)) | ||||
|                 .Subscribe(_ => | ||||
|                 { | ||||
|                     ShopItemExchangeView.ShowDialog(shopData, () => | ||||
|                     { | ||||
|                         // アイテムを増やす | ||||
|                         AddItem(shopData, 1); | ||||
|                         itemView.SetStockCount(GetItemAmount(shopData)); | ||||
|                         GameDataManager.SaveGameData(); | ||||
|                     }); | ||||
|                 }).AddTo(itemView); | ||||
|              | ||||
|             // show detail view | ||||
|             itemView.DetailButtonObservable.ThrottleFirst(TimeSpan.FromSeconds(.3f)).Subscribe(_ => | ||||
|             { | ||||
|  |  | |||
|  | @ -320,6 +320,10 @@ public sealed class GameData { | |||
|         MoveHeart(WaitAddHeart); | ||||
|     } | ||||
|      | ||||
|     public void AddAdCount(){ | ||||
|         ++adCount; | ||||
|     } | ||||
| 
 | ||||
|     // public void ChangeAvatar(AvatarData avatarData){ | ||||
|     //     newAvatarIdList.Remove(avatarData.id); | ||||
|     // } | ||||
|  |  | |||
|  | @ -93,6 +93,7 @@ namespace MyGame.Scripts | |||
|                     { | ||||
|                         if (result) | ||||
|                         { | ||||
|                             GameDataManager.GameData.AddAdCount(); | ||||
|                             LocalCacheManager.Load<Action>(OkCallbackTag, null)?.Invoke(); | ||||
|                             LocalCacheManager.Remove(OkCallbackTag); | ||||
|                         } | ||||
|  |  | |||
|  | @ -20,6 +20,7 @@ public enum GameScenes | |||
|     shopping, | ||||
|     ShoppingExplanation, | ||||
|     Purchase, | ||||
|     ExchangeAchievement, | ||||
|     ProductManagement, | ||||
|     PopcornDescription, | ||||
|     Tasting, | ||||
|  |  | |||
|  | @ -50,6 +50,9 @@ EditorBuildSettings: | |||
|   - enabled: 1 | ||||
|     path: Assets/MyGame/Scenes/shopping/Purchase.unity | ||||
|     guid: 6cdf801ecd42cd543a2b68afba311048 | ||||
|   - enabled: 1 | ||||
|     path: Assets/MyGame/Scenes/shopping/ExchangeAchievement.unity | ||||
|     guid: 0c5950b18bf59e54ab2ac02980fb3051 | ||||
|   - enabled: 1 | ||||
|     path: Assets/MyGame/Scenes/DebugOption/DebugOption.unity | ||||
|     guid: fe763d31ed9d54598b71a92ae78adefe | ||||
|  | @ -102,6 +105,6 @@ EditorBuildSettings: | |||
|     path: Assets/MyGame/Scenes/ApplicationExitConfirmDialog/ApplicationExitConfirmDialog.unity | ||||
|     guid: c25d0bb8eeefa744eb98fc07808adad7 | ||||
|   - enabled: 1 | ||||
|     path: Assets/MyGame/Scenes/Main/Update.unity | ||||
|     path: Assets/MyGame/Scenes/Main/update.unity | ||||
|     guid: 940b0354731698e4381318e56969feaf | ||||
|   m_configObjects: {} | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue