Ejemplo n.º 1
0
    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));
        }
    }
Ejemplo n.º 2
0
    public void RemoveByKey(SourceFood key)
    {
        DataSourceFood element = sourceFoods.Find(data => data.sourceFood == key);

        if (element != null)
        {
            sourceFoods.Remove(element);
        }
    }
Ejemplo n.º 3
0
 public DataSourceFood(DataSourceFood dataSourceFood) : base(expirationTime - (Time.time - dataSourceFood.RegistrationDate))
 {
     this.sourceFood = dataSourceFood.sourceFood;
 }
Ejemplo n.º 4
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;
        }
    }