protected override void OnUpdate()
    {
        var units     = _entityQuery.ToComponentDataArray <Unit>(Allocator.TempJob);
        var movements = _entityQuery.ToComponentDataArray <UnitMovement>(Allocator.TempJob);

        var entities = _entityQuery.ToEntityArray(Allocator.TempJob);

        for (var i = 0; i < units.Length; i++)
        {
            PostUpdateCommands.AddComponent <Initialized>(entities[i]);

            var unit = units[i];
            var move = movements[i];

            if (_mapDataSystem.MapData.TryGetValue(move.CurrentCellCoord, out var cellData))
            {
                cellData.ContentType   = CellContentTypes.UNIT;
                cellData.Fraction      = unit.Fraction;
                cellData.ContentEntity = entities[i];

                _mapDataSystem.MapData[move.CurrentCellCoord] = cellData;
            }
            else
            {
                Debug.LogError("MapData for unit coord not found::" + move.CurrentCellCoord);
            }
        }

        _entityQuery.CopyFromComponentDataArray(units);
        _entityQuery.CopyFromComponentDataArray(movements);

        units.Dispose();
        movements.Dispose();
        entities.Dispose();
    }
Ejemplo n.º 2
0
    protected override void OnUpdate()
    {
        var playerArmatures  = eq.ToComponentArray <UnityArmatureComponent>();
        var playerTransforms = eq.ToComponentDataArray <Translation>(Unity.Collections.Allocator.TempJob);
        var playerScales     = eq.ToComponentDataArray <NonUniformScale>(Unity.Collections.Allocator.TempJob);
        var playerTransform  = playerTransforms[0];
        var playerScale      = playerScales[0];

        if (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.D))
        {
            if (!playerArmatures[0].animation.isPlaying)
            {
                playerArmatures[0].animation.Play("walk");
            }
        }
        else
        {
            playerArmatures[0].animation.Play("walk");
            playerArmatures[0].animation.Stop();
        }
        if (Input.GetKeyDown(KeyCode.A))
        {
            playerScale.Value = new float3(1, 1, 1);
        }
        if (Input.GetKeyDown(KeyCode.D))
        {
            playerScale.Value = new Vector3(-1, 1, 1);
        }
        if (Input.GetKey(KeyCode.A))
        {
            Debug.Log("A按下");
            playerTransform.Value = new Vector3(playerTransform.Value.x - 3f * Time.DeltaTime, playerTransform.Value.y, 1);
        }
        if (Input.GetKey(KeyCode.D))
        {
            Debug.Log("D按下");
            playerTransform.Value = new Vector3(playerTransform.Value.x + 3f * Time.DeltaTime, playerTransform.Value.y, 1);
        }
        if (Input.GetKey(KeyCode.W))
        {
            Debug.Log("W按下");
            playerTransform.Value = new Vector3(playerTransform.Value.x, playerTransform.Value.y + 3f * Time.DeltaTime, 1);
        }
        if (Input.GetKey(KeyCode.S))
        {
            Debug.Log("D按下");
            playerTransform.Value = new Vector3(playerTransform.Value.x, playerTransform.Value.y - 3f * Time.DeltaTime, 1);
        }
        //存一下
        playerTransforms[0] = playerTransform;

        playerScales[0] = playerScale;
        eq.CopyFromComponentDataArray(playerTransforms);
        eq.CopyFromComponentDataArray(playerScales);
        playerTransforms.Dispose();
        playerScales.Dispose();
    }
        protected override void OnUpdate()
        {
            var players = _playerEntityQuery.ToComponentDataArray <PlayerComponent>(Allocator.TempJob);

            int playerScore = -1;

            if (players.Length > 0)
            {
                playerScore = players[0].Score;
            }

            var labels = _entityQuery.ToComponentArray <TextMeshProUGUI>();
            var scores = _entityQuery.ToComponentDataArray <PlayerScore>(Allocator.TempJob);

            for (var i = 0; i < labels.Length; i++)
            {
                var score = scores[i];

                if (playerScore > 0 && score.Score != playerScore)
                {
                    score.Score    = playerScore;
                    labels[i].text = score.Score.ToString("0000");
                    scores[i]      = score;
                }
            }

            _entityQuery.CopyFromComponentDataArray(scores);

            scores.Dispose();
            players.Dispose();
        }
Ejemplo n.º 4
0
        protected override void OnUpdate()
        {
            var postTriggers = _entityQuery.ToComponentDataArray <PostDestroyTrigger>(Allocator.TempJob);
            var entities     = _entityQuery.ToEntityArray(Allocator.TempJob);

            for (var i = 0; i < postTriggers.Length; i++)
            {
                var postTrigger = postTriggers[i];

                postTrigger.SkipFrames -= 1;

                if (postTrigger.SkipFrames < 0)
                {
                    if (_triggerInitSystem.ColliderToTriggerEntity.ContainsKey(postTriggers[i].TriggerId))
                    {
                        _triggerInitSystem.ColliderToTriggerEntity.Remove(postTriggers[i].TriggerId);
                        PostUpdateCommands.RemoveComponent <PostDestroyTrigger>(entities[i]);
                        PostUpdateCommands.DestroyEntity(entities[i]);
                    }
                }

                postTriggers[i] = postTrigger;
            }

            _entityQuery.CopyFromComponentDataArray(postTriggers);

            postTriggers.Dispose();
            entities.Dispose();
        }
Ejemplo n.º 5
0
        protected override void OnUpdate()
        {
            var sparks   = _entityQuery.ToComponentDataArray <SimpleSpark>(Allocator.TempJob);
            var entities = _entityQuery.ToEntityArray(Allocator.TempJob);

            var dt = Time.DeltaTime;

            for (var i = 0; i < sparks.Length; i++)
            {
                var spark = sparks[i];

                spark.Timer += dt;

                if (spark.Timer > spark.DestroyDelay)
                {
                    PostUpdateCommands.DestroyEntity(entities[i]);
                }

                sparks[i] = spark;
            }

            _entityQuery.CopyFromComponentDataArray(sparks);

            sparks.Dispose();
            entities.Dispose();
        }
