Browse Source

Fixed logic tray max length + dropping things back into inventory duplication

master
JoshuaReason 5 years ago
parent
commit
f5468621f3
17 changed files with 278 additions and 21 deletions
  1. +1
    -1
      Assets/Data/Inventory/BaseInventory.asset
  2. +8
    -0
      Assets/Models.meta
  3. +8
    -0
      Assets/Plugins/IngameDebugConsole/Android.meta
  4. +8
    -0
      Assets/Plugins/IngameDebugConsole/Prefabs.meta
  5. +8
    -0
      Assets/Plugins/IngameDebugConsole/Scripts.meta
  6. +8
    -0
      Assets/Plugins/IngameDebugConsole/Sprites/Unused.meta
  7. +60
    -6
      Assets/Prefabs/UI/Player Canvas.prefab
  8. +52
    -5
      Assets/Scenes/Client Scenes/ClientScene.unity
  9. +5
    -0
      Assets/Scripts/Logic/BlockReader.cs
  10. +8
    -0
      Assets/Scripts/LogicBlocks.meta
  11. +14
    -0
      Assets/Scripts/UI/BagItem.cs
  12. +12
    -0
      Assets/Scripts/UI/ILogicElementHolder.cs
  13. +30
    -0
      Assets/Scripts/UI/InventoryCatch.cs
  14. +11
    -0
      Assets/Scripts/UI/InventoryCatch.cs.meta
  15. +6
    -0
      Assets/Scripts/UI/InventoryUI.cs
  16. +10
    -3
      Assets/Scripts/UI/LogicElementUI.cs
  17. +29
    -6
      Assets/Scripts/UI/LogicTrayUI.cs

+ 1
- 1
Assets/Data/Inventory/BaseInventory.asset View File

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:1d0672a6b3709593b57d6964e247a9ccf9ecc89b29d7cc88a1bbf5de996e3296
oid sha256:479be56d3de9e28201b00e89d275b36c21fb25244411ae9838f567db460ee1b1
size 979

+ 8
- 0
Assets/Models.meta View File

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

+ 8
- 0
Assets/Plugins/IngameDebugConsole/Android.meta View File

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

+ 8
- 0
Assets/Plugins/IngameDebugConsole/Prefabs.meta View File

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

+ 8
- 0
Assets/Plugins/IngameDebugConsole/Scripts.meta View File

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

+ 8
- 0
Assets/Plugins/IngameDebugConsole/Sprites/Unused.meta View File

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

+ 60
- 6
Assets/Prefabs/UI/Player Canvas.prefab View File

@ -1,5 +1,55 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &2513432637800871259
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 9187876604664920423}
- component: {fileID: 7314421917572336346}
m_Layer: 5
m_Name: InventoryCatch
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &9187876604664920423
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2513432637800871259}
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: []
m_Father: {fileID: 5195354182462625304}
m_RootOrder: 0
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_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &7314421917572336346
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2513432637800871259}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: c47170bdc5fe12f40b903940535b2e1e, type: 3}
m_Name:
m_EditorClassIdentifier:
Priority: -1
InventoryUI: {fileID: 5195354183134146528}
--- !u!1 &2665231841929910951
GameObject:
m_ObjectHideFlags: 0
@ -191,7 +241,7 @@ RectTransform:
m_Children:
- {fileID: 2665231842684883354}
m_Father: {fileID: 5195354182462625304}
m_RootOrder: 2
m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 1, y: 1}
@ -722,7 +772,7 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: -0.000052183314, y: -0.0000076293945}
m_AnchoredPosition: {x: -0.000052183314, y: -0.000015258789}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0, y: 1}
--- !u!114 &5195354181806561393
@ -793,6 +843,7 @@ RectTransform:
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 0, y: 0, z: 0}
m_Children:
- {fileID: 9187876604664920423}
- {fileID: 5195354183083441315}
- {fileID: 5195354183134146556}
- {fileID: 2665231842396078511}
@ -884,6 +935,7 @@ MonoBehaviour:
TimeText: {fileID: 0}
Title: {fileID: 2665231842396078511}
TotalTime: 30
isTimePaused: 0
--- !u!1 &5195354182925078845
GameObject:
m_ObjectHideFlags: 0
@ -1023,7 +1075,7 @@ RectTransform:
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 5195354182462625304}
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}
@ -1153,7 +1205,7 @@ RectTransform:
- {fileID: 5195354181250555040}
- {fileID: 5195354183157824117}
m_Father: {fileID: 5195354182462625304}
m_RootOrder: 3
m_RootOrder: 4
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0.5}
m_AnchorMax: {x: 1, y: 0.5}
@ -1243,7 +1295,7 @@ RectTransform:
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 5195354182462625304}
m_RootOrder: 1
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 1, y: 1}
@ -1323,7 +1375,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 36cc4df775c8e8b46a89972d8008d56d, type: 3}
m_Name:
m_EditorClassIdentifier:
inventory: {fileID: 11400000, guid: b6fa892e4c159bf46a2c4cda19627e97, type: 2}
inventory: {fileID: 11400000, guid: 9f2bac6895147d444858493b9609d026, type: 2}
ItemPrefab: {fileID: 1021368708357542995, guid: f846db1cf36a645479ce131a2e0cf72f,
type: 3}
Parent: {fileID: 5195354183134146556}
@ -1416,9 +1468,11 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 140e56929e1450a48b2f7716511bb327, type: 3}
m_Name:
m_EditorClassIdentifier:
Priority: 0
Prefab: {fileID: 6973439230367005604, guid: f1daf3f500b22a048bbbad4287c2fcb2, type: 3}
insertIndex: -1
content: {fileID: 5195354181806561359}
maxLength: 6
reader:
LogicChain: []
--- !u!114 &5195354183157824121

