void Update()
    {
        // PROCESS INTERACTIVE OBJECTS
        // Is the crosshair over a usuable item or descriptive item...first get ray from centre of screen
        var ray = _camera.ScreenPointToRay(new Vector3(Screen.width / 2, Screen.height / 2, 0));

        // Cast Ray and collect ALL hits
        var hits = Physics.RaycastAll(ray, 5, _interactiveMask | _backpackMask);

        // Process the hits for the one with the highest priority
        if (hits.Length > 0)
        {
            // Used to record the index of the highest priority
            int             highestPriority = int.MinValue;
            InteractiveItem priorityObject  = null;

            // Iterate through each hit
            foreach (var hit in hits)
            {
                // Fetch its InteractiveItem script from the database
                InteractiveItem interactiveObject = _gameSceneManager.GetInteractiveItem(hit.collider.GetInstanceID());

                // If this is the highest priority object so far then remember it
                if (interactiveObject != null && interactiveObject.Priority > highestPriority)
                {
                    priorityObject  = interactiveObject;
                    highestPriority = priorityObject.Priority;
                }
            }

            if (priorityObject != null)
            {
                if (priorityObject.activationType == ActivationType.MouseButtonPressed && Input.GetMouseButton(0) ||
                    priorityObject.activationType == ActivationType.MouseButtonDown && Input.GetMouseButtonDown(0))
                {
                    priorityObject.Drag(this);
                }
            }
        }

        if (SelectedDraggableItem != null)
        {
            SelectedDraggableItem.Drag(this);
            if (Input.GetMouseButtonUp(0))
            {
                SelectedDraggableItem.Drop();
                SelectedDraggableItem = null;
            }
        }

        if (SelectedStorageItem != null && Input.GetMouseButtonUp(0))
        {
            SelectedStorageItem.Drop();
            SelectedStorageItem = null;
        }
    }
예제 #2
0
    public virtual CollectableItem Drop(Vector3 position)
    {
        if (CollectableItem != null)
        {
            CollectableItem.transform.position = position;
            CollectableItem.Drop();
            return(CollectableItem);
        }

        return(null);
    }