Ejemplo n.º 6
0
        protected override void OnUpdate()
        {
            NativeArray <CameraPos>   camreaPoses  = m_queryCamera.ToComponentDataArray <CameraPos>(Allocator.TempJob);
            NativeArray <Translation> translations = m_query.ToComponentDataArray <Translation>(Allocator.TempJob);

            var cameraPos = camreaPoses[0];

            float allX = 0;

            for (int i = 0; i < translations.Length; i++)
            {
                var charaPos = translations[i];
                allX += charaPos.Value.x;
            }
            allX /= translations.Length;

            int ScreenWidthHalf = Settings.Instance.DrawPos.ScreenWidth >> 1;
            int minX            = ScreenWidthHalf;
            int maxX            = (int)Shared.m_mapMeshMat.m_sizeX - ScreenWidthHalf;
            int cameraY         = Shared.m_mapMeshMat.m_sizeYHalf;

            cameraPos.m_position = math.clamp(allX, minX, maxX);

            Camera.main.transform.position = new Vector3(cameraPos.m_position, cameraY, 0);
            camreaPoses[0] = cameraPos;
            m_queryCamera.CopyFromComponentDataArray(camreaPoses);
            translations.Dispose();
            camreaPoses.Dispose();
        }
        protected override void OnUpdate()
        {
            var effects    = _entityQuery.ToComponentDataArray <TriggerEffectVfxComponent>(Allocator.TempJob);
            var entities   = _entityQuery.ToEntityArray(Allocator.TempJob);
            var transforms = _entityQuery.ToComponentArray <Transform>();

            for (var i = 0; i < effects.Length; i++)
            {
                var effect = effects[i];

                if (!effect.Used)
                {
                    effect.Used = true;

                    var vfxEntity = EntityManager.Instantiate(effect.VfxPrefab);

                    var pos = transforms[i].position;
                    EntityManager.SetComponentData(vfxEntity, new Translation
                    {
                        Value = new float3(pos.x, pos.y, pos.z + effect.DepthDelta)
                    });

                    var particleSystem = EntityManager.GetComponentObject <ParticleSystem>(vfxEntity);

                    particleSystem.Play();
                }

                effects[i] = effect;
            }

            _entityQuery.CopyFromComponentDataArray(effects);

            effects.Dispose();
            entities.Dispose();
        }
    protected override void OnUpdate()
    {
        //todo system to process player selection changes (player selected visual changes)

        var unitControllers = _entityQuery.ToComponentDataArray <UnitController>(Allocator.TempJob);

        for (int i = 0; i < unitControllers.Length; i++)
        {
            var unitController = unitControllers[i];

            if (!unitController.SelectionEnabled)
            {
                unitController.SelectionEnabled = true;

                var selection = EntityManager.GetComponentObject <SpriteRenderer>(unitController.SelectionEntity);
                selection.enabled = true;
            }

            unitControllers[i] = unitController;
        }

        _entityQuery.CopyFromComponentDataArray(unitControllers);

        unitControllers.Dispose();
    }
Ejemplo n.º 9
0
        protected override void OnUpdate()
        {
            Entities
            .WithAllReadOnly <Level, WidgetsVisible, LocalToWorld>()
            .ForEach((Entity levelEntity, ref WidgetsVisible widgetsVisible, ref LocalToWorld levelLocalToWorld) =>
            {
                _getVerticesVisible.SetSharedComponentFilter(EntityManager.GetWithinLevel(levelEntity));

                var vertices        = _getVerticesVisible.ToComponentDataArray <Vertex>(Allocator.TempJob);
                var localToWorlds   = _getVerticesVisible.ToComponentDataArray <LocalToWorld>(Allocator.TempJob);
                var renderBoundsArr = _getVerticesVisible.ToComponentDataArray <RenderBounds>(Allocator.TempJob);

                // TODO
                var xScale = (1f / 64f) / math.length(levelLocalToWorld.Value.c0);

                for (var i = 0; i < vertices.Length; ++i)
                {
                    var vertex       = vertices[i];
                    var localToWorld = localToWorlds[i];
                    var renderBounds = renderBoundsArr[i];

                    var translation    = new float3(vertex.X, (vertex.MinY + vertex.MaxY) * 0.5f, vertex.Z);
                    var scale          = new float3(1f * xScale, (vertex.MaxY - vertex.MinY) * 0.5f, 1f * xScale);
                    var localTransform = float4x4.TRS(translation, quaternion.identity, scale);
                    var finalTransform = math.mul(levelLocalToWorld.Value, localTransform);

                    localToWorld.Value = finalTransform;

                    renderBounds.Value = new AABB
                    {
                        Center  = float3.zero,
                        Extents = scale
                    };

                    localToWorlds[i]   = localToWorld;
                    renderBoundsArr[i] = renderBounds;
                }

                _getVerticesVisible.CopyFromComponentDataArray(localToWorlds);
                _getVerticesVisible.CopyFromComponentDataArray(renderBoundsArr);

                vertices.Dispose();
                renderBoundsArr.Dispose();
                localToWorlds.Dispose();
            });
        }
            protected override void OnUpdate()
            {
                var data  = m_Group.ToComponentDataArray <EcsTestData>(Allocator.TempJob);
                var data2 = m_Group.ToComponentDataArray <EcsTestData2>(Allocator.TempJob);

                for (int i = 0; i < data.Length; ++i)
                {
                    var d2 = data2[i];
                    d2.value0 = 10;
                    data2[i]  = d2;
                }

                m_Group.CopyFromComponentDataArray(data);
                m_Group.CopyFromComponentDataArray(data2);

                data.Dispose();
                data2.Dispose();
            }