+ 52
- 5
Assets/Scenes/Client Scenes/ClientScene.unity View File

@ -38,7 +38,7 @@ RenderSettings:
m_ReflectionIntensity: 1
m_CustomReflection: {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
--- !u!157 &3
LightmapSettings:
@ -199,9 +199,11 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 140e56929e1450a48b2f7716511bb327, type: 3}
m_Name:
m_EditorClassIdentifier:
Priority: 0
Prefab: {fileID: 6973439230367005604, guid: f1daf3f500b22a048bbbad4287c2fcb2, type: 3}
insertIndex: -1
content: {fileID: 1704581577}
maxLength: 6
reader:
LogicChain: []
--- !u!1 &1352513146
@ -672,7 +674,7 @@ PrefabInstance:
- target: {fileID: 5195354181806561359, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f,
type: 3}
propertyPath: m_AnchoredPosition.y
value: 5.547437e-10
value: -0.000048249298
objectReference: {fileID: 0}
- target: {fileID: 5195354181806561359, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f,
type: 3}
@ -682,7 +684,7 @@ PrefabInstance:
- target: {fileID: 5195354181806561359, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f,
type: 3}
propertyPath: m_AnchoredPosition.x
value: -0.00002576159
value: -0.000075660755
objectReference: {fileID: 0}
- target: {fileID: 5195354182462625304, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f,
type: 3}
@ -808,7 +810,7 @@ PrefabInstance:
type: 3}
propertyPath: inventory
value:
objectReference: {fileID: 11400000, guid: 9f2bac6895147d444858493b9609d026,
objectReference: {fileID: 11400000, guid: eea1505cebc20b64b8c421ba71e10781,
type: 2}
- target: {fileID: 2665231842396078511, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f,
type: 3}
@ -958,7 +960,7 @@ PrefabInstance:
- target: {fileID: 5195354183101525346, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f,
type: 3}
propertyPath: m_AspectRatio
value: 8.548341
value: 41.85203
objectReference: {fileID: 0}
- target: {fileID: 5195354183134146559, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f,
type: 3}
@ -1070,6 +1072,51 @@ PrefabInstance:
propertyPath: m_Sprite
value:
objectReference: {fileID: 10911, guid: 0000000000000000f000000000000000, type: 0}
- target: {fileID: 2665231842684883354, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f,
type: 3}
propertyPath: m_AnchoredPosition.y
value: -16.199997
objectReference: {fileID: 0}
- target: {fileID: 9187876604664920423, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f,
type: 3}
propertyPath: m_AnchorMin.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 9187876604664920423, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f,
type: 3}
propertyPath: m_AnchorMin.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 9187876604664920423, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f,
type: 3}
propertyPath: m_AnchorMax.x
value: 1
objectReference: {fileID: 0}
- target: {fileID: 9187876604664920423, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f,
type: 3}
propertyPath: m_AnchorMax.y
value: 1
objectReference: {fileID: 0}
- target: {fileID: 9187876604664920423, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f,
type: 3}
propertyPath: m_SizeDelta.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 9187876604664920423, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f,
type: 3}
propertyPath: m_SizeDelta.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 9187876604664920423, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f,
type: 3}
propertyPath: m_AnchoredPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 9187876604664920423, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f,
type: 3}
propertyPath: m_AnchoredPosition.y
value: 0
objectReference: {fileID: 0}
m_RemovedComponents:
- {fileID: 5195354182462625307, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f, type: 3}
- {fileID: 5195354183157824118, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f, type: 3}

