void Spawn()
    {
        // Create entity prefab from the game object hierarchy once
        var settings      = GameObjectConversionSettings.FromWorld(World.DefaultGameObjectInjectionWorld, new BlobAssetStore());
        var prefab        = GameObjectConversionUtility.ConvertGameObjectHierarchy(Prefab, settings);
        var entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;

        // Efficiently instantiate a bunch of entities from the already converted entity prefab
        var instance = entityManager.Instantiate(prefab);

        // Place the instantiated entity in a grid with some noise
        var position = transform.TransformPoint(new float3(0, 12, 0));

        entityManager.SetComponentData(instance, new Translation {
            Value = position
        });
    }
Beispiel #2
0
    // Start is called before the first frame update
    void Start()
    {
        store         = new BlobAssetStore();
        entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
        var settings = GameObjectConversionSettings.FromWorld(World.DefaultGameObjectInjectionWorld, store);

        Entity virus    = GameObjectConversionUtility.ConvertGameObjectHierarchy(virusPrefab, settings);
        Entity redBlood = GameObjectConversionUtility.ConvertGameObjectHierarchy(redCellsPrefab, settings);

        bullet    = GameObjectConversionUtility.ConvertGameObjectHierarchy(bulletPrefab, settings);
        whiteCell = GameObjectConversionUtility.ConvertGameObjectHierarchy(whiteCellsPrefab, settings);

        // instantiate the viruses
        for (int i = 0; i < virusCount; i++)
        {
            Entity instance = entityManager.Instantiate(virus);
            float  x        = UnityEngine.Random.Range(minPositionValue, maxPositionValue);
            float  y        = UnityEngine.Random.Range(minPositionValue, maxPositionValue);
            float  z        = UnityEngine.Random.Range(minPositionValue, maxPositionValue);

            float3 position = new float3(x, y, z);
            entityManager.SetComponentData(instance, new Translation {
                Value = position
            });
            entityManager.SetComponentData(instance, new FloatData {
                speed = UnityEngine.Random.Range(0.1f, 1.0f)
            });
        }

        // instantiante the blood cells
        for (int i = 0; i < redCellsCount; i++)
        {
            Entity instance = entityManager.Instantiate(redBlood);
            float  x        = UnityEngine.Random.Range(minPositionValue, maxPositionValue);
            float  y        = UnityEngine.Random.Range(minPositionValue, maxPositionValue);
            float  z        = UnityEngine.Random.Range(minPositionValue, maxPositionValue);

            float3 position = new float3(x, y, z);
            entityManager.SetComponentData(instance, new Translation {
                Value = position
            });
            entityManager.SetComponentData(instance, new FloatData {
                speed = UnityEngine.Random.Range(0.1f, 1.0f)
            });
        }
    }