Ejemplo n.º 11
0
        protected override void OnUpdate()
        {
            var detectors  = _entityQuery.ToComponentDataArray <DetectorComponent>(Allocator.TempJob);
            var colliders  = _entityQuery.ToComponentArray <BoxCollider2D>();
            var transforms = _entityQuery.ToComponentArray <Transform>();

            var entities = _entityQuery.ToEntityArray(Allocator.TempJob);

            for (var i = 0; i < detectors.Length; i++)
            {
                var detector  = detectors[i];
                var transform = transforms[i];
                var collider  = colliders[i];

                var count = Physics2D.OverlapBoxNonAlloc(transform.position, collider.size, transform.rotation.eulerAngles.z, _colliders,
                                                         _triggerMask);

                detector.TriggersCount = count;

                var triggerIds = new NativeArray <int>(count, Allocator.Temp);

                for (int j = 0; j < count; j++)
                {
                    triggerIds[j] = _colliders[j].GetInstanceID();
                }

                int triggersHash = Utils.CombineHashCodes(triggerIds);

                if (detector.TriggersHash != triggersHash)
                {
                    detector.TriggersHash = triggersHash;

                    DynamicBuffer <ColliderId> buffer = EntityManager.GetBuffer <ColliderId>(entities[i]);

                    buffer.Clear();

                    for (var index = 0; index < triggerIds.Length; index++)
                    {
                        int id = triggerIds[index];
                        buffer.Add(new ColliderId {
                            Value = id
                        });
                    }
                }

                detectors[i] = detector;

                triggerIds.Dispose();
            }

            _entityQuery.CopyFromComponentDataArray(detectors);

            entities.Dispose();
            detectors.Dispose();
        }
        protected override void OnUpdate()
        {
            entityCommandBufferSystem.CreateCommandBuffer().AsParallelWriter();

            EntityQuery entitiesWithoutTargetComponent = GetEntityQuery(
                new EntityQueryDesc()
            {
                None = new ComponentType[] { typeof(GeometryDataModels.Target) },
            }

                );

            if (entitiesWithoutTargetComponent.CalculateEntityCount() != 0)
            {
                var entitiesWithOutComponent = entitiesWithoutTargetComponent.ToEntityArray(Allocator.TempJob);
                entityManager.AddComponent <GeometryDataModels.Target>(entitiesWithOutComponent);
                entitiesWithOutComponent.Dispose();
            }

            entityQuery = GetEntityQuery(typeof(Translation), typeof(GeometryDataModels.Target));

            var job2 = new ModifyTargets()
            {
                targets      = entityQuery.ToComponentDataArray <GeometryDataModels.Target>(Allocator.TempJob),
                translations = entityQuery.ToComponentDataArray <Translation>(Allocator.TempJob),
                entities     = entityQuery.ToEntityArray(Allocator.TempJob),
            };

            this.Dependency = job2.Schedule(job2.targets.Length, 6);
            this.Dependency.Complete();

            entityQuery.CopyFromComponentDataArray <Translation>(job2.translations);
            entityQuery.CopyFromComponentDataArray <GeometryDataModels.Target>(job2.targets);

            entityCommandBufferSystem.AddJobHandleForProducer(Dependency);
            currentObjectCount = entityQuery.CalculateEntityCount();


            job2.translations.Dispose();
            job2.targets.Dispose();
            job2.entities.Dispose();
        }
Ejemplo n.º 13
0
    protected override void OnUpdate()
    {
        var waterParts = _entityQuery.ToComponentDataArray <WaterMeshComponent>(Allocator.TempJob);
        var entities   = _entityQuery.ToEntityArray(Allocator.TempJob);

        MeshFilter[] meshes = _entityQuery.ToComponentArray <MeshFilter>();

        EntityArchetype waterPointArchetype = EntityManager.CreateArchetype(typeof(WaterPoint));

        for (var i = 0; i < waterParts.Length; i++)
        {
            _vertices = new Vector3[waterParts.Length][];

            WaterMeshComponent waterMeshComponent = waterParts[i];

            waterMeshComponent.PartId = i;

            MeshFilter meshFilter = meshes[i];

            int pointCount = Mathf.FloorToInt(waterMeshComponent.Size.x / waterMeshComponent.Step);

            meshFilter.mesh = GenerateWaterMesh(pointCount, waterMeshComponent.Step, waterMeshComponent.Size.y,
                                                waterMeshComponent.BottomColor, waterMeshComponent.TopColor);

            _vertices[i] = new Vector3[meshFilter.mesh.vertexCount];

            float height = meshFilter.mesh.vertices[1].y;

            waterMeshComponent.PointsRange = new int2(_pointIndex, _pointIndex + pointCount);

            _pointIndex += pointCount;

            for (int j = 0; j < pointCount; j++)
            {
                Entity entity = EntityManager.CreateEntity(waterPointArchetype);

                var waterPoint = new WaterPoint {
                    PartId = i, TargetHeight = height
                };

                EntityManager.SetComponentData(entity, waterPoint);
            }

            waterParts[i] = waterMeshComponent;

            PostUpdateCommands.AddComponent(entities[i], new Initialized());
        }

        _entityQuery.CopyFromComponentDataArray(waterParts);

        entities.Dispose();
        waterParts.Dispose();
    }
Ejemplo n.º 14
0
        protected override void OnUpdate()
        {
            var padScans = m_query.ToComponentDataArray <PadScan>(Allocator.TempJob);

            for (int i = 0; i < padScans.Length; i++)
            {
                var padScan = padScans[i];
                SetCross(ref padScan, i);
                SetButton(ref padScan, i);
                padScans[i] = padScan;
            }
            m_query.CopyFromComponentDataArray(padScans);
            padScans.Dispose();
        }
Ejemplo n.º 15
0
        protected override void OnUpdate()
        {
            NativeArray <FollowCam>   CamArray      = CameraQuery.ToComponentDataArray <FollowCam>(Allocator.TempJob);
            NativeArray <Translation> CamTransArray = CameraQuery.ToComponentDataArray <Translation>(Allocator.TempJob);

            if (CamArray.Length <= 0 || CamTransArray.Length <= 0)
            {
                CamArray.Dispose();
                CamTransArray.Dispose();
                return;
            }


            for (int EntityNum = 0; EntityNum < CamArray.Length; EntityNum++)
            {
                Translation TargetTrans = EntityManager.GetComponentData <Translation>(CamArray[EntityNum].TargetEntity);

                if (CamArray[EntityNum].LastHigher <= TargetTrans.Value.y)
                {
                    var Cam   = CamArray[EntityNum];
                    var Trans = CamTransArray[EntityNum];

                    Cam.LastHigher = TargetTrans.Value.y;
                    Trans.Value.y  = TargetTrans.Value.y + Cam.Offset;

                    CamTransArray[EntityNum] = Trans;
                    CamArray[EntityNum]      = Cam;
                }
            }

            //あくまでもToDataArrayで取得できるArrayはキャッシュの様なものなので、本Entityに書き込む必要があります。
            CameraQuery.CopyFromComponentDataArray(CamArray);
            CameraQuery.CopyFromComponentDataArray(CamTransArray);

            CamArray.Dispose();
            CamTransArray.Dispose();
        }