+ 5
- 0
Assets/Scripts/Logic/BlockReader.cs View File

@ -31,6 +31,11 @@ public class BlockReader
/// </summary>
public LogicBlock CurrentBlock { get { return ((currentBlockIndex < LogicChain.Count) ? LogicChain[currentBlockIndex] : null); } }
/// <summary>
/// Sum of size of all Blocks in the chain
/// </summary>
public int Length { get { int retVal = 0; LogicChain.ForEach(p => retVal += p.Size()); return retVal; } }
#endregion Read-only Variables
#region Private Variables

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

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

+ 14
- 0
Assets/Scripts/UI/BagItem.cs View File

@ -20,6 +20,10 @@ public class BagItem : LogicElementHolder
private TextMeshProUGUI CountText;
#endregion Private Variables
#region Read Only
#endregion Read Only
#region Class Functionality
public void Initialise(Inventory.Data data)
@ -82,6 +86,16 @@ public class BagItem : LogicElementHolder
}
/// <summary>
/// Called to check if this holder can hold the provided element;
/// </summary>
/// <param name="element">element to check if it can hold</param>
/// <returns>returns true if this can hold the element </returns>
public override bool canHold(LogicElementUI element)
{
return element.logicElement.isSameType(InventoryData.element);
}
/// <summary>
/// Called when an element in this holder is double clicked
/// </summary>

+ 12
- 0
Assets/Scripts/UI/ILogicElementHolder.cs View File

