示例#1
0
    void CalculateWorkArea()
    {
        WorkArea calculatedWorkArea = null;

        #region Complicated distance calculation. If successful, returns new work area.
        Dictionary <WorkArea, float> areaDstMap = new Dictionary <WorkArea, float>();
        foreach (var area in allAreas)
        {
            areaDstMap.Add(area, (transform.position - area.transform.position).sqrMagnitude);
        }
        WorkArea[] copy = allAreas.ToArray();
        System.Array.Sort(copy, (x, y) => areaDstMap[x].CompareTo(areaDstMap[y]));

        // Get closest work area. Regardless if it's interactable or not.
        if (copy.Length > 0)
        {
            calculatedWorkArea = copy[0];
        }
        #endregion

        if (workArea != calculatedWorkArea)
        {
            if (workArea != null)
            {
                OnWorkAreaRemoved?.Invoke(workArea);
            }

            workArea = calculatedWorkArea;
            OnWorkAreaChanged?.Invoke(workArea);
        }
    }
示例#2
0
    private void Update()
    {
        if (leftHand.GetItem() != null)
        {
            if (leftHand.GetItem().Spoil())
            {
                OnWorkAreaChanged?.Invoke(workArea);
            }

            if (leftHand.GetItem().Unreturn())
            {
                OnWorkAreaChanged?.Invoke(workArea);
            }
        }

        if (rightHand.GetItem() != null)
        {
            if (rightHand.GetItem().Spoil())
            {
                OnWorkAreaChanged?.Invoke(workArea);
            }

            if (rightHand.GetItem().Unreturn())
            {
                OnWorkAreaChanged?.Invoke(workArea);
            }
        }

        CalculateWorkArea();
    }