Example #1
0
 void OnStartUpgrade(PerformerTask p)
 {
     SetUpgradeInProgress(true);
     pbar = UI.Instance.CreateProgressBar(Position);
     pbar.SetColor(Color.green);
     StartCoroutine(CoUpdateUpgradeProgress(p));
 }
Example #2
0
    void CreateTask(PerformerTask task)
    {
        Transform t = ObjectPool.Instantiate <TaskButton> ().transform;

        t.SetParent(actionsGroup.transform);
        t.Reset();
        t.GetScript <TaskButton> ().Init(task);
        actions.Add(t.gameObject);
    }
Example #3
0
        IEnumerator CoUpdateUpgradeProgress(PerformerTask task)
        {
            upgrading = true;

            while (upgrading)
            {
                pbar.SetProgress(task.Progress);
                yield return(null);
            }
        }
Example #4
0
    void EnableButton(PerformerTask t)
    {
        TaskButton button = buttons.Find(x => !x.gameObject.activeSelf);

        if (button != null)
        {
            button.gameObject.SetActive(true);
            button.Init(t);
            button.Button.interactable = t.Enabled;
        }
    }
Example #5
0
        void OnGenerateUnit(PerformerTask task)
        {
            Unit       unit       = ((GenerateUnit)task).GeneratedUnit;
            StaticUnit staticUnit = unit as StaticUnit;

            staticUnit.Position = Position;
            if (Selected)
            {
                SelectionManager.Select(staticUnit.UnitClickable);
            }
            DestroyThis();
        }
Example #6
0
        public void SetTask(PerformerTask task)
        {
            RemoveTask();
            currentTask               = ObjectPool.Instantiate(renderers[task.GetType()]).GetComponent <UnitRenderer> ();
            currentTask.Parent        = MyTransform;
            currentTask.LocalPosition = Vector3.zero;

            Vector3 originalScale = currentTask.LocalScale;

            currentTask.LocalScale = new Vector3(
                originalScale.x * 0.3f,
                originalScale.y * 0.3f,
                originalScale.z * 0.3f);
        }
Example #7
0
    public void TestEnabled(PerformerTask task = null)
    {
        if (task != null)
        {
            task.Start();
            if ((task.Enabled && task.Performing) || (!task.Enabled && !task.Performing))
            {
                Debug.Log("Enabled test succeeded :)");
            }
            else
            {
                Debug.Log("Enabled test failed because enabled is " + task.Enabled + " but performing is " + task.Performing);
            }
            return;
        }

        EnabledTest enabled = new EnabledTest();

        enabled.enabled = false;
        bool failed = false;

        enabled.Start();
        if (enabled.Performing)
        {
            Debug.Log("Enabled test failed because the task was started but the task is disabled");
            failed = true;
        }

        enabled.enabled = true;
        enabled.Start();
        if (!enabled.Performing)
        {
            Debug.Log("Enabled test failed because the task is enabled but didn't start");
            failed = true;
        }

        if (!failed)
        {
            Debug.Log("Enabled test succeeded :)");
        }
    }
Example #8
0
    public void Init(PerformerTask task, bool hasText = true)
    {
        this.task    = task;
        this.hasText = hasText;

        if (hasText)
        {
            ButtonText.text = task.Settings.Title;
            if (task is CostTask)
            {
                CostTask costTask = task as CostTask;
                ButtonText.text += " (";

                int count = costTask.Costs.Count;

                foreach (var c in costTask.Costs)
                {
                    ButtonText.text += c.Value;
                    if (c.Key == "Coffee")
                    {
                        ButtonText.text += "C";
                    }
                    else
                    {
                        ButtonText.text += "M";
                    }
                    count--;
                    if (count > 0)
                    {
                        ButtonText.text += ", ";
                    }
                }
                ButtonText.text += ")";
            }
        }

        RemoveButtonListeners();
        AddButtonListener(OnPress);
    }
Example #9
0
 IEnumerator CoVisualFollowCursor(PerformerTask task)
 {
     while (visual != null)
     {
         Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
         RaycastHit hit;
         if (Target == null)
         {
             if (Physics.Raycast(ray, out hit, Mathf.Infinity, 1 << (int)InputLayer.Structure))
             {
                 visual.transform.position = Vector3.Lerp(ray.origin, hit.point, 0.9f);
                 visual.transform.rotation = Quaternion.Lerp(visual.transform.rotation, Quaternion.identity, 0.5f);
             }
         }
         else
         {
             visual.transform.position = Vector3.Lerp(visual.transform.position, (Vector3)Target, 0.25f);
             visual.transform.rotation = Quaternion.Lerp(visual.transform.rotation, Rotation, 0.5f);
         }
         yield return(null);
     }
 }
Example #10
0
        void OnCompleteTask(PerformerTask task)
        {
            task.onComplete -= OnCompleteTask;

            PathElement destination;

            if (TaskFinder.PairFromTask(task, currentElement, previousElement, out destination))
            {
                SetDestination(destination);
            }
            else if (!FindMatch())
            {
                if (TaskFinder.NearestPathElementWithTask(currentElement, task, out destination))
                {
                    SetDestination(destination);
                }
                else
                {
                    Idle = true;
                }
            }
        }
Example #11
0
    public void TestAutoStart(PerformerTask autoStart)
    {
        PerformableTasks.Add(autoStart);

        if (!autoStart.Settings.AutoStart)
        {
            throw new System.Exception("The task '" + autoStart.GetType() + "' will not auto start because its data model has AutoStart set to false");
        }

        if (autoStart.Settings.Duration == 0)
        {
            throw new System.Exception("The test '" + autoStart.GetType() + "' will fail because its duratio is 0. Set it to something above 0");
        }

        if (autoStart.Performing)
        {
            Debug.Log("Auto Start test succeeded :)");
        }
        else
        {
            Debug.Log("Auto Start test failed :(");
        }
    }
Example #12
0
    public void TestRepeat(PerformerTask repeat)
    {
        PerformableTasks.Add(repeat);
        repeat.onEnd += (PerformerTask task) => {
            Co2.WaitForFixedUpdate(() => {
                if (repeat.Performing)
                {
                    Debug.Log("Repeat test succeeded :)");
                }
                else
                {
                    Debug.Log("Repeat test failed :(");
                }
                repeat.Stop();
            });
        };

        if (!repeat.Settings.Repeat)
        {
            throw new System.Exception("The task '" + repeat.GetType() + "' will not repeat because its data model has Repeat set to false");
        }

        repeat.Start();
    }
Example #13
0
 void OnGenerateElder(PerformerTask task)
 {
     OnUnitGenerated(((GenerateUnit <Elder>)task).GeneratedUnit);
 }
Example #14
0
 public void SetVisual(PerformerTask task, UnitRenderer newVisual)
 {
     RemoveVisual();
     this.visual = newVisual;
     StartCoroutine(CoVisualFollowCursor(task));
 }
Example #15
0
 void OnGenerateCorpse(PerformerTask task)
 {
     OnUnitGenerated(((GenerateUnit <Corpse>)task).GeneratedUnit);
 }
Example #16
0
 void OnCompleteUpgrade(PerformerTask p)
 {
     SetUpgradeInProgress(false);
     UI.Instance.DestroyProgressBar(pbar);
     upgrading = false;
 }
Example #17
0
 void OnStartPlant(PerformerTask task)
 {
     TaskPen.onRemove -= OnCancelPlant;
     seedProduction.RemoveSeed();
 }
Example #18
0
 void OnGenerateLaborer(PerformerTask task)
 {
     OnUnitGenerated(((GenerateUnit <Laborer>)task).GeneratedUnit);
 }