コード例 #1
0
 public ControllerDevice(NativeList <ControllerUnit> buffer)
 {
     Assert.IsTrue(buffer.IsCreated);
     _buffer = buffer;
     _random = new Random();
     _random.InitState(12345);
 }
コード例 #2
0
        public void Execute(ref RandomMotion motion, [ReadOnly] ref Translation position, ref PhysicsVelocity velocity, [ReadOnly] ref PhysicsMass mass)
        {
            motion.CurrentTime += deltaTime;

            random.InitState((uint)(motion.CurrentTime * 1000));
            var currentOffset = position.Value - motion.InitialPosition;
            var desiredOffset = motion.DesiredPosition - motion.InitialPosition;

            // If we are close enough to the destination pick a new destination
            if (math.lengthsq(position.Value - motion.DesiredPosition) < motion.Tolerance)
            {
                var min = new float3(-math.abs(motion.Range));
                var max = new float3(math.abs(motion.Range));
                desiredOffset          = random.NextFloat3(min, max);
                motion.DesiredPosition = desiredOffset + motion.InitialPosition;
            }
            var offset = desiredOffset - currentOffset;

            // Smoothly change the linear velocity
            velocity.Linear = math.lerp(velocity.Linear, offset, motion.Speed);
            if (mass.InverseMass != 0)
            {
                velocity.Linear -= gravity * deltaTime;
            }
        }
コード例 #3
0
 public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
 {
     _prefabEntity = conversionSystem.GetPrimaryEntity(prefab);
     _random.InitState(12345678u);
     TrailSystem.Initialize(_prefabEntity);
     RenderTrailSystem.Initialize(materialTrail);
 }