Beispiel #3
0
    public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
    {
        dstManager.AddComponentData(entity, new CartoonBody
        {
            BreathingSquashYAmplitude  = BreathingSquashYAmplitude,
            BreathingSquashYRate       = BreathingSquashYRate,
            BreathingSquashXZAmplitude = BreathingSquashXZAmplitude,
            BreathingSquashXZRate      = BreathingSquashXZRate,
            PositionOffset             = PositionOffset
        });
        dstManager.AddComponentData(entity, new NonUniformScale {
            Value = new float3(1, 1, 1)
        });

/*
 * //eye stuff
 *      LeftEyeEntity = conversionSystem.GetPrimaryEntity(LeftEyeSocket);
 *      RightEyeEntity = conversionSystem.GetPrimaryEntity(RightEyeSocket);
 *      EyePrefabEntity = GameObjectConversionUtility.ConvertGameObjectHierarchy(EyePrefab, World.Active);
 *
 *      var leftEye = dstManager.Instantiate(EyePrefabEntity);
 *      dstManager.AddComponentData(leftEye, new CartoonEye(LeftEyeEntity));
 *      var rightEye = dstManager.Instantiate(EyePrefabEntity);
 *      dstManager.AddComponentData(rightEye, new CartoonEye(RightEyeEntity));
 #if UNITY_EDITOR
 *      dstManager.SetName(LeftEyeEntity, "eyeSocket_L" + LeftEyeEntity);
 *      dstManager.SetName(RightEyeEntity, "eyeSocket_R" + RightEyeEntity);
 *      dstManager.SetName(leftEye, "eye_L" + leftEye);
 *      dstManager.SetName(rightEye, "eye_R" + rightEye);
 #endif
 */
        // dust stuff
        DustTrailEntity = GameObjectConversionUtility.ConvertGameObjectHierarchy(DustTrailPrefab, World.Active);
        dstManager.AddComponentData(entity, new DustTrail
        {
            DustPrefabEntity = DustTrailEntity,
            Rate             = 0.25f,
            MinAmount        = 1,
            MaxAmount        = 5,
            m_CurrentTime    = 0
        });
        //dstManager.AddComponentData(entity, new Scale());
        //dstManager.AddComponentData(entity, new ScalePivot {Value = new float3()});
        //dstManager.AddComponentData(entity, new ScalePivotTranslation());
        //dstManager.AddComponentData(entity, new CompositeScale());
    }
    // Start is called before the first frame update
    void Start()
    {
        manager = World.DefaultGameObjectInjectionWorld.EntityManager;
        var settings = GameObjectConversionSettings.FromWorld(World.DefaultGameObjectInjectionWorld, null);
        var prefab   = GameObjectConversionUtility.ConvertGameObjectHierarchy(tankPrefab, settings);

        for (int i = 0; i < numTanks; i++)
        {
            var   instance = manager.Instantiate(prefab);
            float x        = UnityEngine.Random.Range(-100, 100);
            float z        = UnityEngine.Random.Range(-100, 100);
            var   position = transform.TransformPoint(new float3(x, 0, z));
            manager.SetComponentData(instance, new Translation {
                Value = position
            });
        }
    }
Beispiel #5
0
        protected void VerifyNoDataProduced <T>() where T : struct, IComponentData
        {
            var world = new World("Test world");

            try
            {
                GameObjectConversionUtility.ConvertGameObjectHierarchy(Root, world);

                using (var group = world.EntityManager.CreateEntityQuery(typeof(T)))
                    using (var bodies = group.ToComponentDataArray <T>(Allocator.Persistent))
                        Assert.That(bodies.Length, Is.EqualTo(0), $"Conversion pipeline produced {typeof(T).Name}");
            }
            finally
            {
                world.Dispose();
            }
        }
Beispiel #6
0
    private void Start()
    {
        // Initialize manager using world default.
        var manager  = World.DefaultGameObjectInjectionWorld.EntityManager;
        var settings = GameObjectConversionSettings.FromWorld(World.DefaultGameObjectInjectionWorld, null);

        // Convert prefabs into entity.
        var playerEntity  = GameObjectConversionUtility.ConvertGameObjectHierarchy(playerPrefab, settings);
        var missileEntity = GameObjectConversionUtility.ConvertGameObjectHierarchy(missilePrefab, settings);
        var shieldEntity  = GameObjectConversionUtility.ConvertGameObjectHierarchy(shieldPrefab, settings);

        // Instantiate
        InstantiatePlayer(manager, playerEntity, missileEntity);
        InstantiateShield(manager, shieldEntity);

        Destroy(gameObject);
    }
Beispiel #7
0
        private void Awake()
        {
            if (Main != null && Main != this)
            {
                Destroy(gameObject);
                return;
            }

            Main = this;

            _manager = World.DefaultGameObjectInjectionWorld.EntityManager;
            var settings = GameObjectConversionSettings.FromWorld(World.DefaultGameObjectInjectionWorld, new BlobAssetStore());

            _ballEntityPrefab = GameObjectConversionUtility.ConvertGameObjectHierarchy(ballPrefab, settings);

            SpawnBall();
        }
    void Start()
    {
        entityManager  = World.DefaultGameObjectInjectionWorld.EntityManager;
        blobAssetStore = new BlobAssetStore();

        Debug.Log(tilePreFab);
        var settings = GameObjectConversionSettings.FromWorld(World.DefaultGameObjectInjectionWorld,
                                                              blobAssetStore);

        tileEntityPrefab = GameObjectConversionUtility.ConvertGameObjectHierarchy(tilePreFab, settings);

        buildFloor();
        buildEastWestWall(-50f, 50f);
        buildSouthNorthWall(-50f, 50f);
        buildEastWestWall(-50f, -50f);
        buildSouthNorthWall(-50f, -50f);
    }
