public void AddKnowledgeBox(IBotKnowledgeBox box, AITask recievingTask) { if (!_perTaskKnowledgeBases.ContainsKey(recievingTask)) { _perTaskKnowledgeBases[recievingTask] = new BotKnowledgeBase(); } _perTaskKnowledgeBases[recievingTask].AddKnowledgeBox(box); }
public void AddNewTask() { AITask newTask = ScriptableObject.CreateInstance <AITask>(); newTask.name = "new task"; newTask.Name = "new task"; m_tasks.Add(newTask); m_taskNames.Add("new task"); }
public T GetKnowledgeBox <T>(AITask recievingTask = null) where T : IBotKnowledgeBox { if (recievingTask == null) { return(_knowledgeBase.GetKnowledgeBox <T>()); } else { return(_knowledgeBase.GetKnowledgeBox <T>(recievingTask)); } }
public override void OnRunStarted(AITask aiTask) { if (!_snapshotsStack.Any()) { _snapshotsStack.Push(_rootSnapshot); } else { _snapshotsStack.Push(_snapshotsStack.Peek().Children.First(c => c.TaskWithStatus.Task == aiTask)); } }
public void AddKnowledgeBox(IBotKnowledgeBox box, AITask recievingTask = null) { if (recievingTask == null) { _knowledgeBase.AddKnowledgeBox(box); } else { _knowledgeBase.AddKnowledgeBox(box, recievingTask); } }
public void AssignTask(AITask task) { if (!ship) { Start(); } task.CheckRequiredConstraints(); task.Status = AITask.TaskStatus.NEW; task.TaskFollower = this; tasks.AddLast(task); }
protected override void InternalEarlyStart() { if (_rootChild == null) { _rootChild = InternalBuildStory(); Children = new List <AITask>() { _rootChild }; Listeners.ForEach(c => _rootChild.AddListener(c)); _rootChild.OwningBot = OwningBot; } }
public void RespondToPlayerSpawned() { if (_statsRef.Neutral) { CurrentTask = Random.Range(0, 101) < 50 ? AITask.Panic : AITask.Flee; _currentPath.Clear(); _endOfPathWaitTime = 0.0f; _currentNode = 0; } else { CurrentTask = AITask.AttackTarget; } }
public override void Start() { AITask patrolTask = null; if (m_tasks.TryGetValue("patrol_task", out patrolTask)) { if (patrolTask.Result == AITaskResult.Idle) { // Update the destination m_navTargetEntry.SetObject <Vector3>(GameObject.FindGameObjectWithTag("Player").transform.position); m_parentAI.PushTask(patrolTask); } } }
public int CompareTo(object that) { AITask otherTask = (AITask)that; if (Priority == otherTask.Priority) { return(0); } if (Priority > otherTask.Priority) { return(1); } return(-1); }
private AiRegistryTaskSnapshot CreateBaseTaskSnapshot(AITask task) { var snapshot = new AiRegistryTaskSnapshot() { TaskWithStatus = new AiRegistryTaskWithStatus() { Status = task.TaskStatus, Task = task } }; snapshot.Children = task.Children.Select(CreateBaseTaskSnapshot).ToList(); snapshot.ChildCalls = new List <AiRegistryChildCall>(); return(snapshot); }
public void LoadTasks() { #if AI_LOGGING Debug.Log("Loading <b>" + m_requiredTaskPaths.Count + "</b> tasks for behaviour <b>" + m_name + "</b>"); #endif foreach (var task in m_requiredTaskPaths) { AITask newTask = AITask.LoadTask(task); if (newTask != null) { newTask.Behaviour = this; m_tasks.Add(task, newTask); } else { Debug.LogError("Failed to load task: " + task); } } }
public override void OnSceneGUI() { AITask patrolTask = null; if (m_tasks.TryGetValue("patrol_task", out patrolTask)) { if (patrolTask.Result != AITaskResult.Idle) { GUI.enabled = false; } if (GUI.Button(new Rect(10, Screen.height / 2 - 20, 100, 40), "Run Patrol")) { // Update the destination m_navTargetEntry.SetObject <Vector3>(GameObject.FindGameObjectWithTag("Player").transform.position); m_parentAI.PushTask(patrolTask); } GUI.enabled = true; } }
public static AITask LoadTask(string taskName) { var asset = Resources.Load <TextAsset>("ai_tasks/" + taskName); AITask newTask = ScriptableObject.CreateInstance(typeof(AITask)) as AITask; TextAsset taskAsset = asset as TextAsset; if (taskAsset != null) { newTask.Deserialise(taskAsset.text); } else { Debug.LogError("Failed to load task: " + taskName); } newTask.Name = taskName; return(newTask); }
public void DoDeserialise() { #if AI_LOGGING Debug.Log("<color=green>(AI)Deserialising Tasks</color>"); #endif m_tasks.Clear(); var tasks = Resources.LoadAll("ai_tasks"); foreach (var task in tasks) { TextAsset asset = task as TextAsset; if (asset == null) { continue; } #if AI_LOGGING Debug.Log(asset.name); #endif AITask newTask = ScriptableObject.CreateInstance(typeof(AITask)) as AITask; bool succeeded = newTask.Deserialise(asset.text); if (succeeded) { m_tasks.Add(newTask); #if UNITY_EDITOR m_taskNames.Add(newTask.Name); #endif } else { Debug.LogError("Failed to load " + asset.name); } } }
public override void OnRunCompleted(AITask aiTask, AIOneRunStatus result) { _snapshotsStack.Pop(); if (_snapshotsStack.Any()) { var parent = _snapshotsStack.Peek(); parent.ChildCalls.Add(new AiRegistryChildCall() { CallStatus = result, TaskAfterCall = new AiRegistryTaskWithStatus() { Status = aiTask.TaskStatus, Task = aiTask } }); } else { _recorder.RecordSnapshot(new AiBehaviourTreeFrameSnapshot() { Owner = _owner, RootCall = new AiRegistryChildCall() { TaskAfterCall = new AiRegistryTaskWithStatus() { Task = aiTask, Status = aiTask.TaskStatus }, CallStatus = result }, RootChild = _rootSnapshot }); _snapshotsStack = null; _rootSnapshot = null; } }
public void PushTask(AITask task) { task.Result = AITaskResult.Pending; m_taskList.Add(task); }
protected AIStory() : base(new List <AITask>() {}) { _rootChild = null; }
public LoopUntilFailureTask(AITask child) : base(new List <AITask>() { child }) { _child = child; }
/// <summary> /// cancel a task and every task above it in the stack /// </summary> public void CancelTask(AITask cancelled) { Debug.Assert(!!cancelled, "cancelled task must exist"); Debug.Assert(tasks.Contains(cancelled), "can't cancel a task we don't have"); var last = tasks.Last; do { last.Value.Status = AITask.TaskStatus.FINISHED; last.Value.End(); Destroy(last.Value); tasks.RemoveLast(); } while ((last = tasks.Last) != null); }
public void Start() { AITask.Start(); }
public void AddChannel(int channelId, double ranglow, double rangeHigh) { AITask.AddChannel(channelId, ranglow, rangeHigh); }
public void Stop() { AITask.Stop(); AITask.Channels.Clear(); }
public void ReadData(ref double[,] buf, int samplesPerChannel, int timeOut) { AITask.ReadData(ref buf, samplesPerChannel, timeOut); }
public void ReadData(ref double[,] buf, int timeOut = -1) { AITask.ReadData(ref buf, timeOut); }
public void addTask(AITask task) { this.task.Add(task); }
public void SendSoftTrigger() { AITask.SendSoftTrigger(); }
private string GetTaskName(AITask task) { return(task.GetType().Name); }
public void RemoveKnowledgeBox <T>(AITask recievingTask) where T : IBotKnowledgeBox { Preconditions.Assert(_perTaskKnowledgeBases.ContainsKey(recievingTask), "There are no knowledge for task " + recievingTask); _perTaskKnowledgeBases[recievingTask].RemoveKnowledgeBox <T>(); }
public T GetKnowledgeBox <T>(AITask recievingTask) where T : IBotKnowledgeBox { Preconditions.Assert(_perTaskKnowledgeBases.ContainsKey(recievingTask), "There are no knowledge for task " + recievingTask); return(_perTaskKnowledgeBases[recievingTask].GetKnowledgeBox <T>()); }
public void DrawZoomArea() { AIManager manager = AIManager.s_instance; // Start zoomed drawing using the dimensions of the menu section as bounds. EditorZoomArea.Begin(manager.m_zoom, new Rect(0.0f, manager.m_buttonBarHeight, position.width, position.height)); // Mouse-down scrolling if (Event.current.type == EventType.mouseDown && Event.current.button == 2) { m_scrollStart = Event.current.mousePosition; } // These checks fire when I've bodged data during development if (manager.selectedTaskIndex == -1) { return; } if (manager.selectedTaskIndex >= manager.m_tasks.Count) { return; } AITask currentTask = manager.m_tasks[manager.selectedTaskIndex]; //return; // Draw the temporary line when the user is making links /* * if(manager.m_dragStart != null) * { * AIAction source = manager.m_dragStart; * * Vector2 start = new Vector2(source.m_editorPosition.x + source.m_windowWidth + stateHandleSize.x / 2.0f + m_scrollOffset.x, source.m_editorPosition.y + source.m_lastBounds.y + m_scrollOffset.y + stateHandleSize.y / 2.0f); * Vector2 end = Event.current.mousePosition; * * Drawing.bezierLine(start, start + (Vector2.right * lineCurveScale), end, end + (new Vector2(-1.0f, 0.0f) * lineCurveScale), Color.red, 1.0f, true, 20); * } */ // TODO: Loads of these loops can be removed with decent layering // TODO: Only redraw when moved or connections changed! // Draw connections foreach (var action in currentTask.Actions) { float delta = 1.0f / action.Outputs.Count; float currentVal = 0.0f; float expansion = 30.0f; for (int index = 0; index < action.Outputs.Count; index++) { AIAction linkedAction = action.GetOutput(index); if (linkedAction != null) { Vector2 start = new Vector2(action.m_editorPosition.x + action.Outputs[index].outputRect.x + action.Outputs[index].outputRect.width + 10, action.m_editorPosition.y + action.Outputs[index].outputRect.y + 10); Vector2 end = new Vector2(linkedAction.m_editorPosition.x - 5, linkedAction.m_editorPosition.y + linkedAction.m_lastBounds.height / 2.0f); start.x += m_scrollOffset.x; start.y += m_scrollOffset.y; end.x += m_scrollOffset.x; end.y += m_scrollOffset.y; if (action == linkedAction) { Vector2 right = start + (new Vector2(10.0f + (expansion * currentVal), 0.0f)); Vector2 rightTop = right; rightTop.y = action.m_editorPosition.y + m_scrollOffset.y - 50 - (expansion * currentVal); Vector2 leftTop = rightTop; leftTop.x = end.x - 10.0f - (expansion * currentVal); Vector2 left = leftTop; left.y = end.y; Drawing.DrawLine(start, right, Color.red, 1.0f, true); Drawing.DrawLine(right, rightTop, Color.red, 1.0f, true); Drawing.DrawLine(rightTop, leftTop, Color.red, 1.0f, true); Drawing.DrawLine(leftTop, left, Color.red, 1.0f, true); Drawing.DrawLine(left, end, Color.red, 1.0f, true); } else { Drawing.DrawBezierLine(start, start + (Vector2.right * lineCurveScale), end, end + (new Vector2(-1.0f, 0.0f) * lineCurveScale), Color.yellow, 1.0f, true, 20); } } currentVal += delta; } } // input button checks foreach (var action in currentTask.Actions) { if (GUI.Button(new Rect(action.m_editorPosition.x - 10 + m_scrollOffset.x, action.m_editorPosition.y + action.m_lastBounds.height / 2.0f + m_scrollOffset.y - 5, 10, 10), "x")) { if (manager.m_dragAction != null) { manager.m_dragAction.SetOutput(manager.m_dragAction.Outputs[manager.m_dragActionOutput].linkName, action); } } } //Debug.Log(currentTask.m_actiontest); // Clear drag events on left-mouse click if (Event.current.type == EventType.MouseDown && Event.current.button == 0) { manager.m_dragAction = null; } // Show behaviour link output buttons foreach (var action in currentTask.Actions) { int index = 0; foreach (var output in action.Outputs) { GUI.depth = -1; if (GUI.Button(new Rect(action.m_editorPosition.x + action.Outputs[index].outputRect.x + action.Outputs[index].outputRect.width + m_scrollOffset.x + 5, action.m_editorPosition.y + action.Outputs[index].outputRect.y + m_scrollOffset.y + 5, 10, 10), "x")) { action.SetOutput(output.linkName, null); manager.m_dragAction = action; manager.m_dragActionOutput = index; } index++; } } GUI.depth = 1; // Draw nodes BeginWindows(); for (int i = 0; i < currentTask.Actions.Count; i++) { Rect currentPos = currentTask.Actions[i].m_editorPosition; currentPos.x += m_scrollOffset.x; currentPos.y += m_scrollOffset.y; string name = currentTask.Actions[i].Name; Rect thing = GUILayout.Window(i, currentPos, DrawActionWindow, name); currentTask.Actions[i].m_editorPosition = thing; currentTask.Actions[i].m_editorPosition.x -= m_scrollOffset.x; currentTask.Actions[i].m_editorPosition.y -= m_scrollOffset.y; if (Event.current.type == EventType.repaint) { currentTask.Actions[i].m_windowWidth = thing.width; currentTask.Actions[i].m_lastBounds = thing; } } EndWindows(); // I have no idea why, but this nukes drag-scrolling if it's near the top of the function if (Event.current.type == EventType.mouseDrag) { if (Event.current.button == 2) { m_scrollOffset += (Event.current.mousePosition - m_scrollStart) / 2.0f; m_scrollStart = Event.current.mousePosition; } } if (Event.current.type == EventType.ScrollWheel) { manager.m_zoom -= ((float)Event.current.delta.y * 0.01f); manager.m_zoom = Mathf.Max(0.5f, manager.m_zoom); manager.m_zoom = Mathf.Min(1.0f, manager.m_zoom); } // This is pretty shonky, but keeps things smooth. // Disable if performance gets choppy and work out something better Repaint(); EditorZoomArea.End(); }
public virtual void OnRunCompleted(AITask aiTask, AIOneRunStatus result) { }