Browse Source

Prepare scriptable shop factories

Devin Braune 5 years ago
parent
commit
b7177d787f
  1. 8
      Assets/Resources/ScriptedItems.meta
  2. 17
      Assets/Resources/ScriptedItems/BetterSword.asset
  3. 8
      Assets/Resources/ScriptedItems/BetterSword.asset.meta
  4. 17
      Assets/Resources/ScriptedItems/SomeSword.asset
  5. 8
      Assets/Resources/ScriptedItems/SomeSword.asset.meta
  6. 16
      Assets/Resources/StandardShop.asset
  7. 8
      Assets/Resources/StandardShop.asset.meta
  8. 27
      Assets/Resources/StandardShopInventory.asset
  9. 8
      Assets/Resources/StandardShopInventory.asset.meta
  10. 39
      Assets/Scenes/NewShop.unity
  11. 7
      Assets/Scripts/Shop/Model/BuyModel.cs
  12. 6
      Assets/Scripts/Shop/Model/IModelContainer.cs
  13. 11
      Assets/Scripts/Shop/Model/IModelContainer.cs.meta
  14. 25
      Assets/Scripts/Shop/Model/ModelComponent.cs
  15. 11
      Assets/Scripts/Shop/Model/ModelComponent.cs.meta
  16. 13
      Assets/Scripts/Shop/Model/ShopModelComponent.cs
  17. 11
      Assets/Scripts/Shop/Model/ShopModelComponent.cs.meta
  18. 10
      Assets/Scripts/Shop/Scriptable Objects/ItemFactory.cs
  19. 11
      Assets/Scripts/Shop/Scriptable Objects/ItemFactory.cs.meta
  20. 13
      Assets/Scripts/Shop/Scriptable Objects/ScriptedItem.cs
  21. 11
      Assets/Scripts/Shop/Scriptable Objects/ScriptedItem.cs.meta
  22. 15
      Assets/Scripts/Shop/Scriptable Objects/ScriptedItemFactory.cs
  23. 11
      Assets/Scripts/Shop/Scriptable Objects/ScriptedItemFactory.cs.meta
  24. 14
      Assets/Scripts/Shop/Scriptable Objects/ShopObject.cs
  25. 11
      Assets/Scripts/Shop/Scriptable Objects/ShopObject.cs.meta
  26. 1
      Assets/Scripts/Shop/View/GridViewItemContainer.cs

8
Assets/Resources/ScriptedItems.meta

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 5baa559c09c7aa84db8dbacf122bf34d
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

17
Assets/Resources/ScriptedItems/BetterSword.asset

@ -0,0 +1,17 @@
%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: af86c7c2268eed441b882ced845365f4, type: 3}
m_Name: BetterSword
m_EditorClassIdentifier:
Name: Good Sword
Description: Better than the Noob Sword
sprite: {fileID: -4063295180217184869, guid: b00993d063fbc4a87983115070f6145c, type: 3}

8
Assets/Resources/ScriptedItems/BetterSword.asset.meta

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 8ec316abfe61e4b43862dd2c75f0f792
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

17
Assets/Resources/ScriptedItems/SomeSword.asset

@ -0,0 +1,17 @@
%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: af86c7c2268eed441b882ced845365f4, type: 3}
m_Name: SomeSword
m_EditorClassIdentifier:
Name: Noob Sword
Description: This sword is for noobs
sprite: {fileID: -6229739577819397656, guid: b00993d063fbc4a87983115070f6145c, type: 3}

8
Assets/Resources/ScriptedItems/SomeSword.asset.meta

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: b0a77491a8b600245b47aa33287d7585
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

16
Assets/Resources/StandardShop.asset

@ -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: StandardShop
m_EditorClassIdentifier:
Money: 10000
PriceModifier: 1.1

8
Assets/Resources/StandardShop.asset.meta

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 366ca79a0c4a2df4fac53ddd28f65f1a
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

27
Assets/Resources/StandardShopInventory.asset

