public override void Write(Data data) { if (!(data is DataSourceFood)) { return; } DataSourceFood dataSourceFood = data as DataSourceFood; bool exist = false; int index = 0; foreach (DataSourceFood d in sourceFoods) { if (d.sourceFood == dataSourceFood.sourceFood) { exist = true; break; } ++index; } if (exist) { if (dataSourceFood.RegistrationDate >= sourceFoods[index].RegistrationDate) { Replace(new DataSourceFood(dataSourceFood), index); } } else { sourceFoods.Add(new DataSourceFood(dataSourceFood)); } }
public void RemoveByKey(SourceFood key) { DataSourceFood element = sourceFoods.Find(data => data.sourceFood == key); if (element != null) { sourceFoods.Remove(element); } }
public DataSourceFood(DataSourceFood dataSourceFood) : base(expirationTime - (Time.time - dataSourceFood.RegistrationDate)) { this.sourceFood = dataSourceFood.sourceFood; }
public override void Process() { IReadOnlyCollection <DataSourceFood> sources = owner.Memory.FoodSources.Read(); DataSourceFood sourceFoodData = null; float distanceToSourceFood = Mathf.Infinity; foreach (DataSourceFood data in sources) { if (!data.sourceFood) { continue; } SourceFood source = data.sourceFood; if (visited.Contains(source)) { continue; } if (!source.gameObject.activeSelf) { continue; } //ne pas prendre en compte les source food imédiatement vue. //if(Time.time - data.RegistrationDate > 1f) continue; if (!filter(source.FoodType)) { continue; } float distanceToSource = Vector3.Distance(owner.transform.position, source.transform.position); if (distanceToSource < distanceToSourceFood) { sourceFoodData = data; distanceToSourceFood = distanceToSource; } } /*if(sourceFoodData != null){ * if(!owner.Steering.IsArrivedToDestination){ * owner.Steering.SetDestination(sourceFoodData.sourceFood.transform.position); * owner.Steering.Behavior = eSteeringBehavior.Seek; * }else{ * if(owner.Steering.Behavior == eSteeringBehavior.Wander) return; * * owner.Steering.Behavior = eSteeringBehavior.Wander; * } * }else{ * status = GoalStatus.Failed; * }*/ if (sourceFoodData != null) { if (target != sourceFoodData.sourceFood) { target = sourceFoodData.sourceFood; owner.Steering.SetDestination(target.transform.position); owner.Steering.Behavior = eSteeringBehavior.Seek; } else if (owner.Steering.IsArrivedToDestination) { visited.Add(target); target = null; } else if (target == null) { status = GoalStatus.Failed; } } else { status = GoalStatus.Failed; } }