Panel refactoring - chest & make chast dynamics

This commit is contained in:
kabix09 2022-11-19 17:02:31 +01:00
parent 792bcb8466
commit 7f4aec84b3
105 changed files with 1627 additions and 1164 deletions

View File

@ -11,6 +11,7 @@ GameObject:
- component: {fileID: 805898525}
- component: {fileID: 805898527}
- component: {fileID: 805898526}
- component: {fileID: 5462276123095309683}
m_Layer: 0
m_Name: Chest1-InteractionMSG
m_TagString: Untagged
@ -28,6 +29,7 @@ Transform:
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0.095890045, y: -0.058502197, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 4669568061092186073}
m_RootOrder: 0
@ -70,6 +72,18 @@ MonoBehaviour:
_tmpPanelAbove: {fileID: 0}
obj: {fileID: 4669568061092186072}
isAllowedToShowPanels: 1
--- !u!114 &5462276123095309683
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 805898524}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: a532f2b712a01fc4fad02346f1a69e39, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1 &4669568061092186072
GameObject:
m_ObjectHideFlags: 0
@ -81,7 +95,6 @@ GameObject:
- component: {fileID: 4669568061092186073}
- component: {fileID: 4669568061092186078}
- component: {fileID: 4669568061092186079}
- component: {fileID: 4669568061092186076}
m_Layer: 0
m_Name: Gold Chest
m_TagString: Untagged
@ -99,6 +112,7 @@ Transform:
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 58.59589, y: 32.941498, z: 20}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 805898525}
m_Father: {fileID: 0}
@ -115,6 +129,7 @@ SpriteRenderer:
m_CastShadows: 0
m_ReceiveShadows: 0
m_DynamicOccludee: 1
m_StaticShadowCaster: 0
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
@ -166,7 +181,7 @@ BoxCollider2D:
m_Density: 1
m_Material: {fileID: 0}
m_IsTrigger: 0
m_UsedByEffector: 0
m_UsedByEffector: 1
m_UsedByComposite: 0
m_Offset: {x: 0, y: 0}
m_SpriteTilingProperty:
@ -181,19 +196,3 @@ BoxCollider2D:
serializedVersion: 2
m_Size: {x: 0.95, y: 0.9}
m_EdgeRadius: 0
--- !u!114 &4669568061092186076
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4669568061092186072}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 26a44ba4cba1985408fca11ba424361c, type: 3}
m_Name:
m_EditorClassIdentifier:
_panel: {fileID: 5331092055018478733, guid: 2b46aee216d4b304f8aebcb303ebf4f4, type: 3}
isOpen: 0
chest: {fileID: 0}
developerList: []

View File

@ -11,6 +11,7 @@ GameObject:
- component: {fileID: 584661738}
- component: {fileID: 584661740}
- component: {fileID: 584661739}
- component: {fileID: 6369310084342855511}
m_Layer: 0
m_Name: Chest0-InteractionMSG
m_TagString: Untagged
@ -28,6 +29,7 @@ Transform:
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0.19999695, z: -1.8041458}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 5754902894522036728}
m_RootOrder: 0
@ -70,6 +72,18 @@ MonoBehaviour:
_tmpPanelAbove: {fileID: 0}
obj: {fileID: 5754902894522036729}
isAllowedToShowPanels: 1
--- !u!114 &6369310084342855511
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 584661737}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: a532f2b712a01fc4fad02346f1a69e39, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1 &5754902894522036729
GameObject:
m_ObjectHideFlags: 0
@ -81,7 +95,6 @@ GameObject:
- component: {fileID: 5754902894522036728}
- component: {fileID: 5754902894522036731}
- component: {fileID: 5754902894522036730}
- component: {fileID: 5754902894522036733}
m_Layer: 0
m_Name: Prize Chest
m_TagString: Untagged
@ -99,6 +112,7 @@ Transform:
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 16, y: 51.2, z: 18.195854}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 584661738}
m_Father: {fileID: 0}
@ -115,6 +129,7 @@ SpriteRenderer:
m_CastShadows: 0
m_ReceiveShadows: 0
m_DynamicOccludee: 1
m_StaticShadowCaster: 0
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
@ -181,19 +196,3 @@ BoxCollider2D:
serializedVersion: 2
m_Size: {x: 1.35, y: 1.1}
m_EdgeRadius: 0
--- !u!114 &5754902894522036733
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5754902894522036729}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 26a44ba4cba1985408fca11ba424361c, type: 3}
m_Name:
m_EditorClassIdentifier:
_panel: {fileID: 5331092055018478733, guid: 2b46aee216d4b304f8aebcb303ebf4f4, type: 3}
isOpen: 0
chest: {fileID: 0}
developerList: []

View File

@ -11,6 +11,7 @@ GameObject:
- component: {fileID: 1698721847}
- component: {fileID: 1698721849}
- component: {fileID: 1698721848}
- component: {fileID: 3574830714698708195}
m_Layer: 0
m_Name: Chest3-InteractionMSG
m_TagString: Untagged
@ -28,6 +29,7 @@ Transform:
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: 3972494989842158580}
m_RootOrder: 0
@ -70,6 +72,18 @@ MonoBehaviour:
_tmpPanelAbove: {fileID: 0}
obj: {fileID: 3972494989842158579}
isAllowedToShowPanels: 1
--- !u!114 &3574830714698708195
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1698721846}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: a532f2b712a01fc4fad02346f1a69e39, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1 &3972494989842158579
GameObject:
m_ObjectHideFlags: 0
@ -82,7 +96,6 @@ GameObject:
- component: {fileID: 3972494989842158473}
- component: {fileID: 3972494989842158583}
- component: {fileID: 3972494989842158582}
- component: {fileID: 3972494989842158581}
m_Layer: 0
m_Name: Wooden Chest
m_TagString: Untagged
@ -100,6 +113,7 @@ Transform:
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -8.45, y: -3.9, z: 10}
m_LocalScale: {x: 0.5, y: 0.5, z: 1}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 1698721847}
m_Father: {fileID: 0}
@ -116,6 +130,7 @@ SpriteRenderer:
m_CastShadows: 0
m_ReceiveShadows: 0
m_DynamicOccludee: 1
m_StaticShadowCaster: 0
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
@ -208,19 +223,3 @@ BoxCollider2D:
serializedVersion: 2
m_Size: {x: 0.95, y: 1.5900776}
m_EdgeRadius: 0
--- !u!114 &3972494989842158581
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3972494989842158579}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 26a44ba4cba1985408fca11ba424361c, type: 3}
m_Name:
m_EditorClassIdentifier:
_panel: {fileID: 5331092055018478733, guid: 2b46aee216d4b304f8aebcb303ebf4f4, type: 3}
isOpen: 0
chest: {fileID: 0}
developerList: []

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: b0e1c4df7cd61824384676c2e7fb2991
guid: a592c74dcbbaafa4a82cc20d574cb331
folderAsset: yes
DefaultImporter:
externalObjects: {}

View File

@ -29,8 +29,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:
- {fileID: 5331092056807707113}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 5331092055037629063}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
@ -101,9 +101,9 @@ GameObject:
- component: {fileID: 5331092055018478732}
- component: {fileID: 5331092055018478730}
- component: {fileID: 5331092055018478731}
- component: {fileID: 4617582679355695156}
- component: {fileID: 2117488037472856852}
m_Layer: 5
m_Name: chest_panel
m_Name: ChestPanel
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
@ -119,10 +119,12 @@ RectTransform:
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 0.4, y: 0.4, z: 0.4}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 5331092055896533710}
- {fileID: 5331092055037629063}
- {fileID: 5331092055143140113}
- {fileID: 5331092056807707113}
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
@ -169,7 +171,7 @@ MonoBehaviour:
m_FillOrigin: 0
m_UseSpriteMesh: 0
m_PixelsPerUnitMultiplier: 1
--- !u!114 &4617582679355695156
--- !u!114 &2117488037472856852
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
@ -178,15 +180,12 @@ MonoBehaviour:
m_GameObject: {fileID: 5331092055018478733}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 8d9e1061a8038f54a87269aa0bd2db04, type: 3}
m_Script: {fileID: 11500000, guid: 84da00f00bb500c46b1e5629ca4a61b8, type: 3}
m_Name:
m_EditorClassIdentifier:
_panel: {fileID: 5331092056807707114}
_blankSlot: {fileID: 3818338910890019850, guid: e2f95cfb3084e6e4f9f16c14170adfb5, type: 3}
_panelCloseButton: {fileID: 5331092055143140112}
_tmp: {fileID: 0}
_itemTemplate: {fileID: 6570396142606985298, guid: 1304511dd1dfefc449e87c3d904ab15f, type: 3}
chest: {fileID: 0}
_panelContent: {fileID: 5331092056807707114}
ChildBoxTemplate: {fileID: 3818338910890019850, guid: e2f95cfb3084e6e4f9f16c14170adfb5, type: 3}
ChildBoxList: []
--- !u!1 &5331092055037629064
GameObject:
m_ObjectHideFlags: 0
@ -216,6 +215,7 @@ 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_ConstrainProportionsScale: 0
m_Children:
- {fileID: 5331092054895676294}
m_Father: {fileID: 5331092055018478732}
@ -323,6 +323,7 @@ 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_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 5331092055018478732}
m_RootOrder: 2
@ -442,6 +443,7 @@ 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_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 5331092055896533710}
m_RootOrder: 0
@ -576,6 +578,7 @@ 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_ConstrainProportionsScale: 0
m_Children:
- {fileID: 5331092055455069025}
m_Father: {fileID: 5331092055018478732}
@ -652,13 +655,14 @@ 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_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 5331092054895676294}
m_RootOrder: 0
m_Father: {fileID: 5331092055018478732}
m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 0, y: 0.000024795532}
m_AnchoredPosition: {x: 0, y: 0.000030517578}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0, y: 1}
--- !u!114 &5331092056807707111

View File

@ -150,7 +150,7 @@ GameObject:
- component: {fileID: 7379342322136183382}
- component: {fileID: 8625463808668959803}
m_Layer: 5
m_Name: chest_slot
m_Name: ChestSlot
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0

View File