@ -0,0 +1,27 @@
%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: d4a440686e1eaa042a9d58081a9b8dbe, type: 3}
m_Name: StandardShopInventory
m_EditorClassIdentifier:
Items:
- {fileID: 11400000, guid: b0a77491a8b600245b47aa33287d7585, type: 2}
- {fileID: 11400000, guid: b0a77491a8b600245b47aa33287d7585, type: 2}
- {fileID: 11400000, guid: b0a77491a8b600245b47aa33287d7585, type: 2}
- {fileID: 11400000, guid: b0a77491a8b600245b47aa33287d7585, type: 2}
- {fileID: 11400000, guid: b0a77491a8b600245b47aa33287d7585, type: 2}
- {fileID: 11400000, guid: b0a77491a8b600245b47aa33287d7585, type: 2}
- {fileID: 11400000, guid: b0a77491a8b600245b47aa33287d7585, type: 2}
- {fileID: 11400000, guid: b0a77491a8b600245b47aa33287d7585, type: 2}
- {fileID: 11400000, guid: 8ec316abfe61e4b43862dd2c75f0f792, type: 2}
- {fileID: 11400000, guid: 8ec316abfe61e4b43862dd2c75f0f792, type: 2}
- {fileID: 11400000, guid: 8ec316abfe61e4b43862dd2c75f0f792, type: 2}
- {fileID: 11400000, guid: 8ec316abfe61e4b43862dd2c75f0f792, type: 2}

8
Assets/Resources/StandardShopInventory.asset.meta

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: d16c0801001245545908f8b001145a3d
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

39
Assets/Scenes/NewShop.unity

@ -373,6 +373,7 @@ GameObject:
serializedVersion: 6
m_Component:
- component: {fileID: 132445006}
- component: {fileID: 132445007}
m_Layer: 5
m_Name: Shop
m_TagString: Untagged
@ -387,20 +388,34 @@ RectTransform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 132445005}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 2131558511}
- {fileID: 822572996}
- {fileID: 2131558511}
m_Father: {fileID: 1697822368}
m_RootOrder: 2
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: 0, y: 0}
m_SizeDelta: {x: 100, y: 100}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 100, y: 1.2143555}
m_SizeDelta: {x: -199.99988, y: -2.241211}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &132445007
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 132445005}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: be8c4b332c72a3c4b85013b334ebde3a, type: 3}
m_Name:
m_EditorClassIdentifier:
factory: {fileID: 11400000, guid: d16c0801001245545908f8b001145a3d, type: 2}
shop: {fileID: 11400000, guid: 366ca79a0c4a2df4fac53ddd28f65f1a, type: 2}
--- !u!1 &180905778
GameObject:
m_ObjectHideFlags: 0
@ -2883,12 +2898,12 @@ RectTransform:
- {fileID: 779240604}
- {fileID: 1510759986}
m_Father: {fileID: 132445006}
m_RootOrder: 1
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 100, y: 0}
m_SizeDelta: {x: 1300, y: 654.2234}
m_AnchoredPosition: {x: 0, y: -1.2144165}
m_SizeDelta: {x: -0.00012207031, y: 2.4645996}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &822572997
MonoBehaviour:
@ -9328,12 +9343,12 @@ RectTransform:
- {fileID: 849412833}
- {fileID: 889320677}
m_Father: {fileID: 132445006}
m_RootOrder: 0
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 100, y: 0}
m_SizeDelta: {x: 1300, y: 654.2234}
m_AnchoredPosition: {x: 0, y: -1.2144165}
m_SizeDelta: {x: -0.00012207031, y: 2.4645996}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &2131558512
MonoBehaviour:

7
Assets/Scripts/Shop/Model/BuyModel.cs

@ -11,6 +11,13 @@ public class BuyModel : ShopModel
}
// 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 BuyModel(ShopObject pShopInitials) : this(pShopInitials.PriceModifier, 0, pShopInitials.Money)
{
}
//------------------------------------------------------------------------------------------------------------------------
// ConfirmSelectedItem()
//------------------------------------------------------------------------------------------------------------------------

6
Assets/Scripts/Shop/Model/IModelContainer.cs

@ -0,0 +1,6 @@
/// <summary>
/// Just makes sure implementations have an accessible reference to a shop model. Could be an inventory of course.
/// </summary>
public interface IModelContainer{
ShopModel Model { get; }
}

11
Assets/Scripts/Shop/Model/IModelContainer.cs.meta

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: bac32d122ed6934498d1bbe6e2fbabc3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

25
Assets/Scripts/Shop/Model/ModelComponent.cs

