static void CheckAgainstFullConversion(World destinationWorld)
        {
            var dstEntityManager = destinationWorld.EntityManager;

            using (var fullConversionWorld = new World("FullConversion"))
            {
                using (var blobAssetStore = new BlobAssetStore())
                {
                    var conversionSettings = GameObjectConversionSettings.FromWorld(fullConversionWorld, blobAssetStore);
                    conversionSettings.ConversionFlags = ConversionFlags;

                    GameObjectConversionUtility.ConvertScene(SceneManager.GetActiveScene(), conversionSettings);

                    const EntityManagerDifferOptions options =
                        EntityManagerDifferOptions.IncludeForwardChangeSet |
                        EntityManagerDifferOptions.ValidateUniqueEntityGuid;

                    using (var blobAssetCache = new BlobAssetCache(Allocator.TempJob))
                    {
                        EntityDiffer.PrecomputeBlobAssetCache(fullConversionWorld.EntityManager, EntityManagerDiffer.EntityGuidQueryDesc, blobAssetCache);
                        using (var changes = EntityDiffer.GetChanges(
                                   dstEntityManager,
                                   fullConversionWorld.EntityManager,
                                   options,
                                   EntityManagerDiffer.EntityGuidQueryDesc,
                                   blobAssetCache,
                                   Allocator.TempJob
                                   ))
                        {
                            Assert.IsFalse(changes.AnyChanges, "Full conversion and incremental conversion do not match!");
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        public bool CreateGhostCollection(params GameObject[] ghostTypes)
        {
            if (m_GhostCollection != null)
            {
                return(false);
            }
            var collectionGameObject = new GameObject();
            var collection           = collectionGameObject.AddComponent <GhostCollectionAuthoringComponent>();

            var oldGhostDefaults = GhostAuthoringModifiers.GhostDefaultOverrides;

            GhostAuthoringModifiers.InitDefaultOverrides();
            GhostAuthoringModifiers.InitVariantCache();

            foreach (var ghostObject in ghostTypes)
            {
                var ghost = ghostObject.GetComponent <GhostAuthoringComponent>();
                if (ghost == null)
                {
                    ghost = ghostObject.AddComponent <GhostAuthoringComponent>();
                }

                ghost.Name     = ghostObject.name;
                ghost.prefabId = Guid.NewGuid().ToString().Replace("-", "");

                collection.Ghosts.Add(new GhostCollectionAuthoringComponent.Ghost {
                    prefab = ghost, enabled = true
                });
            }
            GhostAuthoringModifiers.GhostDefaultOverrides = oldGhostDefaults;
            m_GhostCollection = collectionGameObject;
            m_BlobAssetStore  = new BlobAssetStore();
            return(true);
        }
Esempio n. 3
0
    private void Awake()
    {
        {
            if (main != null && main != this)
            {
                Destroy(gameObject);
                return;
            }

            main         = this;
            playerScores = new int[2];

            oneSecond = new WaitForSeconds(1f);
            delay     = new WaitForSeconds(respawnDelay);



            manager = World.DefaultGameObjectInjectionWorld.EntityManager;


            bas = new BlobAssetStore();
            GameObjectConversionSettings settings = GameObjectConversionSettings.FromWorld(World.DefaultGameObjectInjectionWorld, bas);



            ballEntityPrefab = GameObjectConversionUtility.ConvertGameObjectHierarchy(ballPrefab, settings);
            StartCoroutine(CountdownAndSpawnBall());
        }
    }
    private void Awake()
    {
        manager        = World.DefaultGameObjectInjectionWorld.EntityManager;
        blobAssetStore = new BlobAssetStore();

        gameStateSystem = manager.World.GetExistingSystem <GameStateSystem>();
    }
Esempio n. 5
0
 private void Awake()
 {
     main              = this;
     blobAssetStore    = new BlobAssetStore();
     entityManager     = World.DefaultGameObjectInjectionWorld.EntityManager;
     scrapEntityPrefab = GameObjectConversionUtility.ConvertGameObjectHierarchy(scrapPrefab, GameObjectConversionSettings.FromWorld(World.DefaultGameObjectInjectionWorld, blobAssetStore));
 }
Esempio n. 6
0
        public APIContext()
        {
            this.MainBlob = new BlobAssetStore();
            this.IoC      = new IoCContainer();

            Current = this;
        }
Esempio n. 7
0
    private void Awake()
    {
        if (main != null && main != this)
        {
            Destroy(gameObject);
            return;
        }

        main         = this;
        playerScores = new int[2];

        // Увидим мир с игрвыми сущностями (Entity) - не обяз. активный
        manager = World.DefaultGameObjectInjectionWorld.EntityManager;

        // получить префаб
        blobAssetStore = new BlobAssetStore();
        GameObjectConversionSettings settings =
            GameObjectConversionSettings.FromWorld(World.DefaultGameObjectInjectionWorld, blobAssetStore);

        ballEntityPrefab = GameObjectConversionUtility.ConvertGameObjectHierarchy(ballPrefab, settings);

        oneSecond = new WaitForSeconds(1f);
        delay     = new WaitForSeconds(respawnDelay);

        StartCoroutine(CountdownAndSpawnBall());
    }
 void Awake()
 {
     blobAssetStore     = new BlobAssetStore();
     _controls          = new Controls();
     entityManager      = World.DefaultGameObjectInjectionWorld.EntityManager;
     bulletEntityPrefab = GameObjectConversionUtility.ConvertGameObjectHierarchy(bulletPrefab, GameObjectConversionSettings.FromWorld(World.DefaultGameObjectInjectionWorld, blobAssetStore));
 }
Esempio n. 9
0
 // Start is called before the first frame update
 void Start()
 {
     _entityManager       = World.DefaultGameObjectInjectionWorld.EntityManager;
     blob                 = new BlobAssetStore();
     _defenseEntityPrefab = GameObjectConversionUtility.ConvertGameObjectHierarchy(defensePrefab,
                                                                                   GameObjectConversionSettings.FromWorld(World.DefaultGameObjectInjectionWorld, blob));
 }
Esempio n. 10
0
    // Start is called before the first frame update
    void Start()
    {
        BlobAssetStore blobAsset = new BlobAssetStore();

        manager = World.DefaultGameObjectInjectionWorld.EntityManager;
        var settings = GameObjectConversionSettings.FromWorld(World.DefaultGameObjectInjectionWorld, blobAsset);
        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(-50, 50),
                    UnityEngine.Random.Range(0, 100),
                    UnityEngine.Random.Range(-50, 50)));
            manager.SetComponentData(instance, new Translation {
                Value = position
            });
            manager.SetComponentData(instance, new Rotation {
                Value = new quaternion(0, 0, 0, 0)
            });
        }

        blobAsset.Dispose();
    }
Esempio n. 11
0
    void Awake()
    {
        if (Instance != null && Instance != this)
        {
            Destroy(gameObject);
        }
        else
        {
            Instance = this;
        }

        enemySpawner = FindObjectOfType <EnemySpawner>();

        // each World has one EntityManager; store a reference to it
        entityManager  = World.DefaultGameObjectInjectionWorld.EntityManager;
        blobAssetStore = new BlobAssetStore();

        // settings used to convert GameObject prefab
        var settings = GameObjectConversionSettings.FromWorld(World.DefaultGameObjectInjectionWorld, blobAssetStore);

        // convert the GameObject prefab into an Entity prefab and store it
        Entity playerEntityPrefab = GameObjectConversionUtility.ConvertGameObjectHierarchy(playerPreFab, settings);

        playerEntity = entityManager.Instantiate(playerEntityPrefab);

        FollowPlayer followPlayer = playerFollower.GetComponent <FollowPlayer>();

        followPlayer.playerEntity = playerEntity;

        PlayerManager = playerFollower.GetComponent <PlayerManager>();

        gameState = GameState.Ready;
    }
Esempio n. 12
0
    // Start is called before the first frame update
    void Start()
    {
        rocks = new List <Entity>();
        uint randomRange = (uint)UnityEngine.Random.Range(1, 10000000);

        rand = new Unity.Mathematics.Random(randomRange);

        blobby         = new BlobAssetStore();
        settings       = GameObjectConversionSettings.FromWorld(World.DefaultGameObjectInjectionWorld, blobby);
        entitiyManager = World.DefaultGameObjectInjectionWorld.EntityManager;

        prefab = new Entity[cube.Length];


        for (int x = 0; x < cube.Length; x++)
        {
            prefab[x] = GameObjectConversionUtility.ConvertGameObjectHierarchy(cube[x], settings);
        }

        for (int x = 0; x < amount; x++)
        {
            var instance = entitiyManager.Instantiate(prefab[rand.NextInt(0, cube.Length)]);
            rocks.Add(instance);
        }

        //Destroy(cube);
    }
    // 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(targetPrefabs, settings);
        EntityManager entityManager         = World.DefaultGameObjectInjectionWorld.EntityManager;

        for (int i = 0; i < 20000; i++)
        {
            var entity = entityManager.Instantiate(convertedTargetPrefab);
            entityManager.SetComponentData(entity, new Translation()
            {
                Value = GetRandomPosition()
            });
        }
        var convertedSearchPrefab = GameObjectConversionUtility.ConvertGameObjectHierarchy(searchPrefabs, settings);

        for (int i = 0; i < 1000; i++)
        {
            var entity = entityManager.Instantiate(convertedSearchPrefab);
            entityManager.SetComponentData(entity, new Translation()
            {
                Value = GetRandomPosition()
            });
        }
    }
Esempio n. 14
0
        private IEnumerator Start()
        {
            Debug.Log("GameWorld::Start: Beginning Setup...");
            //yield return null;

            _defaultWorld  = World.DefaultGameObjectInjectionWorld;
            _entityManager = _defaultWorld.EntityManager;

            using (var blobAssetStore = new BlobAssetStore()) {
                var conversionSettings = GameObjectConversionSettings.FromWorld(_defaultWorld, blobAssetStore);
                _chunkEntityPrefab =
                    GameObjectConversionUtility.ConvertGameObjectHierarchy(chunkGameObjectPrefab, conversionSettings);
                _chunkMeshEntityPrefab =
                    GameObjectConversionUtility.ConvertGameObjectHierarchy(chunkMeshGameObjectPrefab, conversionSettings);
            }

            Debug.Log("GameWorld::Start: Setup complete!");
            //yield return null;

            Debug.Log("GameWorld::Start: Creating world...");
            //yield return null;

            CreateWorld();

            Debug.Log("GameWorld::Start: World done!");
            yield return(null);
        }
Esempio n. 15
0
    void Start()
    {
        //UnityEntity = ConvertToEntity(UnitPrefab);

        var em = World.DefaultGameObjectInjectionWorld.EntityManager;

        world = World.DefaultGameObjectInjectionWorld;

        var blob = new BlobAssetStore();
        GameObjectConversionSettings settings = GameObjectConversionSettings.FromWorld(world, blob);

        //unitEntity = GameObjectConversionUtility.ConvertGameObjectHierarchy(UnitPrefab, settings);
        bulletEntity = GameObjectConversionUtility.ConvertGameObjectHierarchy(BulletPrefab, settings);

        //entities bug workaround
        //https://forum.unity.com/threads/invalidoperationexception-object-is-not-initialized-or-has-already-been-destroyed.882484/

        //addSystem<AssignMovePositionSystem>();


        addSystem <SpawnUnitSystem>();
        addSystem <SpawnShootSystem>();
        addSystem <TargetMoveSystem>();
        addSystem <RotateSystem>();
        addSystem <CollectDamageSystem>();
        addSystem <ApplyDamageSystem>();
        addSystem <WaypointsMoveSystem>();
        addSystem <MakeDynamicBodySystem>();
        addSystem <AttackBuildingSystem>();
        addSystem <EndReachedSystem>();
        addSystem <DestroyDeadSystem>();
    }
    private void Awake()
    {
        World          destinationWorld = World.DefaultGameObjectInjectionWorld;
        BlobAssetStore blobAssetStore   = new BlobAssetStore();
        GameObjectConversionSettings gameObjectConversionSettings = GameObjectConversionSettings.FromWorld(destinationWorld, blobAssetStore);
        Entity           entity           = GameObjectConversionUtility.ConvertGameObjectHierarchy(prefab, gameObjectConversionSettings);
        SineMovementData sineMovementData = new SineMovementData()
        {
            moveSpeed = 10
        };

        for (int x = 0; x < count; x++)
        {
            for (int y = 0; y < count; y++)
            {
                Entity      instanceEntity = destinationWorld.EntityManager.Instantiate(entity);
                Translation translation    = new Translation()
                {
                    Value = new Unity.Mathematics.float3(x - count * 0.5f, 0, y - count * 0.5f)
                };

                sineMovementData.originalPosition = translation.Value;
                destinationWorld.EntityManager.SetComponentData(instanceEntity, translation);
                destinationWorld.EntityManager.SetComponentData(instanceEntity, sineMovementData);
            }
        }

        blobAssetStore.Dispose();
    }
Esempio n. 17
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 boid     = GameObjectConversionUtility.ConvertGameObjectHierarchy(boidPrefab, settings);

        Unity.Mathematics.Random rand = new Unity.Mathematics.Random((uint)System.DateTime.Now.Millisecond);

        for (int i = 0; i < boidSize; ++i)
        {
            var        instance = entityManager.Instantiate(boid);
            float3     xyz      = rand.NextFloat3(minBound, maxBound);
            quaternion q        = rand.NextQuaternionRotation();
            entityManager.SetComponentData(instance, new Translation {
                Value = xyz
            });
            entityManager.SetComponentData(instance, new Rotation {
                Value = q
            });

            float3 velocity = math.mul(q, new float3(0, 0, rand.NextFloat(1f, 10f)));
            entityManager.SetComponentData(instance, new SteerVelocity {
                velocity = velocity, lastVelocity = velocity
            });

            if (entityManager.HasComponent <SteerWander>(instance))
            {
                entityManager.AddComponentData(instance, new SteerWanderEdit()
                {
                    qrot = quaternion.identity
                });
            }
        }
    }
