Browse Source

Made collectables work

Josh_Dev_branch
JoshuaReason 5 years ago
parent
commit
d8169cd5bd
17 changed files with 419 additions and 44 deletions
  1. +2
    -2
      Assets/Data/Inventory/PlayerInventory.asset
  2. +3
    -0
      Assets/Data/Inventory/Tutorial5.asset
  3. +8
    -0
      Assets/Data/Inventory/Tutorial5.asset.meta
  4. +8
    -0
      Assets/Models.meta
  5. +256
    -7
      Assets/Scenes/TuteLevelFive.unity
  6. +12
    -9
      Assets/Scripts/Character.cs
  7. +8
    -0
      Assets/Scripts/Collectables.meta
  8. +10
    -0
      Assets/Scripts/Collectables/Collectable.cs
  9. +11
    -0
      Assets/Scripts/Collectables/Collectable.cs.meta
  10. +34
    -0
      Assets/Scripts/Collectables/LogicCollectable.cs
  11. +11
    -0
      Assets/Scripts/Collectables/LogicCollectable.cs.meta
  12. +26
    -12
      Assets/Scripts/Inventory.cs
  13. +5
    -1
      Assets/Scripts/Logic/Blocks/LogicBlock.cs
  14. +8
    -0
      Assets/Scripts/LogicBlocks.meta
  15. +4
    -4
      Assets/Scripts/UI/BagItem.cs
  16. +1
    -1
      Assets/Scripts/UI/LogicElementUI.cs
  17. +12
    -8
      Assets/Scripts/UI/PlayerUIManager.cs

+ 2
- 2
Assets/Data/Inventory/PlayerInventory.asset View File

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1 version https://git-lfs.github.com/spec/v1
oid sha256:362b0120802255e93f8c0b15edc15dd357571757d07e6a9f75a9666050a1469a
size 962
oid sha256:6c75d69c62bbc00bb4af4493737a2bb52d5212a295007ff7211aced4daac792f
size 750

+ 3
- 0
Assets/Data/Inventory/Tutorial5.asset View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:c81d2820a9790c0163625e9c05c69cb3f8d3d7492404c40895fd21f9848db8f6
size 744

+ 8
- 0
Assets/Data/Inventory/Tutorial5.asset.meta View File

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

+ 8
- 0
Assets/Models.meta View File

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

+ 256
- 7
Assets/Scenes/TuteLevelFive.unity View File

