Created an example for pouch.

This commit is contained in:
tonyomendoza 2022-11-17 17:50:45 -08:00
parent 4a7b254f18
commit 63d27b5b0a
6 changed files with 392 additions and 31 deletions

View File

@ -3431,6 +3431,12 @@ Transform:
type: 3}
m_PrefabInstance: {fileID: 160580645}
m_PrefabAsset: {fileID: 0}
--- !u!4 &168594120 stripped
Transform:
m_CorrespondingSourceObject: {fileID: 41448509920528303, guid: d8382154c724fca4a8ddc89666da0975,
type: 3}
m_PrefabInstance: {fileID: 1673066990}
m_PrefabAsset: {fileID: 0}
--- !u!1 &170152608 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 1150301423181574, guid: 20873817cc3f7fe4288964d76bdb466a,
@ -4053,6 +4059,125 @@ CanvasRenderer:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 191364540}
m_CullTransparentMesh: 0
--- !u!1001 &194366281
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 168594120}
m_Modifications:
- target: {fileID: 8715477175483360852, guid: 6503a074877a8b94db2e933a435264f5,
type: 3}
propertyPath: m_Name
value: Pouch_1x1
objectReference: {fileID: 0}
- target: {fileID: 8715477175483360853, guid: 6503a074877a8b94db2e933a435264f5,
type: 3}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8715477175483360853, guid: 6503a074877a8b94db2e933a435264f5,
type: 3}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8715477175483360853, guid: 6503a074877a8b94db2e933a435264f5,
type: 3}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8715477175483360853, guid: 6503a074877a8b94db2e933a435264f5,
type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8715477175483360853, guid: 6503a074877a8b94db2e933a435264f5,
type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8715477175483360853, guid: 6503a074877a8b94db2e933a435264f5,
type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8715477175483360853, guid: 6503a074877a8b94db2e933a435264f5,
type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 8715477175483360853, guid: 6503a074877a8b94db2e933a435264f5,
type: 3}
propertyPath: m_RootOrder
value: 1
objectReference: {fileID: 0}
- target: {fileID: 8715477175483360853, guid: 6503a074877a8b94db2e933a435264f5,
type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8715477175483360853, guid: 6503a074877a8b94db2e933a435264f5,
type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8715477175483360853, guid: 6503a074877a8b94db2e933a435264f5,
type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8715477175483360853, guid: 6503a074877a8b94db2e933a435264f5,
type: 3}
propertyPath: m_AnchoredPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8715477175483360853, guid: 6503a074877a8b94db2e933a435264f5,
type: 3}
propertyPath: m_AnchoredPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8715477175483360853, guid: 6503a074877a8b94db2e933a435264f5,
type: 3}
propertyPath: m_SizeDelta.x
value: 75
objectReference: {fileID: 0}
- target: {fileID: 8715477175483360853, guid: 6503a074877a8b94db2e933a435264f5,
type: 3}
propertyPath: m_SizeDelta.y
value: 75
objectReference: {fileID: 0}
- target: {fileID: 8715477175483360853, guid: 6503a074877a8b94db2e933a435264f5,
type: 3}
propertyPath: m_AnchorMin.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8715477175483360853, guid: 6503a074877a8b94db2e933a435264f5,
type: 3}
propertyPath: m_AnchorMin.y
value: 1
objectReference: {fileID: 0}
- target: {fileID: 8715477175483360853, guid: 6503a074877a8b94db2e933a435264f5,
type: 3}
propertyPath: m_AnchorMax.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8715477175483360853, guid: 6503a074877a8b94db2e933a435264f5,
type: 3}
propertyPath: m_AnchorMax.y
value: 1
objectReference: {fileID: 0}
- target: {fileID: 8715477175483360853, guid: 6503a074877a8b94db2e933a435264f5,
type: 3}
propertyPath: m_Pivot.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8715477175483360853, guid: 6503a074877a8b94db2e933a435264f5,
type: 3}
propertyPath: m_Pivot.y
value: 1
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 6503a074877a8b94db2e933a435264f5, type: 3}
--- !u!1001 &194914863
PrefabInstance:
m_ObjectHideFlags: 0
@ -10774,6 +10899,7 @@ MonoBehaviour:
itemUI: {fileID: 498874435}
pickUpRange: {fileID: 1933067162}
targetAttachment: {fileID: 0}
PlaceInContainerOfItemInSlot: {fileID: 0}
--- !u!135 &479204072
SphereCollider:
m_ObjectHideFlags: 0
@ -18909,8 +19035,8 @@ RectTransform:
m_Father: {fileID: 1142080337}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 584.8999, y: 2500}
m_Pivot: {x: 0, y: 1}
@ -27659,6 +27785,7 @@ Transform:
m_Children:
- {fileID: 1124594991}
- {fileID: 831625433}
- {fileID: 1602722490}
m_Father: {fileID: 0}
m_RootOrder: 6
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
@ -27678,6 +27805,7 @@ MonoBehaviour:
inventory: {fileID: 0}
targetAttachments:
- {fileID: 762694940}
- {fileID: 1602722489}
--- !u!114 &1216902020
MonoBehaviour:
m_ObjectHideFlags: 0
@ -37360,6 +37488,55 @@ Transform:
type: 3}
m_PrefabInstance: {fileID: 373687958}
m_PrefabAsset: {fileID: 0}
--- !u!1 &1602722488
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1602722490}
- component: {fileID: 1602722489}
m_Layer: 0
m_Name: Misc. Attachments
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &1602722489
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1602722488}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 6bba5ab18652a58438d3818d6575252d, type: 3}
m_Name:
m_EditorClassIdentifier:
itemTag: 0
position: {x: 0, y: 0, z: 0}
rotation: {x: 0, y: 0, z: 0}
scale: {x: 1, y: 1, z: 1}
hideGameObject: 1
KeepOldRotationOnDrop: 1
--- !u!4 &1602722490
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1602722488}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 1216902018}
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1001 &1605431909
PrefabInstance:
m_ObjectHideFlags: 0
@ -38944,6 +39121,90 @@ Transform:
type: 3}
m_PrefabInstance: {fileID: 1665050069}
m_PrefabAsset: {fileID: 0}
--- !u!1001 &1673066990
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 2633167122398440747}
m_Modifications:
- target: {fileID: 41448509920528300, guid: d8382154c724fca4a8ddc89666da0975,
type: 3}
propertyPath: m_Name
value: Pickup
objectReference: {fileID: 0}
- target: {fileID: 41448509920528302, guid: d8382154c724fca4a8ddc89666da0975,
type: 3}
propertyPath: ItemGameObject
value:
objectReference: {fileID: 2128677010}
- target: {fileID: 41448509920528302, guid: d8382154c724fca4a8ddc89666da0975,
type: 3}
propertyPath: itemUI
value:
objectReference: {fileID: 1692348397}
- target: {fileID: 41448509920528302, guid: d8382154c724fca4a8ddc89666da0975,
type: 3}
propertyPath: PlaceInContainerOfItemInSlot
value:
objectReference: {fileID: 5849743408828067761}
- target: {fileID: 41448509920528303, guid: d8382154c724fca4a8ddc89666da0975,
type: 3}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 41448509920528303, guid: d8382154c724fca4a8ddc89666da0975,
type: 3}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 41448509920528303, guid: d8382154c724fca4a8ddc89666da0975,
type: 3}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 41448509920528303, guid: d8382154c724fca4a8ddc89666da0975,
type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 41448509920528303, guid: d8382154c724fca4a8ddc89666da0975,
type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 41448509920528303, guid: d8382154c724fca4a8ddc89666da0975,
type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 41448509920528303, guid: d8382154c724fca4a8ddc89666da0975,
type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 41448509920528303, guid: d8382154c724fca4a8ddc89666da0975,
type: 3}
propertyPath: m_RootOrder
value: 0
objectReference: {fileID: 0}
- target: {fileID: 41448509920528303, guid: d8382154c724fca4a8ddc89666da0975,
type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 41448509920528303, guid: d8382154c724fca4a8ddc89666da0975,
type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 41448509920528303, guid: d8382154c724fca4a8ddc89666da0975,
type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: d8382154c724fca4a8ddc89666da0975, type: 3}
--- !u!1001 &1676822697
PrefabInstance:
m_ObjectHideFlags: 0
@ -39110,7 +39371,7 @@ MonoBehaviour:
m_HandleRect: {fileID: 1584996881}
m_Direction: 0
m_Value: 0
m_Size: 0.99999994
m_Size: 1
m_NumberOfSteps: 0
m_OnValueChanged:
m_PersistentCalls:
@ -39668,6 +39929,18 @@ Transform:
type: 3}
m_PrefabInstance: {fileID: 1687957131}
m_PrefabAsset: {fileID: 0}
--- !u!114 &1692348397 stripped
MonoBehaviour:
m_CorrespondingSourceObject: {fileID: 8715477175483360842, guid: 6503a074877a8b94db2e933a435264f5,
type: 3}
m_PrefabInstance: {fileID: 194366281}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: cc11508cb979f8b4b8253855ce8a0bc5, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1001 &1692860756
PrefabInstance:
m_ObjectHideFlags: 0
@ -41622,7 +41895,7 @@ MonoBehaviour:
m_HandleRect: {fileID: 1186388952}
m_Direction: 0
m_Value: 0
m_Size: 1
m_Size: 0.9999999
m_NumberOfSteps: 0
m_OnValueChanged:
m_PersistentCalls:
@ -48876,6 +49149,12 @@ Transform:
type: 3}
m_PrefabInstance: {fileID: 2128635966}
m_PrefabAsset: {fileID: 0}
--- !u!1 &2128677010 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 8053794548077495502, guid: d47a5475838b12b45a42e76dee4c4b3b,
type: 3}
m_PrefabInstance: {fileID: 5429444027952869713}
m_PrefabAsset: {fileID: 0}
--- !u!1001 &2134052137
PrefabInstance:
m_ObjectHideFlags: 0

