コード例 #1
0
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            var settings = GetSingleton <SettingsComponent>();

            var cachedEntities = new NativeArray <Entity>(settings.Width * settings.Height, Allocator.TempJob);

            var helper = new ArrayHelper(settings.Width, settings.Height);

            var cacheJob = new CacheJob
            {
                CachedEntities = cachedEntities,
                Entities       = _positionsQuery.ToEntityArray(Allocator.TempJob),
                Positions      = _positionsQuery.ToComponentDataArray <PositionComponent>(Allocator.TempJob),
                Helper         = helper
            };

            var destroyJob = new DestroyJob
            {
                CachedEntities    = cachedEntities,
                CommandBuffer     = _commandBuffer.CreateCommandBuffer(),
                ClickedComponents = _clickedQuery.ToComponentDataArray <ClickedComponent>(Allocator.TempJob),
                InGroup           = GetComponentDataFromEntity <InGroupComponent>(true),
                Helper            = helper,
                MinGroupSize      = settings.MinGroupSize
            };

            var jobHandle = cacheJob.Schedule(_positionsQuery.CalculateEntityCount(), 32, inputDeps);

            jobHandle = destroyJob.Schedule(jobHandle);

            _commandBuffer.AddJobHandleForProducer(jobHandle);

            return(jobHandle);
        }
コード例 #2
0
    void Start()
    {
        m_ParticleSystem = GetComponent <ParticleSystem>();

        var main             = m_ParticleSystem.main;
        int maxParticleCount = main.maxParticles;

        m_SortKeys = new NativeArray <SortKey>(maxParticleCount, Allocator.Persistent);

        m_CacheJob = new CacheJob
        {
            sortKeys = m_SortKeys,
        };

        m_SortJob = new SortJob
        {
            sortKeys = m_SortKeys
        };

        m_ConnectionsJob = new ConnectionsJob
        {
            sortKeys = m_SortKeys,
            distance = distance
        };

        m_Mesh = new Mesh();
    }
コード例 #3
0
    void Start()
    {
        m_ParticleSystem = GetComponent <ParticleSystem>();

        var main             = m_ParticleSystem.main;
        var collision        = m_ParticleSystem.collision;
        int maxParticleCount = main.maxParticles;

        m_SortKeys   = new NativeArray <SortKey>(maxParticleCount, Allocator.Persistent);
        m_Collisions = new NativeQueue <Collision>(Allocator.Persistent);

        m_CacheJob = new CacheJob
        {
            sortKeys = m_SortKeys,
        };

        m_SortJob = new SortJob
        {
            sortKeys = m_SortKeys
        };

        m_CollisionJob = new CollisionJob
        {
            sortKeys    = m_SortKeys,
            collisions  = m_Collisions.AsParallelWriter(),
            bounce      = collision.bounceMultiplier,
            radiusScale = collision.radiusScale,
            maxDiameter = main.startSize.constantMax * collision.radiusScale // TODO - handle different size curve modes and size over life if needed
        };

        m_ApplyCollisionsJob = new ApplyCollisionsJob
        {
            collisions = m_Collisions
        };
    }
コード例 #4
0
ファイル: SplitSystem.cs プロジェクト: xingchen1106/match3ecs
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            var settings = GetSingleton <GameBoardSettingsComponent>();

            if (_positionsQuery.CalculateEntityCount() != settings.Width * settings.Height)
            {
                return(inputDeps);
            }

            var cachedEntities = new NativeArray <Entity>(settings.Width * settings.Height, Allocator.TempJob);

            var helper = new ArrayToCoordinatesConverter(settings.Width, settings.Height);

            var cacheJob = new CacheJob
            {
                CachedEntities = cachedEntities,
                Entities       = _positionsQuery.ToEntityArray(Allocator.TempJob),
                Positions      = _positionsQuery.ToComponentDataArray <CellPositionComponent>(Allocator.TempJob),
                Helper         = helper
            };

            var splitJob = new SplitJob
            {
                CachedEntities = cachedEntities,
                CellType       = GetComponentDataFromEntity <CellTypeComponent>(true),
                Helper         = helper
            };

            var jobHandle = cacheJob.Schedule(_positionsQuery.CalculateEntityCount(), 32, inputDeps);

            jobHandle = splitJob.Schedule(jobHandle);

            return(jobHandle);
        }
