Browse Source

Introduce item types

master
Devin 4 years ago
parent
commit
6d52cdc526
  1. 56
      Assets/Prefabs/GridViewItem.prefab
  2. 20
      Assets/Resources/ScriptedItems/ActualSword.asset
  3. 8
      Assets/Resources/ScriptedItems/ActualSword.asset.meta
  4. 20
      Assets/Resources/StandardShopInventory.asset
  5. 2
      Assets/Scripts/Shop/Model/Inventory.cs
  6. 17
      Assets/Scripts/Shop/Model/Item.cs
  7. 24
      Assets/Scripts/Shop/Model/ItemWeapon.cs
  8. 11
      Assets/Scripts/Shop/Model/ItemWeapon.cs.meta
  9. 5
      Assets/Scripts/Shop/Scriptable Objects/ScriptedItem.cs
  10. 2
      Assets/Scripts/Shop/Scriptable Objects/ScriptedItemFactory.cs
  11. 16
      Assets/Scripts/Shop/Scriptable Objects/ScriptedWeapon.cs
  12. 11
      Assets/Scripts/Shop/Scriptable Objects/ScriptedWeapon.cs.meta

56
Assets/Prefabs/GridViewItem.prefab

@ -20,7 +20,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 0
m_IsActive: 1
--- !u!224 &2158945965616558227
RectTransform:
m_ObjectHideFlags: 0
@ -170,9 +170,9 @@ RectTransform:
m_Father: {fileID: 8463177436804160159}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 100, y: -10}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 200, y: 20}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &6276336569359545557
@ -338,9 +338,9 @@ RectTransform:
m_Father: {fileID: 2236248579476745813}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 100, y: -50}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 200, y: 50}
m_Pivot: {x: 0.5, y: 1}
--- !u!222 &6746999582958781488
@ -664,9 +664,9 @@ RectTransform:
m_Father: {fileID: 2236248579476745813}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 100, y: -25}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 200, y: 50}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &6575481395058307399
@ -983,9 +983,9 @@ RectTransform:
m_Father: {fileID: 2158945965616558227}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 100, y: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 200, y: 75}
m_Pivot: {x: 0.5, y: 1}
--- !u!222 &1293282004875046429
@ -1082,9 +1082,9 @@ RectTransform:
m_Father: {fileID: 2236248579476745813}
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 100, y: -100}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 200, y: 50}
m_Pivot: {x: 0.5, y: 1}
--- !u!222 &2677774126614840048
@ -1238,9 +1238,9 @@ RectTransform:
m_Father: {fileID: 8463177436804160159}
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 100, y: -30}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 200, y: 15}
m_Pivot: {x: 0.5, y: 1}
--- !u!222 &6572675765595622057
@ -1472,9 +1472,9 @@ RectTransform:
m_Father: {fileID: 2158945965616558227}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 100, y: -75}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 200, y: 125}
m_Pivot: {x: 0.5, y: 1}
--- !u!222 &644337133234863296
@ -1647,9 +1647,9 @@ RectTransform:
m_Father: {fileID: 8463177436804160159}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 100, y: -25}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 100, y: 10}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &2480338273916655199
@ -1692,9 +1692,9 @@ RectTransform:
m_Father: {fileID: 8463177436804160159}
m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 100, y: -45}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 200, y: 30}
m_Pivot: {x: 0.5, y: 1}
--- !u!222 &1794332670372956633

20
Assets/Resources/ScriptedItems/ActualSword.asset

@ -0,0 +1,20 @@
%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: 1a6faf63d685386429bab9c581992b61, type: 3}
m_Name: ActualSword
m_EditorClassIdentifier:
Name: Actual Sword
Description: This sword is actually a sword though
Sprite: {fileID: 3447626333678633045, guid: b00993d063fbc4a87983115070f6145c, type: 3}
Price: 1000
Attack: 35
Damage: 45

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

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

