public void bagInspectItemEnded(bool separateTrayItems = false)
 {
     Debug.Log("BUSY - " + System.DateTime.Now.Millisecond);
     bagInspectState = BagInspectState.BUSY;
     Misc.AnimateBlurTo("blurCamera", Game.instance.blurCamera.GetComponent <BlurOptimized>(), 0, 0f, 1);
     StartCoroutine(delayedInspectEndActions(separateTrayItems));
 }
 public void inspectBagDone(bool force = false)
 {
     if (force || bagInspectState == BagInspectState.BAG_OPEN)
     {
         Debug.Log("BUSY - " + System.DateTime.Now.Millisecond);
         bagInspectState = BagInspectState.BUSY;
         currentBagInspect.putBackOkContent();
     }
 }
    IEnumerator delayedInspectEndActions(bool separateTrayItems = false, float time = Misc.DEFAULT_ANIMATION_TIME, bool reverse = false)
    {
        yield return(new WaitForSeconds(time));

        switchToGameCamera(reverse);
        PubSub.publish("inspect_inactive");
        Debug.Log("BAG_OPEN - " + System.DateTime.Now.Millisecond);
        bagInspectState = BagInspectState.BAG_OPEN;
        if (separateTrayItems)
        {
            currentBagInspect.separateTrayItems();
        }
    }
 public void bagInspectFinalized()
 {
     currentBagInspect.enableContentColliders(false);
     Debug.Log("NOTHING - " + System.DateTime.Now.Millisecond);
     bagInspectState = BagInspectState.NOTHING;
 }
    public PROPAGATION onMessage(string message, object data)
    {
        if (message == "Click")
        {
            if (Game.instance.cameraXPos == 2 && !Game.instance.zoomedOutState)
            {
                Vector3 position = Vector3.zero;
                if (data.GetType() == typeof(Vector2))
                {
                    Vector2 posV2 = (Vector2)data;
                    position = new Vector3(posV2.x, posV2.y);
                }
                else
                {
                    position = (Vector3)data;
                }

                // Get camera
                Camera     camera = GetComponent <Game>().gameCamera;
                RaycastHit hit;
                Ray        ray = camera.ScreenPointToRay(position);

                if (bagInspectState == BagInspectState.NOTHING)
                {
                    if (Physics.Raycast(ray, out hit))
                    {
                        Debug.Log(hit.transform.gameObject.name);

                        BagProperties clickedBagProperties = hit.transform.GetComponent <BagProperties>();

//                        // TODO - Can't contents be clicked directly when in a bag without lid?
//                        if (clickedBagProperties == null) {}

                        if (clickedBagProperties != null && !clickedBagProperties.isOpen)
                        {
                            clickedBagProperties.showItems(true);
                            clickedBagProperties.animateLidState(true);
                            clickedBagProperties.enableContentColliders(true);
                            currentBagInspect = clickedBagProperties;
                            bagInspectState   = BagInspectState.BAG_OPEN;
                            clickedBagProperties.resetActionOnItems();
                        }
                    }
                }
                else if (bagInspectState == BagInspectState.BAG_OPEN)
                {
//                    Debug.Log("Bag is open; " + BAG_CONTENTS_LAYER_MASK);
                    bool isBagEmpty = currentBagInspect.contents.transform.childCount == 0;
                    if (!isBagEmpty)
                    {
                        if (Physics.Raycast(ray, out hit, Mathf.Infinity, BAG_CONTENTS_LAYER_MASK))
                        {
                            Debug.Log(hit.transform.gameObject.name);

                            BagContentProperties clickedBagContentProperties = hit.transform.GetComponent <BagContentProperties>();
                            if (clickedBagContentProperties != null)
                            {
                                switchToGameCamera(true);

                                clickedBagContentProperties.inspect();
                                Misc.AnimateBlurTo("blurCamera", Game.instance.blurCamera.GetComponent <BlurOptimized>(), 1, 3f, 2);
                                bagInspectState = BagInspectState.ITEM_INSPECT;
                                PubSub.publish("inspect_active");
                                PubSub.publish("bag_inspect_item", new InspectActionBag(currentBagInspect.id, clickedBagContentProperties, InspectUIButton.INSPECT_TYPE.UNDEFINED));
                            }
                        }
                    }
                    else
                    {
                        // Bag is empty, if clicked - close it and end inspect state
                        if (Physics.Raycast(ray, out hit))
                        {
//                        Debug.Log(hit.transform.gameObject.name);

                            BagProperties clickedBagProperties = hit.transform.GetComponent <BagProperties>();
                            if (clickedBagProperties == currentBagInspect)
                            {
                                inspectBagDone();
                            }
                        }
                    }
                }
            }
        }

        return(PROPAGATION.DEFAULT);
    }