public GoapObject QueryClosestObjectWithID(GoapID _queryObjectsID, int _tag, Vector2 _agentPosition, out float _sqrDistanceToTarget) { _sqrDistanceToTarget = float.MaxValue; if (!goapObjects.ContainsKey(_queryObjectsID.value)) { return(null); } List <GoapObject> objects = goapObjects[_queryObjectsID.value]; GoapObject targetObject = null; for (int i = 0; i < objects.Count; i++) { if (!objects[i].CanBeUsed() || objects[i].GetTagHash() != _tag) { continue; } float sqrDist = Vector2.SqrMagnitude(objects[i].GetPositionXZ() - _agentPosition); if (sqrDist < _sqrDistanceToTarget) { _sqrDistanceToTarget = sqrDist; targetObject = objects[i]; } } return(targetObject); }
public void RemoveObject(GoapObject _object) { if (!goapObjects.ContainsKey(_object.GetObjectLayer().value)) { return; } goapObjects[_object.GetObjectLayer().value].Remove(_object); }
public void AddObject(GoapObject _object) { if (!goapObjects.ContainsKey(_object.GetObjectLayer().value)) { goapObjects[_object.GetObjectLayer().value] = new List <GoapObject>(); } goapObjects[_object.GetObjectLayer().value].Add(_object); }
public override void InitPlanning(GoapPlanner.PlanningData _planningData) { base.InitPlanning(_planningData); objectTarget = GoapWorldManager.GetInstance().QueryClosestObjectWithID(queryObjectsID, objectTag, _planningData.agentPositonXZ, out sqrDistanceToTarget); objectTag = queryObjectTag.GetHashCode(); }