/// <summary> /// This method selects the five new tasks for the day. /// </summary> public void newTasks(int confidence) { //Our value for determining the the number of tasks Ollie can handle. int upperRange = confidence >= 95 ? allTasks.Count : allTasks.Count - 1; daysTasks.Clear(); //We empty out on a new day. foreach (Taskable task in allTasks) { task.active = false; // Rather than disabling the entire component, simply flag it as not active. -Sergio } //numActive = 0; for (int i = 0; i < numTasks; i++) { //This code selects the days tasks. We pick a number between 0 and day's tasks. int random = new System.Random().Next(0, upperRange); //And the we use that number to pick a task. Taskable task = allTasks[random].GetComponent <Taskable>(); //We check to see if we already have the task. If so, we pick a random new one. while (daysTasks.Contains(task)) { random = new System.Random().Next(0, upperRange); task = allTasks[random].GetComponent <Taskable>(); } task.active = true; //// Rather than re-enabling the entire component (never disable the component), simply flag it as active. -Sergio //numActive++; // Increase count of active tasks daysTasks.Add(task); //We add it to our day tasks lists - This allows for tracking and adding the names to an onscreen displayed list. } }
/// <summary> /// This method removes a task from the activeList after a maze is completed. /// Triggers a new day if all tasks were completed. /// </summary> /// <param name="task">The Task we need to disable</param> public void RemoveTask(Taskable task) { task.active = false; //// Added by Sergio for Alpha; feel free to update with cleaner fix after Alpha // Note: Added this way to work with current implementation. I tried to minimize changes to the rest of the script. // Decrease count of active tasks daysTasks.Remove(task); // If there are no more active tasks, trigger a new day if (daysTasks.Count <= 0) { GameObject.Find("Ollie_Sprite").GetComponent <DayManager>().newDay(true); } }
void TestRemoveTaskFromTaskable() { Taskable taskable = new Taskable(); Task t = Task.Run(taskable) .Name("Taskable[log]") .Duration(1f) .Loop() .OnLoop(data => Debug.Log("Running Taskable")); taskable.RemoveTask(t); Task.Run(taskable) .Name("Taskable[remove]") .Duration(5f) .OnComplete(data => taskable.StopAllTasks()); }
private static void Animate(Taskable taskable, double factor, string id , string AnimationType, params object[] obj) { double a = 0; bool f = false; bool b = false; Device.StartTimer(TimeSpan.FromMilliseconds(10), () => { if (!f) { a++; } else { a--; } if (a >= 5) { f = true; } if (a <= -5) { f = false; } if (taskable is View) { View view = (View)taskable; if (AnimationType == "growth") { view.Scale += a / factor; } if (view.Scale == 1 && b) { taskable.OnRecieve(id); return(false); } } b = true; return(true); }); }
public static void AnimateColorTo(Taskable taskable, int delay, string id, Color toColor) { int c = 4; Device.StartTimer(TimeSpan.FromMilliseconds(delay), () => { if (taskable is VisualElement) { Color bkg = ((VisualElement)taskable).BackgroundColor; int[] rgb = { (int)(bkg.R * 255), (int)(bkg.G * 255), (int)(255 * bkg.B) }; int[] rgb1 = { (int)(toColor.R * 255), (int)(toColor.G * 255), (int)(255 * toColor.B) }; if (rgb[0] == rgb1[0] && rgb[1] == rgb1[1] && rgb[2] == rgb1[2]) { return(false); } rgb = Inc(rgb, rgb1, 0, c); ((VisualElement)taskable).BackgroundColor = Color.FromRgb(rgb[0], rgb[1], rgb[2]); } else { return(false); } return(true); }); }
void TestTaskable() { Taskable taskable = new Taskable(); Task.Run() .Name("Disposable[main]") .Duration(1f) .Loop() .AddTo(taskable) .OnLoop(data => { Debug.Log(10 - data.CurrentLoop); if (data.CurrentLoop == 10) { taskable.StopAllTasks(); } }); Task.Run().Name("Disposable[1]").Loop().AddTo(taskable); Task.Run().Name("Disposable[2]").Loop().AddTo(taskable); Task.Run().Name("Disposable[3]").Loop().AddTo(taskable); Task.Run().Name("Disposable[4]").Loop().AddTo(taskable); Task.Run().Name("Disposable[5]").Loop().AddTo(taskable); }
public static void AnimateGrowth(Taskable taskable, double factor, string id) { Animate(taskable, factor, id, "growth"); }