Fixed a pickup bug and a pivot bug

This commit is contained in:
tonyomendoza 2023-02-15 00:17:26 -08:00
parent dbcd1a11e0
commit 45397922df
5 changed files with 80 additions and 64 deletions

View File

@ -99,6 +99,7 @@ namespace SimpleInventorySystem
public GameObject ReferencedGrid;
[HideInInspector] public SlotUI slot;
[HideInInspector] public GridUI grid;
public bool lootingGrid = false;
public TagSlotGridPairing()
{
@ -167,13 +168,13 @@ namespace SimpleInventorySystem
//List<GridUI.Cell> cells = new List<GridUI.Cell>();
//bool canMoveInCells = grid.CanMoveInCells(item, slot, cells);
bool dropped = CanStore(item) && grid.DropItemOnGrid(item.gameObject);
Debug.Log("IS:Dropped:" + dropped);
//Debug.Log("IS:Dropped:" + dropped);
return dropped;
}
protected bool DropOntoSlot(ItemUI item)
{
bool dropped = CanStore(item) && slot.DropOntoSlot(item.gameObject);
Debug.Log("IS:Dropped:" + dropped);
//Debug.Log("IS:Dropped:" + dropped);
return dropped;
}

View File

@ -113,10 +113,10 @@ namespace SimpleInventorySystem
{
if (itemUI.Equip())
{
itemUI.transform.localRotation = Quaternion.Euler(new Vector3());
itemUI.transform.localScale = new Vector3(1, 1, 1);
Debug.Log("Pickup: Equipped");
itemUI.FixLocalRotation();
itemUI.FixLocalScale();
HadPickedUp = true;
//Debug.Log("Pickup: Equipped");
// TODO: Handle changing transform here
//ItemGameObject.GetComponent<>;
@ -133,14 +133,14 @@ namespace SimpleInventorySystem
}
else if (itemUI.Store())
{
//Debug.Log("Pickup: Stored");
itemUI.transform.localRotation = Quaternion.Euler(new Vector3());
itemUI.transform.localScale = new Vector3(1, 1, 1);
Debug.Log("Pickup: Stored");
itemUI.FixLocalRotation();
itemUI.FixLocalScale();
HadPickedUp = true;
if (InventorySystem.instance.player.AttachItemGameObject(ItemGameObject, itemUI.ItemTag, itemUI))
{
//Debug.Log("Attached");
Debug.Log("Attached");
ItemRigidBody.useGravity = false;
ItemRigidBody.isKinematic = true;
pickUpCollider.enabled = false;
@ -149,7 +149,7 @@ namespace SimpleInventorySystem
}
else
{
//Debug.Log("Could not pick up");
Debug.Log("Could not pick up");
}
// assume there is no tsp, then try to drop in most available backpack slot
/*else if (PlaceInContainerOfItemInSlot != null)

View File

@ -43,23 +43,16 @@ namespace SimpleInventorySystem
[HideInInspector] public StorageWindowUI StorageWindow;
[HideInInspector] public LimitStackSlotCapacity limitStackSlotCapacity;
internal void ResetTransform()
{
RectTransform rect = GetComponent<RectTransform>();
rect.anchorMin = rect.anchorMax = rect.pivot = new Vector2(0, 1);
rect.anchoredPosition = new Vector2();
imageSizeOnGrid = new Size(width * InventorySystem.instance.DefaultSizeOnGrid.Width, height * InventorySystem.instance.DefaultSizeOnGrid.Height);
rect.sizeDelta = new Vector2(imageSizeOnGrid.Width, imageSizeOnGrid.Height);
}
[HideInInspector] public PickUp pickUp;
[HideInInspector] public TargetAttachment targetAttachment;
// private variables
private float eulerAngle;
public float EulerAngle { get { return eulerAngle; } }
private Vector3 pivot;
private Vector2 oldImageSizeDelta;
private Vector2 oldSizeDelta;
private RectTransform rectTransform;
public RectTransform RectTransform { get { return rectTransform; } }
private CanvasGroup canvasGroup;
private float scale = 1f;
private SlotUI slot;
@ -113,9 +106,57 @@ namespace SimpleInventorySystem
}
}
public void FixLocalScale()
{
rectTransform.localScale = new Vector3(1, 1, 1);
}
public void FixLocalRotation()
{
rectTransform.localRotation = Quaternion.Euler(new Vector3(0, 0, EulerAngle));
}
public bool PointerIsHoveredOver { get { return InventorySystem.IsMouseOverItemUITop(this); } }
//public Item item;
private void InitializeRectTransform()
{
rectTransform.rotation = Quaternion.Euler(new Vector3(0,0,0));
eulerAngle = Mathf.Abs(Mathf.CeilToInt(transform.rotation.eulerAngles.z));
switch (eulerAngle)
{
case -90:
imageOrientation = (height > width) ? Orientation.Portrait : Orientation.Landscape;
rotationIndex = 1;
break;
case 180:
imageOrientation = (width > height) ? Orientation.Landscape : Orientation.Portrait;
rotationIndex = 2;
break;
case 90:
imageOrientation = (height > width) ? Orientation.Portrait : Orientation.Landscape;
rotationIndex = 3;
break;
default:
imageOrientation = (width > height) ? Orientation.Landscape : Orientation.Portrait;
rotationIndex = 0;
break;
}
rectTransform.anchorMin = rectTransform.anchorMax = new Vector2(0, 1);
pivot = rectTransform.pivot = new Vector2(0, 1);
}
internal void ResetTransform()
{
rectTransform = GetComponent<RectTransform>();
rectTransform.anchorMin = rectTransform.anchorMax = new Vector2(0, 1);
// rect.pivot = new Vector2(0, 1);
rectTransform.anchoredPosition = new Vector2();
imageSizeOnGrid = new Size(width * InventorySystem.instance.DefaultSizeOnGrid.Width, height * InventorySystem.instance.DefaultSizeOnGrid.Height);
rectTransform.sizeDelta = new Vector2(imageSizeOnGrid.Width, imageSizeOnGrid.Height);
}
private void Awake()
{
@ -148,29 +189,7 @@ namespace SimpleInventorySystem
Debug.LogError("Inventory ItemUI must contain a positive integer value for Width and Height: " + name);
}
/*eulerAngle = Mathf.Abs(Mathf.CeilToInt(transform.rotation.eulerAngles.z));
switch (eulerAngle)
{
case -90:
imageOrientation = (height > width) ? Orientation.Portrait : Orientation.Landscape;
break;
case 180:
imageOrientation = (width > height) ? Orientation.Landscape : Orientation.Portrait;
break;
case 90:
imageOrientation = (height > width) ? Orientation.Portrait : Orientation.Landscape;
break;
default:
imageOrientation = (width > height) ? Orientation.Landscape : Orientation.Portrait;
break;
}*/
imageOrientation = (width > height) ? Orientation.Landscape : Orientation.Portrait;
rotationIndex = 0;
//rectTransform.pivot = pivot;
//InstantiateItem();
InitializeRectTransform();
}
public Rarity GetRarity()
@ -226,24 +245,11 @@ namespace SimpleInventorySystem
}
}
public void InstantiateItem()
{
//if (item == null && itemPrefab != null)
//{
// item = Instantiate(itemPrefab);
//}
}
public SlotUI GetSlotUI()
{
return slot;
}
public void OnEndDrag(PointerEventData eventData)
{
//rectTransform.localPosition = new Vector3(0, 0);
}
public bool QuickMove()
{
bool moved = false;
@ -265,10 +271,10 @@ namespace SimpleInventorySystem
bool equipped = false;
foreach (TagSlotPairing tsp in InventorySystem.instance.TagSlotPairings)
{
//Debug.Log($"Equip: {tsp.itemTag}, {tsp.slot.gameObject.name}");
Debug.Log($"Equip: {tsp.itemTag}, {tsp.slot.gameObject.name}");
if (tsp.slot == slot)
{
//Debug.Log("Could not equip, storing");
Debug.Log("Could not equip to slot since this item is already occupying the slot.");
continue;
}
@ -299,7 +305,7 @@ namespace SimpleInventorySystem
bool stored = false;
foreach (TagSlotGridPairing tsgp in InventorySystem.instance.TagSlotGridPairings)
{
//Debug.Log($"Store: {tsgp.itemTag}, {tsgp.ReferencedGrid}");
Debug.Log($"Store: {tsgp.itemTag}, {tsgp.ReferencedGrid}");
if (tsgp.CanStore(this))
{
GrabAndDragItem(); // TODO: See if this conflicts with anything
@ -382,8 +388,8 @@ namespace SimpleInventorySystem
{
ApplyRectTransformResize(); // TODO: Fix this so it maintains rotation later
transform.localRotation = Quaternion.Euler(new Vector3(0, 0, eulerAngle));
rectTransform.pivot = pivot;
}
rectTransform.pivot = pivot;
}
public void ApplyRectTransformResize()
@ -569,10 +575,6 @@ namespace SimpleInventorySystem
overrideSortingCanvas.sortingLayerID = 5;
//overrideSortingCanvas.sortingLayerName = "ItemUI";
}*/
eulerAngle = 0;
transform.localRotation = Quaternion.Euler(0, 0, eulerAngle);
pivot = rectTransform.pivot = new Vector2(0, 1);
}
public void InitializeImageSize()

View File

@ -210,6 +210,9 @@ namespace SimpleInventorySystem
{
HideImage();
}
else
{
}
foreach (GroupSlotUI groupSlot in groupSlots)
{

View File

@ -56829,6 +56829,11 @@ PrefabInstance:
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2770326605790841687, guid: 9f005685dc17f4643b4a1156970fe2f6,
type: 3}
propertyPath: TagSlotGridPairings.Array.data[6].lootingGrid
value: 1
objectReference: {fileID: 0}
- target: {fileID: 2770326605790841688, guid: 9f005685dc17f4643b4a1156970fe2f6,
type: 3}
propertyPath: pauseMenu
@ -56997,7 +57002,7 @@ PrefabInstance:
- target: {fileID: 2770326606141421692, guid: 9f005685dc17f4643b4a1156970fe2f6,
type: 3}
propertyPath: m_AnchoredPosition.y
value: -0.00092929165
value: -0.00087603735
objectReference: {fileID: 0}
- target: {fileID: 2770326606150301029, guid: 9f005685dc17f4643b4a1156970fe2f6,
type: 3}
@ -57444,6 +57449,11 @@ PrefabInstance:
propertyPath: m_SizeDelta.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8600850533622123873, guid: 9f005685dc17f4643b4a1156970fe2f6,
type: 3}
propertyPath: FitItemImageInSlotImage
value: 1
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 9f005685dc17f4643b4a1156970fe2f6, type: 3}
--- !u!64 &3968453558880047856