@ -14,6 +14,10 @@ public abstract class LogicElementHolder : MonoBehaviour
/// </summary>
private static List<LogicElementHolder> EnabledHolders = new List<LogicElementHolder>();
[Tooltip("An Element with a higher priority will be used if two object overlap")]
public int Priority = 0;
#region Unity Functions
protected virtual void OnEnable()
{
@ -64,6 +68,14 @@ public abstract class LogicElementHolder : MonoBehaviour
public abstract void OnDoubleClick(LogicElementUI element);
/// <summary>
/// Called to check if this holder can hold the provided element;
/// </summary>
/// <param name="element">element to check if it can hold</param>
/// <returns>returns true if this can hold the element </returns>
public virtual bool canHold(LogicElementUI element) { return true; }
#endregion Class Funtions
#region Static Functions

+ 30
- 0
Assets/Scripts/UI/InventoryCatch.cs View File

@ -0,0 +1,30 @@
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
public class InventoryCatch : LogicElementHolder
{
[SerializeField]
private InventoryUI InventoryUI;
public override void OnAdd(LogicElementUI element)
{
BagItem item = InventoryUI.content.FirstOrDefault(p => p.canHold(element));
if (item != default)
item.OnAdd(element);
Destroy(element.gameObject);
}
public override void OnDoubleClick(LogicElementUI element)
{
//DoNothing
}
public override void OnRemove(LogicElementUI element)
{
//DoNothing
}
}

+ 11
- 0
Assets/Scripts/UI/InventoryCatch.cs.meta View File

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

+ 6
- 0
Assets/Scripts/UI/InventoryUI.cs View File

@ -13,6 +13,9 @@ public class InventoryUI : MonoBehaviour
[SerializeField]
private Transform Parent;
public List<BagItem> content { get; private set; }
private void Start()
{
UpdateUI();
@ -34,10 +37,13 @@ public class InventoryUI : MonoBehaviour
foreach(Transform child in Parent)
Destroy(child.gameObject);
content = new List<BagItem>();
foreach (Inventory.Data data in inventory.BagItems)
{
BagItem item = Instantiate(ItemPrefab.gameObject, Parent).GetComponent<BagItem>();
item.Initialise(data);
content.Add(item);
}
}

+ 10
- 3
Assets/Scripts/UI/LogicElementUI.cs View File

@ -117,12 +117,19 @@ public class LogicElementUI : Dragable
//Call OnHoverStop to each element we are hovering over
lastHover.ForEach(p => p.OnHoverEnd(this));
//order the UIHolders by priority and get the first which will accept this
lastHover = lastHover.OrderByDescending(p => p.Priority).ToList();
lastHover.ForEach(p => Debug.Log(p.gameObject.name));
LogicElementHolder holderToAdd = lastHover.FirstOrDefault(p => p.canHold(this));
//If we are still hovering over anything add this to it
//Else add it back to where it came from
if (lastHover.Count > 0)
if (holderToAdd != default)
{
lastHover[0].OnAdd(this);
currentHolder = lastHover[0];
holderToAdd.OnAdd(this);
currentHolder = holderToAdd;
}
else
currentHolder.OnAdd(this);

+ 29
- 6
Assets/Scripts/UI/LogicTrayUI.cs View File

@ -15,6 +15,8 @@ public class LogicTrayUI : LogicElementHolder
protected int insertIndex = -1;
[SerializeField]
private Transform content;
[SerializeField]
private int maxLength = 6;
[SerializeField]
public BlockReader reader;
@ -72,8 +74,17 @@ public class LogicTrayUI : LogicElementHolder
if (insertIndex != -1)
{
GameObject elementObject = Instantiate(Prefab.gameObject, content);
elementObject.GetComponentInChildren<TextMeshProUGUI>().text = "insert";
elementObject.GetComponentInChildren<Image>().color = new Color(0.5f, 0.5f, 0.5f, 0.25f);
if (reader.Length < maxLength)
{
elementObject.GetComponentInChildren<TextMeshProUGUI>().text = "insert";
elementObject.GetComponentInChildren<Image>().color = new Color(0.5f, 0.5f, 0.5f, 0.25f);
}
else
{
elementObject.GetComponentInChildren<TextMeshProUGUI>().text = "X";
elementObject.GetComponentInChildren<Image>().color = new Color(1.0f, 0.25f, 0.25f, 0.5f);
}
//Set sibling index to where we want it in list + add destroyedCount since technically they are still here
elementObject.transform.SetSiblingIndex(destroyedCount + insertIndex);
@ -91,8 +102,8 @@ public class LogicTrayUI : LogicElementHolder
/// <param name="element">Element which is being dragged</param>
public override void OnRemove(LogicElementUI element)
{
Vector2 offset = new Vector2(element.rectTransform.rect.width/2, 0);
int index = GetInsertIndex(element.rectTransform,offset);
Vector2 offset = new Vector2(element.rectTransform.rect.width / 2, 0);
int index = GetInsertIndex(element.rectTransform, offset);
if (index >= reader.LogicChain.Count)
index = reader.LogicChain.Count - 1;
reader.LogicChain.RemoveAt(index);
@ -142,7 +153,6 @@ public class LogicTrayUI : LogicElementHolder
insertIndex = -1;
UpdateDisplay();
}
#endregion LogicElementHolder Implementation
/// <summary>
/// Called when an element in this holder is double clicked
@ -153,6 +163,20 @@ public class LogicTrayUI : LogicElementHolder
throw new System.NotImplementedException();
}
/// <summary>
/// Called to check if this holder can hold the provided element;
/// </summary>
/// <param name="element">element to check if it can hold</param>
/// <returns>returns true if this can hold the element </returns>
public override bool canHold(LogicElementUI element)
{
return reader.Length < maxLength;
}
#endregion LogicElementHolder Implementation
#region Helper Functions
public int GetInsertIndex(RectTransform rt, Vector2 offset)
@ -175,7 +199,6 @@ public class LogicTrayUI : LogicElementHolder
return GetInsertIndex(rt, Vector2.zero);
}
#endregion Helper Functions
}

Loading…
Cancel
Save