Beispiel #1
0
    /// <summary>
    /// Load/enable cable cutting window and initialize it
    /// </summary>
    public void OpenCableCuttingWindow()
    {
        // get mouse position
        Vector3 mousePosition = MouseUtils.MouseToWorldPos();
        // round mouse position
        Vector3Int roundedMousePosition = Vector3Int.RoundToInt(mousePosition);

        targetWorldPosition = roundedMousePosition;

        // check if window can be enabled, if not - return
        if (!CanWindowBeEnabled())
        {
            return;
        }

        // get matrix
        GameObject hit    = MouseUtils.GetOrderedObjectsUnderMouse().FirstOrDefault();
        Matrix     matrix = hit.GetComponentInChildren <Matrix>();

        // return if matrix is null
        if (matrix == null)
        {
            return;
        }

        Vector3Int cellPosition = matrix.MetaTileMap.WorldToCell(mousePosition);

        // if window exist, just initialize it
        if (cableCuttingWindow != null)
        {
            cableCuttingWindow.InitializeCableCuttingWindow(matrix, cellPosition, mousePosition);
        }
        // else, load window from resources, store reference and initialize
        else
        {
            // only load from resources if the prefab is null
            if (cableCuttingWindowPrefab == null)
            {
                cableCuttingWindowPrefab = Resources.Load <GameObject>(PATH_TO_WINDOW_PREFAB);
            }
            cableCuttingWindow = Instantiate(cableCuttingWindowPrefab).GetComponentInChildren <CableCuttingWindow>();
            cableCuttingWindow.InitializeCableCuttingWindow(matrix, cellPosition, mousePosition);
        }

        // enable window
        cableCuttingWindow.SetWindowActive(true);

        isWindowActive = true;
        itemInHand     = PlayerManager.LocalPlayerScript.DynamicItemStorage.GetActiveHandSlot().ItemObject;
    }
    /// <summary>
    /// Load/enable cable cutting window and initialize it
    /// </summary>
    public void OpenCableCuttingWindow()
    {
        // get mouse position
        Vector3 mousePosition = Camera.main.ScreenToWorldPoint(CommonInput.mousePosition);
        // round mouse position
        Vector3Int roundedMousePosition = Vector3Int.RoundToInt(mousePosition);

        targetWorldPosition = roundedMousePosition;

        // check if window can be enabled, if not - return
        if (!CanWindowBeEnabled())
        {
            return;
        }

        // get matrix
        GameObject hit    = MouseUtils.GetOrderedObjectsUnderMouse().FirstOrDefault();
        Matrix     matrix = hit.GetComponentInChildren <Matrix>();

        // return if matrix is null
        if (matrix == null)
        {
            return;
        }

        Vector3Int cellPosition = matrix.MetaTileMap.WorldToCell(mousePosition);

        // if window exist, just initialize it
        if (cableCuttingWindow != null)
        {
            cableCuttingWindow.InitializeCableCuttingWindow(matrix, cellPosition, mousePosition);
        }
        // else, load window from resources, store reference and initialize
        else
        {
            cableCuttingWindow = Instantiate(cableCuttingWindowPrefab).GetComponentInChildren <CableCuttingWindow>();
            cableCuttingWindow.InitializeCableCuttingWindow(matrix, cellPosition, mousePosition);
        }

        // enable window
        cableCuttingWindow.SetWindowActive(true);

        isWindowActive = true;
        itemInHand     = UIManager.Hands.CurrentSlot.ItemObject;
    }