Пример #1
0
 public ObjectState(KitchenObject obj)
 {
     mObj = obj;
     this.position = obj.transform.position;
     this.rotation = obj.transform.rotation;
     this.ID = obj.ID;
 }
Пример #2
0
 public void ObjectRemoved(KitchenObject obj)
 {
     CurrentPrice -= obj.Price;
 }
Пример #3
0
 public void ObjectAdded(KitchenObject obj)
 {
     CurrentPrice += obj.Price;
 }
Пример #4
0
    public void RemoveClicked()
    {
        string oldObjName = SelectedKitchenObject.gameObject.name;
        int oldObjID = SelectedKitchenObject.ID;
        Vector3 oldPosition = SelectedKitchenObject.transform.position;
        Quaternion oldRotation = SelectedKitchenObject.transform.rotation;
        UndoableAction act = new UndoableAction(
            delegate
            {
                KitchenObject obj = Instantiate(kitchenObjectPrefabs.First(x => oldObjName.StartsWith(x.gameObject.name)));
                obj.Init(oldObjID);
                obj.gameObject.SetActive(true);
                obj.transform.position = oldPosition;
                obj.transform.rotation = oldRotation;
            },
            delegate
            {
                KitchenObject oldObj = GetObject(oldObjID);
                if (SelectedKitchenObject == oldObj)
                    SelectNewObject(null);
                Destroy(oldObj.gameObject);
            });
        UndoManager.Instance.RegisterUndoableAction(act);

        Destroy(SelectedKitchenObject.gameObject);
        SelectedKitchenObject = null;
    }
Пример #5
0
 void Start()
 {
     SelectedKitchenObject = null;
     allKitchenObjects = new List<KitchenObject>();
 }
Пример #6
0
 public void AddObject(KitchenObject obj)
 {
     allKitchenObjects.Add(obj);
 }
Пример #7
0
    void SelectNewObject(Transform newObjTransform)
    {
        resizePanel.gameObject.SetActive(false);

        if(SelectedKitchenObject != null)
        {
            SelectedKitchenObject.GetComponent<Renderer>().material = previousMat;
        }

        if (newObjTransform != null)
        {
            SelectedKitchenObject = newObjTransform.GetComponent<KitchenObject>();
            previousMat = SelectedKitchenObject.GetComponent<Renderer>().material;
            Color newColor = previousMat.color;
            newColor.a = transparentMat.color.a;
            transparentMat.color = newColor;
            SelectedKitchenObject.GetComponent<Renderer>().material = transparentMat;
        }
        else
        {
            SetButtonEnabled(true, 0);
            SetButtonEnabled(false, 1);
            SetButtonEnabled(false, 2);
            SetButtonEnabled(false, 3);
            SetButtonEnabled(false, 4);
        }
    }
Пример #8
0
    void ReplaceSelectedKitchenObject(KitchenObject newObj)
    {
        if (SelectedKitchenObject == null)
            return;
        if (SelectedKitchenObject.isCornerObject != newObj.isCornerObject)
        {
            Debug.Log("Corner objects can only be replaced with another corner objects");
            return;
        }
        if(SelectedKitchenObject.mustLayOnGround != newObj.mustLayOnGround)
        {
            Debug.Log("Cant replace these objects");
            return;
        }

        List<ObjectState> oldState = allKitchenObjects.Select(x => new ObjectState(x)).ToList();

        KitchenObject newObjInstance = Instantiate(newObj, new Vector3(-100, -100, -100), Quaternion.identity) as KitchenObject;
        if(newObjInstance.TryPlace(SelectedKitchenObject.transform.position, SelectedKitchenObject.transform.right))
        {
            Debug.Log("DestroyA");

            List<ObjectState> newState = allKitchenObjects.Where(z => z.ID != SelectedKitchenObject.ID).Select(x => new ObjectState(x)).ToList();

            newObjInstance.Init();
            int newObjID = newObjInstance.ID;
            int oldObjID = SelectedKitchenObject.ID;
            string oldObjName = SelectedKitchenObject.gameObject.name;
            string newObjName = newObjInstance.gameObject.name;
            Vector3 oldObjPosition = SelectedKitchenObject.transform.position;
            Quaternion oldObjRotation = SelectedKitchenObject.transform.rotation;
            Vector3 newObjPosition = newObjInstance.transform.position;
            Quaternion newObjRotation = newObjInstance.transform.rotation;
            UndoableAction act = new UndoableAction(
                delegate
                {
                    KitchenObject oldObj = GetObject(newObjID);
                    Destroy(oldObj.gameObject);
                    KitchenObject obj = Instantiate(kitchenObjectPrefabs.First(x => oldObjName.StartsWith(x.gameObject.name)).gameObject).GetComponent<KitchenObject>();
                    obj.Init(oldObjID);
                    obj.transform.position = oldObjPosition;
                    obj.transform.rotation = oldObjRotation;
                    obj.gameObject.SetActive(true);

                    Helper.WaitOneFrame(
                        delegate
                        {
                            foreach (var state in oldState)
                            {
                                state.Reset();
                            }
                        });

                    SelectNewObject(null);
                },
                delegate
                {
                    KitchenObject oldObj = GetObject(oldObjID);
                    Destroy(oldObj.gameObject);
                    KitchenObject obj = Instantiate(kitchenObjectPrefabs.First(x =>newObjName.StartsWith(x.gameObject.name)).gameObject).GetComponent<KitchenObject>();
                    obj.Init(newObjID);
                    obj.transform.position = newObjPosition;
                    obj.transform.rotation = newObjRotation;
                    obj.gameObject.SetActive(true);

                    Helper.WaitOneFrame(
                        delegate
                        {
                            foreach (var state in newState)
                            {
                                state.Reset();
                            }
                        });
                    SelectNewObject(null);
                });
            UndoManager.Instance.RegisterUndoableAction(act);

            Destroy(SelectedKitchenObject.gameObject);
            newObjInstance.gameObject.SetActive(true);
        }
        else
        {
            Debug.Log("DestroyB");
            Destroy(newObjInstance.gameObject);
        }

        SelectedKitchenObject = null;
    }