@ -1,116 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ChestController : BaseWarehouseController
{
[SerializeField] public GameObject chest;
[SerializeField] public List<Item> developerList = new List<Item>(); // FOR DEVELOPER TESTE - remove later !!!
bool isTrigerred = false;
// Start is called before the first frame update
void Start()
{
chest = gameObject; // set object on current GameObject
// FOR DEVELOPER TESTE - remove later !!!
for(int i = 0; i < developerList.Count; i++)
{
SetItemOnPosition(i, developerList[i]);
}
}
// Update is called once per frame
void Update()
{
if (this._panel && this.isTrigerred && !this.isOpen) // we can open chest only when its closed
{
if (Input.GetKeyDown(KeyCode.E))
{
this.OpenPanel();
InventoryManager.Instance.OpenPanel();
EquipmentManager.Instance.OpenPanel();
}
}
if (!InventoryManager.Instance.isOpen)
{
if (Input.GetKeyDown(KeyCode.I))
{
InventoryManager.Instance.OpenPanel();
}
}
}
void OnTriggerExit2D(Collider2D collision)
{
if (this._panel != null)
{
this.ClosePanel();
}
this.isTrigerred = false;
}
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.tag == "Player")
{
this.isTrigerred = true;
}
}
public override void ClosePanel()
{
base.ClosePanel();
InventoryManager.Instance.ClosePanel();
EquipmentManager.Instance.ClosePanel();
}
protected override void SetupPanel()
{
if(this.dynamicPanel)
{
this.dynamicPanel.GetComponent<ChestPanelController>().Setup(gameObject, _items);
}
}
// WARNING
// DANGER - functon override position which may be not free
///<summary>
/// Function for placed item in inventory on SPECYFIC position
/// Used by SceneInventoryManager for load saved items on their positions
///</summary>
// WHAT WITH FUNCTION - setupItemOnPosition() - ???
public void SetupItemInChest(int key, EquippableItem pickable)
{
this._items[key] = pickable;
}
public override void SetItemOnPosition(int _keyPosition, Item _item)
{
// Drag setup first end second object on the same panel - should only one - this wwere dropped item
// Becouse of this source slot from other panel is settuping in dropped panel too - list get empty item and it cause errors
if(_item != null)
{
this._items[_keyPosition] = _item;
Debug.Log("Put item on chest"+_item.name);
// Inform Map Chests manager about update - update list to be compliant with the local list
SceneChestManager.Instance.AddItemToChest(gameObject.name, _keyPosition, (EquippableItem)_item);
}
// if we assign null its removed later in EndDrag method
}
public override void RemoveItemFromPosition(int _keyPosition)
{
base.RemoveItemFromPosition(_keyPosition);
Debug.Log("Pick up item from chest");
// Inform Map Chests manager about update - update list to be compliant with the local list
SceneChestManager.Instance.RemoveItemFromChest(gameObject.name, _keyPosition);
}
}

View File

@ -1,55 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using System;
public class ChestPanelController : BasePanelController
{
public override void CloseOnClick()
{
Destroy(gameObject); // destroy panel
if(_instance)
{
_instance.GetComponent<ChestController>().ClosePanel();
}
}
public void Setup(GameObject _chest, Dictionary<int, Item> _chestItems)
{
_instance = _chest;
base.Setup(_chestItems);
}
protected override ISlot SetupSlot(int key, GameObject _parent)
{
ChestSlot _tmpSlot = Instantiate(_blankSlot, _parent.transform.position, Quaternion.identity).GetComponent<ChestSlot>();
_tmpSlot.transform.SetParent(_parent.transform);
_tmpSlot.SetupSlot(key, null, this);
return _tmpSlot;
}
// Islot - > Aslot
// - > B slots
// Ipanel -> Apanel
// -> B panel
// ---------------------------
// will work differently depending if its chest, inventory or equipment panel
// public void Equip(EquippableItem item)
// {
// if(RemoveItem(item))
// {
// EquippableItem previousItem;
// }
// }
}

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: c7042c6d06a175543b01bd0e9d316f53
guid: 888d1783775092f48b15c03485e1562a
folderAsset: yes
DefaultImporter:
externalObjects: {}

View File

@ -0,0 +1,29 @@
using UnityEditor;
using UnityEngine;
public class ChestController : MonoBehaviour
{
public void Update()
{
}
private void OnTriggerStay2D(Collider2D collision)
{
if (collision.tag == "Player")
{
ChestUIManager.Instance.CurrentChestName = gameObject.transform.parent.name;
}
}
private void OnTriggerExit2D(Collider2D collision)
{
if (collision.tag == "Player")
{
ChestUIManager.Instance.CurrentChestName = null;
ChestUIManager.Instance.ClosePanel();
}
}
}

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 26a44ba4cba1985408fca11ba424361c
guid: a532f2b712a01fc4fad02346f1a69e39
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@ -0,0 +1,48 @@
using System;
using System.Collections;
using UnityEngine;
[Serializable]
public class SceneChestBuilder : SceneObjectBuilder<ChestPrefabAsset>
{
[SerializeField] int trest = 0;
protected override string MODEL_SOURCE_PATH { get { return "Chests/"; } }
public override void Build(ChestPrefabAsset objectToBuild)
{
GameObject globalGUI = GameObject.FindGameObjectsWithTag("GUI")[0];
if (!globalGUI)
Debug.LogError("GUI frame not found!!");
GameObject newObject = FindModel(objectToBuild.Chest.chestModel.name);
Debug.Log($"Chest {newObject} - name: {objectToBuild.Chest.chestModel.name}");
if (!newObject)
Debug.LogError("Can't find prefarb by name " + objectToBuild.Chest.chestModel.name);
// Build chest on map
GameObject chest = Instantiate(newObject, objectToBuild.Position, Quaternion.identity, globalGUI.transform);
chest.name = objectToBuild.Chest.Name;
chest.transform.localScale = new Vector3(0.5f, 0.5f, 1f);
chest.transform.localPosition = objectToBuild.Position;
// data about chest cpontent should be handled in SceneChestManager class and pass to ChestUIPanel only after opening Panel by Player
// in other words objects dont have full info about its data xd
// confuse and irrational but this way it will be easiet to maintain Data Consistency
}
public override GameObject FindModel(string modelName)
{
var resource = Resources.Load<GameObject>(MODEL_SOURCE_PATH + modelName);
if (!resource)
throw new System.Exception($"Resource {MODEL_SOURCE_PATH + modelName} not found!!");
return resource;
}
}

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: b770806e2f537ac4ab266a6629ae2fd2
guid: 3db499bc88166ac409489e99ce706c8d
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@ -1,23 +1,27 @@
using UnityEngine;
using System.Collections.Generic;
public class ChestDataListManager : SceneDataListManager<ChestPrefarbAsset>
public class ChestDataListManager : DataListManager<ChestPrefabAsset> // or maybe EquippableItem - but its get conflicts...
{
public ChestDataListManager(string gameObjectLocalization, string assetLocalization) : base(gameObjectLocalization, assetLocalization)
[SerializeField] protected new ChestUIManager uiManager;
public new DataListManager<ChestPrefabAsset> SetUiManager(ref ChestUIManager _uiManager)
{
uiManager = _uiManager;
return this;
}
public override void AddElementToList(ChestPrefarbAsset newElement)
public override void AddElementToList(ChestPrefabAsset newElement)
{
Elements.Add(newElement);
}
public override void RemoveElementFromList(ChestPrefabAsset element)
{
throw new System.NotImplementedException();
}
public override void RemoveElementFromList(ChestPrefarbAsset element)
{
throw new System.NotImplementedException();
}
protected override void doBuild(GameObject _object)
{
throw new System.NotImplementedException();
}
//public void AddElement
}

View File

@ -0,0 +1,99 @@
using System.Collections.Generic;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using UnityEngine;
public class SaveChestManager : SaveModelSystem<ChestPrefabAsset>
{
public override bool SaveModelItem(ChestPrefabAsset model)
{
return base.SaveModelItem(model);
}
public override bool SaveModelList(List<ChestPrefabAsset> list)
{
BinaryFormatter formatter = new BinaryFormatter();
Debug.Log("Saved Chest at " + Path);
if (!Directory.Exists(Path)) Directory.CreateDirectory(Path);
/* Main logic of conversion data format */
var data = ConvertObjectsListToListOfDataModels(list);
FileStream stream = new FileStream(
Path + GetFileName(ObjectListName),
FileMode.Create
);
formatter.Serialize(stream, data);
stream.Close();
return true;
}
public override ChestPrefabAsset LoadModelItem()
{
return base.LoadModelItem();
}
public override List<ChestPrefabAsset> LoadModelList()
{
string path = Path + GetFileName(ObjectListName);
if (File.Exists(path))
{
BinaryFormatter formatter = new BinaryFormatter();
FileStream stream = new FileStream(path, FileMode.Open);
List<ChestPrefabAssetData> questsList = formatter.Deserialize(stream) as List<ChestPrefabAssetData>;
stream.Close();
return ConvertListOfDataModelsToListOfObject(questsList);
}
else
{
Debug.Log("Save file not found in " + path);
}
return new List<ChestPrefabAsset>();
}
// Support function
// 1. From model to data format
private ChestPrefabAssetData ConvertObjectToDataModel(ChestPrefabAsset model)
{
return new ChestPrefabAssetData(model);
}
private List<ChestPrefabAssetData> ConvertObjectsListToListOfDataModels(List<ChestPrefabAsset> modelsList)
{
List<ChestPrefabAssetData> convertedList = new List<ChestPrefabAssetData>();
foreach(ChestPrefabAsset model in modelsList)
{
convertedList.Add(ConvertObjectToDataModel(model));
}
return convertedList;
}
// 2. From data to model format
private ChestPrefabAsset ConvertDataModelToObject(ChestPrefabAssetData dataModel)
{
return (ChestPrefabAsset)dataModel.MapDataToPrefabAssetModel();
}
private List<ChestPrefabAsset> ConvertListOfDataModelsToListOfObject(List<ChestPrefabAssetData> dataModelsList)
{
List<ChestPrefabAsset> convertedList = new List<ChestPrefabAsset>();
foreach (ChestPrefabAssetData dataModel in dataModelsList)
{
convertedList.Add(ConvertDataModelToObject(dataModel));
}
return convertedList;
}
}

View File

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

View File