Esempio n. 18
0
    // Start is called before the first frame update
    void Start()
    {
        World world = World.DefaultGameObjectInjectionWorld;

        blobAsset = new BlobAssetStore();

        var conversionSetting = new GameObjectConversionSettings(world, GameObjectConversionUtility.ConversionFlags.AssignName, blobAsset);

        Entity        unitEntity    = GameObjectConversionUtility.ConvertGameObjectHierarchy(prefab, conversionSetting);
        EntityManager entityManager = world.EntityManager;

        NativeArray <Entity> unitsToSpawn = new NativeArray <Entity>(spawnCount, Allocator.Temp);

        entityManager.Instantiate(unitEntity, unitsToSpawn);

        for (int i = 0; i < spawnCount; i++)
        {
            Entity entity = unitsToSpawn[i];
            //entityManager.SetName(entity, name);

            if (disableAtStart)
            {
                entityManager.AddComponent(entity, typeof(Disabled));
            }
        }

        unitsToSpawn.Dispose();
    }
Esempio n. 19
0
 void Start()
 {
     _manager           = World.DefaultGameObjectInjectionWorld.EntityManager;
     _blobAssetStore    = new BlobAssetStore();
     _settings          = GameObjectConversionSettings.FromWorld(World.DefaultGameObjectInjectionWorld, _blobAssetStore);
     bulletEntityPrefab = GameObjectConversionUtility.ConvertGameObjectHierarchy(shot, _settings);
 }