コード例 #4
0
    protected override void OnUpdate()
    {
        var   random        = new Random();
        float deltaTime     = Time.DeltaTime;
        var   stepComponent = HasSingleton <PhysicsStep>() ? GetSingleton <PhysicsStep>() : PhysicsStep.Default;

        Entities
        .WithName("ApplyRandomMotion")
        .WithBurst()
        .ForEach((ref RandomMotion motion, ref PhysicsVelocity velocity, in Translation position, in PhysicsMass mass) =>
        {
            motion.CurrentTime += deltaTime;

            random.InitState((uint)(motion.CurrentTime * 1000));
            var currentOffset = position.Value - motion.InitialPosition;
            var desiredOffset = motion.DesiredPosition - motion.InitialPosition;
            // If we are close enough to the destination pick a new destination
            if (math.lengthsq(position.Value - motion.DesiredPosition) < motion.Tolerance)
            {
                var min                = new float3(-math.abs(motion.Range));
                var max                = new float3(math.abs(motion.Range));
                desiredOffset          = random.NextFloat3(min, max);
                motion.DesiredPosition = desiredOffset + motion.InitialPosition;
            }
            var offset = desiredOffset - currentOffset;
            // Smoothly change the linear velocity
            velocity.Linear = math.lerp(velocity.Linear, offset, motion.Speed);
            if (mass.InverseMass != 0)
            {
                velocity.Linear -= stepComponent.Gravity * deltaTime;
            }
        }).Schedule();
コード例 #5
0
    void OnEnable()
    {
        if (this.enabled)
        {
            random = new Unity.Mathematics.Random();
            random.InitState(seed);
            sourceEntitys   = new List <Entity>();
            sourceColliders = new List <BlobAssetReference <Collider> >();
            sourceJoints    = new List <BlobAssetReference <JointData> >();

            float3 gravity = new float3(0, 0.0f, 0);//float3.zero;

            base.init(gravity, false /* don't add the control script from the base physics */);

            for (int i = 0; i < prefabs.Count; i++)
            {
                var prefab   = prefabs[i];
                var settings = GameObjectConversionSettings.FromWorld(World.DefaultGameObjectInjectionWorld, new BlobAssetStore());
                // Create entity prefab from the game object hierarchy once
                var sourceEntity  = GameObjectConversionUtility.ConvertGameObjectHierarchy(prefab, settings);
                var entityManager = BasePhysicsDemo.DefaultWorld.EntityManager;
                sourceEntitys.Add(sourceEntity);

                var sourceCollider = entityManager.GetComponentData <PhysicsCollider>(sourceEntity).Value;
                sourceColliders.Add(sourceCollider);
                //var sourceJoint = entityManager.GetComponentData<PhysicsJoint>(sourceEntity).Value;
                //sourceJoints.Add(sourceJoint);
            }

            _sketchPlaneStartZ = sketchPlane.transform.position.z;
        }
    }
コード例 #6
0
 public PositionWiggleJob(float timer, int count, float movementMultiplier)
 {
     _rand = new Unity.Mathematics.Random();
     _rand.InitState();
     _movementMultiplier = movementMultiplier;
     fakeTimer           = timer;
 }
        protected override void OnUpdate()
        {
            _rng.InitState((uint)DateTime.UtcNow.Ticks);

            var entityManager = World.Active.EntityManager;
            var query         = entityManager.CreateEntityQuery(typeof(ExplosionCenterComponent));

            if (GameManager.GameConfig.CanExplosion)
            {
                var explosionCenterComponents = query.ToComponentDataArray <ExplosionCenterComponent>(Allocator.TempJob);
                var spawnCount = GameManager.GameConfig.ParticleCount;

                for (var i = 0; i < explosionCenterComponents.Length; i++)
                {
                    for (var j = 0; j < spawnCount; j++)
                    {
                        _CreateExplosion(entityManager, explosionCenterComponents[i]);
                    }
                }

                explosionCenterComponents.Dispose();
            }

            var entityArray = query.ToEntityArray(Allocator.TempJob);

            entityManager.DestroyEntity(entityArray);

            entityArray.Dispose();
            query.Dispose();
        }
コード例 #8
0
        public void Execute()
        {
            var random = new Random();

            random.InitState(Seed);

            var holeCount = (int)(Generator.SizeX * Generator.SizeY * 0.05f);

            for (int i = 0; i < holeCount; ++i)
            {
                var coord = new int2(random.NextInt(Generator.SizeX), random.NextInt(Generator.SizeY));

                // Do not spawn holes in the 4 corners
                if ((coord.x == 0 && coord.y == 0) ||
                    (coord.x == 0 && coord.y == Generator.SizeY - 1) ||
                    (coord.x == Generator.SizeX - 1 && coord.y == 0) ||
                    (coord.x == Generator.SizeX - 1 && coord.y == Generator.SizeY - 1))
                {
                    continue;
                }

                // Do not place holes under homebases
                if (HomebaseMap.ContainsKey(coord))
                {
                    continue;
                }

                if (FloorMap.ContainsKey(coord))
                {
                    CommandBuffer.DestroyEntity(FloorMap[coord]);
                    FloorMap.Remove(coord);
                }
            }
        }
コード例 #9
0
    protected override void OnUpdate()
    {
        var cursorsToInit = m_Cursors.CalculateEntityCount();

        if (cursorsToInit <= 0)
        {
            return;
        }

        var boardCount = m_BoardQuery.CalculateEntityCount();

        if (boardCount <= 0)
        {
            return;
        }

        var board  = m_BoardQuery.GetSingleton <LbBoard>();
        var random = new Unity.Mathematics.Random();

        random.InitState(1);

        Entities.ForEach((Entity entity, ref LbCursorInit ci, ref LbMovementTarget movement, ref LbDistanceToTarget distance) =>
        {
            var position   = new float3(random.NextInt(0, board.SizeX), 1, random.NextInt(0, board.SizeY));
            movement.To    = position;
            distance.Value = 0.0f;

            World.EntityManager.RemoveComponent <LbCursorInit>(entity);
        });
    }
コード例 #10
0
        void Start()
        {
            random_.InitState(1234);
            int  spawnnum = SceneManager.Num;
            bool first    = true;

            while (spawnnum > 0)
            {
                var num    = random_.NextInt(3, 5);
                var center = new float3(random_.NextFloat(-200, 200), 64f, random_.NextFloat(-200, 200));
                var replay_index_center = random_.NextInt(100, 10000);
                for (var j = 0; j < num; ++j)
                {
                    var pos          = center + random_.NextFloat3(-6, 6);
                    var replay_index = replay_index_center + random_.NextInt(20, 40) * (random_.NextBool() ? 1 : -1);
                    var entity       = FighterSystem.Instantiate(FighterManager.Prefab,
                                                                 pos,
                                                                 quaternion.identity,
                                                                 replay_index);
                    if (first)
                    {
                        var fighterSystem = World.DefaultGameObjectInjectionWorld.GetOrCreateSystem <FighterSystem>();
                        fighterSystem.PrimaryEntity = entity;
                        first = false;
                    }
                    --spawnnum;
                    if (spawnnum > 0)
                    {
                        continue;
                    }
                    break;
                }
            }
        }
コード例 #11
0
        void SetupChapters()
        {
            var size = Constants.DefaultImageSize * m_SelectedScaleOption;

            m_ChaptersOneAndTwo = new ChaptersOneAndTwo(size.x, size.y);
            m_ChapterThree      = new ChapterThree(size.x, size.y);
            m_ChapterFour       = new ChapterFour(size.x, size.y);
            m_ChapterFive       = new ChapterFive(size.x, size.y);
            m_ChapterFiveTwo    = new ChapterFiveTwo(size.x, size.y);
            m_ChapterSix        = new ChapterSix(size.x, size.y);
            m_ChapterSeven      = new ChapterSeven(size.x, size.y);

            // from chapter 8 on, the same implementation is re-used
            m_ChapterEight = new BatchedTracer(ExampleSphereSets.ChapterEight(),
                                               CameraFrame.Default, size.x, size.y);
            m_ChapterNine = new BatchedTracer(ExampleSphereSets.FiveWithDielectric(),
                                              CameraFrame.Default, size.x, size.y);
            m_ChapterTen = new BatchedTracer(ExampleSphereSets.FiveWithDielectric(),
                                             CameraFrame.ChapterTen, size.x, size.y);
            m_ChapterEleven = new BatchedTracer(ExampleSphereSets.FiveWithDielectric(),
                                                CameraFrame.ChapterEleven, size.x, size.y);

            // make sure we get a random seed for our random scene
            var tempRng = new Unity.Mathematics.Random();

            tempRng.InitState((uint)UnityEngine.Random.Range(1, 1000));
            m_ChapterTwelve = new BatchedTracer(ExampleSphereSets.RandomScene(500, tempRng.NextUInt()),
                                                CameraFrame.ChapterTwelve, size.x, size.y);
        }
コード例 #12
0
        public void ControllerManater_replay()
        {
            var random = new Random();

            random.InitState(1234567);

            using (var buffer = new NativeList <ControllerUnit>(ControllerBuffer.MaxFrames, Allocator.Persistent)) {
                const int NUM    = 10;
                double    time   = 0;
                var       device = new ControllerDevice(buffer);
                for (var i = 0; i < NUM; ++i)
                {
                    var ppos = new float3(1000, 1000, 1000);
                    var tpos = new float3(0, 0, 0);
                    device.Update(time, ppos, tpos, true /* testing */);
                    time += 1.0 / 60.0;
                }
                Assert.AreEqual(NUM, buffer.Length);

                var filename = "test2.bin";
                ControllerBuffer.Save(buffer, filename);

                using (var buffer2 = ControllerBuffer.Load <ControllerUnit>(filename)) {
                    //var replay = new ControllerReplay();
                    for (var i = 0; i < NUM; ++i)
                    {
                        var ppos  = new float3(1000, 1000, 1000);
                        var tpos  = new float3(0, 0, 0);
                        var unitA = buffer[i];
                        var unitB = buffer2[i];
                        Assert.AreEqual(unitA, unitB);
                    }
                }
            }
        }
コード例 #13
0
    private JobHandle ScheduleWaterWeapon(PlayerShootJobData jobData, JobHandle deps)
    {
        if (!bubbleData.IsCreated)
        {
            bubbleData = new NativeArray <WaterShootData>(
                players.CalculateEntityCount(),
                Allocator.Persistent);
        }

        JobHandle job = new WaterShootJob {
            data                = jobData,
            bubbleData          = bubbleData,
            maxChargeTime       = maxChargeTime,
            bubbleBurstTopSpeed = bubbleBurstTopSpeed
        }.Schedule(players, deps);

        Random rnd = new Random();

        rnd.InitState((uint)(UnityEngine.Random.value * uint.MaxValue));
        job = new WaterShootUpdateBulletJob {
            commandBuffer = jobData.commandBuffer,
            bubbleData    = bubbleData,
            rnd           = rnd,
            effectReqUtil = effectSystem.GetUtility(),
        }.Schedule(waterBullets, job);

        job = new WaterShootPostUpdateJob {
            data       = jobData,
            bubbleData = bubbleData
        }.Schedule(players, job);

        commandBufferSystem.AddJobHandleForProducer(job);
        return(job);
    }
コード例 #14
0
 void Start()
 {
     MyonMyon = this;
     t        = GetComponent <Transform>();
     rng      = new Unity.Mathematics.Random();
     rng.InitState();
     StartCoroutine(DoMovement());
 }
コード例 #15
0
    public void Generate()
    {
        Random.InitState(seed);
        var terrain = CurrentTerrainForGeneration;

        terrain.terrainData = DiamondSquare.GenerateTerrain(terrain.terrainData, this);
        Save();
    }
コード例 #16
0
        public void Execute()
        {
            PlaceSpawner(ref CommandBuffer, Generator.Player1Cursor, int2.zero);
            PlaceSpawner(ref CommandBuffer, Generator.Player2Cursor, int2.zero);
            PlaceSpawner(ref CommandBuffer, Generator.Player3Cursor, int2.zero);
            PlaceSpawner(ref CommandBuffer, Generator.Player4Cursor, int2.zero);

            var spawnLocation1 = new int2(0, 0);
            var spawnLocation2 = new int2(Generator.SizeX - 1, 0);
            var spawnLocation3 = new int2(0, Generator.SizeY - 1);
            var spawnLocation4 = new int2(Generator.SizeX - 1, Generator.SizeY - 1);

            PlaceSpawner(ref CommandBuffer, Generator.SpawnerPrefab, spawnLocation1);
            PlaceSpawner(ref CommandBuffer, Generator.SpawnerPrefab, spawnLocation2);
            PlaceSpawner(ref CommandBuffer, Generator.SpawnerPrefab, spawnLocation3);
            PlaceSpawner(ref CommandBuffer, Generator.SpawnerPrefab, spawnLocation4);

            var random = new Random();

            random.InitState(Seed);

            var checkFlag = kHoleFlag | kHomebaseFlag;

            var spawnerMap = new NativeHashMap <int2, byte>(Generator.AdditionalSpawners + 4, Allocator.Temp);

            spawnerMap.TryAdd(spawnLocation1, 1);
            spawnerMap.TryAdd(spawnLocation2, 1);
            spawnerMap.TryAdd(spawnLocation3, 1);
            spawnerMap.TryAdd(spawnLocation4, 1);

            var remaining = Generator.AdditionalSpawners;

            while (remaining > 0)
            {
                var coord = new int2(random.NextInt(Generator.SizeX), random.NextInt(Generator.SizeY));
                var index = coord.y * Generator.SizeY + coord.x;

                // Avoid placing spawners in holes, homebases and on top of other spawners
                var cellMapValue = DirectionBuffer[index].Value & checkFlag;
                if (cellMapValue == kHoleFlag || cellMapValue == kHomebaseFlag || spawnerMap.ContainsKey(coord))
                {
                    continue;
                }

                PlaceSpawner(ref CommandBuffer, Generator.SpawnerPrefab, coord);
                spawnerMap.TryAdd(coord, 1);
                remaining--;
            }

            spawnerMap.Dispose();

            var entity = CommandBuffer.CreateEntity();

            CommandBuffer.AddComponent(entity, new LbGameTimer()
            {
                Value = LbConstants.GameTime
            });
        }
コード例 #17
0
 public void Execute(int index)
 {
     Random.InitState((uint)(Random.state + index));
     Translations[index] = new Translation()
     {
         Value = Random.NextFloat3(Min, Max)
     };
     Points[index] = new Point(Random.NextInt(PointMin, PointMax));
 }
コード例 #18
0
    protected override void OnCreate()
    {
        Random rnd = new Random();

        rnd.InitState();
        m_timeToInstance = rnd.NextFloat(1, 3);

        commandBufferSystem = World.DefaultGameObjectInjectionWorld.GetOrCreateSystem <EndSimulationEntityCommandBufferSystem>();
    }
コード例 #19
0
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        var throwingArmsComponentArray = m_InitDataQuery.ToComponentDataArray <ThrowingArmsSharedDataComponent>(Allocator.TempJob);
        var rockComponentArray         = m_InitDataQuery.ToComponentDataArray <RockSharedDataComponent>(Allocator.TempJob);
        var ecbs = World.GetOrCreateSystem <EndSimulationEntityCommandBufferSystem>();
        var ecb  = ecbs.CreateCommandBuffer().ToConcurrent();

        Unity.Mathematics.Random rnd = new Unity.Mathematics.Random();
        rnd.InitState();
        var right = new float3(1.0f, 0f, 0f);

        var jobHandle = Entities
                        .WithName("InitRocks")
                        .WithAll <RockComponent, InitComponentTag>()
                        .WithDeallocateOnJobCompletion(throwingArmsComponentArray)
                        .WithDeallocateOnJobCompletion(rockComponentArray)
                        .ForEach(
            (int entityInQueryIndex, Entity e, ref Translation pos) =>
        {
            var tac = throwingArmsComponentArray[0];
            var rc  = rockComponentArray[0];

            ecb.RemoveComponent <InitComponentTag>(entityInQueryIndex, e);
            ecb.SetComponent(entityInQueryIndex, e, new SizeableComponent
            {
                TargetSize  = rnd.NextFloat(rc.MinRockSize, rc.MaxRockSize),
                CurrentSize = 0f,
                ScaleFactor = rc.SizeGrowthFactor,
            });

            var minConveyorX = tac.ConveyorMinX;
            var maxConveyorX = tac.ConveyorMaxX;
            float spacing    = ((float)maxConveyorX - (float)minConveyorX) / (float)math.max((tac.ArmCount - 1), 1);
            float3 basePos   = new float3(minConveyorX, 0f, 1.5f);

            pos.Value = basePos + right * spacing * entityInQueryIndex;
            ecb.AddComponent(entityInQueryIndex, e, new ConveyorComponent
            {
                Speed     = tac.ConveyorSpeed,
                Direction = right,
                ResetX    = minConveyorX,
                MaxX      = maxConveyorX
            });

            ecb.AddComponent(entityInQueryIndex, e, new RigidBodyComponent
            {
                Gravity         = rc.Gravity,
                Velocity        = new float3(0f, 0f, 0f),
                AngularVelocity = new float3(0f, 0f, 0f),
            });
        })
                        .Schedule(inputDeps);

        ecbs.AddJobHandleForProducer(jobHandle);
        return(jobHandle);
    }
            // public int i_eliteScore ;


            public void Execute(int i)
            {
                int i_eliteProbablityCount = na_indexProbability.Length;

                random.InitState((uint)(random.NextInt(i_eliteProbablityCount) + na_randomValues [i]));
                random.NextInt2();

                int i_firstPorbabilityIndex  = random.NextInt(0, i_eliteProbablityCount);
                int i_secondPorbabilityIndex = random.NextInt(0, i_eliteProbablityCount);

                int i_firstParentEntityIndex  = na_indexProbability [i_firstPorbabilityIndex];
                int i_secondParentEntityIndex = na_indexProbability [i_secondPorbabilityIndex];



                Entity firstParentEntity  = na_parentPopulationEntities [i_firstParentEntityIndex];
                Entity secondParentEntity = na_parentPopulationEntities [i_secondParentEntityIndex];

                DynamicBuffer <NNInput2HiddenLayersWeightsBuffer>  a_firstParentInput2HiddenLayersWeights  = input2HiddenLayersWeightsBuffer [firstParentEntity];
                DynamicBuffer <NNHidden2OutputLayersWeightsBuffer> a_firstParentHidden2OutputLayersWeights = hidden2OutputLayersWeightsBuffer [firstParentEntity];

                DynamicBuffer <NNInput2HiddenLayersWeightsBuffer>  a_secondParentInput2HiddenLayersWeights  = input2HiddenLayersWeightsBuffer [secondParentEntity];
                DynamicBuffer <NNHidden2OutputLayersWeightsBuffer> a_secondParentHidden2OutputLayersWeights = hidden2OutputLayersWeightsBuffer [secondParentEntity];

                Entity offspringEntity = na_offspringPopulationEntities [i];

                DynamicBuffer <NNInput2HiddenLayersWeightsBuffer>  a_offspringInput2HiddenLayersWeights   = input2HiddenLayersWeightsBuffer [offspringEntity];
                DynamicBuffer <NNHidden2OutputLayersWeightsBuffer> a_offspringtHidden2OutputLayersWeights = hidden2OutputLayersWeightsBuffer [offspringEntity];


                int i_input2HiddenLayersWeightsCount  = a_firstParentInput2HiddenLayersWeights.Length;
                int i_hidden2OutputLayersWeightsCount = a_firstParentHidden2OutputLayersWeights.Length;

                a_offspringInput2HiddenLayersWeights.ResizeUninitialized(i_input2HiddenLayersWeightsCount);
                a_offspringtHidden2OutputLayersWeights.ResizeUninitialized(i_hidden2OutputLayersWeightsCount);

                // 50 / 50 chance to get trait (NN weights) from parent A or B.
                for (int j = 0; j < a_offspringInput2HiddenLayersWeights.Length; j++)
                {
                    float f = random.NextFloat() < 0.5f ? a_firstParentInput2HiddenLayersWeights [j].f : a_secondParentInput2HiddenLayersWeights [j].f;
                    a_offspringInput2HiddenLayersWeights [j] = new NNInput2HiddenLayersWeightsBuffer()
                    {
                        f = f
                    };
                }

                for (int j = 0; j < a_offspringtHidden2OutputLayersWeights.Length; j++)
                {
                    float f = random.NextFloat() < 0.5f ? a_firstParentHidden2OutputLayersWeights [j].f : a_secondParentHidden2OutputLayersWeights [j].f;
                    a_offspringtHidden2OutputLayersWeights [j] = new NNHidden2OutputLayersWeightsBuffer()
                    {
                        f = f
                    };
                }
            }
