Skip to content

Commit

Permalink
Completing container rework [ready for review] (#824)
Browse files Browse the repository at this point in the history
* Adds tooltip to container parameters

* Take interaction changed to "first in last out"

* Integrates container Item displays to the new container system

container descriptor now handles container item display as well.
  • Loading branch information
stilnat authored Oct 2, 2021
1 parent 0b98c27 commit 7e5a33d
Show file tree
Hide file tree
Showing 6 changed files with 163 additions and 81 deletions.
56 changes: 31 additions & 25 deletions Assets/Content/Entities/Humanoids/Human/Human.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -2066,11 +2066,11 @@ GameObject:
m_Component:
- component: {fileID: 9114095814780560127}
- component: {fileID: 5306361817331504544}
- component: {fileID: 8043091635003570766}
- component: {fileID: 3623899252154688686}
- component: {fileID: 4409330219691020040}
- component: {fileID: 8954022733386996155}
- component: {fileID: 141195248142489828}
- component: {fileID: 2465783307128278743}
m_Layer: 15
m_Name: hand_r
m_TagString: Untagged
Expand Down Expand Up @@ -2116,22 +2116,6 @@ MonoBehaviour:
bodyPartStatuses: 0
skinnedMeshRenderer: {fileID: 6572013783268959225}
body: {fileID: 0}
--- !u!114 &8043091635003570766
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2448277291314358949}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 25610b7ef51d43c7bc0bd2bc58036e61, type: 3}
m_Name:
m_EditorClassIdentifier:
Displays:
- {fileID: 6523730774157206108}
Container: {fileID: 8954022733386996155}
Mirrored: 0
--- !u!114 &3623899252154688686
MonoBehaviour:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -2163,6 +2147,7 @@ MonoBehaviour:
attachedContainer: {fileID: 8954022733386996155}
containerSync: {fileID: 0}
containerInteractive: {fileID: 0}
containerItemDisplay: {fileID: 2465783307128278743}
containerUi: {fileID: 0}
openIcon: {fileID: 0}
takeIcon: {fileID: 0}
Expand All @@ -2175,13 +2160,17 @@ MonoBehaviour:
size: {x: 10, y: 10}
hideItems: 0
attachItems: 1
startFilter: {fileID: 0}
startFilter: {fileID: 11400000, guid: 965f83328d6f0ef4db3ca6b713932c19, type: 2}
initialized: 1
maxDistance: 5
containerType: 0
isOpenable: 0
isInteractive: 0
hasUi: 0
hasCustomInteraction: 0
hasCustomDisplay: 1
displays:
- {fileID: 6523730774157206108}
numberDisplay: 1
--- !u!114 &8954022733386996155
MonoBehaviour:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -2214,6 +2203,20 @@ Animator:
m_HasTransformHierarchy: 1
m_AllowConstantClipSamplingOptimization: 1
m_KeepAnimatorControllerStateOnDisable: 0
--- !u!114 &2465783307128278743
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2448277291314358949}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 25610b7ef51d43c7bc0bd2bc58036e61, type: 3}
m_Name:
m_EditorClassIdentifier:
containerDescriptor: {fileID: 4409330219691020040}
Mirrored: 0
--- !u!1 &2667178978926422381
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -4018,7 +4021,7 @@ GameObject:
- component: {fileID: 3547939921811356850}
- component: {fileID: 3447648068970816323}
- component: {fileID: 5807624756267220038}
- component: {fileID: 7276617234702586979}
- component: {fileID: 7394904886429592793}
m_Layer: 15
m_Name: hand_l
m_TagString: Untagged
Expand Down Expand Up @@ -4079,6 +4082,7 @@ MonoBehaviour:
attachedContainer: {fileID: 3547939921811356850}
containerSync: {fileID: 0}
containerInteractive: {fileID: 0}
containerItemDisplay: {fileID: 7394904886429592793}
containerUi: {fileID: 0}
openIcon: {fileID: 0}
takeIcon: {fileID: 0}
Expand All @@ -4094,10 +4098,14 @@ MonoBehaviour:
startFilter: {fileID: 11400000, guid: edc61d09fc1a5a84e98f63e51d1a0f1b, type: 2}
initialized: 1
maxDistance: 5
containerType: 0
isOpenable: 0
isInteractive: 0
hasUi: 0
hasCustomInteraction: 0
hasCustomDisplay: 1
displays:
- {fileID: 2248284492931446982}
numberDisplay: 1
--- !u!114 &3547939921811356850
MonoBehaviour:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -4146,7 +4154,7 @@ Animator:
m_HasTransformHierarchy: 1
m_AllowConstantClipSamplingOptimization: 1
m_KeepAnimatorControllerStateOnDisable: 0
--- !u!114 &7276617234702586979
--- !u!114 &7394904886429592793
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
Expand All @@ -4158,9 +4166,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 25610b7ef51d43c7bc0bd2bc58036e61, type: 3}
m_Name:
m_EditorClassIdentifier:
Displays:
- {fileID: 8200820077652235051}
Container: {fileID: 3547939921811356850}
containerDescriptor: {fileID: 8869297597610662472}
Mirrored: 0
--- !u!1 &7165410278998248383
GameObject:
Expand Down
41 changes: 23 additions & 18 deletions Assets/Content/Furniture/Machines/Science/CellCharger.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -615,11 +615,11 @@ GameObject:
- component: {fileID: -5812287283981547438}
- component: {fileID: -7336993563048116294}
- component: {fileID: 1326119814106932438}
- component: {fileID: 387266436717436548}
- component: {fileID: 5974712284015357203}
- component: {fileID: 4914324846151129755}
- component: {fileID: 924532214569197786}
- component: {fileID: 5017216499777655807}
- component: {fileID: 4456891875060699839}
m_Layer: 16
m_Name: CellCharger
m_TagString: Untagged
Expand Down Expand Up @@ -813,22 +813,6 @@ MonoBehaviour:
DisplayName: Power Cell Charger
Text:
MaxDistance: 0
--- !u!114 &387266436717436548
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8232994725938073509}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 25610b7ef51d43c7bc0bd2bc58036e61, type: 3}
m_Name:
m_EditorClassIdentifier:
Displays:
- {fileID: 2518627989031759827}
Container: {fileID: 4914324846151129755}
Mirrored: 0
--- !u!114 &5974712284015357203
MonoBehaviour:
m_ObjectHideFlags: 0
Expand All @@ -844,6 +828,7 @@ MonoBehaviour:
attachedContainer: {fileID: 4914324846151129755}
containerSync: {fileID: 0}
containerInteractive: {fileID: 924532214569197786}
containerItemDisplay: {fileID: 4456891875060699839}
containerUi: {fileID: 0}
openIcon: {fileID: 0}
takeIcon: {fileID: 0}
Expand All @@ -852,15 +837,21 @@ MonoBehaviour:
attachmentOffset: {x: 0, y: 0, z: 0}
containerName: container
onlyStoreWhenOpen: 0
openWhenContainerViewed: 0
size: {x: 1, y: 1}
hideItems: 0
attachItems: 1
startFilter: {fileID: 11400000, guid: 47ba41d97fc87d9469fa5be5b67bcbc2, type: 2}
initialized: 1
maxDistance: 5
containerType: 1
isOpenable: 0
isInteractive: 1
hasUi: 0
hasCustomInteraction: 0
hasCustomDisplay: 1
displays:
- {fileID: 2518627989031759827}
numberDisplay: 1
--- !u!114 &4914324846151129755
MonoBehaviour:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -904,3 +895,17 @@ MonoBehaviour:
m_EditorClassIdentifier:
syncMode: 0
syncInterval: 0.1
--- !u!114 &4456891875060699839
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8232994725938073509}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 25610b7ef51d43c7bc0bd2bc58036e61, type: 3}
m_Name:
m_EditorClassIdentifier:
containerDescriptor: {fileID: 5974712284015357203}
Mirrored: 0
3 changes: 2 additions & 1 deletion Assets/Content/Systems/Interactions/TakeInteraction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ public virtual bool CanInteract(InteractionEvent interactionEvent)
public virtual bool Start(InteractionEvent interactionEvent, InteractionReference reference)
{
Hands hands = (Hands) interactionEvent.Source;
Item PickupItem = containerDescriptor.attachedContainer.Container.StoredItems[0].Item;
int index = containerDescriptor.attachedContainer.Container.StoredItems.Count - 1;
Item PickupItem = containerDescriptor.attachedContainer.Container.StoredItems[index].Item;
if (PickupItem != null)
{
hands.Pickup(PickupItem);
Expand Down
10 changes: 10 additions & 0 deletions Assets/Engine/Inventory/ContainerDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class ContainerDescriptor : MonoBehaviour
public AttachedContainer attachedContainer;
public ContainerSync containerSync;
public ContainerInteractive containerInteractive;
public ContainerItemDisplay containerItemDisplay;

// reference towards the container UI linked to this container.
public ContainerUi containerUi;
Expand Down Expand Up @@ -57,6 +58,7 @@ public class ContainerDescriptor : MonoBehaviour
/// Set visibility of objects inside the container (not in the UI, in the actual game object).
/// If the container is Hidden, the visibility of items is always off.
/// </summary>
[Tooltip("Set visibility of items in container.")]
public bool hideItems = true;

/// <summary> If items should be attached as children. </summary>
Expand All @@ -82,6 +84,14 @@ public class ContainerDescriptor : MonoBehaviour
/// <summary> If true, interactions in containerInteractive are ignored, instead, a script should implement IInteractionTarget </summary>
public bool hasCustomInteraction;

/// <summary> If items in the container should be displayed at particular locations in the container</summary>
public bool hasCustomDisplay;

/// <summary> The list of transforms defining where the items are displayed.</summary>
public Transform[] displays;

public int numberDisplay;

/// <summary>
/// How often the observer list should be updated
/// </summary>
Expand Down
28 changes: 12 additions & 16 deletions Assets/Engine/Inventory/ContainerItemDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,7 @@ namespace SS3D.Engine.Inventory
/// </summary>
public class ContainerItemDisplay : MonoBehaviour
{
/// <summary>
/// The list of transforms defining where the items are displayed.
/// </summary>
public Transform[] Displays;

public AttachedContainer Container;
public ContainerDescriptor containerDescriptor;
public bool Mirrored;

/// <summary>
Expand All @@ -28,23 +23,24 @@ public class ContainerItemDisplay : MonoBehaviour

public void Start()
{
Assert.IsNotNull(Container);
Assert.IsNotNull(containerDescriptor);

displayedItems = new Item[Displays.Length];
Container.ItemAttached += ContainerOnItemAttached;
Container.ItemDetached += ContainerOnItemDetached;
displayedItems = new Item[containerDescriptor.displays.Length];
containerDescriptor.attachedContainer.ItemAttached += ContainerOnItemAttached;
containerDescriptor.attachedContainer.ItemDetached += ContainerOnItemDetached;
}

public void OnDestroy()
{
Container.ItemAttached -= ContainerOnItemAttached;
containerDescriptor.attachedContainer.ItemAttached -= ContainerOnItemAttached;
containerDescriptor.attachedContainer.ItemDetached -= ContainerOnItemDetached;
}

private void ContainerOnItemAttached(object sender, Item item)
{
// Defines the transform of the item to be the first available position.
int index = -1;
for (var i = 0; i < Displays.Length; i++)
for (var i = 0; i < containerDescriptor.displays.Length; i++)
{
if (displayedItems[i] == null)
{
Expand Down Expand Up @@ -73,7 +69,7 @@ private void ContainerOnItemAttached(object sender, Item item)
// HACK: Required because rotation pivot can be different
GameObject temporaryPoint = new GameObject("TempPivotPoint");

temporaryPoint.transform.SetParent(Displays[index].transform, false);
temporaryPoint.transform.SetParent(containerDescriptor.displays[index].transform, false);
temporaryPoint.transform.localPosition = Vector3.zero;
temporaryPoint.transform.rotation = attachmentPoint.root.rotation * attachmentPoint.localRotation;

Expand All @@ -86,7 +82,7 @@ private void ContainerOnItemAttached(object sender, Item item)
}
else
{
itemTransform.SetParent(Displays[index].transform, false);
itemTransform.SetParent(containerDescriptor.displays[index].transform, false);
itemTransform.localPosition = new Vector3();
itemTransform.localRotation = new Quaternion();
}
Expand All @@ -97,7 +93,7 @@ private void ContainerOnItemAttached(object sender, Item item)
private void ContainerOnItemDetached(object sender, Item item)
{
int index = -1;
for (var i = 0; i < Displays.Length; i++)
for (var i = 0; i < containerDescriptor.displays.Length; i++)
{
if (displayedItems[i] == item)
{
Expand All @@ -112,7 +108,7 @@ private void ContainerOnItemDetached(object sender, Item item)
}

Transform itemParent = item.transform.parent;
if (itemParent != null && itemParent != Displays[index])
if (itemParent != null && itemParent != containerDescriptor.displays[index])
{
item.transform.SetParent(null, true);
Destroy(itemParent.gameObject);
Expand Down
Loading

0 comments on commit 7e5a33d

Please sign in to comment.