Beispiel #1
0
        protected override void OnUpdate()
        {
            //on
            Entities
            .WithAll <ActorLifetime, ActorAttribute3 <_HP>, Translation, Shield>().WithAllReadOnly <ActorCreator, OnCreateMessage>()
            .ForEach((Entity shieldEntity, ref ActorCreator shipCreator, ref ActorLifetime actorLifetime, ref ActorAttribute3 <_HP> _hp, ref Translation translation, ref Shield shield) =>
            {
                //
                var shipT        = EntityManager.GetComponentObject <Transform>(shipCreator.entity);
                var _ShieldLevel = EntityManager.GetComponentData <ActorAttribute1 <_ShieldLevel> >(shipCreator.entity);
                var shieldLevel  = (short)(_ShieldLevel.value - 1);
                if (shieldLevel < 0)
                {
                    Debug.LogError($"shieldLevel < 0  shipT={shipT}", shipT);
                    return;
                }

                var shieldRootT = shipT.GetChild(ShipSpawner.ShieldRoot_TransformIndex);
                EntityBehaviour._initComponent(shieldRootT, shieldEntity, EntityManager);
                EntityManager.AddComponentObject(shieldEntity, shieldRootT);
                EntityManager.AddComponentObject(shieldEntity, shieldRootT.GetComponent <Rigidbody>());


                var shieldT = shieldRootT.GetChild(shieldLevel);
                shieldT.gameObject.SetActive(true);



                //
                var shipShieldInfos = EntityManager.GetComponentData <ShipShields>(shipCreator.entity);
                var shieldInfo      = shipShieldInfos.get(shieldLevel);
                actorLifetime       = new ActorLifetime {
                    lifetime = shieldInfo.lifetime, value = shieldInfo.lifetime
                };
                _hp = new ActorAttribute3 <_HP> {
                    max = shieldInfo.hp, regain = 0f, value = shieldInfo.hp
                };

                translation = new Translation {
                    Value = shieldRootT.position
                };
                //rotation = new Rotation { Value = shieldRootT.rotation };

                shield = new Shield {
                    curLevel = shieldLevel
                };



                //
                var shipWeaponInstalledArray          = EntityManager.GetComponentData <ShipWeaponArray>(shipCreator.entity);
                shipWeaponInstalledArray.shieldEntity = shieldEntity;
                EntityManager.SetComponentData(shipCreator.entity, shipWeaponInstalledArray);
            });
        }
            public void Execute(Entity bulletEntity, int index,
                                [ReadOnly, ChangedFilter] DynamicBuffer <PhysicsRaycastResults> raycastResults,
                                [ReadOnly] ref ActorAttribute3Offset <_HP> hpOffset, [ReadOnly] ref ActorLifetime actorLifetime,
                                [ReadOnly] ref ActorOwner actorOwner, [ReadOnly] ref Actor actor)
            {
                if (raycastResults.Length <= 0)
                {
                    return;
                }

                var hp = hpOffset.GetValue(actorLifetime.percent);

                for (var i = 0; i < raycastResults.Length; ++i)
                {
                    var targetEntity = raycastResults[i].entity;

                    if (hpModifyFromEntity.Exists(targetEntity))
                    {
                        hpModifyFromEntity[targetEntity].Add(new ActorAttribute3Modifys <_HP>
                        {
                            player = actorOwner.playerEntity,
                            type   = actor.actorType,
                            value  = hp,
                            attribute3ModifyType = Attribute3SubModifyType.ValueOffset
                        });
                    }


                    //
                    var translation = new Translation {
                        Value = raycastResults[i].point
                    };
                    AttributeModifyFxSpawner.createInServer(endCommandBuffer, index, actor.actorType, translation, hp, 0f, default);
                }


                endCommandBuffer.AddComponent(index, bulletEntity, new OnDestroyMessage {
                });
            }