@ -38,7 +38,7 @@ RenderSettings:
m_ReflectionIntensity: 1 m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0} m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 0} m_Sun: {fileID: 0}
m_IndirectSpecularColor: {r: 0.44657874, g: 0.49641258, b: 0.5748172, a: 1}
m_IndirectSpecularColor: {r: 0.44657868, g: 0.49641263, b: 0.57481706, a: 1}
m_UseRadianceAmbientProbe: 0 m_UseRadianceAmbientProbe: 0
--- !u!157 &3 --- !u!157 &3
LightmapSettings: LightmapSettings:
@ -130,6 +130,18 @@ Transform:
type: 3} type: 3}
m_PrefabInstance: {fileID: 1337844285} m_PrefabInstance: {fileID: 1337844285}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
--- !u!114 &20179508 stripped
MonoBehaviour:
m_CorrespondingSourceObject: {fileID: 6815585465521158857, guid: c176f4ae8f7b4074db99b27b2e015a2a,
type: 3}
m_PrefabInstance: {fileID: 421711684}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 0
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: c0bbbf19cb68b2742bd80855243b64e3, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1001 &43307494 --- !u!1001 &43307494
PrefabInstance: PrefabInstance:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -493,6 +505,195 @@ PrefabInstance:
objectReference: {fileID: 0} objectReference: {fileID: 0}
m_RemovedComponents: [] m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: bf82e6870e62966448210c1718aa3fb3, type: 3} m_SourcePrefab: {fileID: 100100000, guid: bf82e6870e62966448210c1718aa3fb3, type: 3}
--- !u!1001 &192739617
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 5195354182462625300, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f,
type: 3}
propertyPath: m_Name
value: Player Canvas
objectReference: {fileID: 0}
- target: {fileID: 5195354182462625304, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f,
type: 3}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5195354182462625304, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f,
type: 3}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5195354182462625304, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f,
type: 3}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5195354182462625304, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f,
type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5195354182462625304, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f,
type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5195354182462625304, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f,
type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5195354182462625304, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f,
type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 5195354182462625304, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f,
type: 3}
propertyPath: m_RootOrder
value: 3
objectReference: {fileID: 0}
- target: {fileID: 5195354182462625304, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f,
type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5195354182462625304, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f,
type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5195354182462625304, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f,
type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5195354182462625304, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f,
type: 3}
propertyPath: m_AnchoredPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5195354182462625304, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f,
type: 3}
propertyPath: m_AnchoredPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5195354182462625304, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f,
type: 3}
propertyPath: m_SizeDelta.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5195354182462625304, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f,
type: 3}
propertyPath: m_SizeDelta.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5195354182462625304, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f,
type: 3}
propertyPath: m_AnchorMin.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5195354182462625304, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f,
type: 3}
propertyPath: m_AnchorMin.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5195354182462625304, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f,
type: 3}
propertyPath: m_AnchorMax.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5195354182462625304, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f,
type: 3}
propertyPath: m_AnchorMax.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5195354182462625304, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f,
type: 3}
propertyPath: m_Pivot.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5195354182462625304, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f,
type: 3}
propertyPath: m_Pivot.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5195354182462625305, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f,
type: 3}
propertyPath: m_RenderMode
value: 1
objectReference: {fileID: 0}
- target: {fileID: 5195354182462625305, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f,
type: 3}
propertyPath: m_Camera
value:
objectReference: {fileID: 222433593}
- target: {fileID: 5195354182462625307, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f,
type: 3}
propertyPath: characterInput
value:
objectReference: {fileID: 20179508}
- target: {fileID: 5195354182462625307, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f,
type: 3}
propertyPath: Inventory
value:
objectReference: {fileID: 994635199}
- target: {fileID: 5195354183101525347, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f,
type: 3}
propertyPath: m_AnchoredPosition.y
value: 149.60864
objectReference: {fileID: 0}
- target: {fileID: 5195354183101525347, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f,
type: 3}
propertyPath: m_AnchorMin.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5195354183101525347, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f,
type: 3}
propertyPath: m_AnchorMax.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5195354183157824117, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f,
type: 3}
propertyPath: m_AnchoredPosition.x
value: -64.200195
objectReference: {fileID: 0}
- target: {fileID: 5195354181806561359, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f,
type: 3}
propertyPath: m_AnchoredPosition.y
value: -0.0000061496803
objectReference: {fileID: 0}
- target: {fileID: 5195354181806561359, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f,
type: 3}
propertyPath: m_SizeDelta.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5195354181806561359, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f,
type: 3}
propertyPath: m_AnchoredPosition.x
value: -0.000035584977
objectReference: {fileID: 0}
- target: {fileID: 5195354183101525346, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f,
type: 3}
propertyPath: m_AspectRatio
value: 30.407776
objectReference: {fileID: 0}
- target: {fileID: 5195354181796512270, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f,
type: 3}
propertyPath: m_havePropertiesChanged
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5195354181796512270, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f,
type: 3}
propertyPath: m_isInputParsingRequired
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f, type: 3}
--- !u!1 &204689275 --- !u!1 &204689275
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -572,7 +773,7 @@ Transform:
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: [] m_Children: []
m_Father: {fileID: 0} m_Father: {fileID: 0}
m_RootOrder: 8
m_RootOrder: 9
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1001 &211889378 --- !u!1001 &211889378
PrefabInstance: PrefabInstance:
@ -723,7 +924,7 @@ Transform:
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: [] m_Children: []
m_Father: {fileID: 0} m_Father: {fileID: 0}
m_RootOrder: 3
m_RootOrder: 4
m_LocalEulerAnglesHint: {x: 49.321003, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 49.321003, y: 0, z: 0}
--- !u!1001 &226508591 --- !u!1001 &226508591
PrefabInstance: PrefabInstance:
@ -1613,11 +1814,28 @@ PrefabInstance:
propertyPath: popUpText propertyPath: popUpText
value: value:
objectReference: {fileID: 1792455937} objectReference: {fileID: 1792455937}
- target: {fileID: 2862111851184665482, guid: c176f4ae8f7b4074db99b27b2e015a2a,
type: 3}
propertyPath: Inventory
value:
objectReference: {fileID: 11400000, guid: b6fa892e4c159bf46a2c4cda19627e97,
type: 2}
- target: {fileID: 2862111851184665482, guid: c176f4ae8f7b4074db99b27b2e015a2a,
type: 3}
propertyPath: startingInventory
value:
objectReference: {fileID: 11400000, guid: 57948efb1cd9603419511d2dd2eabc3d,
type: 2}
- target: {fileID: 2631002120179805110, guid: c176f4ae8f7b4074db99b27b2e015a2a, - target: {fileID: 2631002120179805110, guid: c176f4ae8f7b4074db99b27b2e015a2a,
type: 3} type: 3}
propertyPath: m_Enabled propertyPath: m_Enabled
value: 1 value: 1
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 6815585465521158857, guid: c176f4ae8f7b4074db99b27b2e015a2a,
type: 3}
propertyPath: blockReader.LogicChain.Array.size
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6815585465521158857, guid: c176f4ae8f7b4074db99b27b2e015a2a, - target: {fileID: 6815585465521158857, guid: c176f4ae8f7b4074db99b27b2e015a2a,
type: 3} type: 3}
propertyPath: m_Enabled propertyPath: m_Enabled
@ -2888,6 +3106,18 @@ Transform:
type: 3} type: 3}
m_PrefabInstance: {fileID: 326265431} m_PrefabInstance: {fileID: 326265431}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
--- !u!114 &994635199 stripped
MonoBehaviour:
m_CorrespondingSourceObject: {fileID: 5195354183134146528, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f,
type: 3}
m_PrefabInstance: {fileID: 192739617}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 36cc4df775c8e8b46a89972d8008d56d, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!4 &1045336388 stripped --- !u!4 &1045336388 stripped
Transform: Transform:
m_CorrespondingSourceObject: {fileID: 850440798328794615, guid: bf82e6870e62966448210c1718aa3fb3, m_CorrespondingSourceObject: {fileID: 850440798328794615, guid: bf82e6870e62966448210c1718aa3fb3,
@ -2961,7 +3191,7 @@ Transform:
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: [] m_Children: []
m_Father: {fileID: 0} m_Father: {fileID: 0}
m_RootOrder: 4
m_RootOrder: 5
m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0} m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0}
--- !u!1001 &1061954515 --- !u!1001 &1061954515
PrefabInstance: PrefabInstance:
@ -3088,7 +3318,7 @@ PrefabInstance:
- target: {fileID: 7103365430685043225, guid: 80a26ed87f729434abe07a722ef15e7c, - target: {fileID: 7103365430685043225, guid: 80a26ed87f729434abe07a722ef15e7c,
type: 3} type: 3}
propertyPath: m_RootOrder propertyPath: m_RootOrder
value: 7
value: 8
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 7103365430685043225, guid: 80a26ed87f729434abe07a722ef15e7c, - target: {fileID: 7103365430685043225, guid: 80a26ed87f729434abe07a722ef15e7c,
type: 3} type: 3}
@ -4322,6 +4552,7 @@ GameObject:
- component: {fileID: 1691679949} - component: {fileID: 1691679949}
- component: {fileID: 1691679948} - component: {fileID: 1691679948}
- component: {fileID: 1691679947} - component: {fileID: 1691679947}
- component: {fileID: 1691679951}
m_Layer: 0 m_Layer: 0
m_Name: Jump m_Name: Jump
m_TagString: New Block m_TagString: New Block
@ -4399,8 +4630,26 @@ Transform:
m_LocalScale: {x: 0.3, y: 0.3, z: 0.3} m_LocalScale: {x: 0.3, y: 0.3, z: 0.3}
m_Children: [] m_Children: []
m_Father: {fileID: 0} m_Father: {fileID: 0}
m_RootOrder: 5
m_RootOrder: 6
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &1691679951
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1691679946}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 3de8ea85fe104ee46819ac1ff5e87159, type: 3}
m_Name:
m_EditorClassIdentifier:
Collectable:
element: {fileID: 11400000, guid: dcf80d6bc49692f4d849f5afb0d05911, type: 2}
Count: 2
isInfinit: 0
BlockMenu: {fileID: 1792455936}
popUpText: {fileID: 1792455937}
--- !u!1001 &1718022930 --- !u!1001 &1718022930
PrefabInstance: PrefabInstance:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -4802,7 +5051,7 @@ PrefabInstance:
- target: {fileID: 6379596649083080716, guid: 12c252cb33f8c9d41be9fc3a9adb9bb9, - target: {fileID: 6379596649083080716, guid: 12c252cb33f8c9d41be9fc3a9adb9bb9,
type: 3} type: 3}
propertyPath: m_RootOrder propertyPath: m_RootOrder
value: 6
value: 7
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 6379596649083080716, guid: 12c252cb33f8c9d41be9fc3a9adb9bb9, - target: {fileID: 6379596649083080716, guid: 12c252cb33f8c9d41be9fc3a9adb9bb9,
type: 3} type: 3}