Beispiel #9
0
        private void Awake()
        {
            _assetStore = new BlobAssetStore();
            _manager    = World.DefaultGameObjectInjectionWorld.EntityManager;
            var settings =
                GameObjectConversionSettings.FromWorld(World.DefaultGameObjectInjectionWorld, new BlobAssetStore());

            _creatureEntityPrefab = GameObjectConversionUtility.ConvertGameObjectHierarchy(CreaturePrefab, settings);

            var t     = Plane.transform;
            var pos   = t.position;
            var scale = t.localScale;

            _bounds = new Rect(pos.x - scale.x / 2, pos.y - scale.y / 2, scale.x, scale.y);

            SpawnCreatures();
        }
Beispiel #10
0
    protected override void OnCreate()
    {
        blockQuery = EntityManager.CreateEntityQuery(ComponentType.ReadOnly <BlockTag>());
        ballQuery  = EntityManager.CreateEntityQuery(ComponentType.ReadOnly <BallTag>());

        stepPhysicsWorld = World.GetOrCreateSystem <StepPhysicsWorld>();
        increaseVelocityOverTimeSystem         = World.GetOrCreateSystem <IncreaseVelocityOverTimeSystem>();
        endSimulationEntityCommandBufferSystem = World.GetOrCreateSystem <EndSimulationEntityCommandBufferSystem>();

        // Create Ball Entity.
        var ballPrefab = Resources.Load <GameObject>("Ball");

        blobAssetStore = new BlobAssetStore();
        var settings = GameObjectConversionSettings.FromWorld(World, blobAssetStore);

        ball = GameObjectConversionUtility.ConvertGameObjectHierarchy(ballPrefab, settings);
    }
Beispiel #11
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);
        }
Beispiel #12
0
        public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
        {
            using (var blobAssetStore = new BlobAssetStore())
            {
                var settings = GameObjectConversionSettings.FromWorld(World.DefaultGameObjectInjectionWorld, blobAssetStore);

                var vfxEntity = GameObjectConversionUtility.ConvertGameObjectHierarchy(VfxPrefab, settings);

                dstManager.AddComponentObject(vfxEntity, VfxPrefab.GetComponent <ParticleSystem>());

                dstManager.AddComponentData(entity, new TriggerEffectVfxComponent
                {
                    VfxPrefab  = vfxEntity,
                    DepthDelta = DepthDelta
                });
            }
        }
Beispiel #13
0
    private void Start()
    {
        store   = new BlobAssetStore();
        manager = World.DefaultGameObjectInjectionWorld.EntityManager;
        var settings = GameObjectConversionSettings.FromWorld(World.DefaultGameObjectInjectionWorld, store);

        Entity virus = GameObjectConversionUtility.ConvertGameObjectHierarchy(virusPrefab, settings);

        Instaniate(virus, numVirus);

        Entity redCell = GameObjectConversionUtility.ConvertGameObjectHierarchy(redBloodCellPrefab, settings);

        Instaniate(redCell, numBloodCell);

        bulletEntity = GameObjectConversionUtility.ConvertGameObjectHierarchy(bulletPrefab, settings);
        splatEntity  = GameObjectConversionUtility.ConvertGameObjectHierarchy(splatPrefab, settings);
    }
