Allow proper moving of kitchen objects and player pickup

This commit is contained in:
BuyMyMojo 2023-02-28 22:59:20 +11:00
parent 1729ddf5c6
commit 234e00cb9b
10 changed files with 213 additions and 11 deletions

4
.erp
View file

@ -5,7 +5,7 @@
<resetOnSceneChange>false</resetOnSceneChange> <resetOnSceneChange>false</resetOnSceneChange>
<debugMode>false</debugMode> <debugMode>false</debugMode>
<EditorClosed>true</EditorClosed> <EditorClosed>true</EditorClosed>
<LastTimestamp>1677533527</LastTimestamp> <LastTimestamp>1677589653</LastTimestamp>
<LastSessionID>522683637854076046</LastSessionID> <LastSessionID>8006271043655199372</LastSessionID>
<Errored>false</Errored> <Errored>false</Errored>
</ERPSettings> </ERPSettings>

View file

@ -192,6 +192,11 @@ PrefabInstance:
propertyPath: m_Name propertyPath: m_Name
value: ClearCounter (1) value: ClearCounter (1)
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 7837983985068458341, guid: f62bfcbfbc8097441a9fae9a02652a07,
type: 3}
propertyPath: testing
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7837983985068458341, guid: f62bfcbfbc8097441a9fae9a02652a07, - target: {fileID: 7837983985068458341, guid: f62bfcbfbc8097441a9fae9a02652a07,
type: 3} type: 3}
propertyPath: tomatoPrefab propertyPath: tomatoPrefab
@ -204,6 +209,11 @@ PrefabInstance:
value: value:
objectReference: {fileID: 11400000, guid: 9a7cd1ad975e4124e9873832ba4af356, objectReference: {fileID: 11400000, guid: 9a7cd1ad975e4124e9873832ba4af356,
type: 2} type: 2}
- target: {fileID: 7837983985068458341, guid: f62bfcbfbc8097441a9fae9a02652a07,
type: 3}
propertyPath: secondClearCounter
value:
objectReference: {fileID: 1926678759}
m_RemovedComponents: [] m_RemovedComponents: []
m_RemovedGameObjects: [] m_RemovedGameObjects: []
m_AddedGameObjects: [] m_AddedGameObjects: []
@ -380,6 +390,49 @@ MonoBehaviour:
m_CameraActivatedEvent: m_CameraActivatedEvent:
m_PersistentCalls: m_PersistentCalls:
m_Calls: [] m_Calls: []
--- !u!114 &391596026 stripped
MonoBehaviour:
m_CorrespondingSourceObject: {fileID: 7837983985068458341, guid: f62bfcbfbc8097441a9fae9a02652a07,
type: 3}
m_PrefabInstance: {fileID: 295568153}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: bb159edc225081c408fe7a01d52732e4, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1 &408182761
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 408182762}
m_Layer: 0
m_Name: KitchenObjectHoldPoint
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &408182762
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 408182761}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 1.3, z: 1}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 974939166}
m_RootOrder: -1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &410087039 --- !u!1 &410087039
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -734,6 +787,7 @@ Transform:
m_ConstrainProportionsScale: 0 m_ConstrainProportionsScale: 0
m_Children: m_Children:
- {fileID: 1139635725} - {fileID: 1139635725}
- {fileID: 408182762}
m_Father: {fileID: 0} m_Father: {fileID: 0}
m_RootOrder: 4 m_RootOrder: 4
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
@ -754,6 +808,7 @@ MonoBehaviour:
countersLayerMask: countersLayerMask:
serializedVersion: 2 serializedVersion: 2
m_Bits: 64 m_Bits: 64
kitchenObjectHoldPoint: {fileID: 408182762}
--- !u!1001 &1075657335 --- !u!1001 &1075657335
PrefabInstance: PrefabInstance:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -997,6 +1052,18 @@ Transform:
m_Father: {fileID: 0} m_Father: {fileID: 0}
m_RootOrder: 3 m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &1926678759 stripped
MonoBehaviour:
m_CorrespondingSourceObject: {fileID: 7837983985068458341, guid: f62bfcbfbc8097441a9fae9a02652a07,
type: 3}
m_PrefabInstance: {fileID: 8218183545890461205}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: bb159edc225081c408fe7a01d52732e4, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1 &2099865127 --- !u!1 &2099865127
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -1137,12 +1204,22 @@ PrefabInstance:
propertyPath: m_Name propertyPath: m_Name
value: ClearCounter value: ClearCounter
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 7837983985068458341, guid: f62bfcbfbc8097441a9fae9a02652a07,
type: 3}
propertyPath: testing
value: 1
objectReference: {fileID: 0}
- target: {fileID: 7837983985068458341, guid: f62bfcbfbc8097441a9fae9a02652a07, - target: {fileID: 7837983985068458341, guid: f62bfcbfbc8097441a9fae9a02652a07,
type: 3} type: 3}
propertyPath: kitchenObjectSO propertyPath: kitchenObjectSO
value: value:
objectReference: {fileID: 11400000, guid: 38de64e72d766a34c82d1ef83d41c98d, objectReference: {fileID: 11400000, guid: 38de64e72d766a34c82d1ef83d41c98d,
type: 2} type: 2}
- target: {fileID: 7837983985068458341, guid: f62bfcbfbc8097441a9fae9a02652a07,
type: 3}
propertyPath: secondClearCounter
value:
objectReference: {fileID: 391596026}
m_RemovedComponents: [] m_RemovedComponents: []
m_RemovedGameObjects: [] m_RemovedGameObjects: []
m_AddedGameObjects: [] m_AddedGameObjects: []