@ -0,0 +1,122 @@
using System;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
public class SceneChestDataLoader : SceneBaseDataLoader<ChestPrefabAsset>
{
public SceneChestDataLoader(string _objectListName, string _objectFolderName)
{
SaveModelSystem = new SaveChestManager();
SaveModelSystem.ObjectFolderName = _objectFolderName;
SaveModelSystem.ObjectListName = _objectListName;
}
/*
public void LoadInventoryItemsList()
{
string path = SaveSystem.GetSavePath();
if (!Directory.Exists(path)) // if not exists thats mean there was nothing saved yet - nothing to load
return;
FileInfo[] fileInfo = new DirectoryInfo(path).GetFiles();
foreach(FileInfo file in fileInfo)
{
if(file.Name != this.ItemsListName + ".fun")
continue;
Dictionary<int, EquippableItemPrefabAssetData> equippableItemsList = SaveInventorySystem.LoadInventoryItemsList(this.ItemsListName);
// itemEntry.Value.MapDataToObject() - map data format to object
// save object
foreach(KeyValuePair<int, EquippableItemPrefabAssetData> itemEntry in equippableItemsList)
{
InventoryManager.Instance.SetupItemInInventory(itemEntry.Key, itemEntry.Value.MapDataToEquippableItemPrefarbAsset().equippableItem);
}
}
}
public void SaveInventoryItems()
{
// Case I - if we remember all list
// 1) if after removed item form DynamicList is empty - remove all file
// 2) if after removed item form DynamciList there are another one - save updated list again
if(InventoryManager.Instance._items.Count > 0) {
// 1. Map From Dictionary<int, Item>' to 'Dictionary<int, EquippableItemPrefabAsset>'
Dictionary<int, EquippableItemPrefabAsset> mappedList = new Dictionary<int, EquippableItemPrefabAsset>();
foreach(KeyValuePair<int, Item> itemElement in InventoryManager.Instance._items)
{
mappedList[itemElement.Key] = new EquippableItemPrefabAsset(
itemElement.Value.Name,
itemElement.Value.ItemModel.name,
new Vector3(0,0,0),
(EquippableItem) itemElement.Value
);
}
// 2. Save Items
SaveInventorySystem.SaveInventoryItemsList(mappedList, this.ItemsListName);
} else {
string _path = SaveSystem.GetSavePath() + "/" + this.ItemsListName + ".fun";
try
{
Debug.Log("File to remove: " + _path);
if(File.Exists(_path))
{
File.Delete(_path);
}
}
catch (IOException ioExp)
{
Debug.LogError(ioExp.Message);
}
}
// Case II - if we rememenber object per file
// 1) remove specyfic file
//
// Unfortunatelly we don't use this way of saving items yet :D
}
*/
protected override List<ChestPrefabAsset> LoadStaticData() { throw new System.NotImplementedException(); }
protected override List<ChestPrefabAsset> LoadDynamicData()
{
SaveModelSystem.Path = PathBuilder.BuildSavePath().WithMap(CurrentMap).WithDataType(SceneElementTypeEnum.Dynamic).GetString();
return SaveModelSystem.LoadModelList();
}
protected override bool SaveStaticData(List<ChestPrefabAsset> _elements) { throw new System.NotImplementedException(); }
protected override bool SaveDynamicData(List<ChestPrefabAsset> _elements)
{
SaveModelSystem.Path = PathBuilder.BuildSavePath().WithMap(CurrentMap).WithDataType(SceneElementTypeEnum.Dynamic).GetString();
Debug.Log(SaveModelSystem.Path);
/* try
{*/
SaveModelSystem.SaveModelList(_elements);
return true;
/* }
catch (Exception e) { Debug.LogError(e.Message); }*/
return false;
}
protected override List<ChestPrefabAsset> LoadGenericData() { throw new NotImplementedException(); }
protected override bool SaveGenericData(List<ChestPrefabAsset> _elements) { throw new NotImplementedException(); }
}

View File

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

View File

@ -0,0 +1,133 @@
using System;
using System.Collections.Generic;
using UnityEngine;
[Serializable]
public class SceneChestDataManager : SceneBaseDataManager<ChestPrefabAsset>
{
protected override string OBJECT_FOLDER_NAME { get { return "Chest"; } }
protected override string OBJECT_LIST_NAME { get { return "ChestList"; } }
//protected new SceneBaseDataLoader<ChestPrefabAsset> DataLoader { get; set; }
protected SceneChestBuilder ChestBuilder { get; set; }
[SerializeField] Chest CurrentChest;
[SerializeField] public List<ChestPrefabAssetData> ElementsToBuildOnSceneList = new List<ChestPrefabAssetData>();
[SerializeField] List<ChestPrefabAsset> convertDataToAsset = new List<ChestPrefabAsset>();
// tmp var
bool NewGame = false;
public override void Awake()
{
if (Instance == null)
{
Instance = this;
}
else
{
Destroy(gameObject);
}
}
private void Start()
{
Debug.Log("Start SceneChestData manager");
//TaskUIManager.FindOrCreateInstance();
var chestManager = ChestUIManager.Instance;
if (chestManager == null)
throw new NullReferenceException("ChestUIManager not found!!!");
StaticDataList = (new ChestDataListManager()).SetUiManager(ref chestManager);
DynamicDataList = (new ChestDataListManager()).SetUiManager(ref chestManager);
DataLoader = new SceneChestDataLoader(OBJECT_LIST_NAME, OBJECT_FOLDER_NAME);
ChestBuilder = new SceneChestBuilder();
//ChestBuilder.ElementsToBuildOnSceneList = ElementsToBuildOnSceneList;
//SaveData(StaticDataList.GetList(), SceneElementTypeEnum.None);
//LoadData(SceneElementTypeEnum.None, ref StaticDataList);
// LoadDynamicData();
//inventoryManager.SetList(StaticDataList.GetList());
//inventoryManager.OpenPanel();
if (NewGame)
{
foreach (ChestPrefabAssetData asset in ElementsToBuildOnSceneList) { convertDataToAsset.Add((ChestPrefabAsset)asset.MapDataToPrefabAssetModel()); }
ChestBuilder.ElementsToBuildOnSceneList = convertDataToAsset;
ChestBuilder.BuildList();
DynamicDataList.SetList(convertDataToAsset);
List<Chest> tmp = new List<Chest>();
foreach (ChestPrefabAsset asset in ChestBuilder.ElementsToBuildOnSceneList) { tmp.Add(asset.Chest); }
chestManager.SetList(tmp);
}
else
{
LoadDynamicData();
ChestBuilder.ElementsToBuildOnSceneList = DynamicDataList.GetList();
ChestBuilder.BuildList();
List<Chest> tmp = new List<Chest>();
foreach (ChestPrefabAsset asset in ChestBuilder.ElementsToBuildOnSceneList) { tmp.Add(asset.Chest); }
chestManager.SetList(tmp);
// BuildList();
// when chest detect player in near arrea and player press "c"
// open panel -> chest controller handle Open panel in Scene Chest Manager passing info about what Chest Palyer want to open
// Manager Build panel and pass info about chest content
}
}
// TODO - save ChestPrefabAsset (we need to save coords...) but in manager handle Chest data..
//
protected SceneBaseDataManager<ChestPrefabAsset> GetObjectType()
{
return GameObject.FindObjectOfType<SceneChestDataManager>();
}
protected SceneBaseDataManager<ChestPrefabAsset> CreateInstance(ref GameObject managerGameObject)
{
return managerGameObject.AddComponent<SceneChestDataManager>();
}
// TODO manager api
// open panel extend function
// close panel extend function
public void OpenPanel(string chestName)
{
}
// TODO chest api
// add to chest - find chest by its name np
// remove from chest - select chest by its name -
// chesk item in chest - check chest by tis name
}

View File

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

View File

@ -1,8 +1,9 @@
using System.Collections.Generic;
using UnityEngine;
public class InventoryDataListManager : DataListManager<KeyValuePair<int, Item>> // or maybe EquippableItem - but its get conflicts...
{
public DataListManager<KeyValuePair<int, Item>> SetUiManager(ref UIWarehouseManager _uiManager)
public new DataListManager<KeyValuePair<int, Item>> SetUiManager(ref InventoryUIManager _uiManager)
{
uiManager = _uiManager;
@ -18,12 +19,4 @@ public class InventoryDataListManager : DataListManager<KeyValuePair<int, Item>>
{
throw new System.NotImplementedException();
}
// public override void Build()
// {
// // pass to InventoryManager singleton
// foreach(KeyValuePair<int, EquippableItemPrefabAsset> itemEntry in Elements)
// InventoryManager.Instance.SetupItemInInventory(itemEntry.Key, itemEntry.Value.equippableItem);
//
// }
}

View File

@ -12,81 +12,6 @@ public class SceneInventoryDataLoader : SceneBaseDataLoader<KeyValuePair<int, Eq
SaveModelSystem.ObjectListName = _objectListName;
}
/*
public void LoadInventoryItemsList()
{
string path = SaveSystem.GetSavePath();
if (!Directory.Exists(path)) // if not exists thats mean there was nothing saved yet - nothing to load
return;
FileInfo[] fileInfo = new DirectoryInfo(path).GetFiles();
foreach(FileInfo file in fileInfo)
{
if(file.Name != this.ItemsListName + ".fun")
continue;
Dictionary<int, EquippableItemPrefabAssetData> equippableItemsList = SaveInventorySystem.LoadInventoryItemsList(this.ItemsListName);
// itemEntry.Value.MapDataToEquippableItem() - map data format to object
// save object
foreach(KeyValuePair<int, EquippableItemPrefabAssetData> itemEntry in equippableItemsList)
{
InventoryManager.Instance.SetupItemInInventory(itemEntry.Key, itemEntry.Value.MapDataToEquippableItemPrefarbAsset().equippableItem);
}
}
}
public void SaveInventoryItems()
{
// Case I - if we remember all list
// 1) if after removed item form DynamicList is empty - remove all file
// 2) if after removed item form DynamciList there are another one - save updated list again
if(InventoryManager.Instance._items.Count > 0) {
// 1. Map From Dictionary<int, Item>' to 'Dictionary<int, EquippableItemPrefabAsset>'
Dictionary<int, EquippableItemPrefabAsset> mappedList = new Dictionary<int, EquippableItemPrefabAsset>();
foreach(KeyValuePair<int, Item> itemElement in InventoryManager.Instance._items)
{
mappedList[itemElement.Key] = new EquippableItemPrefabAsset(
itemElement.Value.Name,
itemElement.Value.ItemModel.name,
new Vector3(0,0,0),
(EquippableItem) itemElement.Value
);
}
// 2. Save Items
SaveInventorySystem.SaveInventoryItemsList(mappedList, this.ItemsListName);
} else {
string _path = SaveSystem.GetSavePath() + "/" + this.ItemsListName + ".fun";
try
{
Debug.Log("File to remove: " + _path);
if(File.Exists(_path))
{
File.Delete(_path);
}
}
catch (IOException ioExp)
{
Debug.LogError(ioExp.Message);
}
}
// Case II - if we rememenber object per file
// 1) remove specyfic file
//
// Unfortunatelly we don't use this way of saving items yet :D
}
*/
protected override List<KeyValuePair<int, EquippableItemPrefabAsset>> LoadGenericData()
{
SaveModelSystem.Path = PathBuilder.BuildSavePath().GetString();

View File

@ -28,12 +28,12 @@ public class SceneInventoryDataManager : SceneBaseDataManager<KeyValuePair<int,
//SaveData(StaticDataList.GetList(), SceneElementTypeEnum.None);
LoadData(SceneElementTypeEnum.None, ref StaticDataList);
// LoadData(SceneElementTypeEnum.None, ref StaticDataList);
// LoadDynamicData();
inventoryManager.SetList(StaticDataList.GetList());
//inventoryManager.SetList(StaticDataList.GetList());
inventoryManager.OpenPanel();
//inventoryManager.OpenPanel();
}
#region override load & save
@ -56,7 +56,7 @@ public class SceneInventoryDataManager : SceneBaseDataManager<KeyValuePair<int,
}
catch (Exception e)
{
Debug.LogWarning(e.Message);
Debug.LogError(e.Message);
}
return false;
@ -89,7 +89,7 @@ public class SceneInventoryDataManager : SceneBaseDataManager<KeyValuePair<int,
}
catch (Exception e)
{
Debug.LogWarning(e.Message);
Debug.LogError(e.Message);
}
return false;