View File

@ -52,6 +52,7 @@ MonoBehaviour:
itemUI: {fileID: 0}
pickUpRange: {fileID: 41448510249244371}
targetAttachment: {fileID: 0}
PlaceInContainerOfItemInSlot: {fileID: 0}
--- !u!135 &41448509920528289
SphereCollider:
m_ObjectHideFlags: 0
@ -63,7 +64,7 @@ SphereCollider:
m_IsTrigger: 1
m_Enabled: 1
serializedVersion: 2
m_Radius: 0.25
m_Radius: 1
m_Center: {x: 0, y: 0, z: 0}
--- !u!1 &41448510249244382
GameObject:

View File

@ -19,6 +19,7 @@ namespace SimpleInventorySystem
public PickUpRange pickUpRange;
public bool HadPickedUp { private set; get; }
[HideInInspector] public TargetAttachment targetAttachment;
public SlotUI PlaceInContainerOfItemInSlot;
// Start is called before the first frame update
void Start()
@ -116,6 +117,35 @@ namespace SimpleInventorySystem
}
}
}
// assume there is no tsp, then try to drop in most available backpack slot
if (PlaceInContainerOfItemInSlot != null)
{
if (PlaceInContainerOfItemInSlot.GetItemUI() != null && PlaceInContainerOfItemInSlot.GetItemUI().container != null)
{
GridUI grid = PlaceInContainerOfItemInSlot.GetItemUI().container.GetComponent<GridUI>();
if (grid != null)
{
if (grid.DropItemOnGrid(itemUI.gameObject))
{
Debug.Log("PickUp: Placed in grid.");
HadPickedUp = true;
// TODO: Handle changing transform here
//ItemGameObject.GetComponent<>;
if (InventorySystem.instance.player.AttachItemGameObject(ItemGameObject, itemUI.ItemTag, itemUI))
{
pickUpCollider.enabled = false;
pickUpRange.GetComponent<Collider>().enabled = false;
}
return;
}
}
}
}
Debug.Log("Could not pick up");
}
}

