diff --git a/Assets/Data/Inventory/BaseInventory.asset b/Assets/Data/Inventory/BaseInventory.asset index 010ea95..423f7ed 100644 --- a/Assets/Data/Inventory/BaseInventory.asset +++ b/Assets/Data/Inventory/BaseInventory.asset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:c5679085887a5b78c9d233a70d5fd0ce061945cbe7f8cb80ddfaf9634f6aa58f -size 970 +oid sha256:1d0672a6b3709593b57d6964e247a9ccf9ecc89b29d7cc88a1bbf5de996e3296 +size 979 diff --git a/Assets/Scenes/Client Scenes/ClientScene.unity b/Assets/Scenes/Client Scenes/ClientScene.unity index c49a628..6e57139 100644 --- a/Assets/Scenes/Client Scenes/ClientScene.unity +++ b/Assets/Scenes/Client Scenes/ClientScene.unity @@ -314,7 +314,8 @@ RectTransform: 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_Children: + - {fileID: 1593162621} m_Father: {fileID: 5195354181466942484} m_RootOrder: 1 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} @@ -446,6 +447,134 @@ CanvasRenderer: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1363815576} m_CullTransparentMesh: 0 +--- !u!1 &1593162620 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1593162621} + - component: {fileID: 1593162624} + - component: {fileID: 1593162623} + - component: {fileID: 1593162622} + m_Layer: 0 + m_Name: Button + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &1593162621 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1593162620} + 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: 1363815577} + 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: 0, y: 0.6498871} + m_SizeDelta: {x: 0, y: -0.49163055} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!114 &1593162622 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1593162620} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 1392445389, guid: f70555f144d8491a825f0804e09c671c, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Navigation: + m_Mode: 3 + m_SelectOnUp: {fileID: 0} + m_SelectOnDown: {fileID: 0} + m_SelectOnLeft: {fileID: 0} + m_SelectOnRight: {fileID: 0} + m_Transition: 1 + m_Colors: + m_NormalColor: {r: 1, g: 1, b: 1, a: 1} + m_HighlightedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1} + m_PressedColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 1} + m_DisabledColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 0.5019608} + m_ColorMultiplier: 1 + m_FadeDuration: 0.1 + m_SpriteState: + m_HighlightedSprite: {fileID: 0} + m_PressedSprite: {fileID: 0} + m_DisabledSprite: {fileID: 0} + m_AnimationTriggers: + m_NormalTrigger: Normal + m_HighlightedTrigger: Highlighted + m_PressedTrigger: Pressed + m_DisabledTrigger: Disabled + m_Interactable: 1 + m_TargetGraphic: {fileID: 1593162623} + m_OnClick: + m_PersistentCalls: + m_Calls: + - m_Target: {fileID: 5195354181466942483} + m_MethodName: On_ClickPauseTime + m_Mode: 1 + m_Arguments: + m_ObjectArgument: {fileID: 0} + m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine + m_IntArgument: 0 + m_FloatArgument: 0 + m_StringArgument: + m_BoolArgument: 0 + m_CallState: 2 + m_TypeName: UnityEngine.UI.Button+ButtonClickedEvent, UnityEngine.UI, Version=1.0.0.0, + Culture=neutral, PublicKeyToken=null +--- !u!114 &1593162623 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1593162620} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: -765806418, guid: f70555f144d8491a825f0804e09c671c, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Material: {fileID: 0} + m_Color: {r: 1, g: 1, b: 1, a: 0} + m_RaycastTarget: 1 + m_OnCullStateChanged: + m_PersistentCalls: + m_Calls: [] + m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI, + Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + m_Sprite: {fileID: 10905, guid: 0000000000000000f000000000000000, type: 0} + m_Type: 1 + m_PreserveAspect: 0 + m_FillCenter: 1 + m_FillMethod: 4 + m_FillAmount: 1 + m_FillClockwise: 1 + m_FillOrigin: 0 + m_UseSpriteMesh: 0 +--- !u!222 &1593162624 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1593162620} + m_CullTransparentMesh: 0 --- !u!224 &1704581577 stripped RectTransform: m_CorrespondingSourceObject: {fileID: 5195354181806561359, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f, @@ -543,7 +672,7 @@ PrefabInstance: - target: {fileID: 5195354181806561359, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f, type: 3} propertyPath: m_AnchoredPosition.y - value: -0.000015258307 + value: -0.00009918213 objectReference: {fileID: 0} - target: {fileID: 5195354181806561359, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f, type: 3} @@ -553,7 +682,7 @@ PrefabInstance: - target: {fileID: 5195354181806561359, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f, type: 3} propertyPath: m_AnchoredPosition.x - value: 0.000007958263 + value: -0.000039558963 objectReference: {fileID: 0} - target: {fileID: 5195354183134146528, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f, type: 3} @@ -689,12 +818,12 @@ PrefabInstance: - target: {fileID: 5195354181796512270, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f, type: 3} propertyPath: m_havePropertiesChanged - value: 1 + value: 0 objectReference: {fileID: 0} - target: {fileID: 5195354181796512270, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f, type: 3} propertyPath: m_isInputParsingRequired - value: 1 + value: 0 objectReference: {fileID: 0} - target: {fileID: 2665231842396078511, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f, type: 3} @@ -854,12 +983,12 @@ PrefabInstance: - target: {fileID: 2665231841929910945, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f, type: 3} propertyPath: m_havePropertiesChanged - value: 1 + value: 0 objectReference: {fileID: 0} - target: {fileID: 2665231841929910945, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f, type: 3} propertyPath: m_isInputParsingRequired - value: 1 + value: 0 objectReference: {fileID: 0} - target: {fileID: 2665231841929910945, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f, type: 3} diff --git a/Assets/Scripts/Inventory.cs b/Assets/Scripts/Inventory.cs index 5a7bf5b..e0942bc 100644 --- a/Assets/Scripts/Inventory.cs +++ b/Assets/Scripts/Inventory.cs @@ -7,6 +7,8 @@ using UnityEngine; public class Inventory : ScriptableObject { + public string test; + public List BagItems { get { if (_bagItems == null) _bagItems = new List(); return _bagItems; } } [SerializeField] @@ -28,9 +30,9 @@ public class Inventory : ScriptableObject public void Add(Data data) { - if (_bagItems.Contains(data)) + if (_bagItems.Exists(p => p.element.isSameType(data.element))) { - Data bagData = BagItems.Find(p => p.Equals(data)); + Data bagData = BagItems.Find(p => p.element.isSameType(data.element)); bagData.Count += data.Count; bagData.isInfinit = (data.isInfinit || bagData.isInfinit); @@ -43,14 +45,24 @@ public class Inventory : ScriptableObject public void Remove(LogicBlock element) { - if (!_bagItems.Exists(p => p.element == element)) + + if (!_bagItems.Exists(p => p.element.isSameType(element))) + { return; + } + - Data data = _bagItems.First(p => p.element == element); + Data data = _bagItems.First(p => p.element.isSameType(element)); if (!data.isInfinit) + { data.Count--; + if (data.Count <= 0) + _bagItems.Remove(data); + } + + OnItemsUpdated?.Invoke(); } @@ -69,7 +81,13 @@ public class Inventory : ScriptableObject public static Inventory Clone(Inventory copy) { Inventory retVal = ScriptableObject.CreateInstance(); - retVal._bagItems = new List(copy._bagItems); + retVal._bagItems = new List(); + + foreach (Data data in copy.BagItems) + { + Data dataCopy = new Data(data.element,data.Count,data.isInfinit); + retVal._bagItems.Add(dataCopy); + } return retVal; } @@ -81,5 +99,15 @@ public class Inventory : ScriptableObject public LogicBlock element; public int Count; public bool isInfinit = false; + + + public Data() { } + + public Data(LogicBlock element, int Count, bool isInfinit) + { + this.element = element; + this.Count = Count; + this.isInfinit = isInfinit; + } } } diff --git a/Assets/Scripts/Logic/BlockReader.cs b/Assets/Scripts/Logic/BlockReader.cs index 7e8bf75..d348530 100644 --- a/Assets/Scripts/Logic/BlockReader.cs +++ b/Assets/Scripts/Logic/BlockReader.cs @@ -29,7 +29,7 @@ public class BlockReader /// /// Gets the current block in the logic chain /// - public LogicBlock CurrentBlock { get { return LogicChain[currentBlockIndex]; } } + public LogicBlock CurrentBlock { get { return ((currentBlockIndex < LogicChain.Count) ? LogicChain[currentBlockIndex] : null); } } #endregion Read-only Variables diff --git a/Assets/Scripts/Logic/Blocks/LogicBlock.cs b/Assets/Scripts/Logic/Blocks/LogicBlock.cs index b1e5d4d..e7c9133 100644 --- a/Assets/Scripts/Logic/Blocks/LogicBlock.cs +++ b/Assets/Scripts/Logic/Blocks/LogicBlock.cs @@ -137,7 +137,7 @@ public abstract class LogicBlock : ScriptableObject #endregion Serialisation Functions - public override bool Equals(object other) + public bool isSameType(object other) { if (Object.ReferenceEquals(null, other)) return false; @@ -150,11 +150,6 @@ public abstract class LogicBlock : ScriptableObject && string.Equals(name, otherLogic.name); } - public override int GetHashCode() - { - return name.GetHashCode(); - } - public virtual void OnDoubleClick() { diff --git a/Assets/Scripts/Managers/GameManager.cs b/Assets/Scripts/Managers/GameManager.cs index 40c1566..7d8d437 100644 --- a/Assets/Scripts/Managers/GameManager.cs +++ b/Assets/Scripts/Managers/GameManager.cs @@ -46,7 +46,6 @@ public class GameManager : MonoBehaviour gamemode = CurrentGameMode.Value; RegisterHandlers(); SpawnCharacters(); - gamemode.GameStart(playerArray.ToArray()); ClientList.ForEach(p => p.ChangeScene("ClientScene")); } @@ -99,8 +98,9 @@ public class GameManager : MonoBehaviour { if (!player.waiting) { - if (!player.blockReader.CurrentBlock.hasBeenRemoved) + if (player.blockReader.CurrentBlock != null && !player.blockReader.CurrentBlock.hasBeenRemoved) { + Debug.Log("used Block: " + player.blockReader.CurrentBlock.name); player.client.Inventory.Remove(player.blockReader.CurrentBlock); player.blockReader.CurrentBlock.hasBeenRemoved = true; } diff --git a/Assets/Scripts/UI/LogicTrayUI.cs b/Assets/Scripts/UI/LogicTrayUI.cs index d9320f2..e6a2845 100644 --- a/Assets/Scripts/UI/LogicTrayUI.cs +++ b/Assets/Scripts/UI/LogicTrayUI.cs @@ -91,7 +91,11 @@ public class LogicTrayUI : LogicElementHolder /// Element which is being dragged public override void OnRemove(LogicElementUI element) { - reader.Remove(element.logicElement); + 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); } /// @@ -151,9 +155,10 @@ public class LogicTrayUI : LogicElementHolder #region Helper Functions - public int GetInsertIndex(RectTransform rt) + public int GetInsertIndex(RectTransform rt, Vector2 offset) { Rect rect = rt.GlobalRect(); + rect.center += offset; foreach (Transform child in content) { @@ -165,6 +170,11 @@ public class LogicTrayUI : LogicElementHolder return reader.LogicChain.Count; } + public int GetInsertIndex(RectTransform rt) + { + return GetInsertIndex(rt, Vector2.zero); + } + #endregion Helper Functions diff --git a/Assets/Scripts/UI/NetworkedUIManager.cs b/Assets/Scripts/UI/NetworkedUIManager.cs index 7dc055e..209268f 100644 --- a/Assets/Scripts/UI/NetworkedUIManager.cs +++ b/Assets/Scripts/UI/NetworkedUIManager.cs @@ -17,6 +17,9 @@ public class NetworkedUIManager : PlayerUIManager [SerializeField] private float TotalTime; + [Header("Debug")] + [SerializeField] + private bool isTimePaused; private float StartTime; @@ -29,14 +32,18 @@ public class NetworkedUIManager : PlayerUIManager TrayUI.SetBlockReader(reader); StartTime = Time.time; ShowPosition.y -= Title.rect.height; + OnClick_Show(); } private void Update() { - TimeText.text = ((int)(TotalTime - (Time.time - StartTime))).ToString(); + if (!isTimePaused) + { + TimeText.text = ((int)(TotalTime - (Time.time - StartTime))).ToString(); - if (Time.time - StartTime > TotalTime) - OnClick_Play(); + if (Time.time - StartTime > TotalTime) + OnClick_Play(); + } } public override void OnClick_Play() @@ -49,5 +56,14 @@ public class NetworkedUIManager : PlayerUIManager UnityEngine.SceneManagement.SceneManager.LoadScene("WaitScene"); } + public void On_ClickPauseTime() + { + isTimePaused = !isTimePaused; + + if (isTimePaused) + TimeText.color = Color.grey; + else + TimeText.color = Color.black; + } }