コード例 #21
0
    protected override void OnCreate()
    {
        m_Query          = GetEntityQuery(typeof(LbGameSpawnAll));
        m_GeneratorQuery = GetEntityQuery(typeof(LbBoardGenerator));
        m_BoardQuery     = GetEntityQuery(ComponentType.ReadOnly <LbBoard>(), ComponentType.ReadOnly <LbDirectionMap>());

        m_Barrier = World.GetOrCreateSystem <LbCreationBarrier>();

        m_Random = new Random();
        m_Random.InitState(2000);
    }
コード例 #22
0
        public static void Initialize(EntityManager entityManager)
        {
            EntityManager = entityManager;

            GemArchetype = entityManager.CreateArchetype(
                typeof(Translation),
                typeof(BoardPositionComponent),
                typeof(GemComponent));

            Random = new Random();
            Random.InitState();
        }
コード例 #23
0
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        rnd.InitState((uint)Guid.NewGuid().GetHashCode());

        var job = new RandomMoveJob
        {
            dT  = Time.deltaTime,
            rnd = rnd
        };

        return(job.Schedule(this, inputDeps));
    }
コード例 #24
0
        protected override void OnUpdate()
        {
            _rng.InitState((uint)DateTime.UtcNow.Ticks);

            var entityManager = World.Active.EntityManager;
            var query         = entityManager.CreateEntityQuery(typeof(PlayerComponent));
            var spawnCount    = GameManager.GameConfig.PlayerCount - query.CalculateEntityCount();

            for (var i = 0; i < spawnCount; i++)
            {
                _SpawnPlayer(entityManager);
            }
        }