View File

@ -1,80 +0,0 @@
// using Shared.Manager.Scene;
// using System.Collections.Generic;
// using UnityEngine;
// using UnityEditor;
// using UnityEngine.SceneManagement;
// using System.IO;
// using System.Linq;
// using REFACTORING.Shared.Manager.Scene;
//
// namespace REFACTORING.Scene
// {
// public class SceneChestManager : SceneBaseDataManager<ChestPrefarbAsset>
// {
// private new const string STATIC_ELEMENT_LOCATION = "/StaticElements/";
// private new const string ELEMENT_FOLDER_NAME = "Chest";
// private new const string ITEM_LIST_NAME = "ChestList";
//
// // [SerializeField]
// // public List<ChestPrefarbAsset> StaticElements;
// //
// // [SerializeField]
// // public List<ChestPrefarbAsset> DynamicElements;
//
// public override void AddElementToList()
// {
// throw new System.NotImplementedException();
// }
//
// public override void RemoveElementFromList()
// {
// throw new System.NotImplementedException();
// }
//
// public override void Build()
// {
// throw new System.NotImplementedException();
// }
//
// public override void LoadData()
// {
// this.StaticElements = LoadStaticChestsList();
// }
//
// #region Static list of Chest Loader
// private List<ChestPrefarbAsset> LoadStaticChestsList()
// {
// var path = SaveSystem.GetSavePath(this.MapName + STATIC_ELEMENT_LOCATION);
//
// if (!Directory.Exists(path))
// return new List<ChestPrefarbAsset>();
//
// List<ChestPrefarbAsset> chestPrefabAssetList = new List<ChestPrefarbAsset>();
//
// foreach(var file in new DirectoryInfo(path).GetFiles())
// {
// Debug.Log(file.FullName);
//
// List<ChestPrefarbAssetData> chestPrefabAssetDataList = SaveChestSystem.LoadChestsList(this.MapName + STATIC_ELEMENT_LOCATION, ITEM_LIST_NAME);
//
// chestPrefabAssetList = chestPrefabAssetDataList.Select(chestPrefabAssetData => chestPrefabAssetData.MapDataToChestPrefarbAsset()).ToList();
//
// // Debug.Log("---- Load Chest");
// //
// // foreach(ChestPrefarbAsset chest in chestPrefarbAssetList)
// // {
// // Debug.Log(chest.name);
// // foreach(KeyValuePair<int, EquippableItemPrefabAsset> equippableItemPrefarbAsset in chest.content)
// // {
// // // Debug.Log("item on position " + equippableItemPrefarbAsset.Key +
// // // " " + equippableItemPrefarbAsset.Value.equippableItem.name);
// // }
// // }
//
// }
//
// return chestPrefabAssetList;
// }
// #endregion
// }
// }

View File

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 03ae14a03c0d4cfb83ddf5c7eb84c528
timeCreated: 1660171923

View File

@ -34,7 +34,7 @@ public class SaveTaskDataManager : SaveModelSystem<Task>
return base.LoadModelItem();
}
public override IEnumerable<Task> LoadModelList()
public override List<Task> LoadModelList()
{
string path = Path + GetFileName(ObjectListName);

View File

@ -66,7 +66,7 @@ public class SceneTaskDataLoader : SceneBaseDataLoader<Task>
//
// }
protected override IEnumerable<Task> LoadGenericData()
protected override List<Task> LoadGenericData()
{
SaveModelSystem.Path = PathBuilder.BuildSavePath().GetString();
@ -88,7 +88,7 @@ public class SceneTaskDataLoader : SceneBaseDataLoader<Task>
return false;
}
protected override IEnumerable<Task> LoadStaticData() { throw new System.NotImplementedException(); }
protected override List<Task> LoadStaticData() { throw new System.NotImplementedException(); }
protected override List<Task> LoadDynamicData() { throw new System.NotImplementedException(); }

View File

@ -22,10 +22,11 @@ public class SceneTaskDataManager : SceneBaseDataManager<Task>
DataLoader = new SceneTaskDataLoader(OBJECT_LIST_NAME, OBJECT_FOLDER_NAME);
// taskManager.SetList();
LoadStaticData();
// LoadDynamicData();
//SaveData(taskManager.GetList(), SceneElementTypeEnum.None);
taskManager.SetList(StaticDataList.GetList());
//LoadData(SceneElementTypeEnum.None, ref StaticDataList);
//taskManager.SetList(StaticDataList.GetList());
}
protected SceneBaseDataManager<Task> GetObjectType()

View File

@ -1,10 +1,16 @@
using UnityEngine;
public class TaskDataListManager : DataListManager<Task>
{
// public override void Build()
// {
// foreach(var quest in Elements)
// uiManager.Add(quest);
// }
[SerializeField] protected new TaskUIManager uiManager;
public new DataListManager<Task> SetUiManager(ref TaskUIManager _uiManager)
{
uiManager = _uiManager;
return this;
}
public override void AddElementToList(Task newElement)
{
throw new System.NotImplementedException();

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 5e5b0dc687e02e447a5d3464cc5d7a9d
guid: e3aa9c4c1601f994a96a35cc82056750
folderAsset: yes
DefaultImporter:
externalObjects: {}

View File

@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using UnityEngine;
[Serializable]
public abstract class SceneObjectBuilder<V> : MonoBehaviour, SceneObjectBuilderInterface<V>
{
protected virtual string MODEL_SOURCE_PATH => "";
/// <summary>
/// List of chests deffaultly builded on scene
/// </summary>
[SerializeField] public List<V> ElementsToBuildOnSceneList = new List<V>();
public virtual void BuildList()
{
foreach(var objectToBuild in ElementsToBuildOnSceneList)
{
Build(objectToBuild);
}
}
public abstract void Build(V objectToBuild);
public abstract GameObject FindModel(string modelName);
}

View File

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

View File

@ -0,0 +1,15 @@
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
public interface SceneObjectBuilderInterface<T>
{
/// <summary>
/// Function to find object's model in resources
/// </summary>
/// <returns></returns>
public GameObject FindModel(string modelName);
public void BuildList();
public void Build(T objectToBuild);
}

View File

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

View File

@ -30,6 +30,4 @@ public abstract class DataListManager<T> : SceneDataListManagerInterface<T>
public abstract void AddElementToList(T newElement);
public abstract void RemoveElementFromList(T element);
//public abstract void Build();
}

View File

@ -16,18 +16,17 @@ public abstract class SceneBaseDataManager<T> : MonoBehaviour
public static SceneBaseDataManager<T> Instance; // { get; private set; }
public static SceneBaseDataManager<T> FindOrCreateInstance() // ref GameObject managerGameObject
public virtual void Awake()
{
var instance = GetObjectType();
if (instance != null)
if (Instance == null)
{
return instance;
Instance = this;
}
else
{
Destroy(gameObject);
}
Instance = CreateInstance();
return Instance;
}
protected static SceneBaseDataManager<T> GetObjectType()
@ -54,22 +53,12 @@ public abstract class SceneBaseDataManager<T> : MonoBehaviour
return GameObject.FindGameObjectWithTag("Manager").transform.Find("DataManger").gameObject;
}
// /// <summary>
// /// Part of core functions
// /// </summary>
// private void Build()
// {
// // StaticDataList.Build();
// //
// // DynamicDataList.Build();
// }
protected virtual bool LoadData(SceneElementTypeEnum type, ref DataListManager<T> dataListManager)
{
try
{
dataListManager.SetList(
DataLoader.LoadData(SceneElementTypeEnum.None) as List<T>
DataLoader.LoadData(type) as List<T>
);
return true;
@ -85,12 +74,14 @@ public abstract class SceneBaseDataManager<T> : MonoBehaviour
{
try
{
Debug.Log("SaveData");
Debug.Log(DataLoader);
DataLoader.SaveData(_elements, type);
return true;
}
catch (Exception e) {
Debug.LogWarning(e.Message);
Debug.LogError(e.Message);
}
return false;
@ -156,6 +147,7 @@ public abstract class SceneBaseDataManager<T> : MonoBehaviour
// approach:
// 1. get from outside, update local list && us it
// 2. Handle list synchronized all the time & pass local list
Debug.Log("SaveDynamicData");
return SaveData(DynamicDataList.GetList(), SceneElementTypeEnum.Dynamic);
}

View File

@ -9,6 +9,4 @@ public interface SceneDataListManagerInterface<T>
public void AddElementToList(T element);
public void RemoveElementFromList(T element);
// public void Build();
}

View File

@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using UnityEngine;
using UnityEngine.UI;
@ -43,19 +44,20 @@ public abstract class DraggablePanelController : PanelController<KeyValuePair<in
DraggedSlotController.Instance.UpdatePosition(Input.mousePosition);
}
public void EndDrag(ItemSlot itemSlot)
public virtual void EndDrag(ItemSlot itemSlot)
{
if (!DraggedSlotController.Instance.IsDragged()) // if there was nothing dragged - ignore event
return;
DraggedSlotController.Instance.RemoveDraggedSlot();
// Apply list of items
// Rebuild/apply UiManager content (list of items) base on slots values after its updating
for (int i = 0; i < ChildBoxList.Count; i++)
{
if (ChildBoxList[i].Item != null)
{
UiManager.Add(new KeyValuePair<int, Item>(i, (EquippableItem)ChildBoxList[i].Item));
UiManager.Add(new KeyValuePair<int, Item>(i, ChildBoxList[i].Item));
}
else
{
@ -78,29 +80,21 @@ public abstract class DraggablePanelController : PanelController<KeyValuePair<in
// TODO insert child criterials
Item _tmpDraggedItem = draggedSlot.Item; // InventoryUIManager.Instance.DraggedSlot.Item; // remember temporary currently dragged item
//draggedSlot.Item = (EquippableItem)new Item("test", "test desc", 1, null, null);
Item tmpDraggedItem = draggedSlot.Item == null ? null : new EquippableItem(draggedSlot.Item); // InventoryUIManager.Instance.DraggedSlot.Item; // remember temporary currently dragged item
UiManager.Add(new KeyValuePair<int, Item>(dropItemSlot.Number, tmpDraggedItem));
/*
* not sure why but if you change order of assign, something will ovberride dropItemSlot.Item vale accordint to draggedSlot.Item = dropItemSlot.Item; value
* BUG - not sure where
*/
draggedSlot.Item = dropItemSlot.Item;
UiManager.Add(new KeyValuePair<int, Item>(draggedSlot.Number, (EquippableItem)draggedSlot.Item));
dropItemSlot.Item = _tmpDraggedItem;
UiManager.Add(new KeyValuePair<int, Item>(dropItemSlot.Number, (EquippableItem)dropItemSlot.Item));
// !!! remember item from dropped position to future operation !!!
if (dropItem)
DraggedSlotController.Instance.UpdateItem(new EquippableItem(dropItem));
else
DraggedSlotController.Instance.UpdateItem(null);
}
}
//public ISlot GetDraggedSlotFromManager() => InventoryUIManager.Instance.DraggedSlot;
public ISlot GetDraggedSlot()
{
return DraggedSlotController.Instance.DraggedSlot;
}
public void SetItemOnPosition()
{
throw new System.NotImplementedException();
}
}