Esempio n. 20
0
        void Start()
        {
            // Create entity prefab from the game object hierarchy once
            BlobAssetStore blobAsset = new BlobAssetStore();

            var settings      = GameObjectConversionSettings.FromWorld(World.DefaultGameObjectInjectionWorld, blobAsset);
            var prefab        = GameObjectConversionUtility.ConvertGameObjectHierarchy(Prefab, settings);
            var entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;

            for (var x = 0; x < CountX; x++)
            {
                for (var y = 0; y < CountY; y++)
                {
                    // 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(x * 1.3F, noise.cnoise(new float2(x, y) * 0.21F) * 2, y * 1.3F));
                    entityManager.SetComponentData(instance, new Translation {
                        Value = position
                    });
                }
            }

            blobAsset.Dispose();
        }
        public void ConvertGameObject_HasOnlyTransform_ProducesEntityWithPositionAndRotation()
        {
            var scene = SceneManager.GetActiveScene();
            var go    = CreateGameObject("Test Conversion");

            go.transform.localPosition = new Vector3(1, 2, 3);

            using (var blobAssetStore = new BlobAssetStore())
            {
                var settings = GameObjectConversionSettings.FromWorld(World, blobAssetStore);
                GameObjectConversionUtility.ConvertScene(scene, settings);

                EntitiesAssert.ContainsOnly(m_Manager,
                                            EntityMatch.Exact(
                                                new Translation {
                    Value = new float3(1, 2, 3)
                },
                                                new Rotation {
                    Value = quaternion.identity
                },
                                                new LocalToWorld {
                    Value = go.transform.localToWorldMatrix
                }));
            }
        }
    void Awake()
    {
        // get world and entity manager to keep lines short
        defaultWorld  = World.DefaultGameObjectInjectionWorld;
        entityManager = defaultWorld.EntityManager;

        // set map system
        defaultWorld.GetExistingSystem <ConstrainToMapSystem>().Enabled = (mapSystem == MapSystem.Constrain);
        defaultWorld.GetExistingSystem <WrapToMapSystem>().Enabled      = (mapSystem == MapSystem.Wrap);

        // convert prefabs into entities
        blobAssetStore = new BlobAssetStore();
        GameObjectConversionSettings settings = GameObjectConversionSettings.FromWorld(defaultWorld, blobAssetStore);

        foodSpawnerEntityPrefab = GameObjectConversionUtility.ConvertGameObjectHierarchy(foodSpawnerPrefab, settings);
        foodEntityPrefab        = GameObjectConversionUtility.ConvertGameObjectHierarchy(foodPrefab, settings);

        // map will only be used here, so no need to make it public
        Entity mapEntityPrefab = GameObjectConversionUtility.ConvertGameObjectHierarchy(mapGameObject, settings);

        mapEntity = entityManager.Instantiate(mapEntityPrefab);
        InitializeMap();

        // name entities accordingly
        entityManager.SetName(foodSpawnerEntityPrefab, "foodSpawner");
        entityManager.SetName(foodEntityPrefab, "food");
        entityManager.SetName(mapEntity, "map");

        // initialize arrays
        foodSpawnerOutputLocations = new float3[foodSpawnerAmount];
    }
        protected void TestConvertedData <T>(Action <NativeArray <T> > checkValues, int assumeCount) where T : struct, IComponentData
        {
            var world = new World("Test world");

            try
            {
                using (var blobAssetStore = new BlobAssetStore())
                {
                    var settings = GameObjectConversionSettings.FromWorld(world, blobAssetStore);
                    GameObjectConversionUtility.ConvertGameObjectHierarchy(Root, settings);

                    using (var group = world.EntityManager.CreateEntityQuery(typeof(T)))
                    {
                        using (var components = group.ToComponentDataArray <T>(Allocator.Persistent))
                        {
                            Assume.That(components, Has.Length.EqualTo(assumeCount));
                            checkValues(components);
                        }
                    }
                }
            }
            finally
            {
                world.Dispose();
            }
        }
