Ejemplo n.º 1
0
 void OnStartUpgrade(PerformerTask p)
 {
     SetUpgradeInProgress(true);
     pbar = UI.Instance.CreateProgressBar(Position);
     pbar.SetColor(Color.green);
     StartCoroutine(CoUpdateUpgradeProgress(p));
 }
Ejemplo n.º 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);
    }
Ejemplo n.º 3
0
        IEnumerator CoUpdateUpgradeProgress(PerformerTask task)
        {
            upgrading = true;

            while (upgrading)
            {
                pbar.SetProgress(task.Progress);
                yield return(null);
            }
        }
Ejemplo n.º 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;
        }
    }
Ejemplo n.º 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();
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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 :)");
        }
    }
Ejemplo n.º 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);
    }
Ejemplo n.º 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);
     }
 }
Ejemplo n.º 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;
                }
            }
        }
Ejemplo n.º 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 :(");
        }
    }
Ejemplo n.º 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();
    }
Ejemplo n.º 13
0
 void OnGenerateElder(PerformerTask task)
 {
     OnUnitGenerated(((GenerateUnit <Elder>)task).GeneratedUnit);
 }
Ejemplo n.º 14
0
 public void SetVisual(PerformerTask task, UnitRenderer newVisual)
 {
     RemoveVisual();
     this.visual = newVisual;
     StartCoroutine(CoVisualFollowCursor(task));
 }
Ejemplo n.º 15
0
 void OnGenerateCorpse(PerformerTask task)
 {
     OnUnitGenerated(((GenerateUnit <Corpse>)task).GeneratedUnit);
 }
Ejemplo n.º 16
0
 void OnCompleteUpgrade(PerformerTask p)
 {
     SetUpgradeInProgress(false);
     UI.Instance.DestroyProgressBar(pbar);
     upgrading = false;
 }
Ejemplo n.º 17
0
 void OnStartPlant(PerformerTask task)
 {
     TaskPen.onRemove -= OnCancelPlant;
     seedProduction.RemoveSeed();
 }
Ejemplo n.º 18
0
 void OnGenerateLaborer(PerformerTask task)
 {
     OnUnitGenerated(((GenerateUnit <Laborer>)task).GeneratedUnit);
 }