Пример #9
0
    private void PlaceObjectOnWall(RaycastHit hit, KitchenObject o, float checkDist, LayerMask wallsMask)
    {
        if (hit.transform.tag != "Wall")
            return;

        Vector3 newPos = hit.point + o.transform.forward * o.HalfSize.z;
        if(o.TrySnap(ref newPos, checkDist, wallsMask))
        {
            o.transform.rotation = Quaternion.LookRotation(hit.normal);
            o.transform.position = newPos;
        }
    }
Пример #10
0
    private void PlaceObjectOnGround(RaycastHit hit, KitchenObject o, float checkDist, LayerMask wallsMask)
    {
        Vector3 desiredPos;
        if (hit.transform.tag == "Wall")
        {
            o.transform.rotation = Quaternion.LookRotation(hit.normal);
            desiredPos = hit.point + hit.normal * o.Size.z;
            desiredPos.y = o.HalfSize.y;
        }
        else
        {
            desiredPos = hit.point + new Vector3(0, o.HalfSize.y, 0);
        }

        if(o.TrySnap(ref desiredPos, checkDist, wallsMask))
        {
            o.transform.position = desiredPos;
        }
    }
Пример #11
0
    IEnumerator MoveObject(KitchenObject obj)
    {
        SelectNewObject(null);
        isMovingObject = true;
        SetButtonEnabled(false, 0);
        SetButtonEnabled(false, 1);
        SetButtonEnabled(false, 2);
        SetButtonEnabled(false, 3);
        SetButtonEnabled(false, 4);

        obj.gameObject.layer = Physics.IgnoreRaycastLayer;
        LayerMask layer = obj.mustLayOnGround == true ? LayerMask.GetMask("Floor") : LayerMask.GetMask("Walls");
        layer = LayerMask.GetMask("Floor", "Walls");
        LayerMask wallsMask = LayerMask.GetMask("Walls", "KitchenObjects");
        Vector3 oldPos = obj.transform.position;
        Quaternion oldRot = obj.transform.rotation;
        bool wasMoved = false;

        while (true)
        {
            wasMoved = true;
            if (Input.GetKeyDown(KeyCode.Escape))
            {
                wasMoved = false;
                obj.transform.position = oldPos;
                obj.transform.rotation = oldRot;
                break;
            }

            RaycastHit hit;
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            if (!(Physics.Raycast(ray, out hit, Mathf.Infinity, LayerMask.GetMask("KitchenObjectsSelect")) && hit.transform != obj.transform) && Physics.Raycast(ray, out hit, Mathf.Infinity, layer))
            {
                obj.gameObject.SetActive(true);
                if (obj.mustLayOnGround)
                {
                    PlaceObjectOnGround(hit, obj, 1.5f, wallsMask);
                }
                else
                {
                    PlaceObjectOnWall(hit, obj, 1.5f, wallsMask);
                }

            }
            else
            {
                obj.transform.position = new Vector3(0, 0, -1000);
                //obj.gameObject.SetActive(false);
                yield return null;
                continue;
            }

            if (Input.GetMouseButtonDown(0) && !obj.transform.GetChild(0).GetComponent<ColliderManager>().IsColliding)
            {
                break;
            }

            yield return null;
        }

        if (wasMoved)
        {
            Vector3 newPosition = obj.transform.position;
            Quaternion newRotation = obj.transform.rotation;
            int objID = obj.ID;

            UndoableAction act = new UndoableAction(
                delegate
                {
                    KitchenObject oldObj = GetObject(objID);
                    oldObj.transform.rotation = oldRot;
                    oldObj.transform.position = oldPos;
                },
                delegate
                {
                    KitchenObject oldObj = GetObject(objID);
                    oldObj.transform.rotation = newRotation;
                    oldObj.transform.position = newPosition;
                });
            UndoManager.Instance.RegisterUndoableAction(act);
        }

        obj.gameObject.layer = LayerMask.NameToLayer("KitchenObjects");

        isMovingObject = false;
        SelectNewObject(obj.transform);
        SetButtonEnabled(true, 0);
        SetButtonEnabled(true, 1);
        SetButtonEnabled(true, 2);
        SetButtonEnabled(true, 3);
        SetButtonEnabled(true, 4);
    }
