예제 #1
0
        public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
        {
            var speed = new BallMoveSpeed {
                Value = moveSpeed
            };

            dstManager.AddComponentData(entity, speed);
        }
예제 #2
0
        /// <summary>
        /// Spawn a certain number of Entities;产生count个实体
        /// </summary>
        /// <param name="count">count to spawn</param>
        void spawnEntities(int count)
        {
            Entity  entity;
            Vector2 circle;
            Entity  enPrefab = GameObjectConversionUtility.ConvertGameObjectHierarchy(prefab, World.Active);

            #region Record the count of spawned Entities 记录现有实体数量
            if (ballCount >= maxCount)
            {
                entityManager.DestroyEntity(enPrefab);
                return;
            }
            else if (ballCount + count > maxCount)
            {
                count     = maxCount - ballCount;
                ballCount = maxCount;
            }
            else
            {
                ballCount += count;
            }

            info.text = "Entities:" + ballCount.ToString();
            #endregion

            for (int i = 0; i < count; i++)
            {
                entity = entityManager.Instantiate(enPrefab);

                circle = UnityEngine.Random.insideUnitCircle * Range;

                Translation pos = new Translation()
                {
                    Value = new float3(circle.x, 0, circle.y)
                };

                BallMoveSpeed speed = new BallMoveSpeed()
                {
                    Value = UnityEngine.Random.Range(1, maxSpeed)
                };
                entityManager.SetComponentData(entity, pos);
                entityManager.SetComponentData(entity, speed);
            }

            entityManager.DestroyEntity(enPrefab);
        }