Esempio n. 24
0
    // Start is called before the first frame update
    void Start()
    {
        em  = World.DefaultGameObjectInjectionWorld.EntityManager;
        bas = new BlobAssetStore();
        GameObjectConversionSettings gocs = GameObjectConversionSettings.FromWorld(World.DefaultGameObjectInjectionWorld, bas);

        projectileEntity = GameObjectConversionUtility.ConvertGameObjectHierarchy(projectilePrefab, gocs);
        convertedEntity  = GameObjectConversionUtility.ConvertGameObjectHierarchy(prefabToSpawn, gocs);

        if (colliderMesh != null)
        {
            col = CreateSphereCollider(colliderMesh);
        }
        em.AddComponent <ShooterComponentData>(convertedEntity);
        em.SetComponentData(convertedEntity, new Translation {
            Value = transform.position
        });
        em.SetComponentData(convertedEntity, new ShooterComponentData
        {
            colliderCast       = col,
            projectile         = projectileEntity,
            firingInterval     = projectileFiringInterval,
            projectileSpeed    = projectileSpeed,
            projectileLifeTime = projectileLifeTime
        });
        for (int i = 0; i <= numberOfShooters; i++)
        {
            em.Instantiate(convertedEntity);
            position = (float3)transform.position + (new float3(1.5f * i, 0, 0));
            em.SetComponentData(convertedEntity, new Translation {
                Value = position
            });
        }
    }
