void PerceptionEvent(PerceptionEvent ev) { if (ev.type == global::PerceptionEvent.types.NEW) { BlackboardEntry entry = null; if (memory.TryGetValue("blackboard", out entry)) { entry.timestamp = Time.time; entry.is_inmemory = false; } else { entry = new BlackboardEntry(ev.go, ev.go.transform.position); memory.Add("blackboard", entry); entry.is_inmemory = false; } } else if (ev.type == global::PerceptionEvent.types.LOST) { BlackboardEntry entry = null; if (memory.TryGetValue("blackboard", out entry)) { entry.timestamp = Time.time; entry.is_inmemory = true; entry.position = ev.go.transform.position; } } }
// Update is called once per frame void Update() { // TODO 4: Add text output to the bottom-left panel with the information // of the elements in the Knowledge base //Output.text = "test"; BlackboardEntry entry = null; if (memory.TryGetValue("blackboard", out entry)) { if (entry.is_inmemory) { Cube.transform.position = entry.position; Output.text = "BLACKBOARD:"; Output.text += "\n\tTime: " + (Time.time - entry.timestamp).ToString(); Output.text += "\n\tPosition: " + entry.position.ToString(); } else { Cube.transform.position = player.transform.position; Output.text = "BLACKBOARD:"; Output.text += "\n\tPosition: " + player.transform.position.ToString(); } } else { Cube.transform.position = player.transform.position; } }
void PerceptionEvent(PerceptionEvent ev) { if (ev.type == global::PerceptionEvent.types.NEW) { // Something new if (blackboard.ContainsKey(ev.go.name)) { // Already in memory blackboard[ev.go.name].timestamp = 0.0f; blackboard[ev.go.name].position = ev.go.transform.position; blackboard[ev.go.name].inMemory = false; } else { // Something new BlackboardEntry entry = new BlackboardEntry(); entry.gameObject = ev.go; entry.position = ev.go.transform.position; entry.timestamp = 0.0f; entry.inMemory = false; entry.from = gameObject; blackboard.Add(entry.gameObject.name, entry); if (ev.sense == global::PerceptionEvent.senses.VISION) { foreach (AIMemory friend in friends) { if (!friend.blackboard.ContainsKey(ev.go.name)) { friend.blackboard.Add(entry.gameObject.name, entry); } } } } } else { // Lost something if (blackboard.ContainsKey(ev.go.name)) { // Already in memory blackboard[ev.go.name].position = ev.go.transform.position; blackboard[ev.go.name].inMemory = true; } } }
public bool Commit(BlackboardEntry vEntry) { throw new NotImplementedException(); }