From 64be9103e8221585b5888bec4ddb34123bb9a864 Mon Sep 17 00:00:00 2001 From: Joshua Reason Date: Mon, 25 Mar 2019 23:58:56 +1100 Subject: [PATCH] More UI work --- Assets/Data.meta | 8 ++ Assets/Data/Inventory.meta | 8 ++ Assets/Data/Inventory/PlayerInventory.asset | 3 + .../Data/Inventory/PlayerInventory.asset.meta | 8 ++ Assets/{ => Data}/Logic Blocks.meta | 0 Assets/Data/Logic Blocks/ForLoop.asset | 3 + .../Logic Blocks/ForLoop.asset.meta | 0 Assets/Data/Logic Blocks/Jump.asset | 3 + .../{ => Data}/Logic Blocks/Jump.asset.meta | 0 Assets/Data/Logic Blocks/Move x2.asset | 3 + .../Logic Blocks/Move x2.asset.meta | 0 Assets/Data/Logic Blocks/Move.asset | 3 + .../{ => Data}/Logic Blocks/Move.asset.meta | 0 Assets/Data/Logic Blocks/Rotate Left.asset | 3 + .../Logic Blocks/Rotate Left.asset.meta | 0 Assets/Data/Logic Blocks/Rotate Right.asset | 3 + .../Logic Blocks/Rotate Right.asset.meta | 0 Assets/Scenes/UI_TestScene.unity | 79 ++++++++++--------- Assets/Scripts/Inventory.cs | 50 ++++++++++++ Assets/Scripts/Inventory.cs.meta | 11 +++ Assets/Scripts/UI/BagItem.cs | 11 ++- Assets/Scripts/UI/Dragable.cs | 5 +- Assets/Scripts/UI/InventoryUI.cs | 18 +++++ Assets/Scripts/UI/InventoryUI.cs.meta | 11 +++ Assets/Scripts/UI/LogicElementUI.cs | 13 +-- Assets/Scripts/UI/LogicTrayUI.cs | 11 ++- 26 files changed, 203 insertions(+), 51 deletions(-) create mode 100644 Assets/Data.meta create mode 100644 Assets/Data/Inventory.meta create mode 100644 Assets/Data/Inventory/PlayerInventory.asset create mode 100644 Assets/Data/Inventory/PlayerInventory.asset.meta rename Assets/{ => Data}/Logic Blocks.meta (100%) create mode 100644 Assets/Data/Logic Blocks/ForLoop.asset rename Assets/{ => Data}/Logic Blocks/ForLoop.asset.meta (100%) create mode 100644 Assets/Data/Logic Blocks/Jump.asset rename Assets/{ => Data}/Logic Blocks/Jump.asset.meta (100%) create mode 100644 Assets/Data/Logic Blocks/Move x2.asset rename Assets/{ => Data}/Logic Blocks/Move x2.asset.meta (100%) create mode 100644 Assets/Data/Logic Blocks/Move.asset rename Assets/{ => Data}/Logic Blocks/Move.asset.meta (100%) create mode 100644 Assets/Data/Logic Blocks/Rotate Left.asset rename Assets/{ => Data}/Logic Blocks/Rotate Left.asset.meta (100%) create mode 100644 Assets/Data/Logic Blocks/Rotate Right.asset rename Assets/{ => Data}/Logic Blocks/Rotate Right.asset.meta (100%) create mode 100644 Assets/Scripts/Inventory.cs create mode 100644 Assets/Scripts/Inventory.cs.meta create mode 100644 Assets/Scripts/UI/InventoryUI.cs create mode 100644 Assets/Scripts/UI/InventoryUI.cs.meta diff --git a/Assets/Data.meta b/Assets/Data.meta new file mode 100644 index 0000000..ac2e88d --- /dev/null +++ b/Assets/Data.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 74b59a15d9c2e30459e9b45b426c0972 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Data/Inventory.meta b/Assets/Data/Inventory.meta new file mode 100644 index 0000000..83c97f9 --- /dev/null +++ b/Assets/Data/Inventory.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 2b285f3ab1dbf58489314e4a2ae4d931 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Data/Inventory/PlayerInventory.asset b/Assets/Data/Inventory/PlayerInventory.asset new file mode 100644 index 0000000..1bce486 --- /dev/null +++ b/Assets/Data/Inventory/PlayerInventory.asset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0c95bbb6ed08b700412d51e115fe5989b61124432da37f0bf4b4d51dc54cd8f2 +size 415 diff --git a/Assets/Data/Inventory/PlayerInventory.asset.meta b/Assets/Data/Inventory/PlayerInventory.asset.meta new file mode 100644 index 0000000..aa528b5 --- /dev/null +++ b/Assets/Data/Inventory/PlayerInventory.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: b6fa892e4c159bf46a2c4cda19627e97 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Logic Blocks.meta b/Assets/Data/Logic Blocks.meta similarity index 100% rename from Assets/Logic Blocks.meta rename to Assets/Data/Logic Blocks.meta diff --git a/Assets/Data/Logic Blocks/ForLoop.asset b/Assets/Data/Logic Blocks/ForLoop.asset new file mode 100644 index 0000000..8003853 --- /dev/null +++ b/Assets/Data/Logic Blocks/ForLoop.asset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:815e838d40fc858ba3fca1d9f6ac75c76fdd5b6e1859a7145c142a7f636d3a5f +size 616 diff --git a/Assets/Logic Blocks/ForLoop.asset.meta b/Assets/Data/Logic Blocks/ForLoop.asset.meta similarity index 100% rename from Assets/Logic Blocks/ForLoop.asset.meta rename to Assets/Data/Logic Blocks/ForLoop.asset.meta diff --git a/Assets/Data/Logic Blocks/Jump.asset b/Assets/Data/Logic Blocks/Jump.asset new file mode 100644 index 0000000..3f6b9f7 --- /dev/null +++ b/Assets/Data/Logic Blocks/Jump.asset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4b1a4c27ea4794695f72f8d3f5d345c28103a2b6cc53e67b8f24f0757617b5e7 +size 449 diff --git a/Assets/Logic Blocks/Jump.asset.meta b/Assets/Data/Logic Blocks/Jump.asset.meta similarity index 100% rename from Assets/Logic Blocks/Jump.asset.meta rename to Assets/Data/Logic Blocks/Jump.asset.meta diff --git a/Assets/Data/Logic Blocks/Move x2.asset b/Assets/Data/Logic Blocks/Move x2.asset new file mode 100644 index 0000000..44e05d1 --- /dev/null +++ b/Assets/Data/Logic Blocks/Move x2.asset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6cd2eb3de9510a6319b174a92b11d1966b6f1bf6258b95c60b88af35c2666499 +size 437 diff --git a/Assets/Logic Blocks/Move x2.asset.meta b/Assets/Data/Logic Blocks/Move x2.asset.meta similarity index 100% rename from Assets/Logic Blocks/Move x2.asset.meta rename to Assets/Data/Logic Blocks/Move x2.asset.meta diff --git a/Assets/Data/Logic Blocks/Move.asset b/Assets/Data/Logic Blocks/Move.asset new file mode 100644 index 0000000..1593ce1 --- /dev/null +++ b/Assets/Data/Logic Blocks/Move.asset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8f30f384f120eeb69292d9ff04a9e267e536ef80a35c6a7820a032e88257d9e8 +size 434 diff --git a/Assets/Logic Blocks/Move.asset.meta b/Assets/Data/Logic Blocks/Move.asset.meta similarity index 100% rename from Assets/Logic Blocks/Move.asset.meta rename to Assets/Data/Logic Blocks/Move.asset.meta diff --git a/Assets/Data/Logic Blocks/Rotate Left.asset b/Assets/Data/Logic Blocks/Rotate Left.asset new file mode 100644 index 0000000..da3c338 --- /dev/null +++ b/Assets/Data/Logic Blocks/Rotate Left.asset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:323f3c70cf40755730cb81a31da6a58931177674b836d0b5bbc8b9f88af4b447 +size 456 diff --git a/Assets/Logic Blocks/Rotate Left.asset.meta b/Assets/Data/Logic Blocks/Rotate Left.asset.meta similarity index 100% rename from Assets/Logic Blocks/Rotate Left.asset.meta rename to Assets/Data/Logic Blocks/Rotate Left.asset.meta diff --git a/Assets/Data/Logic Blocks/Rotate Right.asset b/Assets/Data/Logic Blocks/Rotate Right.asset new file mode 100644 index 0000000..45391ed --- /dev/null +++ b/Assets/Data/Logic Blocks/Rotate Right.asset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a6886b6e048617b3ecd1de69b35f0e598467d7d2444a59a26f58fcb16a988960 +size 457 diff --git a/Assets/Logic Blocks/Rotate Right.asset.meta b/Assets/Data/Logic Blocks/Rotate Right.asset.meta similarity index 100% rename from Assets/Logic Blocks/Rotate Right.asset.meta rename to Assets/Data/Logic Blocks/Rotate Right.asset.meta diff --git a/Assets/Scenes/UI_TestScene.unity b/Assets/Scenes/UI_TestScene.unity index 16d2bb6..ddb630f 100644 --- a/Assets/Scenes/UI_TestScene.unity +++ b/Assets/Scenes/UI_TestScene.unity @@ -380,7 +380,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: d900b6d035606e046acdf763c041a7c9, type: 3} m_Name: m_EditorClassIdentifier: - logicElement: {fileID: 0} + logicElement: {fileID: 11400000, guid: 8f19e10be0ee35345a97f600791a8747, type: 2} --- !u!1 &325775536 GameObject: m_ObjectHideFlags: 0 @@ -1612,7 +1612,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, y: 0.000037354246} + m_AnchoredPosition: {x: 0, y: 0.000038146973} m_SizeDelta: {x: 0, y: 0} m_Pivot: {x: 0, y: 1} --- !u!114 &1011283039 @@ -1847,7 +1847,7 @@ MonoBehaviour: m_BlockingObjects: 0 m_BlockingMask: serializedVersion: 2 - m_Bits: 4294967295 + m_Bits: 307 --- !u!114 &1152072199 MonoBehaviour: m_ObjectHideFlags: 0 @@ -1903,8 +1903,8 @@ RectTransform: m_LocalScale: {x: 0, y: 0, z: 0} m_Children: - {fileID: 1822524397} - - {fileID: 1656111474} - {fileID: 5884576982143469529} + - {fileID: 1656111474} m_Father: {fileID: 0} m_RootOrder: 2 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} @@ -2258,13 +2258,13 @@ RectTransform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1656111473} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalPosition: {x: 0, y: 0, z: 83} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: - {fileID: 325775537} - {fileID: 1843091044} m_Father: {fileID: 1152072201} - m_RootOrder: 1 + m_RootOrder: 2 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 0.5} m_AnchorMax: {x: 1, y: 0.5} @@ -3031,21 +3031,6 @@ PrefabInstance: propertyPath: m_Pivot.y value: 0.5 objectReference: {fileID: 0} - - target: {fileID: 6169085588047038480, guid: f846db1cf36a645479ce131a2e0cf72f, - type: 3} - propertyPath: m_Color.g - value: 0.89918447 - objectReference: {fileID: 0} - - target: {fileID: 6169085588047038480, guid: f846db1cf36a645479ce131a2e0cf72f, - type: 3} - propertyPath: m_Color.b - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 6169085588047038480, guid: f846db1cf36a645479ce131a2e0cf72f, - type: 3} - propertyPath: m_Color.a - value: 0.8235294 - objectReference: {fileID: 0} - target: {fileID: 8025955820145340651, guid: f846db1cf36a645479ce131a2e0cf72f, type: 3} propertyPath: m_havePropertiesChanged @@ -3076,6 +3061,26 @@ PrefabInstance: propertyPath: m_isInputParsingRequired value: 1 objectReference: {fileID: 0} + - target: {fileID: 1988277319744889208, guid: f846db1cf36a645479ce131a2e0cf72f, + type: 3} + propertyPath: m_Layer + value: 2 + objectReference: {fileID: 0} + - target: {fileID: 6169085588047038480, guid: f846db1cf36a645479ce131a2e0cf72f, + type: 3} + propertyPath: m_Color.g + value: 0.89918447 + objectReference: {fileID: 0} + - target: {fileID: 6169085588047038480, guid: f846db1cf36a645479ce131a2e0cf72f, + type: 3} + propertyPath: m_Color.b + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 6169085588047038480, guid: f846db1cf36a645479ce131a2e0cf72f, + type: 3} + propertyPath: m_Color.a + value: 0.8235294 + objectReference: {fileID: 0} m_RemovedComponents: - {fileID: 5230025352354844899, guid: f846db1cf36a645479ce131a2e0cf72f, type: 3} m_SourcePrefab: {fileID: 100100000, guid: f846db1cf36a645479ce131a2e0cf72f, type: 3} @@ -3237,7 +3242,7 @@ PrefabInstance: - target: {fileID: 5884576982143469529, guid: f846db1cf36a645479ce131a2e0cf72f, type: 3} propertyPath: m_RootOrder - value: 2 + value: 1 objectReference: {fileID: 0} - target: {fileID: 5884576982143469529, guid: f846db1cf36a645479ce131a2e0cf72f, type: 3} @@ -3324,6 +3329,21 @@ PrefabInstance: propertyPath: m_isInputParsingRequired value: 1 objectReference: {fileID: 0} + - target: {fileID: 6110492942520467780, guid: f846db1cf36a645479ce131a2e0cf72f, + type: 3} + propertyPath: m_havePropertiesChanged + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 6110492942520467780, guid: f846db1cf36a645479ce131a2e0cf72f, + type: 3} + propertyPath: m_isInputParsingRequired + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 5230025352354844899, guid: f846db1cf36a645479ce131a2e0cf72f, + type: 3} + propertyPath: dragOnSurfaces + value: 1 + objectReference: {fileID: 0} - target: {fileID: 1307774795787687732, guid: f846db1cf36a645479ce131a2e0cf72f, type: 3} propertyPath: m_LocalRotation.y @@ -3364,21 +3384,6 @@ PrefabInstance: propertyPath: m_LocalRotation.z value: 0 objectReference: {fileID: 0} - - target: {fileID: 5230025352354844899, guid: f846db1cf36a645479ce131a2e0cf72f, - type: 3} - propertyPath: dragOnSurfaces - value: 1 - objectReference: {fileID: 0} - - target: {fileID: 6110492942520467780, guid: f846db1cf36a645479ce131a2e0cf72f, - type: 3} - propertyPath: m_havePropertiesChanged - value: 1 - objectReference: {fileID: 0} - - target: {fileID: 6110492942520467780, guid: f846db1cf36a645479ce131a2e0cf72f, - type: 3} - propertyPath: m_isInputParsingRequired - value: 1 - objectReference: {fileID: 0} m_RemovedComponents: [] m_SourcePrefab: {fileID: 100100000, guid: f846db1cf36a645479ce131a2e0cf72f, type: 3} --- !u!224 &5884576982143469529 stripped diff --git a/Assets/Scripts/Inventory.cs b/Assets/Scripts/Inventory.cs new file mode 100644 index 0000000..c9d9f1d --- /dev/null +++ b/Assets/Scripts/Inventory.cs @@ -0,0 +1,50 @@ +using System.Linq; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +[CreateAssetMenu(menuName = "Major Project/Inventory", order = 150)] +public class Inventory : ScriptableObject +{ + [SerializeField] + protected List AllElements = new List(); + + public void Add(LogicBlock element) + { + + InventoryData data; + + try + { + data = AllElements.First(p => p.element == element); + } + catch + { + data = new InventoryData() { element = element }; + AllElements.Add(data); + } + + data.Count++; + } + + public void Remove(LogicBlock element) { + + if (!AllElements.Exists(p => p.element == element)) + return; + + InventoryData data = AllElements.First(p => p.element == element); + + if (!data.infinit) + data.Count--; + } + + + + [System.Serializable] + public class InventoryData + { + public LogicBlock element; + public int Count; + public bool infinit = false; + } +} diff --git a/Assets/Scripts/Inventory.cs.meta b/Assets/Scripts/Inventory.cs.meta new file mode 100644 index 0000000..6c9ecec --- /dev/null +++ b/Assets/Scripts/Inventory.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: ff7eab8b11178b24ca0b41861f79cadd +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/UI/BagItem.cs b/Assets/Scripts/UI/BagItem.cs index 9a24d11..256f264 100644 --- a/Assets/Scripts/UI/BagItem.cs +++ b/Assets/Scripts/UI/BagItem.cs @@ -27,6 +27,12 @@ public class BagItem : Dragable { base.OnDrag(data); DoTrayLogic(data); + + string output = ""; + foreach (GameObject hover in data.hovered) + output += hover.name + " "; + Debug.Log(output); + } protected virtual void DoTrayLogic(PointerEventData data) @@ -48,7 +54,7 @@ public class BagItem : Dragable }else if (isHovered) { isHovered = false; - tray.OnHoverEnd(this, rt); + tray.OnHoverEnd(this); } } @@ -60,7 +66,8 @@ public class BagItem : Dragable if (isHovered) { isHovered = false; - //tray.OnHoverEnd(this, rt); + tray.InsertLogicElement(logicElement); + tray.OnHoverEnd(this); } } diff --git a/Assets/Scripts/UI/Dragable.cs b/Assets/Scripts/UI/Dragable.cs index 03324bf..1e1c642 100644 --- a/Assets/Scripts/UI/Dragable.cs +++ b/Assets/Scripts/UI/Dragable.cs @@ -20,12 +20,14 @@ public class Dragable : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDrag m_DraggingIcon.transform.SetParent(canvas.transform, false); m_DraggingIcon.transform.SetAsLastSibling(); + m_DraggingIcon.layer = LayerMask.NameToLayer("Ignore Raycast"); var image = m_DraggingIcon.AddComponent(); image.sprite = GetComponent().sprite; image.SetNativeSize(); + m_DraggingPlane = canvas.transform as RectTransform; SetDraggedPosition(eventData); @@ -50,7 +52,8 @@ public class Dragable : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDrag public virtual void OnEndDrag(PointerEventData eventData) { - + Destroy(m_DraggingIcon); + m_DraggingIcon = null; } static public T FindInParents(GameObject go) where T : Component diff --git a/Assets/Scripts/UI/InventoryUI.cs b/Assets/Scripts/UI/InventoryUI.cs new file mode 100644 index 0000000..a184396 --- /dev/null +++ b/Assets/Scripts/UI/InventoryUI.cs @@ -0,0 +1,18 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class InventoryUI : MonoBehaviour +{ + // Start is called before the first frame update + void Start() + { + + } + + // Update is called once per frame + void Update() + { + + } +} diff --git a/Assets/Scripts/UI/InventoryUI.cs.meta b/Assets/Scripts/UI/InventoryUI.cs.meta new file mode 100644 index 0000000..d03a363 --- /dev/null +++ b/Assets/Scripts/UI/InventoryUI.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 36cc4df775c8e8b46a89972d8008d56d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/UI/LogicElementUI.cs b/Assets/Scripts/UI/LogicElementUI.cs index 849e2cb..310d132 100644 --- a/Assets/Scripts/UI/LogicElementUI.cs +++ b/Assets/Scripts/UI/LogicElementUI.cs @@ -4,15 +4,8 @@ using UnityEngine; public class LogicElementUI : MonoBehaviour { - // Start is called before the first frame update - void Start() - { - - } - // Update is called once per frame - void Update() - { - - } + LogicBlock LogicElement; + + } diff --git a/Assets/Scripts/UI/LogicTrayUI.cs b/Assets/Scripts/UI/LogicTrayUI.cs index b6496f6..6e4dec6 100644 --- a/Assets/Scripts/UI/LogicTrayUI.cs +++ b/Assets/Scripts/UI/LogicTrayUI.cs @@ -28,12 +28,21 @@ public class LogicTrayUI : MonoBehaviour UpdateDisplay(); } - public void OnHoverEnd(BagItem item, RectTransform rect) + public void OnHoverEnd(BagItem item) { insertIndex = -1; UpdateDisplay(); } + public void InsertLogicElement(LogicBlock item) + { + if (insertIndex >= 0 && insertIndex <= list.Count) + { + list.Insert(insertIndex, item); + } + UpdateDisplay(); + } + public void OnHoverUpdate(BagItem item, RectTransform rect) {