Esempio n. 25
0
    private void Awake()
    {
        if (Instance != null)
        {
            Destroy(this);
            return;
        }

        Instance = this;
        //Initialization of pong & dots
        playerScores = new int[2];
        //get a manager reference
        manager = World.DefaultGameObjectInjectionWorld.EntityManager;
        //make some conversions from normal unity scene
        blob = new BlobAssetStore();
        GameObjectConversionSettings settings = GameObjectConversionSettings.FromWorld(World.DefaultGameObjectInjectionWorld, blob);

        BallEntityPrefab = GameObjectConversionUtility.ConvertGameObjectHierarchy(BallPrefab, settings);

        oneSecond = new WaitForSeconds(1f);
        delay     = new WaitForSeconds(respawnDelay);
        //show tutorial info
        StartCoroutine(tutorialTimer(delay));
        //start the game
        StartCoroutine(CountdownAndSpawnBall());
    }
Esempio n. 26
0
    private void Awake()
    {
        if (main != null && main != this)
        {
            Destroy(gameObject);
            return;
        }

        main = this;

        playerScores = new int[2];

        entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;

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

        obstacleEntityPrefab = GameObjectConversionUtility.ConvertGameObjectHierarchy(obstaclePrefab, settings);

        TimeIsOut();

        Entity restart = entityManager.CreateEntity();

        entityManager.AddComponentData(restart, new WaitForRestartTag());
    }
