49 lines
1.2 KiB
C#
49 lines
1.2 KiB
C#
using UnityEngine;
|
|
|
|
public class KitchenObject : MonoBehaviour
|
|
{
|
|
public KitchenObjectSO KitchenObjectSO;
|
|
private IKitchenObjectParent kitchenObjectParent;
|
|
|
|
public void SetKitchenObjectParent(IKitchenObjectParent kOP)
|
|
{
|
|
kOP.KitchenObject = null;
|
|
|
|
kitchenObjectParent = kOP;
|
|
|
|
if (kOP.KitchenObject != null)
|
|
{
|
|
Debug.LogError("IKitchenObjectParent already has a KitchenObject");
|
|
}
|
|
|
|
kOP.KitchenObject = this;
|
|
|
|
transform.parent = kOP.KitchenObjectHoldPoint;
|
|
transform.localPosition = Vector3.zero;
|
|
}
|
|
|
|
public void DestroySelf()
|
|
{
|
|
kitchenObjectParent.KitchenObject = null;
|
|
Destroy(gameObject);
|
|
}
|
|
|
|
public bool TryGetPlate(out PlateKitchenObject plateKitchenObject)
|
|
{
|
|
if (this is PlateKitchenObject)
|
|
{
|
|
plateKitchenObject = this as PlateKitchenObject;
|
|
return true;
|
|
}
|
|
plateKitchenObject = null;
|
|
return false;
|
|
}
|
|
public static KitchenObject SpawnKitchenObject(KitchenObjectSO kitchenObjectSO, IKitchenObjectParent kitchenObjectParent)
|
|
{
|
|
Transform kitchenObjectTransform = Instantiate(kitchenObjectSO.prefab);
|
|
KitchenObject kitchenObject = kitchenObjectTransform.GetComponent<KitchenObject>();
|
|
kitchenObject.SetKitchenObjectParent(kitchenObjectParent);
|
|
kitchenObjectTransform.gameObject.SetActive(true);
|
|
return kitchenObject;
|
|
}
|
|
} |