Пример #12
0
    IEnumerator AddKitchenObject(KitchenObject obj)
    {
        SelectNewObject(null);
        KitchenObject objInstance = Instantiate<KitchenObject>(obj);
        objInstance.gameObject.layer = Physics.IgnoreRaycastLayer;
        isAddingObject = true;
        LayerMask layer = objInstance.mustLayOnGround == true ? LayerMask.GetMask("Floor") : LayerMask.GetMask("Walls");
        layer = LayerMask.GetMask("Floor", "Walls");
        LayerMask wallsMask = LayerMask.GetMask("Walls", "KitchenObjects");
        SetButtonEnabled(false, 0);
        SetButtonEnabled(false, 1);
        SetButtonEnabled(false, 2);
        SetButtonEnabled(false, 3);
        SetButtonEnabled(false, 4);

        while(true)
        {
            if(Input.GetKeyDown(KeyCode.Escape))
            {
                Destroy(objInstance.gameObject);
                SelectNewObject(null);
                yield break;
            }

            RaycastHit hit;
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            if(!(Physics.Raycast(ray, out hit, Mathf.Infinity, LayerMask.GetMask("KitchenObjectsSelect")) && hit.transform != objInstance.transform) && Physics.Raycast(ray, out hit, Mathf.Infinity, layer))
            {
                objInstance.gameObject.SetActive(true);
                if(objInstance.mustLayOnGround)
                {
                    PlaceObjectOnGround(hit, objInstance, 1.5f, wallsMask);
                }
                else
                {
                    PlaceObjectOnWall(hit, objInstance, 1.5f, wallsMask);
                }

            }
            else
            {
                objInstance.transform.position = new Vector3(0, 0, -1000);
                //obj.gameObject.SetActive(false);
                yield return null;
                continue;
            }

            if(Input.GetMouseButtonDown(0) && objInstance.gameObject.activeSelf && !objInstance.transform.GetChild(0).GetComponent<ColliderManager>().IsColliding)
            {
                break;
            }

            yield return null;
        }
        objInstance.Init();
        int objID = objInstance.ID;
        string objName = objInstance.name;
        Vector3 objPosition = objInstance.transform.position;
        Quaternion objRotation = objInstance.transform.rotation;

        UndoableAction act = new UndoableAction(
            delegate
            {
                Destroy(GetObject(objID).gameObject);
                SelectNewObject(null);
            },
            delegate
            {
                KitchenObject newObj = Instantiate(kitchenObjectPrefabs.First(x => objName.StartsWith(x.gameObject.name)));
                newObj.Init(objID);
                newObj.transform.position = objPosition;
                newObj.transform.rotation = objRotation;
                newObj.gameObject.SetActive(true);
                SelectNewObject(null);
            });
        UndoManager.Instance.RegisterUndoableAction(act);

        objInstance.gameObject.layer = LayerMask.NameToLayer("KitchenObjects");
        isAddingObject = false;
        SelectNewObject(objInstance.transform);
        SetButtonEnabled(true, 0);
        SetButtonEnabled(true, 1);
        SetButtonEnabled(true, 2);
        SetButtonEnabled(true, 3);
        SetButtonEnabled(true, 4);
    }
Пример #13
0
 public void RemoveObject(KitchenObject obj)
 {
     allKitchenObjects.Remove(obj);
 }