View File

@ -19,7 +19,5 @@ public interface DraggablePanelInterface
public void Drop(ItemSlot dropItemSlot);
// supports function to use in Drop
public void SetItemOnPosition();
public ISlot GetDraggedSlot();
}

View File

@ -13,8 +13,8 @@ public class DraggedSlotController : MonoBehaviour
[Space]
[Header("Dragged Slot")]
[SerializeField] protected ISlot _draggedSlot;
public ISlot DraggedSlot // in Drag & Drop functionality for Warehouse set of panels I will temporary delegate dragged item to outside static object instance in order to remember it during dragging object from one slot to anothe one
[SerializeField] protected ItemSlot _draggedSlot;
public ItemSlot DraggedSlot // in Drag & Drop functionality for Warehouse set of panels I will temporary delegate dragged item to outside static object instance in order to remember it during dragging object from one slot to anothe one
{
get { return _draggedSlot; }
set
@ -93,4 +93,9 @@ public class DraggedSlotController : MonoBehaviour
return true;
}
public void UpdateItem(Item item)
{
DraggedSlot.Item = (EquippableItem)item;
}
}

View File

@ -1,10 +1,47 @@
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using UnityEngine;
public abstract class WarehousePanelController : DraggablePanelController
{
public override void EndDrag(ItemSlot itemSlot)
{
if (!DraggedSlotController.Instance.IsDragged()) // if there was nothing dragged - ignore event
return;
DraggedSlotController.Instance.RemoveDraggedSlot();
// 1. Remove from slot - for case where EndDrag and Drop work on differen UiManager's
// Important: clear slot not only reset itemn!!!
if (!itemSlot.Item)
((ItemSlot)ChildBoxList.Where(slot => slot.Number == itemSlot.Number).First()).ResetSlot();
else
((ItemSlot)ChildBoxList.Where(slot => slot.Number == itemSlot.Number).First()).SetItem(itemSlot.Item);
// 2. Rebuild/apply UiManager content (list of items) base on slots values after its updating
// 2.1 Make copy because Add -> base.Add() -> base.Add() -> UpdateList() rebuild content ad pass "new" list (in this case with only one - firtst passed - item) to ChestContentUiMangaer.Element
var ChildBoxListCopy = new List<KeyValuePair<int, Item>>(ChildBoxList.Where(slot => slot.Item != null).Select(slot => new KeyValuePair<int, Item>(slot.Number, slot.Item)).ToList());
UiManager.RemoveAll();
foreach(KeyValuePair<int, Item> slot in ChildBoxListCopy)
{
if (slot.Value != null)
{
Debug.Log($"Slot nr: {slot.Key} with item: {slot.Value}");
UiManager.Add(new KeyValuePair<int, Item>(slot.Key, slot.Value));
}
else
{
UiManager.RemoveByPosition(slot.Key);
}
}
}
public override void BuildPanelContent(List<KeyValuePair<int, Item>> elements)
{
base.BuildPanelContent(elements);

View File

@ -5,10 +5,10 @@ using UnityEngine;
[Serializable]
public abstract class UIBaseManager<T> : MonoBehaviour, ManagerInterface<T>
{
public static UIBaseManager<T> Instance { get; private set; }
public static UIBaseManager<T> Instance { get; protected set; }
[SerializeField] protected GameObject DynamicPanel;
[SerializeField] public GameObject DynamicPanel;
[SerializeField] public KeyCode keyToOpen;
@ -22,8 +22,11 @@ public abstract class UIBaseManager<T> : MonoBehaviour, ManagerInterface<T>
if (Instance == null)
{
Instance = this;
} else
}
else
{
Debug.Log(gameObject);
Debug.Log(Instance);
Destroy(gameObject);
}
}
@ -53,12 +56,10 @@ public abstract class UIBaseManager<T> : MonoBehaviour, ManagerInterface<T>
//DynamicPanel = dynamicPanelController;
}
public bool OpenPanel()
public virtual bool OpenPanel()
{
Console.WriteLine("Panel opened");
//try
//{
GameObject globalGUI = GameObject.FindGameObjectWithTag("GUI");
if(!globalGUI)
@ -66,8 +67,6 @@ public abstract class UIBaseManager<T> : MonoBehaviour, ManagerInterface<T>
GameObject uiPanelTemplate = GetTemplatePanel();
//GameObject.Instantiate(muzzleFlashPrefab, transform.position, transform.rotation);
DynamicPanel = GameObject.Instantiate(uiPanelTemplate, uiPanelTemplate.transform.position, Quaternion.identity, globalGUI.transform); // 4'th arg allow set object as child
DynamicPanel.transform.localPosition = uiPanelTemplate.transform.position; // prevent overwritten position by... environment???
@ -75,12 +74,9 @@ public abstract class UIBaseManager<T> : MonoBehaviour, ManagerInterface<T>
SetupPanel();
return true;
//} catch (Exception ex) { Debug.LogError(ex.Message); }
return false;
}
public bool ClosePanel()
public virtual bool ClosePanel()
{
Console.WriteLine("Panel closed");
@ -165,9 +161,4 @@ public abstract class UIBaseManager<T> : MonoBehaviour, ManagerInterface<T>
/// </summary>
/// <returns></returns>
protected abstract GameObject GetTemplatePanel();
/* public T Find(string itemName)
{
throw new NotImplementedException();
}*/
}

View File