コード例 #5
0
ファイル: MoveSystem.cs プロジェクト: Peng2017/ECS_Match3
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            var settings = GetSingleton <SettingsComponent>();

            if (_positionsQuery.CalculateEntityCount() == settings.Width * settings.Height)
            {
                return(inputDeps);
            }

            var helper = new ArrayHelper(settings.Width, settings.Height);

            var cachedEntities = new NativeArray <Entity>(settings.Width * settings.Height, Allocator.TempJob);

            var cacheJob = new CacheJob
            {
                CachedEntities = cachedEntities,
                Entities       = _positionsQuery.ToEntityArray(Allocator.TempJob),
                Positions      = _positionsQuery.ToComponentDataArray <PositionComponent>(Allocator.TempJob),
                Helper         = helper
            };

            var jobHandle = cacheJob.Schedule(_positionsQuery.CalculateEntityCount(), 32, inputDeps);

            var moveJob = new MoveJob
            {
                CachedEntities = cachedEntities,
                Position       = GetComponentDataFromEntity <PositionComponent>(),
                Helper         = helper
            };

            jobHandle = moveJob.Schedule(jobHandle);


            return(jobHandle);
        }
コード例 #6
0
        private void Job_LogAdded(CacheJob sender, string message)
        {
            if (!Dispatcher.CheckAccess())
            {
                Dispatcher.Invoke(() => Job_LogAdded(sender, message));
                return;
            }

            statusLabel.Content = message;
        }
コード例 #7
0
        private void Job_ProgressChanged(CacheJob sender, ProgressChangedEventArgs args)
        {
            if (!Dispatcher.CheckAccess())
            {
                Dispatcher.Invoke(() => Job_ProgressChanged(sender, args));
                return;
            }

            progressBar.Value = args.Progress;
        }
コード例 #8
0
        //private void Job_Started(CacheJob sender, EventArgs args)
        //{
        //	if (!Dispatcher.CheckAccess())
        //		Dispatcher.Invoke(() => Job_Started(sender, args));
        //}

        private void Job_Finished(CacheJob sender, EventArgs args)
        {
            if (!Dispatcher.CheckAccess())
            {
                Dispatcher.Invoke(() => Job_Finished(sender, args));
                return;
            }

            Destroy();
        }
コード例 #9
0
        /// <summary>
        ///     Creates a new user control for the job and adds it to the stackpanel
        /// </summary>
        private void RegisterNewJob(CacheJob sender, EventArgs args)
        {
            if (!Dispatcher.CheckAccess())
            {
                Dispatcher.Invoke(() => RegisterNewJob(sender, args));
                return;
            }

            var userControl = new CacheJobUserControl(sender);

            jobsStackPanel.Children.Add(userControl);
        }
コード例 #10
0
        public CacheJobUserControl(CacheJob job)
        {
            InitializeComponent();

            Job = job;

            //bind events to control
            job.ProgressChanged += Job_ProgressChanged;
            job.Finished        += Job_Finished;

            //job.Started += Job_Started;
            job.LogAdded += Job_LogAdded;
        }
コード例 #11
0
ファイル: SpawnerSystem.cs プロジェクト: auloff/match-3-ecs
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            var settings        = GetSingleton <SettingsComponent>();
            var singletonEntity = GetSingletonEntity <SettingsComponent>();

            if (_positionsQuery.CalculateEntityCount() == settings.Width * settings.Height)
            {
                return(inputDeps);
            }

            var helper = new ArrayHelper(settings.Width, settings.Height);

            var cachedEntities = new NativeArray <Entity>(settings.Width * settings.Height, Allocator.TempJob);
            var randomValues   = new NativeArray <int>(settings.Width * settings.Height, Allocator.TempJob);

            for (var i = 0; i < settings.Width * settings.Height; ++i)
            {
                randomValues[i] = Random.Range(0, settings.SetSize);
            }

            var cacheJob = new CacheJob
            {
                CachedEntities = cachedEntities,
                Entities       = _positionsQuery.ToEntityArray(Allocator.TempJob),
                Positions      = _positionsQuery.ToComponentDataArray <PositionComponent>(Allocator.TempJob),
                Helper         = helper
            };

            var spawnJob = new SpawnJob
            {
                CachedEntities  = cachedEntities,
                RandomValues    = randomValues,
                GemSet          = GetBufferFromEntity <GemSet>(true),
                CommandBuffer   = _commandBuffer.CreateCommandBuffer(),
                SingletonEntity = singletonEntity,
                Helper          = helper
            };

            var spawnHandler = cacheJob.Schedule(_positionsQuery.CalculateEntityCount(), 32, inputDeps);

            spawnHandler = spawnJob.Schedule(spawnHandler);

            _commandBuffer.AddJobHandleForProducer(spawnHandler);

            return(spawnHandler);
        }