diff --git a/Assets/Character Stats/Examples/Items & Inventory/Prefabs/Character Panel.prefab b/Assets/Character Stats/Examples/Items & Inventory/Prefabs/Character Panel.prefab index 9923b525..ae69df55 100644 --- a/Assets/Character Stats/Examples/Items & Inventory/Prefabs/Character Panel.prefab +++ b/Assets/Character Stats/Examples/Items & Inventory/Prefabs/Character Panel.prefab @@ -1101,6 +1101,7 @@ MonoBehaviour: - {fileID: 11445532} - {fileID: 11458674} - {fileID: 11458568} + onJoinedRoom: {fileID: 0} OnItemRightClickedEvent: m_PersistentCalls: m_Calls: [] @@ -2965,6 +2966,7 @@ MonoBehaviour: - {fileID: 11400232} - {fileID: 11439382} - {fileID: 11417996} + onJoinedRoom: {fileID: 0} OnItemRightClickedEvent: m_PersistentCalls: m_Calls: [] diff --git a/Assets/Character Stats/Examples/Items & Inventory/Scripts/EquipmentPanel.cs b/Assets/Character Stats/Examples/Items & Inventory/Scripts/EquipmentPanel.cs index 9ae88e9b..08192a16 100644 --- a/Assets/Character Stats/Examples/Items & Inventory/Scripts/EquipmentPanel.cs +++ b/Assets/Character Stats/Examples/Items & Inventory/Scripts/EquipmentPanel.cs @@ -1,4 +1,5 @@ -using System; +using Photon.Pun; +using System; using UnityEngine; namespace Kryz.CharacterStats.Examples @@ -8,8 +9,17 @@ namespace Kryz.CharacterStats.Examples [SerializeField] Transform equipmentSlotsParent; [SerializeField] EquipmentSlot[] equipmentSlots; + [SerializeField] GameEventListener onJoinedRoom; + public UnityEvent_Item OnItemRightClickedEvent = new UnityEvent_Item(); + EquipmentData equipmentData = new EquipmentData(); + + private void Awake() + { + onJoinedRoom.Response.AddListener(LoadEquipment); + } + private void Start() { for (int i = 0; i < equipmentSlots.Length; i++) @@ -32,6 +42,9 @@ namespace Kryz.CharacterStats.Examples { previousItem = (EquippableItem)equipmentSlots[i].Item; equipmentSlots[i].Item = item; + + equipmentData.equippedItems[i] = ItemIndexer.Instance.Items.IndexOf(item); + PlayerDataHandler.Instance.SaveCharacterEquipmentData(PhotonNetwork.NickName, equipmentData); return true; } } @@ -46,6 +59,8 @@ namespace Kryz.CharacterStats.Examples if (equipmentSlots[i].Item == item) { equipmentSlots[i].Item = null; + equipmentData.equippedItems[i] = -1; + PlayerDataHandler.Instance.SaveCharacterEquipmentData(PhotonNetwork.NickName, equipmentData); return true; } } @@ -56,5 +71,29 @@ namespace Kryz.CharacterStats.Examples { return equipmentSlots; } + + public void LoadEquipment() + { + equipmentData = PlayerDataHandler.Instance.LoadCharacterEquipmentData(PhotonNetwork.NickName); + + if (equipmentData != null) + { + Debug.Log("Success Loading Equipment"); + for (int i = 0; i < equipmentData.equippedItems.Length; i++) + { + if (equipmentData.equippedItems[i] < 0) + { + equipmentSlots[i].Item = null; + } + else + { + equipmentSlots[i].Item = ItemIndexer.Instance.Items[equipmentData.equippedItems[i]]; + } + } + } + else + equipmentData = new EquipmentData(); + } + } } diff --git a/Assets/Character Stats/Examples/Items & Inventory/Scripts/Inventory.cs b/Assets/Character Stats/Examples/Items & Inventory/Scripts/Inventory.cs index bd4135c0..eabf7889 100644 --- a/Assets/Character Stats/Examples/Items & Inventory/Scripts/Inventory.cs +++ b/Assets/Character Stats/Examples/Items & Inventory/Scripts/Inventory.cs @@ -1,4 +1,5 @@ -using System; +using Photon.Pun; +using System; using System.Collections.Generic; using UnityEngine; @@ -10,19 +11,25 @@ namespace Kryz.CharacterStats.Examples [SerializeField] Transform itemsParent; [SerializeField] ItemSlot[] itemSlots; + [SerializeField] GameEventListener onJoinedRoom; + public UnityEvent_Item OnItemRightClickedEvent = new UnityEvent_Item(); + InventoryData inventoryData = new InventoryData(); + private void Awake() { for (int i = 0; i < itemSlots.Length; i++) { itemSlots[i].OnRightClickEvent.AddListener((X) => OnItemRightClickedEvent.Invoke(X)); } + + onJoinedRoom.Response.AddListener(LoadInventory); } private void Start() { - RefreshUI(); + RefreshUI(false); } private void OnValidate() @@ -30,24 +37,33 @@ namespace Kryz.CharacterStats.Examples if (itemsParent != null) { itemSlots = itemsParent.GetComponentsInChildren(); - RefreshUI(); - + RefreshUI(false); } - } - private void RefreshUI() + private void RefreshUI(bool shouldSave) { int i = 0; for (; i < items.Count && i < itemSlots.Length; i++) { itemSlots[i].Item = items[i]; + + inventoryData.inventoryItems[i] = ItemIndexer.Instance.Items.IndexOf(items[i]); + } for (; i < itemSlots.Length; i++) { itemSlots[i].Item = null; + + inventoryData.inventoryItems[i] = -1; } + if (!Application.isPlaying) return; + if (!PhotonNetwork.IsConnected) return; + if (!PhotonNetwork.InRoom) return; + if (!shouldSave) return; + + PlayerDataHandler.Instance.SaveCharacterInventoryData(PhotonNetwork.NickName, inventoryData); } public bool AddItem(Item item) @@ -56,7 +72,8 @@ namespace Kryz.CharacterStats.Examples return false; items.Add(item); - RefreshUI(); + + RefreshUI(true); return true; } @@ -64,7 +81,7 @@ namespace Kryz.CharacterStats.Examples { if (items.Remove(item)) { - RefreshUI(); + RefreshUI(true); return true; } return false; @@ -74,5 +91,25 @@ namespace Kryz.CharacterStats.Examples { return items.Count >= itemSlots.Length; } + + public void LoadInventory() + { + inventoryData = PlayerDataHandler.Instance.LoadCharacterInventoryData(PhotonNetwork.NickName); + + if (inventoryData != null) + { + Debug.Log("Success Loading Inventory"); + for (int i = 0; i < inventoryData.inventoryItems.Length; i++) + { + if (inventoryData.inventoryItems[i] < 0) continue; + + items.Add(ItemIndexer.Instance.Items[inventoryData.inventoryItems[i]]); + } + + RefreshUI(false); + } + else + inventoryData = new InventoryData(); + } } } diff --git a/Assets/Character Stats/Examples/Items & Inventory/Scripts/PlayerCharacterStats.cs b/Assets/Character Stats/Examples/Items & Inventory/Scripts/PlayerCharacterStats.cs index b156613f..0810753b 100644 --- a/Assets/Character Stats/Examples/Items & Inventory/Scripts/PlayerCharacterStats.cs +++ b/Assets/Character Stats/Examples/Items & Inventory/Scripts/PlayerCharacterStats.cs @@ -30,7 +30,6 @@ namespace Kryz.CharacterStats.Examples public int AvailablePointsToAllocate; CharacterData characterData = new CharacterData(); - string characterDataKey; List statsCollection = new List(); @@ -41,8 +40,6 @@ namespace Kryz.CharacterStats.Examples health = player.GetComponent(); mana = player.GetComponent(); - characterDataKey = GameConstants.PlayerPrefsKeys.GetCharacterDataKey(photonView.Owner.NickName); - level = new Level(); base.Awake(); @@ -55,9 +52,11 @@ namespace Kryz.CharacterStats.Examples if (!photonView.IsMine) return; - if (GameStatePersistenceManager.Instance.HasDataForKey(characterDataKey)) + characterData = PlayerDataHandler.Instance.LoadCharacterData(photonView.Owner.NickName); + + if (characterData != null) { - characterData = GameStatePersistenceManager.Instance.LoadData(characterDataKey); + Debug.Log("Success Loading CharacterData"); level = new Level(characterData.currentLevel, characterData.currentExperience); for (int i = 0; i < statsDictionary.Keys.Count; i++) @@ -71,6 +70,8 @@ namespace Kryz.CharacterStats.Examples } else { + characterData = new CharacterData(); + for (int i = 0; i < statsDictionary.Keys.Count; i++) { AllocatedStatPoints.Add(0); @@ -122,7 +123,7 @@ namespace Kryz.CharacterStats.Examples characterData.currentLevel = level.currentLevel; characterData.currentExperience = level.GetCurrentExperience(); - GameStatePersistenceManager.Instance.SaveData(characterDataKey, characterData); + PlayerDataHandler.Instance.SaveCharacterData(photonView.Owner.NickName, characterData); } private void OnLevelUp() @@ -231,7 +232,7 @@ namespace Kryz.CharacterStats.Examples characterData.allocatedStatPoints[i] = AllocatedStatPoints[i]; } - GameStatePersistenceManager.Instance.SaveData(characterDataKey, characterData); + PlayerDataHandler.Instance.SaveCharacterData(photonView.Owner.NickName, characterData); onUpdateStatValues.Invoke(); } diff --git a/Assets/Developer/Prefabs/Persistent Objects.prefab b/Assets/Developer/Prefabs/Persistent Objects.prefab index aaabec7b..fb98f257 100644 --- a/Assets/Developer/Prefabs/Persistent Objects.prefab +++ b/Assets/Developer/Prefabs/Persistent Objects.prefab @@ -1,5 +1,49 @@ %YAML 1.1 %TAG !u! tag:unity3d.com,2011: +--- !u!1 &12404647734564934 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 783112258715650873} + - component: {fileID: 6779425038366157320} + m_Layer: 0 + m_Name: PlayerDataHandler + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &783112258715650873 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 12404647734564934} + 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_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 7475116342638198534} + m_RootOrder: 6 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &6779425038366157320 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 12404647734564934} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 40822b285732f4c4faa78e10ed5932da, type: 3} + m_Name: + m_EditorClassIdentifier: --- !u!1 &185707331849063518 GameObject: m_ObjectHideFlags: 0 @@ -222,7 +266,7 @@ Transform: m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 7475116342638198534} - m_RootOrder: 16 + m_RootOrder: 18 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!114 &8592470823058126151 MonoBehaviour: @@ -294,6 +338,111 @@ MonoBehaviour: Response: m_PersistentCalls: m_Calls: [] +--- !u!1 &5884373015434708458 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 7624448236951792051} + - component: {fileID: 2347411357801055816} + m_Layer: 0 + m_Name: ItemIndexer + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &7624448236951792051 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 5884373015434708458} + 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_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 7475116342638198534} + m_RootOrder: 1 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &2347411357801055816 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 5884373015434708458} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 89530648eb9e4314681d49de96e7f026, type: 3} + m_Name: + m_EditorClassIdentifier: + Items: + - {fileID: 11400000, guid: 7520aac8c5a8a1f469cf449dc9678082, type: 2} + - {fileID: 11400000, guid: 90bdc04dc3054564b9a95d8bcf359c1c, type: 2} + - {fileID: 11400000, guid: d3bc94c8b0e3cbc439f28e38648f9938, type: 2} + - {fileID: 11400000, guid: d27871978f2b7524fac2c4f75d09a277, type: 2} + - {fileID: 11400000, guid: 426542c729b777f4b9080801a5feda74, type: 2} + - {fileID: 11400000, guid: 205970e709df4294991e3cb066bb9d88, type: 2} + - {fileID: 11400000, guid: 26b042abfe9104448a1e9599be66e71a, type: 2} + - {fileID: 11400000, guid: e08687c26614d154cb5a9a01f4b97635, type: 2} + - {fileID: 11400000, guid: bf5ebc199ded3fa48872c4a1caeba0b2, type: 2} + - {fileID: 11400000, guid: 753401cb84e3c5c4ebaef324c0399eb0, type: 2} + - {fileID: 11400000, guid: 60a432442ce35934eb0a7170f0a113f0, type: 2} + - {fileID: 11400000, guid: e2c921ce12afad24f8780b0b7555cb0b, type: 2} +--- !u!1 &6738436602598553486 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 6496815317155126854} + - component: {fileID: 741966922129695396} + m_Layer: 0 + m_Name: OnJoinedRoom + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &6496815317155126854 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 6738436602598553486} + 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_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 7475116342346686368} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &741966922129695396 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 6738436602598553486} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: b18d3d5defd7c6845a22a1583a92bfb1, type: 3} + m_Name: + m_EditorClassIdentifier: + Event: {fileID: 11400000, guid: f1a37dbd6b4904a4f9d9834d72d99370, type: 2} + Response: + m_PersistentCalls: + m_Calls: [] --- !u!1 &7475116340738615313 GameObject: m_ObjectHideFlags: 0 @@ -373,7 +522,7 @@ Transform: m_Children: - {fileID: 7475116341325843503} m_Father: {fileID: 7475116342638198534} - m_RootOrder: 6 + m_RootOrder: 8 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!114 &7475116340768526743 MonoBehaviour: @@ -475,7 +624,7 @@ Transform: - {fileID: 7475116340738615312} - {fileID: 7475116342495084315} m_Father: {fileID: 7475116342638198534} - m_RootOrder: 2 + m_RootOrder: 3 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!114 &7475116340900335230 MonoBehaviour: @@ -675,7 +824,7 @@ Transform: m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 7475116342638198534} - m_RootOrder: 1 + m_RootOrder: 2 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!114 &7475116341184709869 MonoBehaviour: @@ -737,7 +886,7 @@ Transform: - {fileID: 168785440769009768} - {fileID: 2023319060290845352} m_Father: {fileID: 7475116342638198534} - m_RootOrder: 14 + m_RootOrder: 16 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &7475116341218466084 GameObject: @@ -769,7 +918,7 @@ Transform: m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 7475116342638198534} - m_RootOrder: 4 + m_RootOrder: 5 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!114 &7475116341218466091 MonoBehaviour: @@ -813,7 +962,7 @@ Transform: m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 7475116342638198534} - m_RootOrder: 13 + m_RootOrder: 15 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!114 &7475116341269730137 MonoBehaviour: @@ -1165,7 +1314,7 @@ Transform: m_Children: - {fileID: 7475116341368155189} m_Father: {fileID: 7475116342638198534} - m_RootOrder: 12 + m_RootOrder: 14 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!114 &7475116342078506345 MonoBehaviour: @@ -1502,9 +1651,10 @@ Transform: m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 - m_Children: [] + m_Children: + - {fileID: 6496815317155126854} m_Father: {fileID: 7475116342638198534} - m_RootOrder: 8 + m_RootOrder: 10 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!114 &7475116342346686373 MonoBehaviour: @@ -1526,6 +1676,7 @@ MonoBehaviour: - {fileID: 7475116342276826859} - {fileID: 7475116342277038037} - {fileID: 7475116342277008207} + onJoinedRoom: {fileID: 741966922129695396} OnItemRightClickedEvent: m_PersistentCalls: m_Calls: [] @@ -1597,6 +1748,7 @@ MonoBehaviour: - {fileID: 7475116342277044191} - {fileID: 7475116342277016241} - {fileID: 7475116342277016267} + onJoinedRoom: {fileID: 741966922129695396} OnItemRightClickedEvent: m_PersistentCalls: m_Calls: [] @@ -1958,7 +2110,7 @@ Transform: m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 7475116342638198534} - m_RootOrder: 10 + m_RootOrder: 12 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!114 &7475116342606929481 MonoBehaviour: @@ -2037,10 +2189,12 @@ Transform: m_ConstrainProportionsScale: 0 m_Children: - {fileID: 7475116341162077651} + - {fileID: 7624448236951792051} - {fileID: 7475116341184709870} - {fileID: 7475116340900335231} - {fileID: 7475116342680308986} - {fileID: 7475116341218466090} + - {fileID: 783112258715650873} - {fileID: 7475116342785696725} - {fileID: 7475116340768526742} - {fileID: 7475116342844710275} @@ -2154,7 +2308,7 @@ Transform: m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 7475116342638198534} - m_RootOrder: 3 + m_RootOrder: 4 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!114 &7475116342680308985 MonoBehaviour: @@ -2207,7 +2361,7 @@ Transform: - {fileID: 7475116342145954546} - {fileID: 7475116342871483252} m_Father: {fileID: 7475116342638198534} - m_RootOrder: 5 + m_RootOrder: 7 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!114 &7475116342785696726 MonoBehaviour: @@ -2228,6 +2382,7 @@ MonoBehaviour: onPlayerVoted: {fileID: 11400000, guid: 60ad71c35f341824ba50d350a4dbc039, type: 2} onPlayerVoteCanceled: {fileID: 11400000, guid: d78f3b47e5f2863419b4dad25bd8b5c2, type: 2} onLoadLevelStarting: {fileID: 11400000, guid: c86d4c85a149f9648adda7cdcbdefbd9, type: 2} + onJoinedRoom: {fileID: 11400000, guid: f1a37dbd6b4904a4f9d9834d72d99370, type: 2} onGameSceneLoaded: {fileID: 1384308382823606702} onPlayerSpawned: {fileID: 7475116342871483259} changeLevelVoteText: {fileID: 5087666242074858168} @@ -2338,7 +2493,7 @@ Transform: m_Children: - {fileID: 7475116342491251794} m_Father: {fileID: 7475116342638198534} - m_RootOrder: 11 + m_RootOrder: 13 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!114 &7475116342821100537 MonoBehaviour: @@ -2354,6 +2509,7 @@ MonoBehaviour: m_EditorClassIdentifier: coinText: {fileID: 7475116342562358806} onCoinDrop: {fileID: 7475116342491251793} + onJoinedRoom: {fileID: 741966922129695396} currentCoin: 0 --- !u!1 &7475116342844710300 GameObject: @@ -2390,7 +2546,7 @@ Transform: - {fileID: 2373817044568623682} - {fileID: 3217804259877291692} m_Father: {fileID: 7475116342638198534} - m_RootOrder: 7 + m_RootOrder: 9 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!114 &7475116342844710274 MonoBehaviour: @@ -2547,7 +2703,7 @@ Transform: m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 7475116342638198534} - m_RootOrder: 9 + m_RootOrder: 11 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!114 &7475116342873915129 MonoBehaviour: @@ -2599,7 +2755,7 @@ Transform: m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 7475116342638198534} - m_RootOrder: 15 + m_RootOrder: 17 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!114 &6750135566758250123 MonoBehaviour: diff --git a/Assets/Resources/Enemies/AngrySkellyPrefab.prefab b/Assets/Resources/Enemies/AngrySkellyPrefab.prefab index a5f90250..08c81094 100644 --- a/Assets/Resources/Enemies/AngrySkellyPrefab.prefab +++ b/Assets/Resources/Enemies/AngrySkellyPrefab.prefab @@ -271,6 +271,7 @@ GameObject: - component: {fileID: 480484079} - component: {fileID: 4251418928517888926} - component: {fileID: 2777423608586637068} + - component: {fileID: 7237991582445384820} m_Layer: 0 m_Name: AngrySkellyPrefab m_TagString: Untagged @@ -523,6 +524,18 @@ CapsuleCollider: m_Height: 2 m_Direction: 1 m_Center: {x: 0, y: 0.7, z: 0} +--- !u!114 &7237991582445384820 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1857032755411982495} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 15740b3357d70f34d8e5e53ca9c27cb0, type: 3} + m_Name: + m_EditorClassIdentifier: --- !u!1 &2882927273311943532 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Resources/Enemies/SkellyMagePrefab.prefab b/Assets/Resources/Enemies/SkellyMagePrefab.prefab index afbc633c..d0256351 100644 --- a/Assets/Resources/Enemies/SkellyMagePrefab.prefab +++ b/Assets/Resources/Enemies/SkellyMagePrefab.prefab @@ -357,6 +357,7 @@ GameObject: - component: {fileID: 419546842284062756} - component: {fileID: 4526844801487198549} - component: {fileID: 2547317405899484615} + - component: {fileID: 7642269519336869515} m_Layer: 0 m_Name: SkellyMagePrefab m_TagString: Untagged @@ -609,6 +610,18 @@ CapsuleCollider: m_Height: 2 m_Direction: 1 m_Center: {x: 0, y: 0.7, z: 0} +--- !u!114 &7642269519336869515 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2024094060611992148} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 15740b3357d70f34d8e5e53ca9c27cb0, type: 3} + m_Name: + m_EditorClassIdentifier: --- !u!1 &2129182132073812335 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Scriptables/Events/Party/OnJoinedRoom.asset b/Assets/Scriptables/Events/Party/OnJoinedRoom.asset new file mode 100644 index 00000000..13fd4629 --- /dev/null +++ b/Assets/Scriptables/Events/Party/OnJoinedRoom.asset @@ -0,0 +1,14 @@ +%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: 83fe5321976e21d4b96c6d7182a5b8e2, type: 3} + m_Name: OnJoinedRoom + m_EditorClassIdentifier: diff --git a/Assets/Scriptables/Events/Party/OnJoinedRoom.asset.meta b/Assets/Scriptables/Events/Party/OnJoinedRoom.asset.meta new file mode 100644 index 00000000..61a4ba88 --- /dev/null +++ b/Assets/Scriptables/Events/Party/OnJoinedRoom.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: f1a37dbd6b4904a4f9d9834d72d99370 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/CharacterAnimatorController.cs b/Assets/Scripts/CharacterAnimatorController.cs index 4f4523a7..a9728406 100644 --- a/Assets/Scripts/CharacterAnimatorController.cs +++ b/Assets/Scripts/CharacterAnimatorController.cs @@ -28,8 +28,18 @@ public class CharacterAnimatorController : MonoBehaviour { return; } + } + + private void OnEnable() + { + parentController = GetComponentInParent(); + Debug.Log("OnEnable: parentController is " + (parentController != null ? "not null" : "null")); CastBarHandler.Instance.OnCastingStateChanged.AddListener(UpdateIsCastingState); } + private void OnDisable() + { + CastBarHandler.Instance.OnCastingStateChanged.RemoveListener(UpdateIsCastingState); + } // Update is called once per frame void Update() @@ -46,6 +56,15 @@ public class CharacterAnimatorController : MonoBehaviour { anim.SetFloat("throwingTime", (1 / CastBarHandler.Instance.currentCastTime)); SetTriggerBasedOnAbility(CastBarHandler.Instance.currentAbility.animationType); + + if (parentController == null) + { + parentController = GetComponentInParent(); + Debug.Log("OnEnable: parentController is " + (parentController != null ? "not null" : "null")); + } + + Debug.Log("NULL: " + parentController); + parentController.SetRemoteTriggerBasedOnAbility((int)CastBarHandler.Instance.currentAbility.animationType); } } diff --git a/Assets/Scripts/Game/GameConstants.cs b/Assets/Scripts/Game/GameConstants.cs index 6d17d456..e81b6aa0 100644 --- a/Assets/Scripts/Game/GameConstants.cs +++ b/Assets/Scripts/Game/GameConstants.cs @@ -5,12 +5,22 @@ public static class GameConstants #region PlayerPrefs Keys public static string CharacterDataKey = "characterData"; + public static string CharacterInventoryDataKey = "characterInventoryData"; + public static string CharacterEquipmentDataKey = "characterEquipmentData"; public static string PlayerCoinKey = "playerCoin"; public static string GetCharacterDataKey(string characterName) { return CharacterDataKey + "-" + characterName; } + public static string GetCharacterInventoryDataKey(string characterName) + { + return CharacterInventoryDataKey + "-" + characterName; + } + public static string GetCharacterEquipmentDataKey(string characterName) + { + return CharacterEquipmentDataKey + "-" + characterName; + } public static string GetPlayerCoinKey(string playerName) { return PlayerCoinKey + "-" + playerName; @@ -42,4 +52,10 @@ public static class GameConstants #endregion } + public static class Sizes + { + public static int TotalEquipmentSlots = 6; + public static int TotalInventorySlots = 18; + } + } \ No newline at end of file diff --git a/Assets/Scripts/Items.meta b/Assets/Scripts/Items.meta new file mode 100644 index 00000000..77d5e0dc --- /dev/null +++ b/Assets/Scripts/Items.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 1b44a0180a8ad7345baaa9131bfdd225 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Items/EquipmentData.cs b/Assets/Scripts/Items/EquipmentData.cs new file mode 100644 index 00000000..a271d7ab --- /dev/null +++ b/Assets/Scripts/Items/EquipmentData.cs @@ -0,0 +1,29 @@ +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using UnityEngine; + +[System.Serializable] +public class EquipmentData +{ + public int[] equippedItems; + + public EquipmentData() + { + equippedItems = new int[GameConstants.Sizes.TotalEquipmentSlots]; + + for (int i = 0; i < equippedItems.Length; i++) + { + equippedItems[i] = -1; + } + } + public EquipmentData(int[] equippedItems) + { + this.equippedItems = new int[GameConstants.Sizes.TotalEquipmentSlots]; + + for (int i = 0; i < equippedItems.Length; i++) + { + this.equippedItems[i] = equippedItems[i]; + } + } +} diff --git a/Assets/Scripts/Items/EquipmentData.cs.meta b/Assets/Scripts/Items/EquipmentData.cs.meta new file mode 100644 index 00000000..2d4597b3 --- /dev/null +++ b/Assets/Scripts/Items/EquipmentData.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 544936ba1c15dca458f0c21534bbd311 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Items/InventoryData.cs b/Assets/Scripts/Items/InventoryData.cs new file mode 100644 index 00000000..147691c5 --- /dev/null +++ b/Assets/Scripts/Items/InventoryData.cs @@ -0,0 +1,28 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +[System.Serializable] +public class InventoryData +{ + public int[] inventoryItems; + + public InventoryData() + { + inventoryItems = new int[GameConstants.Sizes.TotalInventorySlots]; + + for (int i = 0; i < inventoryItems.Length; i++) + { + inventoryItems[i] = -1; + } + } + public InventoryData(int[] inventoryItems) + { + this.inventoryItems = new int[GameConstants.Sizes.TotalInventorySlots]; + + for (int i = 0; i < inventoryItems.Length; i++) + { + this.inventoryItems[i] = inventoryItems[i]; + } + } +} diff --git a/Assets/Scripts/Items/InventoryData.cs.meta b/Assets/Scripts/Items/InventoryData.cs.meta new file mode 100644 index 00000000..03b3ee69 --- /dev/null +++ b/Assets/Scripts/Items/InventoryData.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 0a05b9f8bb51da546a37f79a8794fec7 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Items/ItemIndexer.cs b/Assets/Scripts/Items/ItemIndexer.cs new file mode 100644 index 00000000..659e9f1b --- /dev/null +++ b/Assets/Scripts/Items/ItemIndexer.cs @@ -0,0 +1,48 @@ +using Kryz.CharacterStats.Examples; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class ItemIndexer : MonoBehaviour +{ + #region Singleton + private static ItemIndexer _instance; + + // Public reference to the singleton instance + public static ItemIndexer Instance + { + get + { + // If the instance doesn't exist, try to find it in the scene + if (_instance == null) + { + _instance = FindObjectOfType(); + + // If it's still null, create a new GameObject and add the component + if (_instance == null) + { + GameObject singletonObject = new GameObject(typeof(ItemIndexer).Name); + _instance = singletonObject.AddComponent(); + } + } + return _instance; + } + } + #endregion + + public List Items = new List(); + + protected void Awake() + { + // Ensure there's only one instance + if (_instance != null && _instance != this) + { + Destroy(gameObject); + return; + } + + // If this is the first instance, set it as the singleton + _instance = this; + DontDestroyOnLoad(gameObject); + } +} diff --git a/Assets/Scripts/Items/ItemIndexer.cs.meta b/Assets/Scripts/Items/ItemIndexer.cs.meta new file mode 100644 index 00000000..b475d575 --- /dev/null +++ b/Assets/Scripts/Items/ItemIndexer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 89530648eb9e4314681d49de96e7f026 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Items/PlayerDataHandler.cs b/Assets/Scripts/Items/PlayerDataHandler.cs new file mode 100644 index 00000000..2af2e4eb --- /dev/null +++ b/Assets/Scripts/Items/PlayerDataHandler.cs @@ -0,0 +1,129 @@ +using Kryz.CharacterStats.Examples; +using Photon.Pun; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class PlayerDataHandler : MonoBehaviour +{ + #region Singleton + private static PlayerDataHandler _instance; + + // Public reference to the singleton instance + public static PlayerDataHandler Instance + { + get + { + // If the instance doesn't exist, try to find it in the scene + if (_instance == null) + { + _instance = FindObjectOfType(); + + // If it's still null, create a new GameObject and add the component + if (_instance == null) + { + GameObject singletonObject = new GameObject(typeof(PlayerDataHandler).Name); + _instance = singletonObject.AddComponent(); + } + } + return _instance; + } + } +#endregion + + CharacterData characterData = new CharacterData(); + string characterDataKey; + + CoinData coinData = new CoinData(); + string playerCoinKey; + + EquipmentData equipmentData = new EquipmentData(); + string equipmentDataKey; + + InventoryData inventoryData = new InventoryData(); + string inventoryDataKey; + + private void Awake() + { + DontDestroyOnLoad(this); + } + + // Character Data (Level, exp etc) + public CharacterData LoadCharacterData(string characterName) + { + characterDataKey = GameConstants.PlayerPrefsKeys.GetCharacterDataKey(characterName); + + if (GameStatePersistenceManager.Instance.HasDataForKey(characterDataKey)) + { + characterData = GameStatePersistenceManager.Instance.LoadData(characterDataKey); + return characterData; + } + else return null; + } + public void SaveCharacterData(string characterName, CharacterData characterData) + { + characterDataKey = GameConstants.PlayerPrefsKeys.GetCharacterDataKey(characterName); + + GameStatePersistenceManager.Instance.SaveData(characterDataKey, characterData); + } + + // Player Coin Data (global coin amount) + public CoinData LoadPlayerCoinData(string characterName) + { + playerCoinKey = GameConstants.PlayerPrefsKeys.GetPlayerCoinKey(characterName); + + if (GameStatePersistenceManager.Instance.HasDataForKey(playerCoinKey)) + { + coinData = GameStatePersistenceManager.Instance.LoadData(playerCoinKey); + return coinData; + } + else + return null; + } + public void SavePlayerCoinData(string characterName, CoinData coinData) + { + playerCoinKey = GameConstants.PlayerPrefsKeys.GetPlayerCoinKey(characterName); + + GameStatePersistenceManager.Instance.SaveData(playerCoinKey, coinData); + } + + + // Character Equipment Data (equipped items) + public EquipmentData LoadCharacterEquipmentData(string characterName) + { + equipmentDataKey = GameConstants.PlayerPrefsKeys.GetCharacterEquipmentDataKey(characterName); + + if (GameStatePersistenceManager.Instance.HasDataForKey(equipmentDataKey)) + { + equipmentData = GameStatePersistenceManager.Instance.LoadData(equipmentDataKey); + return equipmentData; + } + else return null; + } + public void SaveCharacterEquipmentData(string characterName, EquipmentData equipmentData) + { + equipmentDataKey = GameConstants.PlayerPrefsKeys.GetCharacterEquipmentDataKey(characterName); + + GameStatePersistenceManager.Instance.SaveData(equipmentDataKey, equipmentData); + } + + + // Character Inventory Data (items on inventory) + public InventoryData LoadCharacterInventoryData(string characterName) + { + inventoryDataKey = GameConstants.PlayerPrefsKeys.GetCharacterInventoryDataKey(characterName); + + if (GameStatePersistenceManager.Instance.HasDataForKey(inventoryDataKey)) + { + inventoryData = GameStatePersistenceManager.Instance.LoadData(inventoryDataKey); + return inventoryData; + } + else return null; + } + public void SaveCharacterInventoryData(string characterName, InventoryData inventoryData) + { + inventoryDataKey = GameConstants.PlayerPrefsKeys.GetCharacterInventoryDataKey(characterName); + + GameStatePersistenceManager.Instance.SaveData(inventoryDataKey, inventoryData); + } +} diff --git a/Assets/Scripts/Items/PlayerDataHandler.cs.meta b/Assets/Scripts/Items/PlayerDataHandler.cs.meta new file mode 100644 index 00000000..2c7fcf45 --- /dev/null +++ b/Assets/Scripts/Items/PlayerDataHandler.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 40822b285732f4c4faa78e10ed5932da +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Networking/NetworkManager.cs b/Assets/Scripts/Networking/NetworkManager.cs index 60c520d6..2bb58be0 100644 --- a/Assets/Scripts/Networking/NetworkManager.cs +++ b/Assets/Scripts/Networking/NetworkManager.cs @@ -20,6 +20,7 @@ public class NetworkManager : MonoBehaviourPunCallbacks, IOnEventCallback [SerializeField] private GameEvent_Player onPlayerVoted; [SerializeField] private GameEvent_Player onPlayerVoteCanceled; [SerializeField] private GameEvent onLoadLevelStarting; + [SerializeField] private GameEvent onJoinedRoom; [SerializeField] private GameEventListener_ZoneData onGameSceneLoaded; [SerializeField] private GameEventListener_PhotonView onPlayerSpawned; @@ -85,6 +86,8 @@ public class NetworkManager : MonoBehaviourPunCallbacks, IOnEventCallback PhotonNetwork.LoadLevel(huntersInn); } } + + onJoinedRoom.Raise(); } public void OnGameSceneLoaded(ZoneData zoneData) diff --git a/Assets/Scripts/Player/CoinBag.cs b/Assets/Scripts/Player/CoinBag.cs index 2eb4509f..554f294a 100644 --- a/Assets/Scripts/Player/CoinBag.cs +++ b/Assets/Scripts/Player/CoinBag.cs @@ -8,26 +8,18 @@ public class CoinBag : MonoBehaviour { [SerializeField] private TMP_Text coinText; [SerializeField] private GameEventListener_Int onCoinDrop; + [SerializeField] private GameEventListener onJoinedRoom; public int currentCoin; CoinData coinData = new CoinData(); - string playerCoinKey; private void Awake() { - playerCoinKey = GameConstants.PlayerPrefsKeys.GetPlayerCoinKey(PhotonNetwork.NickName); - - if (GameStatePersistenceManager.Instance.HasDataForKey(playerCoinKey)) - { - coinData = GameStatePersistenceManager.Instance.LoadData(playerCoinKey); - currentCoin = coinData.totalCoin; - } - else - currentCoin = 0; - onCoinDrop.Response.AddListener(ChangeAmount); + onJoinedRoom.Response.AddListener(LoadCoins); + UpdateCoinText(); } @@ -63,7 +55,20 @@ public class CoinBag : MonoBehaviour { coinData.totalCoin = currentCoin; - GameStatePersistenceManager.Instance.SaveData(playerCoinKey, coinData); + PlayerDataHandler.Instance.SavePlayerCoinData(PhotonNetwork.NickName, coinData); } + + private void LoadCoins() + { + coinData = PlayerDataHandler.Instance.LoadPlayerCoinData(PhotonNetwork.NickName); + if (coinData != null) + { + Debug.Log("Success Loading CoinData"); + currentCoin = coinData.totalCoin; + UpdateCoinText(); + } + else + coinData = new CoinData(); + } } diff --git a/Assets/Scripts/ProjectileSpawnLocationController.cs b/Assets/Scripts/ProjectileSpawnLocationController.cs index 64aecee8..701233d5 100644 --- a/Assets/Scripts/ProjectileSpawnLocationController.cs +++ b/Assets/Scripts/ProjectileSpawnLocationController.cs @@ -20,9 +20,16 @@ public class ProjectileSpawnLocationController : MonoBehaviour protected virtual void Awake() { photonView = GetComponentInParent(); + } + private void OnEnable() + { CastBarHandler.Instance.OnCastingStateChanged.AddListener(UpdateIsCastingState); } + private void OnDisable() + { + CastBarHandler.Instance.OnCastingStateChanged.RemoveListener(UpdateIsCastingState); + } // Start is called before the first frame update protected virtual void Start()