@ -7,21 +7,10 @@ public abstract class UIWarehouseManager : UIBaseManager<KeyValuePair<int, Item>
{
public virtual int SLOTS_NUMBER => 0;
public static new UIWarehouseManager Instance { get; private set; }
public static new UIWarehouseManager Instance { get; protected set; }
/*
* not sure why but childrens of this class dont interfere on parents Awake
*/
public void Awake()
{
if (Instance == null)
{
Instance = this;
}
else
{
Destroy(gameObject);
}
}
/// <summary>
/// Function to find item in warehouser by its id, returns list of all slots where item occured
@ -49,8 +38,9 @@ public abstract class UIWarehouseManager : UIBaseManager<KeyValuePair<int, Item>
/// Function (SetItemOnPosition) to add slot with its number and item to list (which will be mapped with panel content)
/// </summary>
/// <param name="itemOnSlot"></param>
public void Add(KeyValuePair<int, Item> itemOnSlot)
public virtual void Add(KeyValuePair<int, Item> itemOnSlot)
{
if (!CheckIfSlotIsInRange(itemOnSlot.Key))
throw new System.Exception($"Slot number: {itemOnSlot.Key} is out of range, avaiable: {SLOTS_NUMBER} slots");
@ -59,7 +49,6 @@ public abstract class UIWarehouseManager : UIBaseManager<KeyValuePair<int, Item>
if(itemOnSlot.Value != null)
{
Debug.Log($" Added {itemOnSlot.Value} on position {itemOnSlot.Key}");
base.Add(itemOnSlot);
}
}
@ -68,7 +57,7 @@ public abstract class UIWarehouseManager : UIBaseManager<KeyValuePair<int, Item>
/// Function to add item on first empty slot to list (which will be mapped with panel content)
/// </summary>
/// <param name="item"></param>
public void Add(Item item)
public virtual void Add(Item item)
{
if(IsFull())
throw new System.Exception($"Warehouse is full!!!");
@ -81,7 +70,7 @@ public abstract class UIWarehouseManager : UIBaseManager<KeyValuePair<int, Item>
public void RemoveByPosition(int keyPosition)
public virtual void RemoveByPosition(int keyPosition)
{
if (!CheckIfSlotExists(keyPosition))
return; // throw new System.Exception($"Slot with number: {keyPosition} don't exist");
@ -91,16 +80,20 @@ public abstract class UIWarehouseManager : UIBaseManager<KeyValuePair<int, Item>
Elements.RemoveAll(itemSlot => itemSlot.Key == keyPosition);
}
public int RemoveByItemId(int itemId)
public virtual int RemoveByItemId(int itemId)
{
return Elements.RemoveAll(itemSlot => itemSlot.Value.Id == itemId);
}
public int RemoveByItemName(string itemName)
public virtual int RemoveByItemName(string itemName)
{
return Elements.RemoveAll(itemSlot => itemSlot.Value.Name == itemName);
}
public virtual void RemoveAll()
{
Elements.Clear();
}
public bool IsFull()
{

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 09dff9a30bb15e24492815f4b548638f
guid: c2dc097533c72c34aada9077f5b81301
folderAsset: yes
DefaultImporter:
externalObjects: {}

View File

@ -0,0 +1,112 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ChestContentUIManager : UIWarehouseManager
{
public static new ChestContentUIManager Instance { get; protected set; }
public override int SLOTS_NUMBER { get { return 48; } }
public const string ITEM_LOCALIZATION = "UiPanels/";
public const string PANEL_NAME = null;
public void Awake()
{
if (Instance == null)
{
Instance = this;
}
else
{
Debug.Log(Instance);
Debug.Log("destroiy inventory UI");
Destroy(gameObject);
}
}
/*
public override void UpdateList()
{
// TODO something like rebuild associated panel content
// depending on which class we use it mayu be Inventory / Chest / Shop Panel Controller
DynamicPanel.GetComponent<InventoryPanelController>(); //.Refresh() -- rebuild content
}*/
public void Update()
{
// use empty function to override parent Update
// to prevent using Open Panel and Close Panel!!!
// this UI manager mustn't open panel - only manage passed chest content and return updated data
}
public bool OpenPanel() { return true; }
public bool ClosePanel() { return true; }
protected override GameObject GetTemplatePanel() { throw new System.NotImplementedException(); }
public override void SetupPanel()
{
base.SetupPanel();
Debug.Log(Elements);
// setup models list
DynamicPanel.GetComponent<ChestPanelController>().SetUp(Elements);
}
public override void UpdateList()
{
DynamicPanel.GetComponent<ChestPanelController>().BuildPanelContent(Elements);
}
#region adust parent function
public override void Add(KeyValuePair<int, Item> itemOnSlot)
{
base.Add(itemOnSlot);
UpdateChestContent();
}
public override void Add(Item item)
{
base.Add(item);
UpdateChestContent();
}
public override void RemoveByPosition(int keyPosition)
{
base.RemoveByPosition(keyPosition);
UpdateChestContent();
}
public override int RemoveByItemId(int itemId)
{
var result = base.RemoveByItemId(itemId);
UpdateChestContent();
return result;
}
public override int RemoveByItemName(string itemName)
{
var result = base.RemoveByItemName(itemName);
UpdateChestContent();
return result;
}
public override void RemoveAll()
{
Elements.Clear();
UpdateChestContent();
}
#endregion
private void UpdateChestContent()
{
ChestUIManager.Instance.UpdateChestContent(ChestUIManager.Instance.CurrentChestName, Elements);
}
}

View File

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

View File

@ -0,0 +1,100 @@
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
[Serializable]
public class ChestUIManager : UIBaseManager<Chest>
{
public new static ChestUIManager Instance { get; private set; }
public const string ITEM_LOCALIZATION = "UiPanels/";
public const string PANEL_NAME = "ChestPanel";
public int SLOTS_NUMBER => 48;
public string CurrentChestName = null;
public void Awake()
{
if (Instance == null)
{
Instance = this;
}
else
{
Debug.Log(gameObject);
Debug.Log(Instance);
Destroy(gameObject);
}
}
public override bool OpenPanel()
{
if (CurrentChestName == null || CurrentChestName == "")
{
Debug.Log($"You re not in collision with any chest");
return false;
}
return base.OpenPanel();
}
public override bool ClosePanel()
{
base.ClosePanel();
ChestContentUIManager.Instance.DynamicPanel = null;
return true;
}
public override void SetupPanel()
{
base.SetupPanel();
var chest = FindChestInCollection(CurrentChestName);
if (chest == null)
throw new Exception($"Chest {CurrentChestName} not found");
ChestContentUIManager.Instance.SetList(chest.GetContent());
ChestContentUIManager.Instance.DynamicPanel = DynamicPanel;
ChestContentUIManager.Instance.SetupPanel();
// setup models list
//DynamicPanel.GetComponent<ChestPanelController>().SetUp(chest.GetContent());
}
public override void UpdateList()
{
if (CurrentChestName == null || CurrentChestName == "")
throw new Exception($"You re not in collision with any chest");
var chest = FindChestInCollection(CurrentChestName);
if (chest == null)
throw new Exception($"Chest {CurrentChestName} not found");
ChestContentUIManager.Instance.SetList(chest.GetContent());
ChestContentUIManager.Instance.DynamicPanel = DynamicPanel;
ChestContentUIManager.Instance.UpdateList();
//DynamicPanel.GetComponent<ChestPanelController>().BuildPanelContent(chest.GetContent());
}
public void UpdateChestContent(string chestName, List<KeyValuePair<int, Item>> chestContent)
{
Elements.Where(chest => chest.name == chestName).ToList().ForEach(chest => chest.SetContent(chestContent));
}
protected override GameObject GetTemplatePanel()
{
// Resources = default path - Asset/Resources ... .obj
return Resources.Load(ITEM_LOCALIZATION + PANEL_NAME) as GameObject;
}
private Chest FindChestInCollection(string _chestName)
{
return Elements.Find(chest => chest.Name == _chestName);
}
}

View File

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

View File

@ -5,12 +5,28 @@ using UnityEngine;
[Serializable]
public class InventoryUIManager : UIWarehouseManager
{
public static new InventoryUIManager Instance { get; protected set; }
public override int SLOTS_NUMBER { get { return 48; } }
public const string ITEM_LOCALIZATION = "UiPanels/";
public const string PANEL_NAME = "InventoryPanel";
/* public override void UpdateList()
public void Awake()
{
if (Instance == null)
{
Instance = this;
}
else
{
Debug.Log(Instance);
Debug.Log("destroiy inventory UI");
Destroy(gameObject);
}
}
/* public override void UpdateList()
{
// TODO something like rebuild associated panel content
// depending on which class we use it mayu be Inventory / Chest / Shop Panel Controller

View File

@ -0,0 +1,91 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using System;
public class ChestPanelController : WarehousePanelController
{
protected override UIBaseManager<KeyValuePair<int, Item>> FetchUiManager()
{
return GameObject.FindObjectOfType<ChestContentUIManager>();
}
// build panel sunction
// - setup - main function to build panel on screen
// - setPanelISlots - build slots on panel dependiong on declared amount
// - setPanelItems - invoking building items on slots
// api for drag and drop
// - set item on position
// - remove item from position
// - find item in warehouse
// 1. Prepare empty panel
public override void BuildPanelSlots()
{
if (_panelContent == null)
throw new Exception("Panel content is not attaches");
for (int _position = 0; _position < UiManager.SLOTS_NUMBER; _position++)
{
//ISlot newSlot = SetupSlot(_position, _panel);
GameObject newSlot = BuildSlot(_position, _panelContent);
// Set new Slot instance
ChildBoxList.Add(newSlot.GetComponent<ChestSlot>());
// Assign events
ChildBoxList[_position] = SetupDragAndDropToSlot(ChildBoxList[_position]);
}
}
public override GameObject BuildSlot(int key, GameObject _parent)
{
if (ChildBoxTemplate == null)
throw new Exception("chestslotbox_template is empty");
GameObject _newItemSlot = MonoBehaviour.Instantiate(ChildBoxTemplate, _parent.transform.position, Quaternion.identity); //.GetComponent<InventorySlot>();
_newItemSlot.transform.SetParent(_parent.transform);
_newItemSlot.transform.localScale = new Vector3(1.15f, 1.15f, 1.15f);
_newItemSlot.GetComponent<ChestSlot>().SetupSlot(key, null, this);
return _newItemSlot;
}
// 2. Set up panel additn items to it
public override void SetUp(List<KeyValuePair<int, Item>> elements)
{
// Build panel content template
BuildPanelSlots();
// Fill with items
BuildPanelContent(elements);
}
public override void BuildPanelContent(List<KeyValuePair<int, Item>> elements)
{
base.BuildPanelContent(elements);
Debug.Log("Build content");
foreach (KeyValuePair<int, Item> element in elements)
{
Debug.Log($"key: {element.Key} - value: {element.Value}");
ChildBoxList[element.Key].SetItem(new EquippableItem(element.Value));
}
}
}
//Chest content manager
// gest new elements list after open chest
// remove: -> remove from list, (binding) update list in chest

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 8d9e1061a8038f54a87269aa0bd2db04
guid: 84da00f00bb500c46b1e5629ca4a61b8
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@ -85,7 +85,7 @@ public class InventoryPanelController : WarehousePanelController
foreach (KeyValuePair<int, Item> element in elements)
{
Debug.Log($"key: {element.Key} - value: {element.Value}");
ChildBoxList[element.Key].SetItem(element.Value);
ChildBoxList[element.Key].SetItem((EquippableItem)element.Value);
}
}
}

View File

@ -0,0 +1,10 @@

[System.Serializable]
public enum ChestTypeEnum
{
Wodden,
Silver,
Golden,
Prize,
Extra
}

View File

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

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 8f774df0851945f084c9d38c173b3a19
timeCreated: 1660483048

View File

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

View File

@ -0,0 +1,106 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[System.Serializable]
public struct IndexValuePair<T>
{
[SerializeField] public int Key;
[SerializeField] public T Value;
public IndexValuePair(int key, T value)
{
Key = key;
Value = value;
}
}
[System.Serializable]
[CreateAssetMenu(fileName = "New Chest", menuName = "Inventory/Chest")]
public class Chest
{
public int id;
public int Id
{
get { return id; }
set { id = value; }
}
public string name;
public string Name
{
get { return name; }
set { name = value; }
}
public string description;
public string Description
{
get { return description; }
set { description = value; }
}
public GameObject chestModel;
public GameObject ChestModel
{
get { return chestModel; }
set { chestModel = value; }
}
public ChestTypeEnum ChestType;
public List<IndexValuePair<Item>> Content = new List<IndexValuePair<Item>>();
public Chest() { }
public Chest(Chest _chest)
{
this.Name = _chest.Name;
this.Description = _chest.Description;
this.ChestModel = _chest.ChestModel;
this.ChestType = _chest.ChestType;
this.Content = _chest.Content;
}
public Chest(string _name, string _description, GameObject _chestModel, ChestTypeEnum _type)
{
this.Name = _name;
this.Description = _description;
this.ChestModel = _chestModel;
this.ChestType = _type;
}
public Chest(string _name, string _description, GameObject _chestModel, ChestTypeEnum _type, List<KeyValuePair<int, Item>> _content)
{
this.Name = _name;
this.Description = _description;
this.ChestModel = _chestModel;
this.ChestType = _type;
SetContent(_content);
}
public void SetContent(List<KeyValuePair<int, Item>> _content)
{
Content.Clear();
foreach (KeyValuePair<int, Item> element in _content)
{
Content.Add(new IndexValuePair<Item>(element.Key, element.Value));
}
}
public List<KeyValuePair<int, Item>> GetContent()
{
List<KeyValuePair<int, Item>> castedContent = new List<KeyValuePair<int, Item>>();
foreach (IndexValuePair<Item> element in Content)
{
castedContent.Add(new KeyValuePair<int, Item>(element.Key, element.Value));
}
return castedContent;
}
}

View File

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

View File

@ -0,0 +1,64 @@
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
[System.Serializable]
public class ChestData : ModelData<Chest, GameObject>
{
[SerializeField]
public string description;
[SerializeField]
public ChestTypeEnum type;
[SerializeField]
public List<IndexValuePair<EquippableItemData>> content = new List<IndexValuePair<EquippableItemData>>();
protected override string SPRITE_LOCALIZATION => "Sprites/Object Sprites/";
protected override string MODEL_LOCALIZATION => "Chests/";
public ChestData(Chest chest) : base(chest.id, chest.name, chest.chestModel.name)
{
description = chest.description;
foreach(IndexValuePair<Item> item in chest.Content)
{
content.Add(
new IndexValuePair<EquippableItemData>(item.Key, new EquippableItemData(item.Value))
);
}
}
// dont use parameter - chest is not scriptable object, dont have its model in Assets
public override Chest MapDataToObject()
{
// 1. Find object
GameObject chestGameObject = TryFindResource(modelName);
var chest = new Chest(name, description, chestGameObject, type);
// 2. Set chest content from passed data
chest.Content.Clear();
foreach (IndexValuePair<EquippableItemData> item in content)
{
chest.Content.Add(
new IndexValuePair<Item>(item.Key, item.Value.MapDataToObject())
);
}
return chest;
}
public override Chest MapDataToObject(string prefarbAssetName) { throw new System.NotImplementedException(); }
protected override GameObject TryFindResource(string modelName)
{
var resource = Resources.Load<GameObject>(MODEL_LOCALIZATION + modelName);
if (!resource)
throw new System.Exception($"Resource {modelName} not found!!");
return resource;
}
}

View File

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

View File

@ -0,0 +1,29 @@
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
[System.Serializable]
public class ChestPrefabAsset : PrefabAssetModel
{
[SerializeField]
public Chest Chest = null;
//public List<KeyValuePair<int, EquippableItemPrefabAsset>> Content { get; set; }
public ChestPrefabAsset(Chest _chest)
: base(_chest.name, _chest.ChestModel.name, new Vector3(0,0,0))
{
Chest = _chest;
}
public ChestPrefabAsset(string _name, string _prefabAssetName, Vector3 _position, Chest _chest = null)
: base(_name, _prefabAssetName, _position)
{
Chest = _chest;
}
public ChestPrefabAssetData MapPrefabAssetModelToData()
{
return new ChestPrefabAssetData(this);
}
}

View File

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

View File

@ -0,0 +1,60 @@
using System.Collections.Generic;
using UnityEngine;
[System.Serializable]
public class ChestPrefabAssetData : PrefabAssetModelData
{
[SerializeField] ChestData ChestData;
//public List<KeyValuePair<int, EquippableItemPrefabAssetData>> Content { get; set; }
public ChestPrefabAssetData(ChestPrefabAsset assetModel) : base(assetModel)
{
ChestData = MapModelToData(assetModel.Chest);
/* Content = new List<KeyValuePair<int, EquippableItemPrefabAssetData>>();
Debug.Log("ChestPrefarbAsset to ChestPrefarbAssetData - " + assetModel.Name);
foreach(KeyValuePair<int, EquippableItemPrefabAsset> itemEntry in assetModel.Content)
{
Debug.Log("Slot nr " + itemEntry.Key);
Content[itemEntry.Key] = itemEntry.Value.MapPrefabAssetModelToData();
}*/
}
public ChestData MapModelToData(Chest chest)
{
return new ChestData(chest);
}
public override PrefabAssetModelData PrefabAssetModelToData(PrefabAssetModel assetModel)
{
return new ChestPrefabAssetData((ChestPrefabAsset)assetModel);
}
public override PrefabAssetModel MapDataToPrefabAssetModel()
{
ChestPrefabAsset chestPrefabAsset = new ChestPrefabAsset(
Name,
PrefabAssetName,
new Vector3(Position[0], Position[1], Position[2])
);
// todo convert each item to data
Debug.Log(ChestData);
chestPrefabAsset.Chest = ChestData.MapDataToObject();
// clear content and set items from data - this will modify Scri-0ptableObject data also in source
//chestPrefabAsset.Chest.Content.Clear();
/* foreach (IndexValuePair<EquippableItemData> modelData in ChestData.content)
{
var objectFromData = (modelData.Value).MapDataToObject();
Debug.Log(objectFromData);
chestPrefabAsset.Chest.Content.Add(
new IndexValuePair<Item>(modelData.Key, objectFromData)
);
}*/
return chestPrefabAsset;
}
}

View File

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

View File

@ -2,14 +2,14 @@ using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu]
[System.Serializable]
[CreateAssetMenu(fileName = "New Item", menuName = "Inventory/EquippableItem")]
public class EquippableItem : Item
{
public int StrengthBonus;
public int AgilityBonus;
public int InteligenceBonus;
public int VitalityBonus;
public int StrengthBonus = 0;
public int AgilityBonus = 0;
public int InteligenceBonus = 0;
public int VitalityBonus = 0;
[Space]
public bool isStackable = false;
@ -21,6 +21,14 @@ public class EquippableItem : Item
public EquippableItem(Item _item) : base(_item){}
public EquippableItem(EquippableItem _item) : base(_item.name, _item.description, _item.level, _item.itemModel, _item.image)
{
StrengthBonus = _item.StrengthBonus;
AgilityBonus = _item.AgilityBonus;
InteligenceBonus = _item.InteligenceBonus;
VitalityBonus = _item.VitalityBonus;
}
public EquippableItem(string _name, string _description, int _level, GameObject _itemModel, Sprite _image) : base(_name, _description, _level, _itemModel, _image) { }
}

View File

@ -1,25 +1,26 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
[System.Serializable]
public class EquippableItemData : ItemData
{
[SerializeField]
public int strengthBonus;
[SerializeField]
public int agilityBonus;
[SerializeField]
public int inteligenceBonus;
[SerializeField]
public int vitalityBonus;
[SerializeField]
public bool isStackable;
[SerializeField]
public EquipmentTypeEnum equipmentType;
private const string ITEM_LOCALIZATION = "Assets/Items/";
public EquippableItemData(EquippableItem equippableItem) : base(equippableItem)
{
strengthBonus = equippableItem.StrengthBonus;
@ -31,31 +32,14 @@ public class EquippableItemData : ItemData
equipmentType = equippableItem.EquipmentType;
}
public EquippableItem MapDataToEquippableItem(string prefarbAssetName)
public EquippableItemData(Item item) : base(item)
{
// Find prefarb in Assets/
//Debug.Log("MapDataToEquippableItem: " + ITEM_LOCALIZATION + prefarbAssetName + ".asset");
EquippableItem equippableItem = (EquippableItem)AssetDatabase.LoadAssetAtPath(ITEM_LOCALIZATION + prefarbAssetName + ".asset", typeof(EquippableItem));
strengthBonus = 0;
agilityBonus = 0;
inteligenceBonus = 0;
vitalityBonus = 0;
///
// DONT OVERWRITE PROPERTIES BECOUSE ITS EDIT MAIN OBJECT IN ASSET/
///
// equippableItem.StrengthBonus = strengthBonus;
// equippableItem.AgilityBonus = agilityBonus;
// equippableItem.InteligenceBonus = inteligenceBonus;
// equippableItem.VitalityBonus = vitalityBonus;
// equippableItem.isStackable = isStackable;
// equippableItem.EquipmentTypeEnum = equipmentType;
// Item item = base.MapDataToItem(prefarbAssetName);
// equippableItem.Name = item.Name;
// equippableItem.Description = item.Description;
// equippableItem.Level = item.Level;
// equippableItem.ItemModel = item.ItemModel;
// equippableItem.Image = item.Image;
return equippableItem;
isStackable = true;
equipmentType = EquipmentTypeEnum.Other;
}
}

View File

@ -3,11 +3,11 @@ using UnityEngine;
[System.Serializable]
public class EquippableItemPrefabAssetData : PrefabAssetModelData
{
EquippableItemData EquippableItemData;
public EquippableItemData EquippableItemData;
public EquippableItemPrefabAssetData(EquippableItemPrefabAsset assetModel) : base(assetModel)
{
EquippableItemData = MapEquippableItemToData(assetModel.EquippableItem);
EquippableItemData = MapModelToData(assetModel.EquippableItem);
}
/// <summary>
@ -15,7 +15,7 @@ public class EquippableItemPrefabAssetData : PrefabAssetModelData
/// </summary>
/// <param name="equippableItem"></param>
/// <returns></returns>
public EquippableItemData MapEquippableItemToData(EquippableItem equippableItem)
public EquippableItemData MapModelToData(EquippableItem equippableItem)
{
return new EquippableItemData(equippableItem);
}
@ -38,7 +38,7 @@ public class EquippableItemPrefabAssetData : PrefabAssetModelData
new Vector3(Position[0], Position[1], Position[2])
);
equippableItemPrefabAsset.EquippableItem = EquippableItemData.MapDataToEquippableItem(equippableItemPrefabAsset.PrefabAssetName);
equippableItemPrefabAsset.EquippableItem = (EquippableItem)EquippableItemData.MapDataToObject(equippableItemPrefabAsset.PrefabAssetName);
return equippableItemPrefabAsset;
}