@ -0,0 +1,25 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// This component basically associates a model with a gameobject. This allows to know its location in the world
/// (2D or 3D!) for fancy effects, or allows a view to switch between different models as it sees fit.
/// The actual model can be anything from a buymodel to an inventorymodel
/// </summary>
public abstract class ModelComponent : MonoBehaviour, IModelContainer
{
public ShopModel Model { get => model; }
[SerializeField] private ItemFactory factory;
protected ShopModel model;
private void Awake()
{
Debug.Assert(factory != null,"Item factory not assigned!",this);
CreateModel(); // Of course, a generic model component can't select which type of model to use. So we use polymorphism!
factory.PopulateModel(model);
}
protected abstract void CreateModel();
}

11
Assets/Scripts/Shop/Model/ModelComponent.cs.meta

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1abae9da667453942bb6221fd22826ee
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

13
Assets/Scripts/Shop/Model/ShopModelComponent.cs

@ -0,0 +1,13 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ShopModelComponent : ModelComponent
{
[SerializeField] private ShopObject shop;
protected override void CreateModel()
{
Debug.Assert(shop != null,"Shop model initial object never assigned!",this);
model = new BuyModel(shop);
}
}

11
Assets/Scripts/Shop/Model/ShopModelComponent.cs.meta

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: be8c4b332c72a3c4b85013b334ebde3a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

10
Assets/Scripts/Shop/Scriptable Objects/ItemFactory.cs

@ -0,0 +1,10 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// An item factory is simply meant to procedurally (or pre-scripted) populate a shop model.
/// </summary>
public abstract class ItemFactory : ScriptableObject
{
public abstract void PopulateModel(ShopModel model);
}

11
Assets/Scripts/Shop/Scriptable Objects/ItemFactory.cs.meta

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 46c010061a3c73145bc36b2b3efac6df
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

13
Assets/Scripts/Shop/Scriptable Objects/ScriptedItem.cs

@ -0,0 +1,13 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// This represents anything needed to construct one item with pre-scripted information
/// </summary>
[CreateAssetMenu]//Allows creating ViewConfig objects in Assets -> Create menu in the Unity Editor
public class ScriptedItem : ScriptableObject
{
public string Name;
public string Description;
public Sprite sprite;
}

11
Assets/Scripts/Shop/Scriptable Objects/ScriptedItem.cs.meta

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: af86c7c2268eed441b882ced845365f4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

15
Assets/Scripts/Shop/Scriptable Objects/ScriptedItemFactory.cs

@ -0,0 +1,15 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// This item factory literally just takes a handcrafted list of items and populates the model with that!
/// </summary>
[CreateAssetMenu]//Allows creating ViewConfig objects in Assets -> Create menu in the Unity Editor
public class ScriptedItemFactory : ItemFactory
{
public List<ScriptedItem> Items;
public override void PopulateModel(ShopModel model)
{
}
}

11
Assets/Scripts/Shop/Scriptable Objects/ScriptedItemFactory.cs.meta

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d4a440686e1eaa042a9d58081a9b8dbe
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

14
Assets/Scripts/Shop/Scriptable Objects/ShopObject.cs

@ -0,0 +1,14 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// This shop object allows us to script which kind of stuff a shop starts out with. Models are meant to be created
/// by using the appropriate unity component, which requires a shopobject to be able to which kind of money and other
/// things specific to a shop they start with.
/// </summary>
[CreateAssetMenu]//Allows creating ViewConfig objects in Assets -> Create menu in the Unity Editor
public class ShopObject : ScriptableObject
{
public int Money;
public float PriceModifier; // How much more expensive than retail price does this shop sell stuff?
}

11
Assets/Scripts/Shop/Scriptable Objects/ShopObject.cs.meta

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3145dd14dac0cf84a909862b61ec2893
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

1
Assets/Scripts/Shop/View/GridViewItemContainer.cs

@ -50,7 +50,6 @@ public class GridViewItemContainer : MonoBehaviour, IItemContainer
// Clones the first Sprite in the icon atlas that matches the iconName and uses it as the sprite of the icon image.
Sprite sprite = iconAtlas.GetSprite(item.iconName);
if (sprite != null) {
icon.sprite = sprite;
}

Loading…
Cancel
Save