Ejemplo n.º 16
0
        protected override void OnUpdate()
        {
            var fieldScans   = m_query.ToComponentDataArray <FieldScan>(Allocator.TempJob);
            var fieldBanishs = m_query.ToComponentDataArray <FieldBanish>(Allocator.TempJob);

            for (int i = 0; i < fieldScans.Length; i++)
            {
                var fieldScan = fieldScans[i];
                Scan(ref fieldScan);
                fieldScans[i] = fieldScan;
            }

            m_query.CopyFromComponentDataArray(fieldScans);

            fieldScans.Dispose();
            fieldBanishs.Dispose();
        }
    protected override void OnUpdate()
    {
        var nodes    = _entityQuery.ToComponentDataArray <Node>(Allocator.TempJob);
        var entities = _entityQuery.ToEntityArray(Allocator.TempJob);

        for (var i = 0; i < nodes.Length; i++)
        {
            var node = nodes[i];

            var x = node.Coord.x * 1.28f;
            var y = node.Coord.y * 1.28f;

            //Debug.DrawLine(new Vector3(x - 0.25f, y, -1), new Vector3(x + 0.25f, y, -1));

            //Debug.DrawLine(new Vector3(x, y - 0.25f, -1), new Vector3(x, y + 0.25f, -1));

            float width = 0.5f;

            Debug.DrawLine(new Vector3(x - width, y - width, -1), new Vector3(x + width, y - width, -1));
            Debug.DrawLine(new Vector3(x - width, y + width, -1), new Vector3(x + width, y + width, -1));

            Debug.DrawLine(new Vector3(x - width, y - width, -1), new Vector3(x - width, y + width, -1));
            Debug.DrawLine(new Vector3(x + width, y - width, -1), new Vector3(x + width, y + width, -1));

            DynamicBuffer <NodeLink> buffer = EntityManager.GetBuffer <NodeLink>(entities[i]);

            foreach (NodeLink nodeLink in buffer)
            {
                var lx = nodeLink.LinkedEntityCoord.x * 1.28f;
                var ly = nodeLink.LinkedEntityCoord.y * 1.28f;

                Debug.DrawLine(new Vector3(x, y, -1.1f), new Vector3(lx, ly, -1.1f), new Color(1f, 1f, 0, 0.1f));
            }
        }

        _entityQuery.CopyFromComponentDataArray(nodes);

        nodes.Dispose();
        entities.Dispose();
    }
        private void CopyFromComponentDataArray_Performance_LargeComponent(int entityCount, bool unique)
        {
            NativeArray <EntityArchetype> archetypes;

            if (unique)
            {
                archetypes = CreateUniqueArchetypes(entityCount, typeof(LargeComponent));
                for (int entIter = 0; entIter < entityCount; entIter++)
                {
                    m_Manager.CreateEntity(archetypes[entIter]);
                }
            }
            else
            {
                archetypes = CreateUniqueArchetypes(1, typeof(LargeComponent));
                m_Manager.CreateEntity(archetypes[0], entityCount);
            }

            archetypes.Dispose();

            EntityQuery query = default;

            query = m_Manager.CreateEntityQuery(ComponentType.ReadOnly(typeof(LargeComponent)));

            var result = query.ToComponentDataArray <LargeComponent>(Allocator.TempJob);

            Assert.AreEqual(entityCount, result.Length);

            Measure.Method(
                () => { query.CopyFromComponentDataArray(result); })
            .SampleGroup("CopyFromComponentDataArray")
            .WarmupCount(1)     // make sure we're not timing job compilation on the first run
            .MeasurementCount(100)
            .Run();

            result.Dispose();
            query.Dispose();
        }
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        var tileMap   = q_tileMap.ToComponentDataArray <Tile>(Allocator.TempJob);
        var Resources = q_Resources.ToComponentDataArray <Resource>(Allocator.TempJob);
        var resourceGatherBuilding = q_resourceGatherBuilding.ToComponentDataArray <ResourceGatherBuilding>(Allocator.TempJob);
        var countDown       = q_resourceGatherBuilding.ToComponentDataArray <CountdownTimer>(Allocator.TempJob);
        var buildings       = q_resourceGatherBuilding.ToComponentDataArray <Building>(Allocator.TempJob);
        var resourceStorage = q_resourceStorage.ToComponentDataArray <ResourceStorage>(Allocator.TempJob);

        var buildingGatherJob = new BuildingGatherJob
        {
            tileMap         = tileMap,
            tilesPerWidth   = TerrainSystem.tilesPerWidth,
            tileWidth       = TerrainSystem.tileWidth,
            r               = Resources,
            b               = resourceGatherBuilding,
            c               = countDown,
            building        = buildings,
            resourceStorage = resourceStorage,
        }.Schedule();

        buildingGatherJob.Complete();


        q_Resources.CopyFromComponentDataArray(Resources);
        q_resourceGatherBuilding.CopyFromComponentDataArray(countDown);
        q_resourceStorage.CopyFromComponentDataArray(resourceStorage);


        tileMap.Dispose();
        Resources.Dispose();
        resourceGatherBuilding.Dispose();
        countDown.Dispose();
        buildings.Dispose();
        resourceStorage.Dispose();

        return(buildingGatherJob);
    }
    protected override void OnUpdate()
    {
        var ripples    = _entityQuery.ToComponentDataArray <WaterRipplesComponent>(Allocator.TempJob);
        var waterParts = _entityQuery.ToComponentDataArray <WaterMeshComponent>(Allocator.TempJob);
        var points     = _pointsQuery.ToComponentDataArray <WaterPoint>(Allocator.TempJob);

        float dt = Time.DeltaTime;

        for (var i = 0; i < ripples.Length; i++)
        {
            var waterRipples = ripples[i];

            waterRipples.Timer += dt;

            if (waterRipples.Timer > 1f / waterRipples.Freq)
            {
                waterRipples.Timer = 0;

                int pointId = Random.Range(waterParts[i].PointsRange.x, waterParts[i].PointsRange.y);

                var point = points[pointId];

                point.Velocity = Random.Range(waterRipples.Power.x, waterRipples.Power.y);

                points[pointId] = point;
            }

            ripples[i] = waterRipples;
        }

        _entityQuery.CopyFromComponentDataArray(ripples);
        _pointsQuery.CopyFromComponentDataArray(points);

        waterParts.Dispose();
        ripples.Dispose();
        points.Dispose();
    }