View File

@ -1,57 +1,66 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
[System.Serializable]
public class ItemData
public abstract class ItemData : ModelData<Item, Item>
{
public int id;
public string name;
[SerializeField]
public string description;
[SerializeField]
public int level;
[SerializeField]
public string imageName;
// to handle object created on scene for example after removing from inventory
public string itemModelName;
protected override string SPRITE_LOCALIZATION => "Sprites/Object Sprites/";
protected override string MODEL_LOCALIZATION => "Items/";
private const string SPRITE_LOCALIZATION = "Sprites/Object Sprites/";
private const string ITEM_LOCALIZATION = "Assets/Items/";
public ItemData(Item item)
public ItemData(Item item) : base(item.id, item.name, item.itemModel.name)
{
id = item.id;
name = item.name;
description = item.description;
level = item.level;
imageName = item.image.name;
itemModelName = item.itemModel.name;
}
public Item MapDataToItem(string prefarbAssetName)
public override Item MapDataToObject(string prefarbAssetName)
{
// Find prefarb in Assets/
Item item = (Item)AssetDatabase.LoadAssetAtPath(ITEM_LOCALIZATION + prefarbAssetName + ".asset", typeof(Item));
Debug.Log("item prefab from asset name - data to object");
Debug.Log(MODEL_LOCALIZATION + prefarbAssetName + ".asset");
return TryFindResource(prefarbAssetName);
///
// DONT OVERWRITE PROPERTIES BECOUSE ITS EDIT MAIN OBJECT IN ASSET/
///
// item.Id = this.id;
// item.Name = this.name;
// item.Description = this.description;
// item.Level = this.level;
// equippableItem.StrengthBonus = strengthBonus;
// equippableItem.AgilityBonus = agilityBonus;
// equippableItem.InteligenceBonus = inteligenceBonus;
// equippableItem.VitalityBonus = vitalityBonus;
// equippableItem.isStackable = isStackable;
// equippableItem.EquipmentTypeEnum = equipmentType;
// Debug.Log(ITEM_LOCALIZATION + this.imageName);
// item.Image = (Sprite)AssetDatabase.LoadAssetAtPath(ITEM_LOCALIZATION + this.imageName, typeof(Sprite));
// Debug.Log(item.Image);
// Item item = base.MapDataToItem(prefarbAssetName);
// equippableItem.Name = item.Name;
// equippableItem.Description = item.Description;
// equippableItem.Level = item.Level;
// equippableItem.ItemModel = item.ItemModel;
// equippableItem.Image = item.Image;
}
// item.ItemModel = (GameObject)AssetDatabase.LoadAssetAtPath(ITEM_LOCALIZATION + "Gold Ore" + ".prefab", typeof(GameObject));
public override Item MapDataToObject()
{
return TryFindResource(modelName);
}
return item;
protected override Item TryFindResource(string modelName)
{
var resource = Resources.Load<Item>(MODEL_LOCALIZATION + modelName);
Debug.Log(MODEL_LOCALIZATION + modelName);
if (!resource)
throw new System.Exception($"Resource {modelName} not found!!");
return resource;
}
}

