Esempio n. 1
0
    private void ProcessPointerInput()
    {
        Pointer p = Pointer.CreateOnPointerDown();

        if (p != null)
        {
            var        ray = p.GetRay(GameManager.instance.Camera);
            RaycastHit hitInfo;
            Physics.Raycast(ray, out hitInfo, 100.0f, 1 << LayerMask.NameToLayer("UI"));
            if (hitInfo.collider != null)
            {
                ControllableCharacter ch = hitInfo.collider.GetComponentInParent <ControllableCharacter>();
                if (ch != null)
                {
                    GameManager.instance.Level.SwitchCharacter(ch);
                }
            }
        }
    }
Esempio n. 2
0
    private void UpdatePicking()
    {
        Pointer pointerDown = Pointer.CreateOnPointerDown();

        if (pointerDown != null)
        {
            InteractableObject hitObject = GetObjectFromRay(pointerDown.GetRay(PickingCamera));
            if (hitObject != null)
            {
                // pick up the item if no item is currently picked up
                if (CurrentPickedObject == null && hitObject.InteractionMode != InteractionMode.None)
                {
                    if (hitObject.InteractionMode == InteractionMode.Clicking ||  hitObject.InteractionMode == InteractionMode.TargetForPickedObjects)
                    {
                        this.OnClickItem(hitObject, RoomGenerator.Instance.GetRoomStateByRoom(hitObject.ParentRoom));
                    }
                    else if (hitObject.InteractionMode == InteractionMode.Picking)
                    {
                        CurrentPickedObject = hitObject;
                        CurrentPointer      = pointerDown;
                    }
                }
                // try to use the picked object on another item
                else if (CurrentPickedObject != null)
                {
                    var useItemAction = TryGetUseItemAction(CurrentPickedObject, hitObject, RoomGenerator.Instance.GetRoomStateByRoom(hitObject.ParentRoom));
                    if (useItemAction != null)
                    {
                        bool success = useItemAction();
                        if (success)
                        {
                            CurrentPickedObject.gameObject.SetActive(false);
                            CurrentPickedObject = null;
                        }
                    }
                }
            }
        }
    }