Esempio n. 27
0
 public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
 {
     using (BlobAssetStore blobAssetStore = new BlobAssetStore())
     {
         PrefabEntity = GameObjectConversionUtility.ConvertGameObjectHierarchy(prefab,
                                                                               GameObjectConversionSettings.FromWorld(dstManager.World, blobAssetStore));
     }
 }
Esempio n. 28
0
    void Start()
    {
        InitEntityManager();
        CreateArcheType();

        blobAssetStore = new BlobAssetStore();
        InstantiateEntityGrid(xSize, ySize, spacing);
    }
Esempio n. 29
0
    private void Awake()
    {
        entityManager  = World.DefaultGameObjectInjectionWorld.EntityManager;
        blobAssetStore = new BlobAssetStore();
        GameObjectConversionSettings settings = GameObjectConversionSettings.FromWorld(World.DefaultGameObjectInjectionWorld, blobAssetStore);

        shipEntity = GameObjectConversionUtility.ConvertGameObjectHierarchy(shipPrefab, settings);
    }
Esempio n. 30
0
        protected virtual void Setup()
        {
            World = DefaultWorldInitialization.Initialize("Test World");
            DefaultWorldInitialization.AddSystemsToRootLevelSystemGroups(World,
                                                                         DefaultWorldInitialization.GetAllSystems(WorldSystemFilterFlags.Editor));

            BlobStore = new BlobAssetStore();
        }