This commit is contained in:
julius
2022-02-15 10:32:41 +01:00
parent 27b7415f2e
commit da69229fe8
9 changed files with 1187 additions and 11 deletions

View File

@@ -505,6 +505,141 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: ee2fcb6d299019740bbede78bbc6a1d7, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1 &1404527750
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1404527751}
- component: {fileID: 1404527753}
- component: {fileID: 1404527752}
m_Layer: 0
m_Name: Text (TMP)
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 0
--- !u!224 &1404527751
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1404527750}
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: 1632946789}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 1, y: 0}
m_AnchorMax: {x: 1, y: 0}
m_AnchoredPosition: {x: -25, y: 15}
m_SizeDelta: {x: 40, y: 20}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &1404527752
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1404527750}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: f4688fdb7df04437aeb418b961361dc5, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_text: 100
m_isRightToLeft: 0
m_fontAsset: {fileID: 11400000, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
m_sharedMaterial: {fileID: 2100000, guid: 79459efec17a4d00a321bdcc27bbc385, type: 2}
m_fontSharedMaterials: []
m_fontMaterial: {fileID: 0}
m_fontMaterials: []
m_fontColor32:
serializedVersion: 2
rgba: 4294967295
m_fontColor: {r: 1, g: 1, b: 1, a: 1}
m_enableVertexGradient: 0
m_colorMode: 3
m_fontColorGradient:
topLeft: {r: 1, g: 1, b: 1, a: 1}
topRight: {r: 1, g: 1, b: 1, a: 1}
bottomLeft: {r: 1, g: 1, b: 1, a: 1}
bottomRight: {r: 1, g: 1, b: 1, a: 1}
m_fontColorGradientPreset: {fileID: 0}
m_spriteAsset: {fileID: 0}
m_tintAllSprites: 0
m_StyleSheet: {fileID: 0}
m_TextStyleHashCode: -1183493901
m_overrideHtmlColors: 0
m_faceColor:
serializedVersion: 2
rgba: 4294967295
m_fontSize: 18
m_fontSizeBase: 20
m_fontWeight: 400
m_enableAutoSizing: 1
m_fontSizeMin: 18
m_fontSizeMax: 72
m_fontStyle: 0
m_HorizontalAlignment: 4
m_VerticalAlignment: 512
m_textAlignment: 65535
m_characterSpacing: 0
m_wordSpacing: 0
m_lineSpacing: 0
m_lineSpacingMax: 0
m_paragraphSpacing: 0
m_charWidthMaxAdj: 0
m_enableWordWrapping: 1
m_wordWrappingRatios: 0.4
m_overflowMode: 0
m_linkedTextComponent: {fileID: 0}
parentLinkedComponent: {fileID: 0}
m_enableKerning: 1
m_enableExtraPadding: 0
checkPaddingRequired: 0
m_isRichText: 1
m_parseCtrlCharacters: 1
m_isOrthographic: 1
m_isCullingEnabled: 0
m_horizontalMapping: 0
m_verticalMapping: 0
m_uvLineOffset: 0
m_geometrySortingOrder: 0
m_IsTextObjectScaleStatic: 0
m_VertexBufferAutoSizeReduction: 0
m_useMaxVisibleDescender: 1
m_pageToDisplay: 1
m_margin: {x: 0, y: 0, z: 0, w: 0}
m_isUsingLegacyAnimationComponent: 0
m_isVolumetricText: 0
m_hasFontAssetChanged: 0
m_baseMaterial: {fileID: 0}
m_maskOffset: {x: 0, y: 0, z: 0, w: 0}
--- !u!222 &1404527753
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1404527750}
m_CullTransparentMesh: 1
--- !u!1 &1618529780
GameObject:
m_ObjectHideFlags: 0
@@ -551,6 +686,29 @@ Transform:
m_Father: {fileID: 0}
m_RootOrder: 4
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1632946788 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 1031884711933943707, guid: ac29b266608f92b419b28a16d8ee7c1b, type: 3}
m_PrefabInstance: {fileID: 4215392547039679762}
m_PrefabAsset: {fileID: 0}
--- !u!224 &1632946789 stripped
RectTransform:
m_CorrespondingSourceObject: {fileID: 2917703646420147887, guid: ac29b266608f92b419b28a16d8ee7c1b, type: 3}
m_PrefabInstance: {fileID: 4215392547039679762}
m_PrefabAsset: {fileID: 0}
--- !u!114 &1632946793
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1632946788}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 8e3ae0ca7d3fa0f4cb5a877a7f8183ec, type: 3}
m_Name:
m_EditorClassIdentifier:
index: 0
--- !u!1 &1683721763
GameObject:
m_ObjectHideFlags: 0
@@ -707,12 +865,28 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 2310262034725730047, guid: ac29b266608f92b419b28a16d8ee7c1b, type: 3}
propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.data[0].m_Mode
value: 1
value: 3
objectReference: {fileID: 0}
- target: {fileID: 2310262034725730047, guid: ac29b266608f92b419b28a16d8ee7c1b, type: 3}
propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.data[0].m_Target
value:
objectReference: {fileID: 831773411}
- target: {fileID: 2310262034725730047, guid: ac29b266608f92b419b28a16d8ee7c1b, type: 3}
propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.data[0].m_CallState
value: 2
objectReference: {fileID: 0}
- target: {fileID: 2310262034725730047, guid: ac29b266608f92b419b28a16d8ee7c1b, type: 3}
propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.data[0].m_MethodName
value: buttonEvent
objectReference: {fileID: 0}
- target: {fileID: 2310262034725730047, guid: ac29b266608f92b419b28a16d8ee7c1b, type: 3}
propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.data[0].m_TargetAssemblyTypeName
value: UI_Inventory, Assembly-CSharp
objectReference: {fileID: 0}
- target: {fileID: 2310262034725730047, guid: ac29b266608f92b419b28a16d8ee7c1b, type: 3}
propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.data[0].m_Arguments.m_ObjectArgumentAssemblyTypeName
value: UnityEngine.Object, UnityEngine
objectReference: {fileID: 0}
- target: {fileID: 4215392545672552185, guid: ac29b266608f92b419b28a16d8ee7c1b, type: 3}
propertyPath: m_IsActive
value: 0