20
Assets/Resources/StandardShopInventory.asset

@ -13,15 +13,11 @@ MonoBehaviour:
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}
- {fileID: 11400000, guid: 107c94e65e6618040a4ea352a7b7c0ed, type: 2}
- {fileID: 11400000, guid: 107c94e65e6618040a4ea352a7b7c0ed, type: 2}
- {fileID: 11400000, guid: 107c94e65e6618040a4ea352a7b7c0ed, type: 2}
- {fileID: 11400000, guid: 107c94e65e6618040a4ea352a7b7c0ed, type: 2}
- {fileID: 11400000, guid: 107c94e65e6618040a4ea352a7b7c0ed, type: 2}
- {fileID: 11400000, guid: 107c94e65e6618040a4ea352a7b7c0ed, type: 2}
- {fileID: 11400000, guid: 107c94e65e6618040a4ea352a7b7c0ed, type: 2}
- {fileID: 11400000, guid: 107c94e65e6618040a4ea352a7b7c0ed, type: 2}

2
Assets/Scripts/Shop/Model/Inventory.cs

@ -100,7 +100,7 @@ public class Inventory
Random random = new Random();
for (int index = 0; index < itemCount; index++)
{
Item item = new Item("Student Sword", "items_" + random.Next(73, 145), 50); //item name, item icon, cost
Item item = new ItemWeapon("Student Sword", "items_" + random.Next(73, 145), 50,0,0); //item name, item icon, cost
itemList.Add(item);
}
}

17
Assets/Scripts/Shop/Model/Item.cs

@ -1,7 +1,7 @@
/// <summary>
/// This class holds data for an Item. Currently it has a name, an iconName and a base price.
/// </summary>
public class Item
public abstract class Item
{
public readonly string name;
public readonly string iconName;
@ -18,5 +18,20 @@ public class Item
this.basePrice = pbasePrice;
}
// This is supposed to return what type an item identifies as, purely used for filtering
public abstract ItemType GetItemType();
// Returns a nicely formatted text about the item's stats. Implementation-specific, because different types of items generate these differently
public abstract string GetStats();
}
/// <summary>
/// Item type, mostly used as an identifier for item filters
/// </summary>
public enum ItemType
{
Weapon,
Armor,
Potion
}

24
Assets/Scripts/Shop/Model/ItemWeapon.cs

@ -0,0 +1,24 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ItemWeapon : Item
{
public readonly int Attack;
public readonly int Damage;
public ItemWeapon(string name, string iconName, int pbasePrice,int pAttack, int pDamage) : base(name, iconName, pbasePrice)
{
Attack = pAttack;
Damage = pDamage;
}
public override ItemType GetItemType()
{
return ItemType.Weapon;
}
public override string GetStats()
{
return "Attack: " + Attack + "\tDamage: " + Damage; // Empty placeholder
}
}

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

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

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

@ -4,11 +4,12 @@ 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 abstract class ScriptedItem : ScriptableObject
{
public string Name;
public string Description;
public Sprite Sprite;
public int Price;
public abstract Item GenerateItem();
}

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

@ -12,7 +12,7 @@ public class ScriptedItemFactory : ItemFactory
{
foreach (var item in Items)
{
model.inventory.AddItem(new Item(item.name,item.Sprite.name,item.Price));
model.inventory.AddItem(item.GenerateItem());
}
}
}

16
Assets/Scripts/Shop/Scriptable Objects/ScriptedWeapon.cs

@ -0,0 +1,16 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// The scripted weapon generates a weapon type scripted item, adding attack and damage variables to it
/// </summary>
[CreateAssetMenu]//Allows creating ViewConfig objects in Assets -> Create menu in the Unity Editor
public class ScriptedWeapon : ScriptedItem
{
public int Attack;
public int Damage;
public override Item GenerateItem()
{
return new ItemWeapon(Name, Sprite.name, Price, Attack, Damage);
}
}

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

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