Пример #1
0
    protected override void OnUpdate()
    {
        Entities.WithNone <BEResourceSource>().ForEach((Entity entity, ref TriggerGather trigger) =>
        {
            PostUpdateCommands.AddBuffer <BEResourceSource>(entity);
        });

        //agrega elementos al buffer y si no hay elementos. Se quita
        Entities.WithAll <BEResourceSource>().ForEach((Entity entity, ref TriggerGather trigger) =>
        {
            var buffer = EntityManager.GetBuffer <BEResourceSource>(entity);
            buffer.Clear();
            //necesito conocer donde hay recursos.
            ResourceSourceAndEntity res;

            if (ResourceSourceManagerSystem.TryGetResourceAtHex(trigger.targetResourcePos, out res))
            {
                var type = res.resourceSource.resourceType;
                var allConectedResources = ResourceSourceManagerSystem.GetAllConectedResourcesOfType(trigger.targetResourcePos, type);
                foreach (var keyValue in allConectedResources)
                {
                    buffer.Add((BEResourceSource)keyValue.Value);
                }

                if (EntityManager.HasComponent <GroupOnGather>(entity))
                {
                    PostUpdateCommands.SetComponent <GroupOnGather>(entity, new GroupOnGather()
                    {
                        GatheringResourceType = type
                    });
                }
                else
                {
                    PostUpdateCommands.AddComponent <GroupOnGather>(entity, new GroupOnGather()
                    {
                        GatheringResourceType = type
                    });
                }
            }
            else
            {
                //NO HAY RECURSOS EN EL HEXAGONO.
                //detiene ejecucion de gather.
                //es decir no agrega el componente "GroupOnGather" que trigerrea el resto de componentes del systema de gather.
            }
        });



        //remove the component after use
        Entities.ForEach((Entity entity, ref TriggerGather trigger) =>
        {
            PostUpdateCommands.RemoveComponent <TriggerGather>(entity);
        });
    }
Пример #2
0
    protected override void OnUpdate()
    {
        //actualiza el buffer y ve si aun hay recursos disponibles. y luego elimina el componente que update buffer.

        /*
         * para lograrlo lo que hace es que actualiza todas las frames el buffer.
         */

        //ANTES INCLUIA EL COMPONENTE UpdateResourceBuffer EN EL WITH ALL
        Entities.WithAll <BEResourceSource>().ForEach((Entity entity, ref GroupOnGather onGather) =>
        {
            var buffer = EntityManager.GetBuffer <BEResourceSource>(entity);

            bool haveValidSource = false;
            Hex startinghex      = new Hex(0, 0);

            for (int i = 0; i < buffer.Length; i++)
            {
                var resSourceData = buffer[i];
                if (ResourceSourceManagerSystem.TryGetResourceAtHex(resSourceData.position, onGather.GatheringResourceType, out ResourceSourceAndEntity res))
                {
                    haveValidSource = true;
                    startinghex     = resSourceData.position;
                    break;
                }
            }

            buffer.Clear();

            if (haveValidSource)
            {
                var allConectedResources = ResourceSourceManagerSystem.GetAllConectedResourcesOfType(startinghex, onGather.GatheringResourceType);
                foreach (var keyValue in allConectedResources)
                {
                    buffer.Add((BEResourceSource)keyValue.Value);
                }
            }
            //else
            //{
            //    PostUpdateCommands.RemoveComponent<GroupOnGather>(entity);


            //}



            PostUpdateCommands.RemoveComponent <UpdateResourceBuffer>(entity);
        });
    }