void OnStartUpgrade(PerformerTask p) { SetUpgradeInProgress(true); pbar = UI.Instance.CreateProgressBar(Position); pbar.SetColor(Color.green); StartCoroutine(CoUpdateUpgradeProgress(p)); }
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); }
IEnumerator CoUpdateUpgradeProgress(PerformerTask task) { upgrading = true; while (upgrading) { pbar.SetProgress(task.Progress); yield return(null); } }
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; } }
void OnGenerateUnit(PerformerTask task) { Unit unit = ((GenerateUnit)task).GeneratedUnit; StaticUnit staticUnit = unit as StaticUnit; staticUnit.Position = Position; if (Selected) { SelectionManager.Select(staticUnit.UnitClickable); } DestroyThis(); }
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); }
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 :)"); } }
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); }
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); } }
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; } } }
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 :("); } }
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(); }
void OnGenerateElder(PerformerTask task) { OnUnitGenerated(((GenerateUnit <Elder>)task).GeneratedUnit); }
public void SetVisual(PerformerTask task, UnitRenderer newVisual) { RemoveVisual(); this.visual = newVisual; StartCoroutine(CoVisualFollowCursor(task)); }
void OnGenerateCorpse(PerformerTask task) { OnUnitGenerated(((GenerateUnit <Corpse>)task).GeneratedUnit); }
void OnCompleteUpgrade(PerformerTask p) { SetUpgradeInProgress(false); UI.Instance.DestroyProgressBar(pbar); upgrading = false; }
void OnStartPlant(PerformerTask task) { TaskPen.onRemove -= OnCancelPlant; seedProduction.RemoveSeed(); }
void OnGenerateLaborer(PerformerTask task) { OnUnitGenerated(((GenerateUnit <Laborer>)task).GeneratedUnit); }