Пример #1
0
    private void EraseObject()
    {
        Ray   r     = cam.ScreenPointToRay(Input.mousePosition);
        float enter = 0.0f;

        if (zeroPlane.Raycast(r, out enter))
        {
            //Get the point that is clicked
            Vector3    hitPoint = r.GetPoint(enter);
            Collider[] cols;
            cols = Physics.OverlapSphere(hitPoint, 0.5f);
            if (cols.Length > 0)
            {
                for (int i = 0; i < cols.Length; i++)
                {
                    Debug.Log(cols[i].name);
                    NeedSatisfier ns = cols[i].GetComponentInParent <NeedSatisfier>();
                    if (ns == null)
                    {
                        continue;
                    }
                    if (ns.Need == Employee.SatisfactionStatus.WORK)
                    {
                        Destroy(ns.owner.gameObject);
                    }

                    GameManager.Instance.AddMoney(ns.Value);
                    Destroy(ns.gameObject);
                    break;
                }
            }
        }
    }
    public NeedSatisfier GetNearestSatisfier(Employee.SatisfactionStatus key, Vector3 position)
    {
        if (!Satisfiers.ContainsKey(key))
        {
            return(null);
        }

        List <NeedSatisfier> satisfiers = Satisfiers[key];
        // If there's no satisfier available (this is, if they're all being used or there aren't any) return null.
        NeedSatisfier nearestSatisfier = null;

        float lastDistance = Mathf.Infinity;

        foreach (NeedSatisfier satisfier in satisfiers)
        {
            if (!satisfier.isAvailable)
            {
                // Can't use this guy... next!
                continue;
            }

            float distance = Vector3.Distance(satisfier.transform.position, position);
            if (distance < lastDistance)
            {
                lastDistance     = distance;
                nearestSatisfier = satisfier;
            }
        }
        return(nearestSatisfier);
    }
 public void RemoveSatisfier(Employee.SatisfactionStatus key, NeedSatisfier satisfier)
 {
     if (!Satisfiers.ContainsKey(key))
     {
         return;
     }
     Satisfiers[key].Remove(satisfier);
 }
 public void AddSatisfier(Employee.SatisfactionStatus key, NeedSatisfier satisfier)
 {
     if (!Satisfiers.ContainsKey(key))
     {
         Satisfiers[key] = new List <NeedSatisfier>();
     }
     Satisfiers[key].Add(satisfier);
 }
Пример #5
0
 public void SetWorkstation(NeedSatisfier Workstation)
 {
     if (Workstation.Need != SatisfactionStatus.WORK)
     {
         Debug.LogError("Wrong workstation");
         return;
     }
     this.Workstation = Workstation;
 }
Пример #6
0
    private void Start()
    {
        agent = GetComponent <NavMeshAgent>();
        currentSatisfactionStatus = SatisfactionStatus.IDLE;
        currentMovementStatus     = MovementStatus.IDLE;
        currentSatisfier          = null;

        EntertainmentSatisfaction = 100f;
        FoodSatisfaction          = 100f;
        BathroomSatisfaction      = 100f;
    }
Пример #7
0
    private void SpawnSatisfier()
    {
        currentPrefab = Instantiate(satisfierPrefab);
        for (int i = 0; i < currentPrefab.transform.childCount; i++)
        {
            Transform child = currentPrefab.transform.GetChild(i);
            if (child.CompareTag("SnapPoint"))
            {
                child.gameObject.SetActive(false);
            }
        }
        NeedSatisfier ns = currentPrefab.GetComponent <NeedSatisfier>();

        updater.ShowHint("Placing " + ns.ObjectName + " ($" + ns.Value + ") \n Press R to rotate, press S to place again");
        isSatisfier = true;
    }
Пример #8
0
    private void Need(SatisfactionStatus need)
    {
        // Are we moving towards something? (AKA: Are we trying to satisfy a need?)
        if (currentMovementStatus == MovementStatus.MOVING || currentMovementStatus == MovementStatus.SATISFYING)
        {
            // Don't update anything.
            return;
        }

        // Set need, and move to the nearest satisfier
        currentSatisfactionStatus = need;

        // Do we need to work? if so, go to our station, no need to find nearest one.
        if (currentSatisfactionStatus == SatisfactionStatus.WORK)
        {
            if (Workstation == null)
            {
                // We didn't set workstation or it was removed...
                Debug.LogError("Workstation not found");
                currentMovementStatus = MovementStatus.CANT_REACH;
                return;
            }
            currentMovementStatus = MovementStatus.MOVING;
            currentSatisfier      = Workstation;
            MoveTo(Workstation.satisfierStandPlace.position);
            return;
        }

        // Find the nearest need satisfaction and go there
        NeedSatisfier satisfier = SatisfierLocationDictionary.Instance.GetNearestSatisfier(need, transform.position);

        if (satisfier == null)
        {
            // No satisfier available
            currentMovementStatus = MovementStatus.CANT_REACH;
            Debug.LogError("No Satisfier Available");
            FindObjectOfType <UIUpdater>().ShowHint("An employee can't reach location for " + need.ToString());
            Anger += 15;
            return;
        }

        currentMovementStatus = MovementStatus.MOVING;
        currentSatisfier      = satisfier;
        MoveTo(satisfier.waitingQueue.position);
    }
Пример #9
0
    private void SpawnEmployee(NeedSatisfier ns)
    {
        GameObject go       = Instantiate(employeePrefab, employeeSpawnPoint.position, employeeSpawnPoint.rotation);
        Employee   employee = go.GetComponent <Employee>();

        employee.BathroomSatisfactionFactor    = UnityEngine.Random.Range(1, 5);
        employee.BathroomSatisfactionThreshold = UnityEngine.Random.Range(30, 60);

        employee.FoodSatisfactionFactor    = UnityEngine.Random.Range(1, 5);
        employee.FoodSatisfactionThreshold = UnityEngine.Random.Range(30, 60);

        // TODO: Set when entertainment satisfiers are added.
        employee.EntertainmentFactor    = 0;
        employee.EntertainmentThreshold = UnityEngine.Random.Range(30, 60);

        employee.SetWorkstation(ns);
        ns.owner = employee;
    }
Пример #10
0
    private void PlacePrefab()
    {
        if (isSatisfier)
        {
            isSatisfier = false;
            NeedSatisfier ns = currentPrefab.GetComponent <NeedSatisfier>();

            try
            {
                GameManager.Instance.RemoveMoney(ns.Value);
            }
            catch (Exception)
            {
                Debug.LogError("Not Enough Money!");
                CancelOperation();
                updater.ShowHint("Not Enough Money!");
                return;
            }

            SatisfierLocationDictionary.Instance.AddSatisfier(ns.Need, ns);
            if (ns.Need == Employee.SatisfactionStatus.WORK)
            {
                SpawnEmployee(ns);
            }

            // Enable snappoints
            for (int i = 0; i < currentPrefab.transform.childCount; i++)
            {
                Transform child = currentPrefab.transform.GetChild(i);
                if (child.CompareTag("SnapPoint"))
                {
                    child.gameObject.SetActive(true);
                }
            }
        }
        updater.HideHint();
        currentPrefab = null;
    }