예제 #1
0
    public void RemoveByKey(SourceFood key)
    {
        DataSourceFood element = sourceFoods.Find(data => data.sourceFood == key);

        if (element != null)
        {
            sourceFoods.Remove(element);
        }
    }
예제 #2
0
 public DataSourceFood(DataSourceFood dataSourceFood) : base(expirationTime - (Time.time - dataSourceFood.RegistrationDate))
 {
     this.sourceFood = dataSourceFood.sourceFood;
 }
예제 #3
0
 public DataSourceFood(SourceFood sourceFood) : base(expirationTime)
 {
     this.sourceFood = sourceFood;
 }
예제 #4
0
 private void AnalyseAndSaveFoodSource(SourceFood foodsource)
 {
     VisibleSourceFood.Add(foodsource);
     owner.Memory.FoodSources.Write(new DataSourceFood(foodsource));
 }
예제 #5
0
    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;
        }
    }