Пример #1
0
 private void PickNewTarget(GameObject obj, FollowTarget follow)
 {
     //only pick new target once or if the new target want to do a Vendetta
     //it will chase it down until he is dead
     if (follow.Target == null || follow.Target.GetECSComponent <Vendetta>().WantToDoVendetta)
     {
         float dist = float.MaxValue;
         new EntityQuery()
         .With <Score>()
         .With <Vendetta>()
         .ForEach(objToFollow =>
         {
             //only pick green pecsman
             Vendetta vendetta = objToFollow.GetECSComponent <Vendetta>();
             if (!vendetta.WantToDoVendetta)
             {
                 if (Vector3.Distance(obj.transform.position, objToFollow.transform.position) < dist)
                 {
                     follow.Target = objToFollow;
                     dist          = Vector3.Distance(obj.transform.position, objToFollow.transform.position);
                 }
             }
         });
         EntityActionBuffer.Instance.ApplyComponentChanges(obj, follow);
     }
 }
Пример #2
0
        private void Create()
        {
            for (int i = 0; i < _number; i++)
            {
                //entity
                GameObject tmp = EntityActionBuffer.Instance.CreateEntity(_prefab);
                tmp.transform.position = GameMananger.RandomNavmeshLocation(40f, tmp);

                //component
                TargetEdible  miam          = new TargetEdible();
                Score         score         = new Score(i, 0, false);
                Vendetta      vendetta      = new Vendetta(false, null);
                TrailRenderer trailRenderer = new TrailRenderer(tmp);
                MeshRenderer  meshRenderer  = new MeshRenderer(tmp);
                NavMeshAgent  navMeshAgent  = new NavMeshAgent(tmp);

                //merging both
                EntityActionBuffer.Instance.AddComponent(tmp, miam);
                EntityActionBuffer.Instance.AddComponent(tmp, score);
                EntityActionBuffer.Instance.AddComponent(tmp, vendetta);
                EntityActionBuffer.Instance.AddComponent(tmp, trailRenderer);
                EntityActionBuffer.Instance.AddComponent(tmp, meshRenderer);
                EntityActionBuffer.Instance.AddComponent(tmp, navMeshAgent);
            }
        }
Пример #3
0
        public override void Update()
        {
            new EntityQuery()
            .With <TargetEdible>()
            .With <Score>()
            .With <Vendetta>()
            .ForEach(obj =>
            {
                Vendetta vendetta = obj.GetECSComponent <Vendetta>();

                //pecsman death
                Death(obj);

                //normal behavior is not in vendetta state
                if (!vendetta.WantToDoVendetta)
                {
                    TargetEdible food = obj.GetECSComponent <TargetEdible>();

                    PickClosestFood(obj, food);

                    EatFood(obj, food);

                    if (food.Target != null)
                    {
                        obj.GetECSComponent <NavMeshAgent>().UnityComponent.SetDestination(food.Target.transform.position);
                    }
                }
                else
                {
                    //in vendetta state so now just want to kill is killer nothing else
                    if (!vendetta.Target.GetECSComponent <FollowTarget>().HasBeenCalmDown)
                    {
                        obj.GetECSComponent <NavMeshAgent>().UnityComponent.SetDestination(vendetta.Target.transform.position);

                        if (Vector3.Distance(obj.transform.position, vendetta.Target.transform.position) <= 1.2f)
                        {
                            FollowTarget traget    = vendetta.Target.GetECSComponent <FollowTarget>();
                            traget.HasBeenCalmDown = true;
                            EntityActionBuffer.Instance.ApplyComponentChanges(vendetta.Target, traget);
                        }
                    }
                    else
                    {
                        vendetta.WantToDoVendetta = false;
                        obj.GetECSComponent <MeshRenderer>().UnityComponent.material.color  = Color.green;
                        obj.GetECSComponent <TrailRenderer>().UnityComponent.material.color = Color.green;
                        obj.GetECSComponent <NavMeshAgent>().UnityComponent.speed           = 4.5f;
                        EntityActionBuffer.Instance.ApplyComponentChanges(obj, vendetta);
                    }
                }
            });
        }
Пример #4
0
        private void KillTarget(GameObject obj, FollowTarget follow)
        {
            if (follow.Target != null && Vector3.Distance(obj.transform.position, follow.Target.transform.position) <= 1.0f)
            {
                EntityActionBuffer.Instance.ApplyComponentChanges(obj, follow);

                Score score = follow.Target.GetECSComponent <Score>();
                score.IsDead = true;
                EntityActionBuffer.Instance.ApplyComponentChanges(follow.Target, score);

                //we set the target of the dead pecsman to the killer
                Vendetta vendetta = follow.Target.GetECSComponent <Vendetta>();
                vendetta.WantToDoVendetta = true;
                vendetta.Target           = obj;

                follow.Target.GetECSComponent <MeshRenderer>().UnityComponent.material.color  = Color.magenta;
                follow.Target.GetECSComponent <TrailRenderer>().UnityComponent.material.color = Color.magenta;
                follow.Target.GetECSComponent <NavMeshAgent>().UnityComponent.speed           = 10.0f;

                EntityActionBuffer.Instance.ApplyComponentChanges(follow.Target, vendetta);
            }
        }