コード例 #25
0
    protected override void OnUpdate()
    {
        Unity.Mathematics.Random rng = new Unity.Mathematics.Random();
        GraphData graphData          = GetSingleton <GraphData>();

        {
            Entities.With(SpawnerQueryEnter).ForEach((
                                                         Unity.Entities.Entity SpawnerQueryEntity,
                                                         ref LogoSpawner SpawnerQueryEnterLogoSpawner) =>
            {
                rng.InitState((uint)Time.frameCount * 3889 ^ 1851936439 ^ (uint)SpawnerQueryEntity.Index * 7907);
                rng.InitState((uint)Time.frameCount * 3889 ^ 1851936439 ^ (uint)SpawnerQueryEntity.Index * 7907);
                rng.InitState((uint)Time.frameCount * 3889 ^ 1851936439 ^ (uint)SpawnerQueryEntity.Index * 7907);
                int Index = 0;
                for (; (Index < SpawnerQueryEnterLogoSpawner.InstanceCount); Index++)
                {
                    Unity.Entities.Entity entity = PostUpdateCommands.Instantiate(
                        SpawnerQueryEnterLogoSpawner.PrefabEntity);
                    PostUpdateCommands.SetComponent <LogoPosition>(
                        entity,
                        new LogoPosition {
                        Value = new Unity.Mathematics.float3 {
                            x = rng.NextFloat(
                                graphData.range.x,
                                graphData.range.y), y = rng.NextFloat(
                                graphData.range.x,
                                graphData.range.y), z = rng.NextFloat(
                                graphData.range.x,
                                graphData.range.y)
                        }
                    });
                }
            }

                                                     );
        }

        PostUpdateCommands.AddComponent(SpawnerQueryEnter, typeof(SpawnerQueryTracking));
    }