View File

@@ -0,0 +1,10 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ButtonEventHandler : MonoBehaviour
{
[SerializeField] UI_Inventory inventory;
}

View File

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

View File

@@ -0,0 +1,8 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Identity : MonoBehaviour
{
public int index;
}

View File

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

View File

@@ -14,6 +14,7 @@ public class Slot
/// [Methods]
/// void addItem(int count = 1)
/// void removeItem(int count = 1)
/// void clear()
/// </summary>
Item item;
@@ -36,5 +37,18 @@ public class Slot
{
// removes any number of items from the slot will also go negative
this.count -= count;
}
}
public void clear()
{
item = null;
count = 0;
}
public Slot copy()
{
Slot slot = new Slot(maxItems);
slot.count = count;
slot.ItemType = ItemType;
return slot;
}
}

View File

@@ -1,5 +1,6 @@
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
@@ -8,13 +9,51 @@ public class UI_Inventory : MonoBehaviour
Inventory playerInventory;
public Transform inventoryContainer;
public Transform itemSlotTemplate;
private RectTransform[] UIItemSlots;
private Button[] buttons;
private Slot pickedItem = new Slot();
private RectTransform pickedItemSlot;
private void Awake()
{
//itemSlotTemplate = inventoryContainer.Find("containerTemplate");
pickedItemSlot = Instantiate(itemSlotTemplate, this.transform).GetComponent<RectTransform>();
}
void pickItem(int index)
{
pickedItem = playerInventory.getInventory[index].copy();
playerInventory.getInventory[index].clear();
UIItemSlots[index].GetChild(0).Find("Icon").gameObject.SetActive(false);
}
void placeItem()
{
}
public void buttonEvent(int index)
{
Debug.Log("yeet");
if (pickedItem.ItemType == null && playerInventory.getInventory[index].ItemType != null)
{
pickItem(index);
}
else
{
if (pickedItem.ItemType != null)
{
int rest = playerInventory.addItemAt(index, pickedItem.ItemType, pickedItem.Count);
if (rest == 0)
{
pickedItem.clear();
}
else
{
pickedItem.Count = rest;
}
//placeItem(index);
}
}
//Debug.Log("button " + index + " has been pressed!");
}
public void setInventory(Inventory inventory)
{
@@ -22,6 +61,27 @@ public class UI_Inventory : MonoBehaviour
inventory.onItemChangedCallback += updateInventory;
updateInventory();
}
private void Update()
{
//buttons[index] = itemSlotRectTransform.Find("Button").GetComponent<Button>();
//itemSlotRectTransform.Find("Button").GetComponent<Identity>().index = index;
//buttons[index].onClick.AddListener(() => buttonEvent(itemSlotRectTransform.Find("Button").GetComponent<Identity>().index));
pickedItemSlot.anchoredPosition = new Vector2(Input.mousePosition.x, 0);
pickedItemSlot.gameObject.SetActive(true);
pickedItemSlot.gameObject.name = "pickedItem";
if (pickedItem.ItemType != null)
{
Transform item = pickedItemSlot.GetChild(0).Find("Icon");
item.gameObject.SetActive(true);
item.GetComponent<Image>().sprite = pickedItem.ItemType.sprite;
}
else
{
Transform item = pickedItemSlot.GetChild(0).Find("Icon");
item.gameObject.SetActive(false);
}
}
private void updateInventory()
{
@@ -31,20 +91,37 @@ public class UI_Inventory : MonoBehaviour
int x = 0;
int y = 0;
int index = 0;
if (UIItemSlots != null) {
foreach (RectTransform ItemSLot in UIItemSlots)
{
Destroy(ItemSLot.gameObject);
}
}
UIItemSlots = new RectTransform[playerInventory.getInventory.Count];
buttons = new Button[playerInventory.getInventory.Count];
//inventoryContainer.GetComponent<RectTransform>().
foreach (Slot slot in playerInventory.getInventory)
{
RectTransform itemSlotRectTransform = Instantiate(itemSlotTemplate, inventoryContainer).GetComponent<RectTransform>();
buttons[index] = itemSlotRectTransform.Find("Button").GetComponent<Button>();
itemSlotRectTransform.Find("Button").GetComponent<Identity>().index = index;
buttons[index].onClick.AddListener(() => buttonEvent(itemSlotRectTransform.Find("Button").GetComponent<Identity>().index));
itemSlotRectTransform.anchoredPosition = new Vector2(x* slotSize + slotSize * 0.5f,y * slotSize - slotSize * 0.5f );
itemSlotRectTransform.gameObject.SetActive(true);
itemSlotRectTransform.gameObject.name = "ItemSlot" + index;
if (slot.ItemType != null)
{
Transform Item = itemSlotRectTransform.GetChild(0).Find("Icon");
Item.gameObject.SetActive(true);
Item.GetComponent<Image>().sprite = slot.ItemType.sprite;
Transform item = itemSlotRectTransform.GetChild(0).Find("Icon");
Transform itemCount = itemSlotRectTransform.GetChild(0).Find("Count");
item.gameObject.SetActive(true);
item.GetComponent<Image>().sprite = slot.ItemType.sprite;
if (slot.Count > 1)
{
itemCount.gameObject.SetActive(true);
itemCount.GetComponent<TextMeshProUGUI>().text = slot.Count.ToString();
}
}
x++;
if (x > 3)
@@ -52,6 +129,7 @@ public class UI_Inventory : MonoBehaviour
x = 0;
y--;
}
UIItemSlots[index] = itemSlotRectTransform;
index++;
}
}

