Beispiel #1
0
    public override Entity Create(EntityManager entityManager, int predictingPlayerId)
    {
        entities.Clear();

        var entity = entityManager.CreateEntity();

        // We add CharBehaviour to BehaviourController so we have a common way to define character
        entityManager.AddComponentData(entity, new CharBehaviour());

        // Add uninitialized replicated entity
        var repData = new ReplicatedDataEntity
        {
            id                 = -1,
            typeId             = registryId,
            predictingPlayerId = predictingPlayerId,
        };

        entityManager.AddComponentData(entity, repData);

        var internalState = new InternalState
        {
            abilityMovement = abilityMovement.Create(entityManager, entities),
//            abilityPrimFire = abilityPrimFire.Create(entityManager, entities),
//            abilitySecFire = abilitySecFire.Create(entityManager, entities),
            abilitySprint = abilitySprint.Create(entityManager, entities),
            abilityMelee  = abilityMelee.Create(entityManager, entities),
            abilityEmote  = abilityEmote.Create(entityManager, entities),
            abilityDead   = abilityDead.Create(entityManager, entities),
        };

        entityManager.AddComponentData(entity, internalState);
        entityManager.AddComponentData(entity, new PredictedState());


        // Register replicated entity children so they all get serialized as data on this entity
        entityManager.AddBuffer <EntityGroupChildren>(entity);
        var buffer = entityManager.GetBuffer <EntityGroupChildren>(entity);

        GameDebug.Assert(entities.Count <= buffer.Capacity, "Buffer capacity is to small to fit all behaviors");
        for (int i = 0; i < entities.Count; i++)
        {
            var elm = new EntityGroupChildren
            {
                entity = entities[i]
            };
            buffer.Add(elm);
        }

        return(entity);
    }
Beispiel #2
0
    public override Entity Create(EntityManager entityManager, BundledResourceManager resourceManager,
                                  GameWorld world)
    {
        entities.Clear();

        var entity = entityManager.CreateEntity();

        var repData = new ReplicatedEntityData(guid);

        var internalState = new InternalState
        {
        };

        entityManager.AddComponentData(entity, repData);
        entityManager.AddComponentData(entity, internalState);


        // Create ability entities
        var abilityEntities = new List <Entity>(abilities.Length);

        for (int i = 0; i < abilities.Length; i++)
        {
            abilityEntities.Add(abilities[i].factory.Create(entityManager, entities));
        }

        // Add abilities to ability buffer
        entityManager.AddBuffer <AbilityEntry>(entity);
        var abilityBuffer = entityManager.GetBuffer <AbilityEntry>(entity);

        for (int i = 0; i < abilities.Length; i++)
        {
            uint canRunWith = 0;
            foreach (var ability in abilities[i].canRunWith)
            {
                var abilityIndex = GetAbilityIndex(ability);
                canRunWith |= 1U << abilityIndex;
            }

            uint canInterrupt = 0;
            if (abilities[i].canInterruptAll)
            {
                canInterrupt = ~0U;
            }
            else
            {
                foreach (var ability in abilities[i].canInterrupt)
                {
                    var abilityIndex = GetAbilityIndex(ability);
                    canInterrupt |= 1U << abilityIndex;
                }
            }

            abilityBuffer.Add(new AbilityEntry
            {
                ability      = abilityEntities[i],
                canRunWith   = canRunWith,
                canInterrupt = canInterrupt,
            });
        }



        // Register replicated entity children so they all get serialized as data on this entity
        entityManager.AddBuffer <EntityGroupChildren>(entity);
        var buffer = entityManager.GetBuffer <EntityGroupChildren>(entity);

        GameDebug.Assert(entities.Count <= buffer.Capacity, "Buffer capacity is to small to fit all behaviors");
        for (int i = 0; i < entities.Count; i++)
        {
            var elm = new EntityGroupChildren
            {
                entity = entities[i]
            };
            buffer.Add(elm);
        }

        return(entity);
    }