Beispiel #1
0
    protected override void OnUpdate()
    {
        if (!Input.GetKeyDown(KeyCode.Space))
        {
            return;
        }

        var ecb       = m_SelectEcbSystem.CreateCommandBuffer().AsParallelWriter();
        var formGroup = new FormationGroup()
        {
            LeaderId = -1
        };

        Entities
        //.WithoutBurst()
        .WithAll <FormationGroup>()
        .ForEach((Entity entity, int entityInQueryIndex, in Translation translation /*, in RenderBounds bounds*/) =>
        {
            ecb.AddComponent <SelectedComponent>(entityInQueryIndex, entity);
            ////ecb.RemoveComponent<FormationIndex>(entityInQueryIndex, entity);
            //if (selectionBounds.Contains(translation.Value))
            //{
            //    //ecb.SetSharedComponent(entityInQueryIndex, entity, formGroup);

            //    //m_CenterPosition += translation.Value;
            //}
        }).ScheduleParallel();

        m_SelectEcbSystem.AddJobHandleForProducer(this.Dependency);
    }
Beispiel #2
0
    // Start is called before the first frame update
    void Start()
    {
        var formationPositions = new NativeArray <float3>(numUnits, Allocator.Temp);

        Type _formationType;

        switch (formationType)
        {
        case FORMATIONS.Testudo:
            _formationType = typeof(TestudoFormationTag);
            GetTestudoPositions(formationPositions);
            break;

        case FORMATIONS.Orb:
            _formationType = typeof(OrbFormationTag);
            break;

        case FORMATIONS.Wedge:
            _formationType = typeof(WedgeFormationTag);
            break;

        default:
            return;
        }

        World         world         = World.DefaultGameObjectInjectionWorld;
        EntityManager entityManager = world.EntityManager;

        blobAsset = new BlobAssetStore();

        _selectedIndicatorsQuery = entityManager.CreateEntityQuery(
            ComponentType.Exclude(typeof(FormationGroup)),
            ComponentType.ReadOnly(typeof(SelectedIndicatorTag))
            );

        var conversionSetting = new GameObjectConversionSettings(world, GameObjectConversionUtility.ConversionFlags.AssignName, blobAsset);

        Entity unitEntity          = GameObjectConversionUtility.ConvertGameObjectHierarchy(unitPrefab, conversionSetting);
        Entity dragIndicatorEntity = GameObjectConversionUtility.ConvertGameObjectHierarchy(dragIndicatorPrefab, conversionSetting);

        NativeArray <Entity> unitsToSpawn          = new NativeArray <Entity>(numUnits, Allocator.Temp, NativeArrayOptions.UninitializedMemory);
        NativeArray <Entity> dragIndicatorsToSpawn = new NativeArray <Entity>(numUnits, Allocator.Temp, NativeArrayOptions.UninitializedMemory);

        entityManager.Instantiate(unitEntity, unitsToSpawn);
        entityManager.Instantiate(dragIndicatorEntity, dragIndicatorsToSpawn);

        entityManager.DestroyEntity(unitEntity);
        entityManager.DestroyEntity(dragIndicatorEntity);

        var formationGroup = new FormationGroup {
            ID = TEMP_FORMATION_ID
        };                                                                  // TEMP
        var selectedFormationGroup = new SelectedFormationSharedComponent {
            IsSelected = false
        };

        // Initialize blob asset (aabb) because all the units share them
        BlobAssetReference <AABBBlobAsset> blobAssetReference;

        using (BlobBuilder blobBuilder = new BlobBuilder(Allocator.Temp))
        {
            ref AABBBlobAsset aabbBlobAsset = ref blobBuilder.ConstructRoot <AABBBlobAsset>();
            blobBuilder.Allocate(ref aabbBlobAsset.Ptr) = UnitData.aabb;

            blobAssetReference = blobBuilder.CreateBlobAssetReference <AABBBlobAsset>(Allocator.Persistent);
        }
        /// <summary>
        /// Keeps track of agents in dictionaries and decides if they get banners
        /// </summary>
        /// <param name="agent"></param>
        /// <returns>true if the agent should receive a banner</returns>
        public bool AgentGetsBanner(IBMBAgent agent)
        {
            string              agentParty     = agent.PartyName;
            IBMBCharacter       agentCharacter = agent.Character;
            TroopSpecialization agentSpec      = agent.Character.Type;
            FormationGroup      agentFormation = agent.Formation;

            /* Caravan masters bypass count if they lead caravans */
            if (_settings.AllowCaravanGuards == CaravanAssignMode.OnlyMasters && agent.IsInCaravanParty)
            {
                if (agent.IsCaravanPartyLeader)
                {
                    CountBannerGivenToParty(agentParty);
                    return(true);
                }
                return(false);//Other caravan guards in the caravan party don't get banner
            }

            /* Add to maps */
            if (!_processedByTroop.ContainsKey(agentParty))
            {
                _processedByTroop.Add(agentParty, new Dictionary <IBMBCharacter, List <IBMBAgent> >());
            }
            if (!_processedByTroop[agentParty].ContainsKey(agentCharacter))
            {
                _processedByTroop[agentParty].Add(agentCharacter, new List <IBMBAgent>());
            }

            if (!_processedByFormation.ContainsKey(agentParty))
            {
                _processedByFormation.Add(agentParty, new Dictionary <FormationGroup, List <IBMBAgent> >());
            }
            if (!_processedByFormation[agentParty].ContainsKey(agentFormation))
            {
                _processedByFormation[agentParty].Add(agentFormation, new List <IBMBAgent>());
            }

            if (!_processedBySpec.ContainsKey(agentParty))
            {
                _processedBySpec.Add(agentParty, new Dictionary <TroopSpecialization, List <IBMBAgent> >());
            }
            if (!_processedBySpec[agentParty].ContainsKey(agentSpec))
            {
                _processedBySpec[agentParty].Add(agentSpec, new List <IBMBAgent>());
            }

            _processedBySpec[agentParty][agentSpec].Add(agent);
            _processedByFormation[agentParty][agentFormation].Add(agent);
            _processedByTroop[agentParty][agentCharacter].Add(agent);

            /* Give banner or skip */
            //int processedTroops = _settings.UnitCountMode == UnitCountMode.Type ? _processedByType[agentParty][agentSpec].Count : _processedByTroop[agentParty][agentCharacter].Count;
            int processedTroops = GetProcessedTroopsByMode(agentParty, agentSpec, agentFormation, agentCharacter);

            if (agentCharacter.IsHero || processedTroops % _settings.BearerToTroopRatio == 0)
            {
                CountBannerGivenToParty(agentParty);
                return(true);
            }
            return(false);
        }
        private int GetProcessedTroopsByMode(string agentParty, TroopSpecialization agentSpec, FormationGroup agentFormation, IBMBCharacter agentCharacter)
        {
            switch (_settings.UnitCountMode)
            {
            case UnitCountMode.Spec:
            default:
                return(_processedBySpec[agentParty][agentSpec].Count);

            case UnitCountMode.Formation:
                return(_processedByFormation[agentParty][agentFormation].Count);

            case UnitCountMode.Troop:
                return(_processedByTroop[agentParty][agentCharacter].Count);
            }
        }