Beispiel #14
0
        private Entity[] CreateEntityPrefabs(GameObject[] ballPrefabs, GameObjectConversionSettings settings)
        {
            var ballEntityPrefabs = new Entity[ballPrefabs.Length];

            for (var i = 0; i < _ballPrefabs.Length; i++)
            {
                ballEntityPrefabs[i] = (GameObjectConversionUtility.ConvertGameObjectHierarchy(ballPrefabs[i], settings));
                _manager.AddComponentData(ballEntityPrefabs[i], new Color {
                    Value = i
                });
                _manager.AddComponentData(ballEntityPrefabs[i], new Speed {
                    Value = _fallSpeed
                });
            }

            return(ballEntityPrefabs);
        }
Beispiel #15
0
    private void Awake()
    {
        if (S == null)
        {
            S = this;
        }
        else
        {
            Debug.LogError("Attempt to create multiple Constant Managers.");
        }

        BloodEnt = GameObjectConversionUtility.ConvertGameObjectHierarchy(BloodPrefab, World.Active);
        SmokeEnt = GameObjectConversionUtility.ConvertGameObjectHierarchy(SmokePrefab, World.Active);

        BloodRenderMesh = World.Active.EntityManager.GetSharedComponentData <RenderMesh>(BloodEnt);
        SmokeRenderMesh = World.Active.EntityManager.GetSharedComponentData <RenderMesh>(SmokeEnt);
    }
        /// <summary>Get prefabs from Resourcefolder and store them in a dictionary as GO
        /// Also convert them to Entity and store in dictionary for entity prefab
        /// </summary>
        private void GetPrefabs()
        {
            prefabEntities    = new Dictionary <string, Entity>();
            prefabGameObjects = new Dictionary <string, GameObject>();
            var prefabsToInitialize = new List <string> {
                "Floor", "Ball", "Cube", "FinishPrefab"
            };

            foreach (var prefab in prefabsToInitialize)
            {
                GameObject ob = Resources.Load <GameObject>($"{prefab}");
                prefabGameObjects.Add(prefab, ob);
                World world    = World.DefaultGameObjectInjectionWorld;
                var   settings = GameObjectConversionSettings.FromWorld(world, blobAssetStore);
                prefabEntities.Add(prefab, GameObjectConversionUtility.ConvertGameObjectHierarchy(ob, settings));
            }
        }
Beispiel #17
0
    // Start is called before the first frame update
    void Start()
    {
        blobAssetStore = new BlobAssetStore();
        // Create entity prefab from the game object hierarchy once
        var           settings = GameObjectConversionSettings.FromWorld(World.DefaultGameObjectInjectionWorld, blobAssetStore);
        var           convertedTargetPrefab = GameObjectConversionUtility.ConvertGameObjectHierarchy(unitPrefabs, settings);
        EntityManager entityManager         = World.DefaultGameObjectInjectionWorld.EntityManager;

        for (int i = 0; i < 20; i++)
        {
            var entity = entityManager.Instantiate(convertedTargetPrefab);
            entityManager.SetComponentData(entity, new Translation()
            {
                Value = GetRandomPosition(new float3(8f, 8f, 0f))
            });
        }
    }
Beispiel #18
0
    public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
    {
        var gunCD = new GunComponentData();

        gunCD.muzzleX = muzzle.localPosition.x;
        gunCD.muzzleY = muzzle.localPosition.y;
        gunCD.muzzleZ = muzzle.localPosition.z;

        gunCD.hashCode = this.GetHashCode();

        var settings     = GameObjectConversionSettings.FromWorld(World.DefaultGameObjectInjectionWorld, null);
        var entityBullet = GameObjectConversionUtility.ConvertGameObjectHierarchy(bulletPrefab, settings);

        gunCD.bulletPrefab = entityBullet;

        dstManager.AddSharedComponentData(entity, gunCD);
    }