+ 12
- 9
Assets/Scripts/Character.cs View File

@ -7,10 +7,11 @@ using UnityEngine.SceneManagement;
public class Character : MonoBehaviour public class Character : MonoBehaviour
{ {
public string nextScene; public string nextScene;
public GameObject BlockMenu;
public Text popUpText;
#region Inspector Fields
#region Inspector Fields
[SerializeField]
private Inventory startingInventory;
[SerializeField] [SerializeField]
[Tooltip ("Will move to this block at start, else will try and find a block below")] [Tooltip ("Will move to this block at start, else will try and find a block below")]
@ -20,7 +21,8 @@ public class Character : MonoBehaviour
[Tooltip ("Layers to ignore when checking for blocks")] [Tooltip ("Layers to ignore when checking for blocks")]
private LayerMask Ignore; private LayerMask Ignore;
public string PickUpTag = "NewBlock";
[Tooltip("Current Inventory of the player")]
public Inventory Inventory;
#endregion Inspector Fields #endregion Inspector Fields
@ -28,6 +30,8 @@ public class Character : MonoBehaviour
private void Awake () private void Awake ()
{ {
Inventory.Clone(startingInventory);
//If no starting block find one below it //If no starting block find one below it
if (CurrentBlock == null) if (CurrentBlock == null)
Block.isBlockAtPosition (transform.position + Vector3.down / 2, 1, ~Ignore, out CurrentBlock); Block.isBlockAtPosition (transform.position + Vector3.down / 2, 1, ~Ignore, out CurrentBlock);
@ -76,11 +80,10 @@ public class Character : MonoBehaviour
/// <param name="other">name of collided object</param> /// <param name="other">name of collided object</param>
void OnTriggerEnter (Collider other) void OnTriggerEnter (Collider other)
{ {
if (other.gameObject.tag == PickUpTag) {
BlockMenu.SetActive (true);
other.gameObject.SetActive (false);
Debug.Log ("You picked up the new coding block " + other.gameObject.name + "!");
popUpText.text = other.gameObject.name.ToUpper ();
Collectable collectable = other.GetComponentInChildren<Collectable>();
if (other != null) {
collectable.OnCollect(this);
} }
if (other.gameObject.name == "End Portal") { if (other.gameObject.name == "End Portal") {
other.GetComponent<Collider> ().enabled = false; other.GetComponent<Collider> ().enabled = false;

+ 8
- 0
Assets/Scripts/Collectables.meta View File

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

+ 10
- 0
Assets/Scripts/Collectables/Collectable.cs View File

@ -0,0 +1,10 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public abstract class Collectable : MonoBehaviour
{
public abstract void OnCollect(Character character);
}

+ 11
- 0
Assets/Scripts/Collectables/Collectable.cs.meta View File

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

+ 34
- 0
Assets/Scripts/Collectables/LogicCollectable.cs View File

@ -0,0 +1,34 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class LogicCollectable : Collectable
{
[SerializeField]
protected Inventory.Data Collectable;
[SerializeField]
protected GameObject BlockMenu;
[SerializeField]
protected Text popUpText;
public override void OnCollect(Character character)
{
character.Inventory.Add(Collectable);
if (BlockMenu != null)
{
BlockMenu.SetActive(true);
Debug.Log("You picked up the new coding block " + Collectable.element.DisplayName + "!");
popUpText.text = Collectable.element.DisplayName.ToUpper();
}
Destroy(gameObject);
}
}

+ 11
- 0
Assets/Scripts/Collectables/LogicCollectable.cs.meta View File

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

+ 26
- 12
Assets/Scripts/Inventory.cs View File

@ -12,22 +12,29 @@ public class Inventory : ScriptableObject
[SerializeField] [SerializeField]
protected List<Data> _bagItems = new List<Data>(); protected List<Data> _bagItems = new List<Data>();
public void Add(LogicBlock element)
public void Add(LogicBlock element,int count = 1, bool isInfinit = false)
{ {
Data data;
Data data = new Data {
element = element,
Count = count,
isInfinit = isInfinit };
try
Add(data);
}
public void Add(Data data)
{
if (_bagItems.Contains(data))
{ {
data = _bagItems.First(p => p.element == element);
Data bagData = BagItems.Find(p => p.Equals(data));
bagData.Count += data.Count;
bagData.isInfinit = (data.isInfinit || bagData.isInfinit);
} }
catch
{
data = new Data() { element = element };
else
_bagItems.Add(data); _bagItems.Add(data);
}
data.Count++;
} }
public void Remove(LogicBlock element) { public void Remove(LogicBlock element) {
@ -37,10 +44,17 @@ public class Inventory : ScriptableObject
Data data = _bagItems.First(p => p.element == element); Data data = _bagItems.First(p => p.element == element);
if (!data.infinit)
if (!data.isInfinit)
data.Count--; data.Count--;
} }
public void Clone(Inventory inventory)
{
_bagItems = new List<Data>(inventory._bagItems);
}
[System.Serializable] [System.Serializable]
@ -48,6 +62,6 @@ public class Inventory : ScriptableObject
{ {
public LogicBlock element; public LogicBlock element;
public int Count; public int Count;
public bool infinit = false;
public bool isInfinit = false;
} }
} }

+ 5
- 1
Assets/Scripts/Logic/Blocks/LogicBlock.cs View File

@ -17,7 +17,7 @@ public abstract class LogicBlock : ScriptableObject
[SerializeField] [SerializeField]
[Tooltip("Name which will appear in the UI")] [Tooltip("Name which will appear in the UI")]
public string DisplayName;
protected string _DisplayName;
[SerializeField] [SerializeField]
[Header("Base Settings")] [Header("Base Settings")]
@ -29,6 +29,10 @@ public abstract class LogicBlock : ScriptableObject
protected int RepeatAmount = 1; protected int RepeatAmount = 1;
#endregion Inspector Fields #endregion Inspector Fields
#region ReadOnly Variables
public string DisplayName { get {return (string.IsNullOrEmpty(_DisplayName)) ? name : _DisplayName; } }
#endregion
#region private variables #region private variables
/// <summary> /// <summary>

+ 8
- 0
Assets/Scripts/LogicBlocks.meta View File

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

+ 4
- 4
Assets/Scripts/UI/BagItem.cs View File

@ -39,7 +39,7 @@ public class BagItem : LogicElementHolder
public void UpdateUI() public void UpdateUI()
{ {
if (!InventoryData.infinit)
if (!InventoryData.isInfinit)
CountText.text = Count.ToString(); CountText.text = Count.ToString();
else else
CountText.text = "∞"; CountText.text = "∞";
@ -57,7 +57,7 @@ public class BagItem : LogicElementHolder
{ {
Destroy(element.gameObject); Destroy(element.gameObject);
if (!InventoryData.infinit)
if (!InventoryData.isInfinit)
Count++; Count++;
UpdateUI(); UpdateUI();
@ -69,9 +69,9 @@ public class BagItem : LogicElementHolder
/// <param name="element">Element which is being dragged</param> /// <param name="element">Element which is being dragged</param>
public override void OnRemove(LogicElementUI element) public override void OnRemove(LogicElementUI element)
{ {
if (!InventoryData.infinit && Count > 0)
if (!InventoryData.isInfinit && Count > 0)
Count--; Count--;
else if (!InventoryData.infinit)
else if (!InventoryData.isInfinit)
Destroy(element.gameObject); Destroy(element.gameObject);
LogicElementUI logicElement = Instantiate(LogicElementPrefab.gameObject, LogicElementLocation).GetComponent<LogicElementUI>(); LogicElementUI logicElement = Instantiate(LogicElementPrefab.gameObject, LogicElementLocation).GetComponent<LogicElementUI>();

+ 1
- 1
Assets/Scripts/UI/LogicElementUI.cs View File

@ -62,7 +62,7 @@ public class LogicElementUI : Dragable
if (LogicElement != null) if (LogicElement != null)
{ {
//If name null use file name //If name null use file name
nameText.text = (string.IsNullOrEmpty(LogicElement.DisplayName)) ? LogicElement.name : LogicElement.DisplayName;
nameText.text = LogicElement.DisplayName;
background.color = LogicElement.Color; background.color = LogicElement.Color;
} }
} }

+ 12
- 8
Assets/Scripts/UI/PlayerUIManager.cs View File

@ -6,7 +6,7 @@ public class PlayerUIManager : MonoBehaviour
{ {
[SerializeField] [SerializeField]
private RectTransform Inventory;
private InventoryUI Inventory;
[SerializeField] [SerializeField]
private float AnimationSpeed = 0.5f; private float AnimationSpeed = 0.5f;
@ -19,14 +19,17 @@ public class PlayerUIManager : MonoBehaviour
private Vector3 ShowPosition; private Vector3 ShowPosition;
private Vector3 HidePosition; private Vector3 HidePosition;
private RectTransform inventoryRect { get { return Inventory.transform as RectTransform; } }
private void Awake() private void Awake()
{ {
ShowPosition = new Vector3(0, -Inventory.rect.height / 2, 0);
HidePosition = new Vector3(0, Inventory.rect.height/2, 0);
Debug.Log(Inventory.rect.height);
Inventory.anchoredPosition = HidePosition;
ShowPosition = new Vector3(0, -inventoryRect.rect.height / 2, 0);
HidePosition = new Vector3(0, inventoryRect.rect.height/2, 0);
inventoryRect.anchoredPosition = HidePosition;
TrayUI.SetBlockReader(characterInput.blockReader); TrayUI.SetBlockReader(characterInput.blockReader);
} }
@ -34,7 +37,8 @@ public class PlayerUIManager : MonoBehaviour
public void OnClick_Show() public void OnClick_Show()
{ {
StopAllCoroutines(); StopAllCoroutines();
StartCoroutine( LerpPosition(Inventory, ShowPosition, AnimationSpeed));
Inventory.UpdateUI();
StartCoroutine( LerpPosition(inventoryRect, ShowPosition, AnimationSpeed));
} }
[ContextMenu("Hide")] [ContextMenu("Hide")]
@ -42,12 +46,12 @@ public class PlayerUIManager : MonoBehaviour
{ {
StopAllCoroutines(); StopAllCoroutines();
StartCoroutine( LerpPosition(Inventory, HidePosition, AnimationSpeed));
StartCoroutine( LerpPosition(inventoryRect, HidePosition, AnimationSpeed));
} }
public void OnClick_Toggle() public void OnClick_Toggle()
{ {
if (Vector3.Distance(Inventory.anchoredPosition,ShowPosition) < Vector3.Distance(Inventory.anchoredPosition, HidePosition))
if (Vector3.Distance(inventoryRect.anchoredPosition,ShowPosition) < Vector3.Distance(inventoryRect.anchoredPosition, HidePosition))
{ {
Debug.Log("Hiding Menu"); Debug.Log("Hiding Menu");
OnClick_Hide(); OnClick_Hide();

Loading…
Cancel
Save