Ejemplo n.º 21
0
        protected override void OnUpdate()
        {
            var detectors = _entityQuery.ToComponentDataArray <DetectorComponent>(Allocator.TempJob);
            var colliders = _entityQuery.ToComponentArray <BoxCollider2D>();
            var entities  = _entityQuery.ToEntityArray(Allocator.TempJob);

            for (var i = 0; i < detectors.Length; i++)
            {
                DetectorComponent detector = detectors[i];

                detector.DetectorId = colliders[i].GetInstanceID();

                detectors[i] = detector;

                PostUpdateCommands.AddComponent(entities[i], new Initialized());

                EntityManager.AddBuffer <ColliderId>(entities[i]);
            }

            _entityQuery.CopyFromComponentDataArray(detectors);

            entities.Dispose();
            detectors.Dispose();
        }
Ejemplo n.º 22
0
        protected override void OnUpdate()
        {
            var triggers  = _entityQuery.ToComponentDataArray <TriggerComponent>(Allocator.TempJob);
            var colliders = _entityQuery.ToComponentArray <BoxCollider2D>();
            var entities  = _entityQuery.ToEntityArray(Allocator.TempJob);

            for (var i = 0; i < triggers.Length; i++)
            {
                TriggerComponent trigger = triggers[i];

                trigger.TriggerId = colliders[i].GetInstanceID();

                triggers[i] = trigger;

                ColliderToTriggerEntity.TryAdd(colliders[i].GetInstanceID(), entities[i]);

                PostUpdateCommands.AddComponent(entities[i], new Initialized());
            }

            _entityQuery.CopyFromComponentDataArray(triggers);

            entities.Dispose();
            triggers.Dispose();
        }
    protected override void OnUpdate()
    {
        var entities          = _query.ToEntityArray(Allocator.TempJob);
        var exampleComponents = _query.ToComponentDataArray <ExampleComponent>(Allocator.TempJob);

        for (var i = 0; i < entities.Length; i++)
        {
            var exampleComponent = exampleComponents[i];
            var entity           = entities[i];

            exampleComponent.Time += Time.DeltaTime;

            if (DynamicBufferHashSet.Length <TestHashSetBufferElement>(EntityManager, entity) == 0 &&
                !exampleComponent.Remove && exampleComponent.Time > 3f && exampleComponent.Time < 5f)
            {
                DynamicBufferHashSet.TryAdd(EntityManager, entity, new TestHashSetBufferElement
                {
                    Value = 12345
                });
                DynamicBufferHashSet.TryAdd(EntityManager, entity, new TestHashSetBufferElement
                {
                    Value = 78901
                });
                DynamicBufferHashSet.TryAdd(EntityManager, entity, new TestHashSetBufferElement
                {
                    Value = 5674654
                });
            }

            if (exampleComponent.Remove)
            {
                DynamicBufferHashSet.TryRemove(EntityManager, entity, new TestHashSetBufferElement
                {
                    Value = 78901
                });
                DynamicBufferHashSet.TryRemove(EntityManager, entity, new TestHashSetBufferElement
                {
                    Value = 5674654
                });
            }

            if (exampleComponent.Time > 7f)
            {
                exampleComponent.Remove = true;
            }

            if (exampleComponent.Time > 10f && exampleComponent.Remove)
            {
                exampleComponent.Remove = false;
                exampleComponent.Check1 = DynamicBufferHashSet.Contains(EntityManager, entity, new TestHashSetBufferElement
                {
                    Value = 12345
                });
                exampleComponent.Check2 = DynamicBufferHashSet.Contains(EntityManager, entity, new TestHashSetBufferElement
                {
                    Value = 54321
                });
            }

            exampleComponents[i] = exampleComponent;
        }

        _query.CopyFromComponentDataArray(exampleComponents);

        entities.Dispose();
        exampleComponents.Dispose();
    }
Ejemplo n.º 24
0
    protected override void OnUpdate()
    {
        NativeArray <GageComponent> GageDatas = GageQuery.ToComponentDataArray <GageComponent>(Allocator.TempJob);

        var Input = EntityManager.World.GetExistingSystem <InputSystem>();

        if (GageDatas.Length <= 0)
        {
            GageDatas.Dispose();

            return;
        }

        bool InputButton = false;

        InputButton = Input.GetMouseButtonDown(0);

        Entities.With(GlassQuery).ForEach((ref RigidBody Rigid, ref GlassComponent GlassData) =>
        {
            if (GlassData.Active)
            {
                return;
            }

            float DltTime = World.TinyEnvironment().fixedFrameDeltaTime;
            if (GlassData.charging)
            {
                if (InputButton)
                {
                    GlassData.charging = false;
                    GlassData.Active   = true;
                    Rigid.Velocity.x  += GlassData.NowValue * 2.4f;
                }
                else
                {
                    GlassData.NowValue += GlassData.AddSpeed * DltTime * 3;

                    if (GlassData.NowValue >= GlassData.MaxValue)
                    {
                        GlassData.NowValue  = GlassData.MaxValue;
                        GlassData.AddSpeed *= -1;
                    }
                    else if (0 >= GlassData.NowValue)
                    {
                        GlassData.NowValue  = 0;
                        GlassData.AddSpeed *= -1;
                    }
                }
            }
            else
            {
                if (InputButton)
                {
                    GlassData.charging = true;
                    GlassData.NowValue = 0;
                    GlassData.AddSpeed = GlassData.AddSpeed < 0 ? GlassData.AddSpeed * -1 : GlassData.AddSpeed;
                }
            }

            var Tmp      = GageDatas[0];
            Tmp.NowValue = GlassData.NowValue;
            GageDatas[0] = Tmp;
        });

        GageQuery.CopyFromComponentDataArray(GageDatas);

        GageDatas.Dispose();
    }