Beispiel #19
0
    void Start()
    {
        /* 创建实体时需要指定配置,这里涉及到World的概念,可以先不管,照抄就是了 */
        var settings = GameObjectConversionSettings.FromWorld(World.DefaultGameObjectInjectionWorld, null);

        /* 从我们的prefab中创建一个实体对象 */
        var entityFromPrefab = GameObjectConversionUtility.ConvertGameObjectHierarchy(Prefab, settings);

        /* 实体管理器 */
        var entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;

        EntityArchetype entityArchetype = entityManager.CreateArchetype(
            typeof(RenderBounds),
            typeof(Translation),
            typeof(RenderMesh),
            typeof(LocalToWorld),
            typeof(MoveComponent)
            );

        // NativeArray<Entity> entityArray = new NativeArray<Entity> (10, Allocator.Temp);
        // entityManager.CreateEntity (entityArchetype, entityArray);

        /* 循环创建多个实体 */
        for (var i = 0; i < Count; i++)
        {
            /* 赋值新的实体 */
            var entity = entityManager.Instantiate(entityFromPrefab);
            // var entity = entityArray[i];
            // 设置原型
            entityManager.SetArchetype(entity, entityArchetype);
            /* 修改实体的组件 */
            var position = transform.TransformPoint(UnityEngine.Random.Range(-rangePos, rangePos), 0, UnityEngine.Random.Range(-rangePos, rangePos));
            // entityManager.SetComponentData (entity, new RotationComponent { Speed = UnityEngine.Random.Range (-10, 10) });
            entityManager.SetComponentData(entity, new MoveComponent {
                Speed = UnityEngine.Random.Range(-10, 10), Range = rangePos
            });
            entityManager.SetComponentData(entity, new Translation {
                Value = position
            });
            // RenderMesh renderMesh = new RenderMesh ();
            // renderMesh.material = material;
            // renderMesh.mesh = mesh;
            // entityManager.SetSharedComponentData (entity, renderMesh);
        }
    }
Beispiel #20
0
    public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
    {
        var snapshotType = FindSnapshot();

#if !UNITY_CLIENT || UNITY_SERVER || UNITY_EDITOR
        if (World.Active == ClientServerBootstrap.serverWorld)
        {
            var prefabEntity = GameObjectConversionUtility.ConvertGameObjectHierarchy(prefab, World.Active);
            dstManager.AddComponentData(entity, new GhostServerPrefabComponent {
                prefab = prefabEntity
            });
        }
#endif
#if !UNITY_SERVER
        bool isClientPrefab = false;
        foreach (var clientWorld in ClientServerBootstrap.clientWorld)
        {
            isClientPrefab |= World.Active == clientWorld;
        }
        if (isClientPrefab)
        {
            var ghostAuth       = prefab.GetComponent <GhostAuthoringComponent>();
            var origInstantiate = ghostAuth.ClientInstantiateTarget;
            ghostAuth.ClientInstantiateTarget = GhostAuthoringComponent.ClientInstantiateTargetType.Interpolated;
            var prefabEntity = GameObjectConversionUtility.ConvertGameObjectHierarchy(prefab, World.Active);
            ghostAuth.ClientInstantiateTarget = GhostAuthoringComponent.ClientInstantiateTargetType.Predicted;
            var predictedPrefabEntity = GameObjectConversionUtility.ConvertGameObjectHierarchy(prefab, World.Active);
            ghostAuth.ClientInstantiateTarget = origInstantiate;
            // TODO: should these be part of GhostAuthoringComponent conversion too?
            dstManager.AddComponent(prefabEntity, snapshotType);
            dstManager.AddComponent(predictedPrefabEntity, snapshotType);
            dstManager.AddComponentData(entity, new GhostClientPrefabComponent {
                predictedPrefab = predictedPrefabEntity, interpolatedPrefab = prefabEntity
            });
            dstManager.AddComponent(entity, snapshotType);
        }
#endif
#if UNITY_EDITOR || (!UNITY_SERVER && !UNITY_CLIENT)
        if (!isClientPrefab && World.Active != ClientServerBootstrap.serverWorld)
        {
            throw new InvalidOperationException(
                      $"A ghost prefab can only be created in the client or server world, not {World.Active.Name}");
        }
#endif
    }