View file

@ -1,20 +1,53 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine; using UnityEngine;
public class ClearCounter : MonoBehaviour public class ClearCounter : MonoBehaviour, IKitchenObjectParent
{ {
[SerializeField] private KitchenObjectSO kitchenObjectSO; [SerializeField] private KitchenObjectSO kitchenObjectSO;
[SerializeField] private Transform counterTopPoint; [SerializeField] private Transform counterTopPoint;
public void Interact() private KitchenObject kitchenObject;
public void Interact(Player player)
{ {
Debug.Log("Interacted!"); if (kitchenObject == null)
{
Transform kitchenObjectTransform = Instantiate(kitchenObjectSO.prefab, counterTopPoint);
kitchenObjectTransform.GetComponent<KitchenObject>().SetKitchenObjectParent(this);
} else
{
// Give object to player
kitchenObject.SetKitchenObjectParent(player);
}
}
Transform kitchenObjectTransform = Instantiate(kitchenObjectSO.prefab, counterTopPoint); public Transform GetKitchenObjectFollowTransform()
{
return counterTopPoint;
}
kitchenObjectTransform.localPosition = Vector3.zero; public void SetKitchenObject(KitchenObject kitchenObject)
{
this.kitchenObject = kitchenObject;
}
Debug.Log(kitchenObjectTransform.GetComponent<KitchenObject>().GetKitchenObjectSO().objectName); public KitchenObject GetKitchenObject()
{
return kitchenObject;
}
public void ClearKitchenObject()
{
kitchenObject = null;
}
public bool HasKitchenObject()
{
return kitchenObject != null;
} }
} }

View file

@ -1,3 +1,5 @@
using System.Collections;
using System.Collections.Generic;
using System; using System;
using UnityEngine; using UnityEngine;

View file

@ -0,0 +1,16 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public interface IKitchenObjectParent
{
public Transform GetKitchenObjectFollowTransform();
public void SetKitchenObject(KitchenObject kitchenObject);
public KitchenObject GetKitchenObject();
public void ClearKitchenObject();
public bool HasKitchenObject();
}

View file

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

View file

@ -7,6 +7,37 @@ public class KitchenObject : MonoBehaviour
[SerializeField] private KitchenObjectSO kitchenObjectSO; [SerializeField] private KitchenObjectSO kitchenObjectSO;
public KitchenObjectSO GetKitchenObjectSO() { return kitchenObjectSO; } private IKitchenObjectParent kitchenObjectParent;
public KitchenObjectSO GetKitchenObjectSO()
{
return kitchenObjectSO;
}
public void SetKitchenObjectParent(IKitchenObjectParent kitchenObjectParent)
{
if (this.kitchenObjectParent != null)
{
this.kitchenObjectParent.ClearKitchenObject();
}
this.kitchenObjectParent = kitchenObjectParent;
if (kitchenObjectParent.HasKitchenObject())
{
Debug.LogError("IKitchenObjectParent already has KitchenObject!");
}
kitchenObjectParent.SetKitchenObject(this);
transform.parent = kitchenObjectParent.GetKitchenObjectFollowTransform();
transform.localPosition = Vector3.zero;
}
public IKitchenObjectParent GetKitchenObjectParent()
{
return kitchenObjectParent;
}
} }

View file

@ -1,8 +1,10 @@
using System.Collections;
using System.Collections.Generic;
using System; using System;
using UnityEditorInternal; using UnityEditorInternal;
using UnityEngine; using UnityEngine;
public class Player : MonoBehaviour public class Player : MonoBehaviour, IKitchenObjectParent
{ {
public static Player Instance { get; private set; } public static Player Instance { get; private set; }
@ -16,10 +18,12 @@ public class Player : MonoBehaviour
[SerializeField] private float moveSpeed = 7f; [SerializeField] private float moveSpeed = 7f;
[SerializeField] private GameInput gameInput; [SerializeField] private GameInput gameInput;
[SerializeField] private LayerMask countersLayerMask; [SerializeField] private LayerMask countersLayerMask;
[SerializeField] private Transform kitchenObjectHoldPoint;
private bool isWalking; private bool isWalking;
private Vector3 lastInteractDir; private Vector3 lastInteractDir;
private ClearCounter selectedCounter; private ClearCounter selectedCounter;
private KitchenObject kitchenObject;
private void Start() private void Start()
{ {
@ -30,7 +34,7 @@ public class Player : MonoBehaviour
{ {
if (selectedCounter != null) if (selectedCounter != null)
{ {
selectedCounter.Interact(); selectedCounter.Interact(this);
} }
} }
@ -155,4 +159,28 @@ public class Player : MonoBehaviour
}); });
} }
public Transform GetKitchenObjectFollowTransform()
{
return kitchenObjectHoldPoint;
}
public void SetKitchenObject(KitchenObject kitchenObject)
{
this.kitchenObject = kitchenObject;
}
public KitchenObject GetKitchenObject()
{
return kitchenObject;
}
public void ClearKitchenObject()
{
kitchenObject = null;
}
public bool HasKitchenObject()
{
return kitchenObject != null;
}
} }

View file

@ -1,3 +1,5 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine; using UnityEngine;
public class PlayerAnimator : MonoBehaviour public class PlayerAnimator : MonoBehaviour

View file

@ -1,3 +1,5 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine; using UnityEngine;
public class SelectedCounterVisual : MonoBehaviour public class SelectedCounterVisual : MonoBehaviour