Ejemplo n.º 25
0
        protected override void OnUpdate()
        {
            NativeArray <RigidBody>   RigidBodyArray   = RigidBodyQuery.ToComponentDataArray <RigidBody>(Allocator.TempJob);
            NativeArray <Translation> TranslationArray = RigidBodyQuery.ToComponentDataArray <Translation>(Allocator.TempJob);

            if (RigidBodyArray.Length <= 0 || TranslationArray.Length <= 0)
            {
                TranslationArray.Dispose();
                RigidBodyArray.Dispose();
                return;
            }

            float DeltaTime = World.TinyEnvironment().fixedFrameDeltaTime;

            for (int EntityNum = 0; EntityNum < RigidBodyArray.Length; EntityNum++)
            {
                RigidBody   NowRigidBody   = RigidBodyArray[EntityNum];
                Translation NowTranslation = TranslationArray[EntityNum];

                if (!NowRigidBody.IsActive)
                {
                    continue;
                }

                if (NowRigidBody.UseGravity)
                {
                    NowRigidBody.Velocity.y -= Gravity * DeltaTime;
                    if (NowRigidBody.Velocity.y < -2f)
                    {
                        NowRigidBody.Velocity.y = -2f;
                    }
                }

                if (NowRigidBody.ActiveVec.x)
                {
                    NowTranslation.Value.x += NowRigidBody.Velocity.x * DeltaTime;

                    NowRigidBody.Velocity.x *= (1 - NowRigidBody.Drag);

                    if (NowRigidBody.Velocity.x < 0.003)
                    {
                        NowRigidBody.Velocity.x = 0;
                    }
                }

                if (NowRigidBody.ActiveVec.y)
                {
                    NowTranslation.Value.y += NowRigidBody.Velocity.y * DeltaTime;
                }

                if (NowRigidBody.ActiveVec.z)
                {
                    NowTranslation.Value.z += NowRigidBody.Velocity.z * DeltaTime;
                }

                RigidBodyArray[EntityNum]   = NowRigidBody;
                TranslationArray[EntityNum] = NowTranslation;
            }

            //あくまでもToDataArrayで取得できるArrayはキャッシュの様なものなので、本Entityに書き込む必要があります。
            RigidBodyQuery.CopyFromComponentDataArray(RigidBodyArray);
            RigidBodyQuery.CopyFromComponentDataArray(TranslationArray);

            //NativeArrayはUnsafeな動的確保のため、自動で解放されません。
            //ちゃんと開放しましょう。
            TranslationArray.Dispose();
            RigidBodyArray.Dispose();
        }
Ejemplo n.º 26
0
        protected override void OnUpdate()
        {
            NativeArray <Entity>    KnifeEntitys      = KnifeQuery.ToEntityArray(Allocator.TempJob);
            NativeArray <KnifeTag>  KnifeTags         = KnifeQuery.ToComponentDataArray <KnifeTag>(Allocator.TempJob);
            NativeArray <RigidBody> KnifeRigidBodys   = KnifeQuery.ToComponentDataArray <RigidBody>(Allocator.TempJob);
            NativeArray <Entity>    SceneChangeEntity = SceneChangeButtonQuery.ToEntityArray(Allocator.TempJob);

            if (SceneChangeEntity.Length <= 0 || KnifeRigidBodys.Length <= 0 || KnifeEntitys.Length <= 0 || KnifeTags.Length <= 0)
            {
                SceneChangeEntity.Dispose();
                KnifeRigidBodys.Dispose();
                KnifeEntitys.Dispose();
                KnifeTags.Dispose();
                return;
            }

            Entities.With(TargetQuery).ForEach((Entity ThisEntity, ref Translation Ttrans) =>
            {
                var HitEntity = EntityManager.GetBuffer <HitBoxOverlap>(ThisEntity);
                for (int i = 0; i < KnifeEntitys.Length; i++)
                {
                    if (KnifeTags[i].ActiveTag == false)
                    {
                        continue;
                    }
                    bool HitResultFlag = false;

                    for (int k = 0; k < HitEntity.Length; k++)
                    {
                        if (KnifeEntitys[i] == HitEntity[k].otherEntity)
                        {
                            HitResultFlag = true;
                            break;
                        }
                    }

                    if (HitResultFlag == true)
                    {
                        var Tmp        = KnifeTags[i];
                        var Rigid      = KnifeRigidBodys[i];
                        Rigid.IsActive = false;
                        Tmp.ActiveTag  = false;
                        Tmp.ScoreUp    = true;
                        Entities.With(SceneChangeButtonQuery).ForEach((ref RectTransform CamData) =>
                        {
                            CamData.anchoredPosition.y = 0;
                        });
                        KnifeTags[i]       = Tmp;
                        KnifeRigidBodys[i] = Rigid;
                        var Config         = World.TinyEnvironment().GetConfigData <GameStateConfig>();

                        Config.IsActive = false;

                        World.TinyEnvironment().SetConfigData(Config);
                    }
                }
            });

            KnifeQuery.CopyFromComponentDataArray(KnifeTags);
            KnifeQuery.CopyFromComponentDataArray(KnifeRigidBodys);

            SceneChangeEntity.Dispose();
            KnifeRigidBodys.Dispose();
            KnifeEntitys.Dispose();
            KnifeTags.Dispose();
        }
        protected override void OnUpdate()
        {
            var pathes   = _entityQuery.ToComponentDataArray <Path>(Allocator.TempJob);
            var entities = _entityQuery.ToEntityArray(Allocator.TempJob);

            for (var i = 0; i < pathes.Length; i++)
            {
                var path = pathes[i];

                if (!path.InProgress && path.Reachable)
                {
                    DynamicBuffer <PathNode> buffer = EntityManager.GetBuffer <PathNode>(entities[i]);

                    foreach (PathNode nodeLink in buffer)
                    {
                        var x = nodeLink.Coord.x * 1.28f;
                        var y = nodeLink.Coord.y * 1.28f;

                        Debug.DrawLine(new Vector3(x - 0.15f, y + 0.15f, -1.1f), new Vector3(x + 0.15f, y - 0.15f, -1.1f), Color.cyan);

                        Debug.DrawLine(new Vector3(x + 0.15f, y + 0.15f, -1.1f), new Vector3(x - 0.15f, y - 0.15f, -1.1f), Color.cyan);
                    }

                    DynamicBuffer <DebugNode> debugBuffer = EntityManager.GetBuffer <DebugNode>(entities[i]);

                    for (var index = 0; index < Mathf.Clamp(PathfindingTest.DebugNodeIndexValue, 0, debugBuffer.Length); index++)
                    {
                        DebugNode debugNode = debugBuffer[index];
                        var       x         = debugNode.Coord.x * 1.28f;
                        var       y         = debugNode.Coord.y * 1.28f;

                        var px = debugNode.PrevCoord.x * 1.28f;
                        var py = debugNode.PrevCoord.y * 1.28f;

                        Debug.DrawLine(new Vector3(x - 0.1f, y + 0.1f, -1.1f), new Vector3(x + 0.1f, y - 0.1f, -1.1f), Color.magenta);

                        Debug.DrawLine(new Vector3(x + 0.1f, y + 0.1f, -1.1f), new Vector3(x - 0.1f, y - 0.1f, -1.1f), Color.magenta);

                        Debug.DrawLine(new Vector3(x + 0.1f, y + 0.1f, -1.1f), new Vector3(px - 0.1f, py - 0.1f, -1.1f), Color.magenta);
                    }
                }

                var sx = path.StartCoord.x * 1.28f;
                var sy = path.StartCoord.y * 1.28f;

                var gx = path.GoalCoord.x * 1.28f;
                var gy = path.GoalCoord.y * 1.28f;

                Debug.DrawLine(new Vector3(sx - 0.15f, sy, -1.3f), new Vector3(sx + 0.15f, sy, -1.3f), Color.red);

                Debug.DrawLine(new Vector3(sx, sy - 0.15f, -1.3f), new Vector3(sx, sy + 0.15f, -1.3f), Color.red);

                Debug.DrawLine(new Vector3(gx - 0.15f, gy, -1.3f), new Vector3(gx + 0.15f, gy, -1.3f), Color.blue);

                Debug.DrawLine(new Vector3(gx, gy - 0.15f, -1.3f), new Vector3(gx, gy + 0.15f, -1.3f),
                               Color.blue);
            }

            _entityQuery.CopyFromComponentDataArray(pathes);

            pathes.Dispose();
            entities.Dispose();
        }