Beispiel #21
0
        public void ErrorDuringSelfConversion_RecordsError()
        {
            var go = CreateGameObject();

            go.AddComponent <JournalTestAuthoring>().ShouldError = true;

            var entity = GameObjectConversionUtility.ConvertGameObjectHierarchy(go, m_Settings);

            EntitiesAssert.ContainsOnly(m_Manager, EntityMatch.Any(entity));

            Assert.That(m_Events.EventsOfType <LogEventData>(), Is.EqualTo(new[] {
                JournalDataDebug.Create(go.GetInstanceID(), new LogEventData {
                    Type = LogType.Error, Message = "JournalTestAuthoring.Convert error"
                })
            }));

            LogAssert.Expect(LogType.Error, "JournalTestAuthoring.Convert error");
        }
Beispiel #22
0
    private void Awake()
    {
        if (instance != null && instance != this)
        {
            Destroy(gameObject);
            return;
        }

        instance = this;

        manager        = World.DefaultGameObjectInjectionWorld.EntityManager;
        blobAssetStore = new BlobAssetStore();
        GameObjectConversionSettings settings = GameObjectConversionSettings.FromWorld(World.DefaultGameObjectInjectionWorld, blobAssetStore);

        ballEntityPrefab = GameObjectConversionUtility.ConvertGameObjectHierarchy(ballPrefab, settings);

        cubeEntityPrefab = GameObjectConversionUtility.ConvertGameObjectHierarchy(cubePrefab, settings);
    }
Beispiel #23
0
    private void AddingEntityFromPrefab()
    {
        // Create EntityManager and prefabEntity that convert our GameObject into an entity
        EntityManager entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
        var           settings      = GameObjectConversionSettings.FromWorld(World.DefaultGameObjectInjectionWorld, null);
        var           prefabEntity  = GameObjectConversionUtility.ConvertGameObjectHierarchy(palmTreePrefab, settings);

        // Create an instance of the entity and add Translation and Rotation components to it
        var instance = entityManager.Instantiate(prefabEntity);
        var position = transform.TransformPoint(new float3(UnityEngine.Random.Range(-15, 15), 0, UnityEngine.Random.Range(-15, 15)));

        entityManager.SetComponentData(instance, new Translation {
            Value = position
        });
        entityManager.SetComponentData(instance, new Rotation {
            Value = new quaternion(0, 0, 0, 0)
        });
    }
Beispiel #24
0
    private void Start()
    {
        manager = World.DefaultGameObjectInjectionWorld.EntityManager;
        var settings = GameObjectConversionSettings.FromWorld(World.DefaultGameObjectInjectionWorld, null);
        var prefab   = GameObjectConversionUtility.ConvertGameObjectHierarchy(sheepPrefab, settings);

        for (int i = 0; i < numSheep; i++)
        {
            var instance = manager.Instantiate(prefab);
            var position = transform.TransformPoint(new float3(UnityEngine.Random.Range(-range, range), UnityEngine.Random.Range(0, range * 2), UnityEngine.Random.Range(-range, range)));
            manager.SetComponentData(instance, new Translation {
                Value = position
            });
            manager.SetComponentData(instance, new Rotation {
                Value = new quaternion(0, 0, 0, 0)
            });
        }
    }
        protected void VerifyLogsException <T>(Regex message = null) where T : Exception
        {
            var world = new World("Test world");

            try
            {
                using (var blobAssetStore = new BlobAssetStore())
                {
                    LogAssert.Expect(LogType.Exception, message ?? new Regex($"\b{typeof(T).Name}\b"));
                    var settings = GameObjectConversionSettings.FromWorld(world, blobAssetStore);
                    GameObjectConversionUtility.ConvertGameObjectHierarchy(Root, settings);
                }
            }
            finally
            {
                world.Dispose();
            }
        }