コード例 #26
0
    public static void RandomPointsOnCircle(float3 center, float3 range, ref NativeArray <float3> positions, ref NativeArray <quaternion> rotations)
    {
        var count = positions.Length;

        // initialize the seed of the random number generator
        Unity.Mathematics.Random random = new Unity.Mathematics.Random();
        random.InitState(10);
        for (int i = 0; i < count; i++)
        {
            positions[i] = center + random.NextFloat3(-range, range);
            rotations[i] = random.NextQuaternionRotation();
        }
    }
コード例 #27
0
        protected override void OnUpdate()
        {
            if (_mapLoad || GameManager.GameConfig == null)
            {
                return;
            }

            _mapLoad = true;

            var rng = new Unity.Mathematics.Random();

            rng.InitState((uint)DateTime.UtcNow.Ticks);

            var entityManager = World.Active.EntityManager;
            var blockEntities = new NativeArray <Entity>(GameManager.GameConfig.TerrainSize * GameManager.GameConfig.TerrainSize * 3, Allocator.Temp);

            entityManager.CreateEntity(GameManager.BlockArchetype, blockEntities);

            var index = 0;

            var offsets = new float3((1f - GameManager.GameConfig.HighTreeRatio), (1f - GameManager.GameConfig.HighTreeRatio - GameManager.GameConfig.TreeRatio), (1f - GameManager.GameConfig.HighTreeRatio - GameManager.GameConfig.TreeRatio - GameManager.GameConfig.RockRatio));

            for (var x = 0; x < GameManager.GameConfig.TerrainSize; x++)
            {
                for (var y = 0; y < GameManager.GameConfig.TerrainSize; y++)
                {
                    var rndResult = rng.NextFloat();
                    var blockType = BlockType.LAND;
                    if (rndResult > offsets[0])
                    {
                        blockType = BlockType.HIGHTREE;
                    }
                    else if (rndResult > offsets[1])
                    {
                        blockType = BlockType.TREE;
                    }
                    else if (rndResult > offsets[2])
                    {
                        blockType = BlockType.ROCK;
                    }

                    for (var level = 0; level < 3; level++)
                    {
                        _CreateBlock(entityManager, blockEntities[index], blockType, level, new int2(x, y));
                        index++;
                    }
                }
            }

            blockEntities.Dispose();
        }