Ejemplo n.º 28
0
        protected override void OnUpdate()
        {
            NativeArray <ChangeTitleSceneTag> ChangeButtonsEnt = SceneChangeButtonQuery.ToComponentDataArray <ChangeTitleSceneTag>(Allocator.TempJob);
            NativeArray <PointerInteraction>  ChangeButtons    = SceneChangeButtonQuery.ToComponentDataArray <PointerInteraction>(Allocator.TempJob);
            NativeArray <RectTransform>       MoveButtonTrans  = SceneChangeButtonQuery.ToComponentDataArray <RectTransform>(Allocator.TempJob);
            NativeArray <EmitterComp>         EmitComp         = EmitCompQuery.ToComponentDataArray <EmitterComp>(Allocator.TempJob);

            NativeArray <Entity> TargetEntity    = TargetQuery.ToEntityArray(Allocator.TempJob);
            NativeArray <Entity> GuideLineEntity = GuideLineQuery.ToEntityArray(Allocator.TempJob);

            if (MoveButtonTrans.Length <= 0 || ChangeButtonsEnt.Length <= 0 ||
                ChangeButtons.Length <= 0 || TargetEntity.Length <= 0 ||
                GuideLineEntity.Length <= 0 || EmitComp.Length <= 0)
            {
                TargetEntity.Dispose();
                GuideLineEntity.Dispose();
                EmitComp.Dispose();
                MoveButtonTrans.Dispose();
                ChangeButtonsEnt.Dispose();
                ChangeButtons.Dispose();

                return;
            }

            for (int i = 0; i < ChangeButtons.Length; i++)
            {
                if (ChangeButtons[i].clicked == true)
                {
                    Entities.With(KnifeQuery).ForEach((ref Translation Ttrans, ref RigidBody Rigid, ref KnifeTag Tag) =>
                    {
                        Rigid.IsActive   = false;
                        Tag.ActiveTag    = true;
                        Tag.ScoreUp      = false;
                        Rigid.Velocity.y = 0;
                        Ttrans.Value.y   = 0;
                    });

                    Entities.With(CameraQuery).ForEach((ref FollowCam CamData, ref Translation Ttrans) =>
                    {
                        CamData.LastHigher = 0;
                        Ttrans.Value.y     = 0;
                    });

                    for (int EntityNum = 0; EntityNum < TargetEntity.Length; EntityNum++)
                    {
                        EntityManager.DestroyEntity(TargetEntity[EntityNum]);
                    }

                    for (int EntityNum = 0; EntityNum < GuideLineEntity.Length; EntityNum++)
                    {
                        EntityManager.DestroyEntity(GuideLineEntity[EntityNum]);
                    }

                    var Config = World.TinyEnvironment().GetConfigData <GameStateConfig>();

                    Config.IsActive = true;

                    World.TinyEnvironment().SetConfigData(Config);

                    var TmpEmitComp = EmitComp[0];

                    TmpEmitComp.LastEmitHigher = 0;

                    EmitComp[0] = TmpEmitComp;

                    var Tmp = MoveButtonTrans[i];
                    Tmp.anchoredPosition.y = 800;
                    MoveButtonTrans[i]     = Tmp;
                    break;
                }
            }

            SceneChangeButtonQuery.CopyFromComponentDataArray(MoveButtonTrans);
            EmitCompQuery.CopyFromComponentDataArray(EmitComp);

            TargetEntity.Dispose();
            GuideLineEntity.Dispose();
            EmitComp.Dispose();
            MoveButtonTrans.Dispose();
            ChangeButtonsEnt.Dispose();
            ChangeButtons.Dispose();
        }
