Allow proper moving of kitchen objects and player pickup
This commit is contained in:
parent
1729ddf5c6
commit
234e00cb9b
10 changed files with 213 additions and 11 deletions
|
@ -1,20 +1,53 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class ClearCounter : MonoBehaviour
|
||||
public class ClearCounter : MonoBehaviour, IKitchenObjectParent
|
||||
{
|
||||
|
||||
|
||||
[SerializeField] private KitchenObjectSO kitchenObjectSO;
|
||||
[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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
|
|
16
Assets/Scripts/IKitchenObjectParent.cs
Normal file
16
Assets/Scripts/IKitchenObjectParent.cs
Normal 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();
|
||||
}
|
11
Assets/Scripts/IKitchenObjectParent.cs.meta
Normal file
11
Assets/Scripts/IKitchenObjectParent.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 9e041dba01fc1ec41940caf2038dcec5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -7,6 +7,37 @@ public class KitchenObject : MonoBehaviour
|
|||
|
||||
[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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using UnityEditorInternal;
|
||||
using UnityEngine;
|
||||
|
||||
public class Player : MonoBehaviour
|
||||
public class Player : MonoBehaviour, IKitchenObjectParent
|
||||
{
|
||||
|
||||
public static Player Instance { get; private set; }
|
||||
|
@ -16,10 +18,12 @@ public class Player : MonoBehaviour
|
|||
[SerializeField] private float moveSpeed = 7f;
|
||||
[SerializeField] private GameInput gameInput;
|
||||
[SerializeField] private LayerMask countersLayerMask;
|
||||
[SerializeField] private Transform kitchenObjectHoldPoint;
|
||||
|
||||
private bool isWalking;
|
||||
private Vector3 lastInteractDir;
|
||||
private ClearCounter selectedCounter;
|
||||
private KitchenObject kitchenObject;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
|
@ -30,7 +34,7 @@ public class Player : MonoBehaviour
|
|||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class PlayerAnimator : MonoBehaviour
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class SelectedCounterVisual : MonoBehaviour
|
||||
|
|
Reference in a new issue