コード例 #28
0
    protected override JobHandle OnUpdate(JobHandle deps)
    {
        Random rnd = new Random();

        rnd.InitState((uint)(UnityEngine.Random.value * uint.MaxValue));
        return(new ParallaxJob {
            topBound = topBound,
            bottomBound = bottomBound,
            leftBound = leftBound,
            rightBound = rightBound,
            dt = Time.deltaTime,
            rnd = rnd
        }.Schedule(parallaxParticles, deps));
    }
コード例 #29
0
ファイル: MeteorManager.cs プロジェクト: maku693/fmttm
    void OnEnable()
    {
        var meteors = GetComponentsInChildren <Meteor>();

        foreach (var meteor in meteors)
        {
            Destroy(meteor.gameObject);
        }
        _meteorSpeed   = meteorSpeed;
        _spawnInterval = spawnInterval;
        lastSpawnedAt  = Time.time;
        random.InitState((uint)DateTime.Now.ToBinary());
        SpawnMeteor();
    }
コード例 #30
0
        void SpawnSphere()
        {
            BlobAssetReference <Collider> sourceCollider = entityManager.GetComponentData <PhysicsCollider>(sourceEntity).Value;

            Unity.Mathematics.Random random = new Unity.Mathematics.Random();
            random.InitState(10);
            for (int i = 0; i < spawnCount; i++)
            {
                var instance = entityManager.Instantiate(sourceEntity);
                entityManager.SetComponentData(instance, new Translation {
                    Value = center + random.NextFloat3(-range, range)
                });
            }
        }