16 changed files with 126 additions and 15 deletions
@ -0,0 +1,16 @@ |
|||||
|
%YAML 1.1 |
||||
|
%TAG !u! tag:unity3d.com,2011: |
||||
|
--- !u!114 &11400000 |
||||
|
MonoBehaviour: |
||||
|
m_ObjectHideFlags: 0 |
||||
|
m_CorrespondingSourceObject: {fileID: 0} |
||||
|
m_PrefabInstance: {fileID: 0} |
||||
|
m_PrefabAsset: {fileID: 0} |
||||
|
m_GameObject: {fileID: 0} |
||||
|
m_Enabled: 1 |
||||
|
m_EditorHideFlags: 0 |
||||
|
m_Script: {fileID: 11500000, guid: 3145dd14dac0cf84a909862b61ec2893, type: 3} |
||||
|
m_Name: InventoryStart |
||||
|
m_EditorClassIdentifier: |
||||
|
Money: 6500 |
||||
|
PriceModifier: 0.75 |
||||
@ -0,0 +1,8 @@ |
|||||
|
fileFormatVersion: 2 |
||||
|
guid: 5832c828db6d00c42a09217f7b743233 |
||||
|
NativeFormatImporter: |
||||
|
externalObjects: {} |
||||
|
mainObjectFileID: 11400000 |
||||
|
userData: |
||||
|
assetBundleName: |
||||
|
assetBundleVariant: |
||||
@ -0,0 +1,13 @@ |
|||||
|
using System.Collections; |
||||
|
using System.Collections.Generic; |
||||
|
using UnityEngine; |
||||
|
|
||||
|
public class InventoryModelComponent : ModelComponent |
||||
|
{ |
||||
|
[SerializeField] private ShopObject shop; |
||||
|
protected override void CreateModel() |
||||
|
{ |
||||
|
Debug.Assert(shop != null,"Shop model initial object never assigned!",this); |
||||
|
model = new SellModel(shop); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,11 @@ |
|||||
|
fileFormatVersion: 2 |
||||
|
guid: 8e211938370fd3d43a99aae3848bdd1c |
||||
|
MonoImporter: |
||||
|
externalObjects: {} |
||||
|
serializedVersion: 2 |
||||
|
defaultReferences: [] |
||||
|
executionOrder: 0 |
||||
|
icon: {instanceID: 0} |
||||
|
userData: |
||||
|
assetBundleName: |
||||
|
assetBundleVariant: |
||||
@ -0,0 +1,33 @@ |
|||||
|
using System; |
||||
|
using System.Configuration; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// This is a concrete, empty model for the sell state of the shop for you to implement
|
||||
|
/// </summary>
|
||||
|
public class SellModel : ShopModel |
||||
|
{ |
||||
|
public SellModel(float pPriceModifier, int pItemCount, int pMoney) : base(pPriceModifier, pItemCount, pMoney) |
||||
|
{ |
||||
|
|
||||
|
} |
||||
|
|
||||
|
// Rather than modifying the whole class, we just reuse the existing stuff but don't make it create any items.
|
||||
|
// This makes it less work to make proper functionality, without having to break any potential old functionality.
|
||||
|
// Additionally, saves us work having to rip out the inventory's own ability to generate items.
|
||||
|
public SellModel(ShopObject pShopInitials) : this(pShopInitials.PriceModifier, 0, pShopInitials.Money) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
//------------------------------------------------------------------------------------------------------------------------
|
||||
|
// ConfirmSelectedItem()
|
||||
|
//------------------------------------------------------------------------------------------------------------------------
|
||||
|
//Currently it just removes the selected item from the shop's inventory, rewrite this function and don't forget the unit test.
|
||||
|
|
||||
|
public override void ConfirmSelectedItem() |
||||
|
{ |
||||
|
OnRemove(GetSelectedItem()); // If there's a view subscribed, this will probably remove the item from it
|
||||
|
inventory.RemoveItemByIndex(selectedItemIndex); // Before removing the item from the model's actual inventory
|
||||
|
SelectItemByIndex(selectedItemIndex >= inventory.GetItemCount() ? --selectedItemIndex : selectedItemIndex); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,11 @@ |
|||||
|
fileFormatVersion: 2 |
||||
|
guid: cb5965a2261e8144cb8f7323d65e465e |
||||
|
MonoImporter: |
||||
|
externalObjects: {} |
||||
|
serializedVersion: 2 |
||||
|
defaultReferences: [] |
||||
|
executionOrder: 0 |
||||
|
icon: {instanceID: 0} |
||||
|
userData: |
||||
|
assetBundleName: |
||||
|
assetBundleVariant: |
||||
Loading…
Reference in new issue