View File

@ -51,7 +51,7 @@ namespace SimpleInventorySystem
{
if(storedPickUp != null && pickUpsInRange.Contains(storedPickUp))
{
Debug.Log("Picking up");
Debug.Log("Picking up" + storedPickUp.name);
storedPickUp.PickUpHandler();
}
}

View File

@ -17,7 +17,7 @@ namespace SimpleInventorySystem
public bool AttachItemGameObject(GameObject go, ItemTags targetItemTag, PickUp pickUp)
{
if (itemTag == targetItemTag)
if (itemTag == targetItemTag || itemTag == ItemTags.Any)
{
itemGameObject = go;
@ -48,6 +48,10 @@ namespace SimpleInventorySystem
public void DetachItemGameObject(GameObject go)
{
if (hideGameObject)
{
itemGameObject.SetActive(true);
}
itemGameObject = null;
// TODO: Most likely, implement drop here.
go.transform.SetParent(null);

View File

@ -29,6 +29,7 @@ namespace SimpleInventorySystem
public GameObject[] testItems;
private Size cellSize;
public Size CellSize { get { return cellSize; } }
private Vector2 nextAvailableCellCoords;
private void Awake()
{
@ -109,7 +110,7 @@ namespace SimpleInventorySystem
int i = 0;
int x = 0, y = 0;
int lootCount = 1;
foreach (GameObject testItemUI in testItems)
foreach (GameObject testItem in testItems)
{
bool dropped = false;
GameObject item = null;
@ -120,14 +121,13 @@ namespace SimpleInventorySystem
x = i % gridSize.Width;
y = i / gridSize.Width;
item = Instantiate(testItemUI);
item = Instantiate(testItem);
item.name = item.name + " " + lootCount;
dropped = cells[y, x].slot.DropOntoSlot(item);
if (!dropped)
{
Destroy(item);
}
else
{
@ -146,53 +146,100 @@ namespace SimpleInventorySystem
Debug.LogWarning("Could not add all test items");
break;
}
// TODO: Make sure this works as expected
nextAvailableCellCoords = new Vector2(i % gridSize.Width, i / gridSize.Width);
}
}
}
}
public bool DropItemOnGrid(GameObject item)
{
if (item != null)
{
int i = 0;
int x = (int)nextAvailableCellCoords.x, y = (int)nextAvailableCellCoords.y;
bool dropped = false;
try
{
do
{
x = i % gridSize.Width;
y = i / gridSize.Width;
dropped = cells[y, x].slot.DropOntoSlot(item);
if (!dropped)
{
}
else
{
item.transform.localScale = new Vector3(1, 1, 1);
// TODO: Make sure this works as expected
nextAvailableCellCoords = new Vector2(i % gridSize.Width, i / gridSize.Width);
return true;
}
i++;
} while (!dropped); // TODO: perhaps add a check to make sure i has not exceeded the total number of slots
}
catch (IndexOutOfRangeException err)
{
Debug.LogWarning("GridUI: " + x + ", " + y);
return false;
}
return false;
}
else
{
Debug.LogWarning("GridUI: Could not add item to grid.");
return false;
}
}
// Start is called before the first frame update
void Start()
{
if (!generateCells)
{
//if (slots != null)
for (int i = 0; i < gridLayout.transform.childCount; i++)
for (int i = 0; i < gridLayout.transform.childCount; i++)
{
int x = i % gridSize.Width;
int y = (i - x) / gridSize.Width;
int y = (i - x) / gridSize.Width;
if (cells[y, x] != null)
{
continue;
}
if (cells[y, x] != null)
{
continue;
}
Transform child = gridLayout.transform.GetChild(i);
SlotUI slot = child.GetComponentInChildren<SlotUI>();
if (slot != null)
{
cells[y, x] = new Cell(x, y, slot, true);
slot.SetCell(cells[y, x]);
Transform child = gridLayout.transform.GetChild(i);
SlotUI slot = child.GetComponentInChildren<SlotUI>();
if (slot != null)
{
cells[y, x] = new Cell(x, y, slot, true);
slot.SetCell(cells[y, x]);
slot.grid = this;
if (slot.width > 1 || slot.height > 1)
{
for (int j = 0; j < slot.height; j++)
{
for (int j = 0; j < slot.height; j++)
for (int k = 1; k < slot.width; k++)
{
for (int k = 1; k < slot.width; k++)
{
cells[y + j, x + k] = new Cell(x + k, y + j, slot, false);
}
cells[y + j, x + k] = new Cell(x + k, y + j, slot, false);
}
}
}
Debug.Log("START: " + (slot.cell == null));
}
else
{
cells[y, x] = null;// new Cell(null, false, false); // Setting null so that we can reserve memory
}
else
{
cells[y, x] = null;// new Cell(null, false, false); // Setting null so that we can reserve memory
}
}
}
else
{