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} type: 3}
m_PrefabInstance: {fileID: 160580645} m_PrefabInstance: {fileID: 160580645}
m_PrefabAsset: {fileID: 0} 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 --- !u!1 &170152608 stripped
GameObject: GameObject:
m_CorrespondingSourceObject: {fileID: 1150301423181574, guid: 20873817cc3f7fe4288964d76bdb466a, m_CorrespondingSourceObject: {fileID: 1150301423181574, guid: 20873817cc3f7fe4288964d76bdb466a,
@ -4053,6 +4059,125 @@ CanvasRenderer:
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 191364540} m_GameObject: {fileID: 191364540}
m_CullTransparentMesh: 0 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 --- !u!1001 &194914863
PrefabInstance: PrefabInstance:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -10774,6 +10899,7 @@ MonoBehaviour:
itemUI: {fileID: 498874435} itemUI: {fileID: 498874435}
pickUpRange: {fileID: 1933067162} pickUpRange: {fileID: 1933067162}
targetAttachment: {fileID: 0} targetAttachment: {fileID: 0}
PlaceInContainerOfItemInSlot: {fileID: 0}
--- !u!135 &479204072 --- !u!135 &479204072
SphereCollider: SphereCollider:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -18909,8 +19035,8 @@ RectTransform:
m_Father: {fileID: 1142080337} m_Father: {fileID: 1142080337}
m_RootOrder: 1 m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0} m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 0} m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 0, y: 0} m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 584.8999, y: 2500} m_SizeDelta: {x: 584.8999, y: 2500}
m_Pivot: {x: 0, y: 1} m_Pivot: {x: 0, y: 1}
@ -27659,6 +27785,7 @@ Transform:
m_Children: m_Children:
- {fileID: 1124594991} - {fileID: 1124594991}
- {fileID: 831625433} - {fileID: 831625433}
- {fileID: 1602722490}
m_Father: {fileID: 0} m_Father: {fileID: 0}
m_RootOrder: 6 m_RootOrder: 6
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
@ -27678,6 +27805,7 @@ MonoBehaviour:
inventory: {fileID: 0} inventory: {fileID: 0}
targetAttachments: targetAttachments:
- {fileID: 762694940} - {fileID: 762694940}
- {fileID: 1602722489}
--- !u!114 &1216902020 --- !u!114 &1216902020
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -37360,6 +37488,55 @@ Transform:
type: 3} type: 3}
m_PrefabInstance: {fileID: 373687958} m_PrefabInstance: {fileID: 373687958}
m_PrefabAsset: {fileID: 0} 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 --- !u!1001 &1605431909
PrefabInstance: PrefabInstance:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -38944,6 +39121,90 @@ Transform:
type: 3} type: 3}
m_PrefabInstance: {fileID: 1665050069} m_PrefabInstance: {fileID: 1665050069}
m_PrefabAsset: {fileID: 0} 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 --- !u!1001 &1676822697
PrefabInstance: PrefabInstance:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -39110,7 +39371,7 @@ MonoBehaviour:
m_HandleRect: {fileID: 1584996881} m_HandleRect: {fileID: 1584996881}
m_Direction: 0 m_Direction: 0
m_Value: 0 m_Value: 0
m_Size: 0.99999994 m_Size: 1
m_NumberOfSteps: 0 m_NumberOfSteps: 0
m_OnValueChanged: m_OnValueChanged:
m_PersistentCalls: m_PersistentCalls:
@ -39668,6 +39929,18 @@ Transform:
type: 3} type: 3}
m_PrefabInstance: {fileID: 1687957131} m_PrefabInstance: {fileID: 1687957131}
m_PrefabAsset: {fileID: 0} 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 --- !u!1001 &1692860756
PrefabInstance: PrefabInstance:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -41622,7 +41895,7 @@ MonoBehaviour:
m_HandleRect: {fileID: 1186388952} m_HandleRect: {fileID: 1186388952}
m_Direction: 0 m_Direction: 0
m_Value: 0 m_Value: 0
m_Size: 1 m_Size: 0.9999999
m_NumberOfSteps: 0 m_NumberOfSteps: 0
m_OnValueChanged: m_OnValueChanged:
m_PersistentCalls: m_PersistentCalls:
@ -48876,6 +49149,12 @@ Transform:
type: 3} type: 3}
m_PrefabInstance: {fileID: 2128635966} m_PrefabInstance: {fileID: 2128635966}
m_PrefabAsset: {fileID: 0} 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 --- !u!1001 &2134052137
PrefabInstance: PrefabInstance:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

View File

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

View File

@ -19,6 +19,7 @@ namespace SimpleInventorySystem
public PickUpRange pickUpRange; public PickUpRange pickUpRange;
public bool HadPickedUp { private set; get; } public bool HadPickedUp { private set; get; }
[HideInInspector] public TargetAttachment targetAttachment; [HideInInspector] public TargetAttachment targetAttachment;
public SlotUI PlaceInContainerOfItemInSlot;
// Start is called before the first frame update // Start is called before the first frame update
void Start() 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)) if(storedPickUp != null && pickUpsInRange.Contains(storedPickUp))
{ {
Debug.Log("Picking up"); Debug.Log("Picking up" + storedPickUp.name);
storedPickUp.PickUpHandler(); storedPickUp.PickUpHandler();
} }
} }

View File

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

View File

@ -29,6 +29,7 @@ namespace SimpleInventorySystem
public GameObject[] testItems; public GameObject[] testItems;
private Size cellSize; private Size cellSize;
public Size CellSize { get { return cellSize; } } public Size CellSize { get { return cellSize; } }
private Vector2 nextAvailableCellCoords;
private void Awake() private void Awake()
{ {
@ -109,7 +110,7 @@ namespace SimpleInventorySystem
int i = 0; int i = 0;
int x = 0, y = 0; int x = 0, y = 0;
int lootCount = 1; int lootCount = 1;
foreach (GameObject testItemUI in testItems) foreach (GameObject testItem in testItems)
{ {
bool dropped = false; bool dropped = false;
GameObject item = null; GameObject item = null;
@ -120,14 +121,13 @@ namespace SimpleInventorySystem
x = i % gridSize.Width; x = i % gridSize.Width;
y = i / gridSize.Width; y = i / gridSize.Width;
item = Instantiate(testItemUI); item = Instantiate(testItem);
item.name = item.name + " " + lootCount; item.name = item.name + " " + lootCount;
dropped = cells[y, x].slot.DropOntoSlot(item); dropped = cells[y, x].slot.DropOntoSlot(item);
if (!dropped) if (!dropped)
{ {
Destroy(item); Destroy(item);
} }
else else
{ {
@ -146,11 +146,58 @@ namespace SimpleInventorySystem
Debug.LogWarning("Could not add all test items"); Debug.LogWarning("Could not add all test items");
break; 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 // Start is called before the first frame update
void Start() void Start()
{ {