View File

@@ -32,14 +32,14 @@ Material:
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MainTex:
m_Texture: {fileID: 28684132378477856, guid: 8f586378b4e144a9851e7b34d9b748ee,
type: 2}
m_Texture: {fileID: 28684132378477856, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _OutlineTex:
m_Texture: {fileID: 2800000, guid: f88677df267a41d6be1e7a6133e7d227, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Ints: []
m_Floats:
- _Ambient: 0
- _Bevel: 1
@@ -50,6 +50,7 @@ Material:
- _BumpFace: 0
- _BumpOutline: 0
- _ColorMask: 15
- _CullMode: 0
- _Diffuse: 0
- _FaceDilate: 0.15
- _FaceUVSpeedX: 0
@@ -69,8 +70,8 @@ Material:
- _PerspectiveFilter: 0
- _Reflectivity: 12.76
- _ScaleRatioA: 0.9
- _ScaleRatioB: 0.6525
- _ScaleRatioC: 0.6525
- _ScaleRatioB: 0.59624994
- _ScaleRatioC: 0.59624994
- _ScaleX: 1
- _ScaleY: 1
- _ShaderFlags: 0
@@ -102,3 +103,4 @@ Material:
- _ReflectOutlineColor: {r: 0, g: 0, b: 0, a: 1}
- _SpecularColor: {r: 0.7689687, g: 1, b: 0.75000346, a: 1}
- _UnderlayColor: {r: 0, g: 0, b: 0, a: 0.5}
m_BuildTextureStacks: []