Ejemplo n.º 29
0
        protected override void OnUpdate()
        {
            NativeArray <Translation> KnifeTrans = KnifeQuery.ToComponentDataArray <Translation>(Allocator.TempJob);

            NativeArray <Entity> PrefabEntity    = PrefabObjQuery.ToEntityArray(Allocator.TempJob);
            NativeArray <Entity> GuideLineEntity = GuideLineQuery.ToEntityArray(Allocator.TempJob);

            NativeArray <EmitterComp> EmitComponent = EmitCompQuery.ToComponentDataArray <EmitterComp>(Allocator.TempJob);

            if (PrefabEntity.Length <= 0 || EmitComponent.Length <= 0 || KnifeTrans.Length <= 0 || GuideLineEntity.Length <= 0)
            {
                GuideLineEntity.Dispose();
                PrefabEntity.Dispose();
                EmitComponent.Dispose();
                KnifeTrans.Dispose();
                return;
            }


            if (KnifeTrans[0].Value.y >= EmitComponent[0].LastEmitHigher)
            {
                var NowEmitComp = EmitComponent[0];

                Entity      EmitObj  = EntityManager.Instantiate(PrefabEntity[0]);
                Translation ObjTrans = EntityManager.GetComponentData <Translation>(EmitObj);
                ObjTrans.Value.y = NowEmitComp.LastEmitHigher + 5f;
                ObjTrans.Value.x = RandomData.NextInt(-3, 3);

                Entity      GuideObj   = EntityManager.Instantiate(GuideLineEntity[0]);
                Translation GuideTrans = EntityManager.GetComponentData <Translation>(GuideObj);

                GuideTrans.Value.y = ObjTrans.Value.y;
                GuideTrans.Value.x = 0;

                EntityManager.SetComponentData <Translation>(GuideObj, GuideTrans);

                WallComp NowWallComp = EntityManager.GetComponentData <WallComp>(EmitObj);

                NowWallComp.StartPos = 0;

                int SendSpeed = RandomData.NextInt(-4, 4);

                if (SendSpeed == 0)
                {
                    SendSpeed = 1;
                }

                NowWallComp.MoveSpeed = SendSpeed;

                EntityManager.SetComponentData <Translation>(EmitObj, ObjTrans);
                EntityManager.SetComponentData <WallComp>(EmitObj, NowWallComp);

                NowEmitComp.LastEmitHigher += 5f;
                EmitComponent[0]            = NowEmitComp;
            }

            EmitCompQuery.CopyFromComponentDataArray(EmitComponent);

            PrefabEntity.Dispose();
            EmitComponent.Dispose();
            KnifeTrans.Dispose();
            GuideLineEntity.Dispose();
        }
Ejemplo n.º 30
0
    protected override void OnUpdate()
    {
        var commandBuffer = m_EntityCommandBufferSystem.CreateCommandBuffer().AsParallelWriter();
        var spawner       = m_ProjectileSpawner.ToComponentDataArray <GeneralSpawner>(Allocator.TempJob);

        var SpawnJob = Entities.ForEach((Entity entity, int entityInQueryIndex, ref Weapon w, ref LocalToWorld t) =>
        {
            if (w.gotTarget == 1)
            {
                if (HasComponent <Target>(w.targetEntity))
                {
                    if (w.firingTimer == 0)
                    {
                        // FIRE!
                        var instance          = commandBuffer.Instantiate(entityInQueryIndex, spawner[0].projectile);
                        Projectile projectile = new Projectile
                        {
                            dst            = w.targetEntity,
                            dstVec         = t.Position, // default the destination vector to its starting position
                            speed          = w.projectileSpeed,
                            damage         = w.damage,
                            placedInBuffer = false,
                            targetHit      = false,
                            markForDestroy = false
                        };

                        commandBuffer.SetComponent(entityInQueryIndex, instance, projectile);
                        commandBuffer.SetComponent(entityInQueryIndex, instance, t);

                        w.firingTimer = w.firingRate;
                    }
                    else
                    {
                        w.firingTimer--;
                    }
                }
            }
        }).Schedule(Dependency);

        var targets        = m_targetQuery.ToComponentDataArray <Target>(Allocator.TempJob);
        var targetEntities = m_targetQuery.ToEntityArray(Allocator.TempJob);

        var UpdateLocationJob = Entities
                                .ForEach((Entity entity, int entityInQueryIndex, ref Projectile p) =>
        {
            if (targetEntities.Contains(p.dst))
            {
                p.dstVec = GetComponent <LocalToWorld>(p.dst).Position;
            }
        }).Schedule(SpawnJob);


        var MoveProjectileJob = Entities
                                .ForEach((Entity entity, int entityInQueryIndex, ref Projectile p, ref Translation t, ref Rotation r) =>
        {
            Vector3 currentPos = GetComponent <LocalToWorld>(entity).Position;

            float dist = math.distance(currentPos, p.dstVec);

            if (dist < 1)
            {
                if (targetEntities.Contains(p.dst))
                {
                    p.targetHit = true;
                }
                else
                {
                    p.markForDestroy = true;
                }
            }
            else
            {
                Vector3 newPos = Vector3.MoveTowards(currentPos, p.dstVec, p.speed);

                Quaternion r1 = r.Value;
                Vector3 dir   = Vector3.RotateTowards(r1 * Vector3.forward, currentPos - p.dstVec, 1000f, 0f);
                r.Value       = Quaternion.LookRotation(dir);
                t.Value       = newPos;
            }
        }).Schedule(UpdateLocationJob);


        var ProcessHitsJob = Entities
                             .ForEach((Entity entity, int entityInQueryIndex, ref Projectile p) =>
        {
            if (p.targetHit)
            {
                if (targetEntities.Contains(p.dst))
                {
                    int i = targetEntities.IndexOf <Entity>(p.dst);

                    Target t   = targets[i];
                    t.health  -= p.damage;
                    targets[i] = t;
                }
                p.markForDestroy = true;
            }
        }).Schedule(MoveProjectileJob);


        ProcessHitsJob.Complete();
        m_targetQuery.CopyFromComponentDataArray(targets);

        var DestroyProjectiles = Entities
                                 .ForEach((Entity entity, int entityInQueryIndex, in Projectile p) =>
        {
            if (p.markForDestroy)
            {
                commandBuffer.DestroyEntity(entityInQueryIndex, entity);
            }
        }).Schedule(ProcessHitsJob);

        DestroyProjectiles.Complete();

        NativeList <Vector3> deathLocations = new NativeList <Vector3>(Allocator.TempJob);

        var DestroyUnits = Entities
                           .ForEach((Entity entity, int entityInQueryIndex, in Target t, in LocalToWorld l, in SpaceShip s) =>
        {
            if (t.health <= 0)
            {
                deathLocations.Add(l.Position);
                commandBuffer.DestroyEntity(entityInQueryIndex, entity);
            }
        }).Schedule(ProcessHitsJob);