View File

@ -1,9 +1,15 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class ChestSlot : ItemSlot
{
/* public ChestSlot(int number, Item item): base(number, item)
{
}*/
public override bool CanReceiveItem(Item item)
{
return true;

View File

@ -8,7 +8,7 @@ using System;
public interface ISlot
{
int Number { get; set; }
Item Item { get; set; }
EquippableItem Item { get; set; }
// enum typ dziecka
// A : enum A
@ -19,7 +19,7 @@ public interface ISlot
event Action<ItemSlot> OnDropEvent;
//(B)Islot // as B
public void SetupSlot(int _number, Item _item, WarehousePanelController _PanelController);
public void SetItem(Item _item);
public void SetupSlot(int _number, EquippableItem _item, WarehousePanelController _PanelController);
public void SetItem(EquippableItem _item);
bool CanReceiveItem(Item item);
}

View File

@ -4,6 +4,11 @@ using UnityEngine;
public class InventorySlot : ItemSlot
{
/* public InventorySlot(int number, Item item) : base(number, item)
{
}*/
public override bool CanReceiveItem(Item item)
{
return true;

View File

@ -27,8 +27,8 @@ public class ItemSlot : MonoBehaviour, ISlot, IBeginDragHandler, IEndDragHandler
}
}
[SerializeField]
protected Item _item;
public Item Item {
protected EquippableItem _item;
public EquippableItem Item {
get { return _item; }
set {
_item = value;
@ -48,7 +48,23 @@ public class ItemSlot : MonoBehaviour, ISlot, IBeginDragHandler, IEndDragHandler
public event Action<ItemSlot> OnDragEvent;
public event Action<ItemSlot> OnDropEvent;
public void SetupSlot(int _number, Item _item, WarehousePanelController _PanelController)
/* public ItemSlot() { }
public ItemSlot(int number, EquippableItem item = null)
{
Number = number;
Item = item;
}*/
/*
public ItemSlot(ItemSlot slot)
{
Number = slot.Number;
Item = slot.Item;
slotItemNumberText = slot.slotItemNumberText;
itemImage = slot.itemImage;
}*/
public void SetupSlot(int _number, EquippableItem _item, WarehousePanelController _PanelController)
{
this._PanelController = _PanelController;
@ -60,7 +76,7 @@ public class ItemSlot : MonoBehaviour, ISlot, IBeginDragHandler, IEndDragHandler
}
}
public void SetItem(Item _item) // dont change slot numer after assign new item, numbers are bind during object init
public void SetItem(EquippableItem _item) // dont change slot numer after assign new item, numbers are bind during object init
{
Item = _item;

View File

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 08674bb7d06248b8b6174ac07b325ee7
timeCreated: 1662917411

View File

@ -0,0 +1,39 @@
using System.Collections;
using UnityEngine;
[System.Serializable]
public abstract class ModelData<T, V>
{
[SerializeField]
public int id;
[SerializeField]
public string name;
// to handle object created on scene for example after removing from inventory
[SerializeField]
public string modelName;
protected virtual string SPRITE_LOCALIZATION => "";
protected virtual string MODEL_LOCALIZATION => "";
public ModelData(int _id, string _name)
{
id = _id;
name = _name;
}
public ModelData(int _id, string _name, string _modelName)
{
id = _id;
name = _name;
modelName = _modelName; // name of the prefab
}
public abstract T MapDataToObject(string prefarbAssetName);
public abstract T MapDataToObject();
protected abstract V TryFindResource(string modelName);
}

View File

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

View File

@ -2,13 +2,13 @@ using System;
using UnityEngine;
[Serializable]
public abstract class PrefabAssetModelData
public class PrefabAssetModelData
{
[SerializeField] public string Name { get; set; }
[SerializeField] public string Name;
[SerializeField] public string PrefabAssetName { get; set; }
[SerializeField] public string PrefabAssetName;
[SerializeField] public float[] Position { get; set; }
[SerializeField] public float[] Position;
public PrefabAssetModelData(PrefabAssetModel assetModel)
@ -22,7 +22,17 @@ public abstract class PrefabAssetModelData
Position[2] = assetModel.Position.z;
}
public abstract PrefabAssetModelData PrefabAssetModelToData(PrefabAssetModel assetModel);
public virtual PrefabAssetModelData PrefabAssetModelToData(PrefabAssetModel assetModel)
{
return new PrefabAssetModelData(assetModel);
}
public abstract PrefabAssetModel MapDataToPrefabAssetModel();
public virtual PrefabAssetModel MapDataToPrefabAssetModel()
{
return new PrefabAssetModel(
Name,
PrefabAssetName,
new Vector3(Position[0], Position[1], Position[2])
);
}
}

View File

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

View File

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

View File

@ -1,26 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[System.Serializable]
public class ChestPrefarbAsset
{
[SerializeField]
public string name;
[SerializeField]
public string prefarbAssetName;
[SerializeField]
public Vector3 position;
[SerializeField]
public Dictionary<int, EquippableItemPrefarbAsset> content = new Dictionary<int, EquippableItemPrefarbAsset>();
public ChestPrefarbAsset() {}
public ChestPrefarbAsset(string _name, string _prefarbAssetName, Vector3 _position, Dictionary<int, EquippableItemPrefarbAsset> _content)
{
name = _name;
prefarbAssetName = _prefarbAssetName;
position = _position;
content = _content;
}
}

View File

@ -1,54 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;
[System.Serializable]
public class ChestPrefarbAssetData
{
public string name;
public string prefarbAssetName;
public float[] position;
public Dictionary<int, EquippableItemPrefarbAssetData> content = new Dictionary<int, EquippableItemPrefarbAssetData>();
public ChestPrefarbAssetData(ChestPrefarbAsset chestPrefarbAsset)
{
name = chestPrefarbAsset.name;
prefarbAssetName = chestPrefarbAsset.prefarbAssetName;
position = new float[3];
position[0] = chestPrefarbAsset.position.x;
position[1] = chestPrefarbAsset.position.y;
position[2] = chestPrefarbAsset.position.z;
Debug.Log("ChestPrefarbAsset to ChestPrefarbAssetData - " + chestPrefarbAsset.name);
foreach(KeyValuePair<int, EquippableItemPrefarbAsset> itemEntry in chestPrefarbAsset.content)
{
Debug.Log("Slot nr " + itemEntry.Key);
this.content[itemEntry.Key] = this.EquippableItemPrefarbAssetToData(itemEntry.Value);
}
}
public EquippableItemPrefarbAssetData EquippableItemPrefarbAssetToData(EquippableItemPrefarbAsset equippableItemPrefarbAsset)
{
return new EquippableItemPrefarbAssetData(equippableItemPrefarbAsset);
}
public ChestPrefarbAsset MapDataToChestPrefarbAsset()
{
ChestPrefarbAsset chestPrefarbAsset = new ChestPrefarbAsset();
chestPrefarbAsset.name = this.name;
chestPrefarbAsset.prefarbAssetName = this.prefarbAssetName;
chestPrefarbAsset.position = new Vector3(this.position[0], this.position[1], this.position[2]);
foreach(KeyValuePair<int, EquippableItemPrefarbAssetData> equippableItemPrefarbAssetDataEntry in this.content)
{
chestPrefarbAsset.content[equippableItemPrefarbAssetDataEntry.Key] = equippableItemPrefarbAssetDataEntry.Value.MapDataToEquippableItemPrefarbAsset();
}
return chestPrefarbAsset;
}
}

View File

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

Some files were not shown because too many files have changed in this diff Show More