public static Entity CreateCharacter(EntityManager entityManager, float3 position)
        {
            var e = entityManager.Instantiate(entityPrefab);

            var rotation = Quaternion.identity;

            CreateCharacterUtilities.CreateCharacterComponent(entityManager, e, position, rotation);


            var characterPresentation = Object.Instantiate(presentationPrefab);

            characterPresentation.SetActive(false);


            //   var chooseEffect= Object.Instantiate(chooseEffectPrefab);
            //   chooseEffect.SetActive(false);


            entityManager.AddComponentData(e, new  CharacterPresentation()
            {
                CharacterObject = characterPresentation,
                ChooseEffect    = null
            });

            return(e);
        }
Ejemplo n.º 2
0
        protected override void OnUpdate()
        {
            var entity = GetSingletonEntity <SpawnPlayerServer>();
            var buffer = EntityManager.GetBuffer <SpawnPlayerBuffer>(entity);

            if (buffer.Length == 0)
            {
                return;
            }

            var spawnPlayers = buffer.ToNativeArray(Allocator.Temp);

            buffer.Clear();

            foreach (var spawnPlayer in spawnPlayers)
            {
                //创建Player
                var e = EntityManager.Instantiate(playerPrefab);

                var position = GetSpawnPoint();
                var rotation = Quaternion.identity;

                CreateCharacterUtilities.CreateCharacterComponent(EntityManager, e, position, rotation);

                EntityManager.AddBuffer <UserCommandBuffer>(e);

                if (spawnPlayer.IsRobot)
                {
                    EntityManager.AddComponentData(e, new Robot());
                }
                else
                {
                    EntityManager.AddComponentData(e, new Connection
                    {
                        SessionId = spawnPlayer.PlayerId
                    });
                }


                var id = networkServerSystem.RegisterEntity(-1, (ushort)EntityType.Character, spawnPlayer.PlayerId, e);

                //var interpolatedState = EntityManager.GetComponentData<CharacterInterpolatedState>(e);
                //interpolatedState.MaterialId =  (byte) (spawnPlayer.PlayerId % 4);
                //EntityManager.SetComponentData(e, interpolatedState);

                EntityManager.SetComponentData(e, new ReplicatedEntityData
                {
                    Id = id,
                    PredictingPlayerId = spawnPlayer.PlayerId
                });
            }


            spawnPlayers.Dispose();
        }