Beispiel #26
0
        public void HybridComponent_OnDisabledGameObject_IsConvertedAndDisabled()
        {
            var gameObject = CreateGameObject();

            gameObject.AddComponent <ConversionTestHybridComponent>().SomeValue = 123;
            gameObject.SetActive(false);
            var entity          = GameObjectConversionUtility.ConvertGameObjectHierarchy(gameObject, MakeDefaultSettings().WithExtraSystem <MonoBehaviourComponentConversionSystem>());
            var hybridComponent = m_World.EntityManager.GetComponentObject <ConversionTestHybridComponent>(entity);

            Assert.AreEqual(123, hybridComponent.SomeValue);

            // give the hybrid component system a chance to activate this object, and check it did not in fact do it.
            m_World.Update();

            var companion = m_World.EntityManager.GetComponentObject <CompanionLink>(entity);

            Assert.IsFalse(companion.Companion.activeSelf);
        }
Beispiel #27
0
    private NativeArray <Entity> CreateEntitiesFromPrefab(GameObject _prefab, Vector3[] _spawnPositions)
    {
        NativeArray <Entity> nativeArray = new NativeArray <Entity>(_spawnPositions.Length, Allocator.Temp);
        var entityFromPrefab             = GameObjectConversionUtility.ConvertGameObjectHierarchy(_prefab, World.Active);

        for (int i = 0; i < _spawnPositions.Length; i++)
        {
            var instance = entityManager.Instantiate(entityFromPrefab);
            entityManager.SetComponentData(instance, new Translation {
                Value = _spawnPositions[i]
            });
            entityManager.SetComponentData(instance, new Rotation {
                Value = Quaternion.identity
            });
            nativeArray[i] = instance;
        }
        return(nativeArray);
    }
Beispiel #28
0
        private void Start()
        {
            defaultWorld  = World.DefaultGameObjectInjectionWorld;
            entityManager = defaultWorld.EntityManager;

            GameObjectConversionSettings settings = GameObjectConversionSettings.FromWorld(defaultWorld, null);

            asteroidEntities = new NativeArray <Entity>(asteroidPrefabs.Length, Allocator.Temp);
            for (var i = 0; i < asteroidEntities.Length; i++)
            {
                asteroidEntities[i] = GameObjectConversionUtility.ConvertGameObjectHierarchy(asteroidPrefabs[i], settings);
            }
            for (var i = 0; i < asteroidsToSpawn; i++)
            {
                SpawnRandomAsteroid(new Vector3(UnityEngine.Random.Range(-200, 200), UnityEngine.Random.Range(-200, 200), UnityEngine.Random.Range(-20, -50)));
            }
            asteroidEntities.Dispose();
        }
Beispiel #29
0
    private void Awake()
    {
        if (instanse != null && instanse != this)
        {
            Destroy(gameObject); //зачем дестроить?
            return;
        }

        instanse = this;

        manager        = World.DefaultGameObjectInjectionWorld.EntityManager; //чтобы настраивать энтити
        blobAssetStore = new BlobAssetStore();
        //Чтобы спавнить новые энтити
        GameObjectConversionSettings settings = GameObjectConversionSettings.FromWorld(World.DefaultGameObjectInjectionWorld, blobAssetStore);

        ballEntityPrefab    = GameObjectConversionUtility.ConvertGameObjectHierarchy(ballPrefab, settings);
        capsuleEntityPrefab = GameObjectConversionUtility.ConvertGameObjectHierarchy(capsulePrefab, settings);
    }
    void Start()
    {
#if UNITY_EDITOR
        UnityEditor.SceneView.FocusWindowIfItsOpen(typeof(UnityEditor.SceneView));
#endif

        defaultWorld  = World.DefaultGameObjectInjectionWorld;
        entityManager = defaultWorld.EntityManager;

        var conversionSettings = GameObjectConversionSettings.FromWorld(defaultWorld, null);
        entityPrefab = GameObjectConversionUtility.ConvertGameObjectHierarchy(gameObjectPrefab, conversionSettings);

        //InstantiateEntity(new float3(0, 0, 0));

        InstantiateEntityGrid(dimensionX, dimensionY, spacing, isCentered);
        //InstantiateEntity(new float3(4f, 0f, 4f));
        //MakeEntity();     Function for first commit: create Entity
    }