public void Dispose() { if (m_World.IsCreated) { if (m_World.EntityManager.IsQueryValid(m_RootEntitiesQuery)) { m_RootEntitiesQuery.Dispose(); } if (m_World.EntityManager.IsQueryValid(m_ParentEntitiesQuery)) { m_ParentEntitiesQuery.Dispose(); } } m_SceneTagPerEntity.Dispose(); m_EntityNodes.Dispose(); m_SceneNodes.Dispose(); m_Versions.Dispose(); m_Parents.Dispose(); new FreeChildrenListsJob { ChildrenLists = m_Children.GetValueArray(Allocator.TempJob) }.Run(); m_Children.Dispose(); }
public void Dispose() { _LoadedScenesQuery.Dispose(); _UnloadedScenesQuery.Dispose(); m_PreviousScenes.Dispose(); m_PreviousRemovedScenes.Dispose(); }
/// <summary> /// 计算剩下的小球数量 /// </summary> void BallRemained() { EntityQuery EQ = EM.CreateEntityQuery(typeof(BallMoveSpeed)); ballCount = EQ.CalculateLength(); info.text = "Entities:" + ballCount.ToString(); EQ.Dispose(); }
public override void TearDown() { job1.Complete(); job2.Complete(); entityQuery.Dispose(); base.TearDown(); }
public void Dispose() { m_EntityDiffer.Dispose(); if (m_MainQuery != default && m_MainQuery != m_Hierarchy.World.EntityManager.UniversalQuery && m_Hierarchy.World.EntityManager.IsQueryValid(m_MainQuery)) { m_MainQuery.Dispose(); } foreach (var componentDataDiffer in m_ComponentDataDiffers) { componentDataDiffer.Dispose(); } foreach (var sharedComponentDataDiffer in m_SharedComponentDataDiffers) { sharedComponentDataDiffer.Dispose(); } }
public override void TearDown() { if (m_World.IsCreated) { entities1.Dispose(); entities2.Dispose(); entities3.Dispose(); group.Dispose(); } base.TearDown(); }
protected override void OnDestroy() { DeInitNative(wrapper); CPlusPlus.ReleaseHandleForEntityManager(wrapper); wrapper = IntPtr.Zero; groupAddTextBitmap.Dispose(); groupRemoveTextBitmap.Dispose(); groupRemoveGlyphHtml.Dispose(); groupInitializeBuffer.Dispose(); base.OnDestroy(); }
public override void TearDown() { if (m_Manager != null) { entities1.Dispose(); entities2.Dispose(); entities3.Dispose(); group.Dispose(); } base.TearDown(); }
public void Dispose() { if (World == null) { return; } MissingRenderDataQuery.Dispose(); MissingSceneQuery.Dispose(); BlobAssets.Dispose(); World.Dispose(); BlobAssetStore.Dispose(); }
private static void EditorApplicationOnPlayModeStateChanged(PlayModeStateChange obj) { if (obj == PlayModeStateChange.EnteredPlayMode) { m_partOwnerQuery = World.DefaultGameObjectInjectionWorld.EntityManager.CreateEntityQuery(typeof(PartOwner.InputState), typeof(PartOwner.RegistryAsset)); } if (obj == PlayModeStateChange.ExitingPlayMode) { m_partOwnerQuery.Dispose(); m_partOwnerQuery = null; } }
protected override void OnDestroy() { if (m_BeginConvertingRefCount > 0) { CleanupConversion(); } if (EntityManager.IsQueryValid(m_SceneSectionEntityQuery)) { m_SceneSectionEntityQuery.Dispose(); } m_JournalData.Dispose(); m_Dependencies.Dispose(); }
/// <summary> /// create materials based on the original object however make sure not to create two material with the same color /// to set up GPU instancing and to optimise performance /// </summary> public void AssignColors() { List <Color> colors = transformObjectToEntity.Colors; Dictionary <Color, Material> materials = transformObjectToEntity.Materials; Material material = transformObjectToEntity.Material; EntityQuery queryForChangingRenderMesh = _entityManager.CreateEntityQuery( ComponentType.ReadWrite <RenderMesh>(), ComponentType.ReadOnly <ObjectConvertedToEntity>()); NativeArray <Entity> entities = queryForChangingRenderMesh.ToEntityArray(Allocator.TempJob); for (int i = 0; i < entities.Length; i++) { RenderMesh renderMesh = _entityManager.GetSharedComponentData <RenderMesh>(entities[i]); RenderMesh newRenderMesh = new RenderMesh(); newRenderMesh.mesh = renderMesh.mesh; //check if a material with this color already exist is so assign this material if (materials.ContainsKey(colors[i])) { if (CheckIfMaterialExist(colors[i], materials, out var materialToAssign)) { newRenderMesh.material = materialToAssign; } else { Debug.LogError($"this key: {colors[i]}, does not exist"); } } //create a new material and add it to the dictionary of materials else { Material newMaterial = new Material(material); newMaterial.name = "material" + materials.Count; newMaterial.SetColor("_BaseColor", colors[i]); newRenderMesh.material = newMaterial; materials.Add(colors[i], newMaterial); } _entityManager.SetSharedComponentData(entities[i], newRenderMesh); } entities.Dispose(); queryForChangingRenderMesh.Dispose(); }
private void KillUnit(Entity unit) { EntityQuery thanatosQ = GetEntityQuery(typeof(SoulEater), typeof(HP), typeof(Attack)); if (thanatosQ.CalculateLength() > 0) { var thanatosA = thanatosQ.ToEntityArray(Allocator.TempJob); foreach (var thanatos in thanatosA) { var thanatosAttack = EntityManager.GetComponentData <Attack>(thanatos); var thanatosHP = EntityManager.GetComponentData <HP>(thanatos); PostUpdateCommands.SetComponent <Attack>(thanatos, new Attack() { amountOfCubes = thanatosAttack.amountOfCubes + 1, index = thanatosAttack.index, typeOfCubes = thanatosAttack.typeOfCubes }); PostUpdateCommands.SetComponent <HP>(thanatos, new HP() { startValue = thanatosHP.startValue, currentValue = thanatosHP.currentValue + 8 }); } thanatosA.Dispose(); thanatosQ.Dispose(); } int targetId = EntityManager.GetComponentData <Id>(unit).value; if (SquadsManagement.instance.userSquad.ContainsKey(targetId)) { SquadsManagement.instance.userSquad.Remove(targetId); SquadsManagement.instance.userScrollListContent.GetComponent <RectTransform>().sizeDelta = new Vector2(0, SquadsManagement.instance.userSquad.Count * 280); foreach (var card in SquadsManagement.instance.allCards) { if (SquadsManagement.instance.userSquad.ContainsKey(card.Key) && card.Value.transform.localPosition.y < SquadsManagement.instance.allCards[targetId].transform.localPosition.y) { card.Value.transform.localPosition += new Vector3(0, 280, 0); } } GameObject.Destroy(SquadsManagement.instance.allCards[targetId]); } PostUpdateCommands.RemoveComponent <Unit>(unit); PostUpdateCommands.RemoveComponent <Action>(unit); PostUpdateCommands.AddComponent(unit, new View() { frame = 0, state = 0 }); PostUpdateCommands.AddComponent(unit, new Dead() { }); PostUpdateCommands.AddComponent(unit, new UnitAnimation() { }); }
// 飞剑前往目标点 public void GetTargetModelPos(float3 pos) { Debug.Log("11"); EntityQueryDesc description = new EntityQueryDesc { None = new ComponentType[] { typeof(GoTag), typeof(TempEntityTag) }, All = new ComponentType[] { typeof(Rotation), ComponentType.ReadOnly <SwordTag>() } }; //获取飞剑群 EntityQuery entityQuery = _manager.CreateEntityQuery(description); NativeArray <Entity> newgroupArray = entityQuery.ToEntityArray(Allocator.Persistent); if (newgroupArray.Length < swordGroupAmount) { Debug.Log("当前长度:" + newgroupArray.Length); entityQuery.Dispose(); newgroupArray.Dispose(); return; } for (int i = 0; i < swordGroupAmount; i++) { //Translation aaa = _manager.GetComponentData<Translation>(newgroupArray[i]); //Entity temp = SpawnTempEntity(aaa.Value); float randomSpeed = UnityEngine.Random.Range(6f, 10f); Target target = new Target { isGo = true, Tpos = pos, // entity=temp }; } entityQuery.Dispose(); newgroupArray.Dispose(); }
public void OnPlayerDeath() { EntityManager entityManager = World.Active.EntityManager; EntityQuery enemies = entityManager.CreateEntityQuery(typeof(Enemy)); var enemyEntities = enemies.ToEntityArray(Allocator.TempJob); entityManager.DestroyEntity(enemyEntities); enemies.Dispose(); enemyEntities.Dispose(); PlayerEntity = null; playerInputBehaviour.SetPlayer(null); InitPlayer(); }
public void TearDown() { if (m_Manager != null) { entities1.Dispose(); entities2.Dispose(); entities3.Dispose(); group.Dispose(); m_World.Dispose(); m_World = null; World.Active = m_PreviousWorld; m_PreviousWorld = null; m_Manager = null; } }
public void SetNewWorld(World newWorld) { fullData.Clear(); FilteredData.Clear(); query?.Dispose(); if (newWorld == null) { world = null; query = null; return; } // Need to refresh the query. world = newWorld; query = world.EntityManager.CreateEntityQuery(ComponentType.ReadOnly <SpatialEntityId>()); }
public void CreateDuplicateFunc() { //set the position of the entities _whereToPlaceEntity += separationAmount; EntityQuery query = _entityManager.CreateEntityQuery(ComponentType.ReadOnly <ObjectConvertedToEntity>()); //create job responsible for creating duplicate CreateDuplicate job = new CreateDuplicate() { Entities = query.ToEntityArray(Allocator.TempJob), EntityPlacementPosition = _whereToPlaceEntity }; job.Execute(); query.Dispose(); }
public void Dispose() { if (m_World.IsCreated) { if (m_World.EntityManager.IsQueryValid(m_RootEntitiesQuery)) { m_RootEntitiesQuery.Dispose(); } if (m_World.EntityManager.IsQueryValid(m_ParentEntitiesQuery)) { m_ParentEntitiesQuery.Dispose(); } } m_SceneTagPerEntity.Dispose(); m_SceneNodes.Dispose(); }
public override void Unload() { m_EntityGuidToEntity.Dispose(); m_QueryGuids.Dispose(); m_QueryGuids = null; m_QueryConfigEntity.Dispose(); m_QueryConfigEntity = null; World.Dispose(); World = null; World.Active = m_LastActiveWorld; // Temporary fix for WordStorage instance leak if (WordStorage.Instance != null) { WordStorage.Instance.Dispose(); WordStorage.Instance = null; } }
void Update() { /// Entity Method m_sphrQuery = em.CreateEntityQuery(typeof(seekBoid)); NativeArray <Entity> nEnts = m_sphrQuery.ToEntityArray(Allocator.TempJob); for (int i = 0; i < nEnts.Length; ++i) { m_targetPosition[i] = em.GetComponentData <Translation>(nEnts[i]).Value; em.SetComponentData(nEnts[i], new TargetPosition() { Value = m_targetPosition[m_relationIndex[i]] }); m_arrSpheres[i].transform.position = m_targetPosition[m_relationIndex[i]]; } nEnts.Dispose(); m_sphrQuery.Dispose(); }
public void TooManySharedComponentsQuery() { var archetype = m_Manager.CreateArchetype( typeof(EcsTestData), typeof(SharedData1), typeof(SharedData2), typeof(SharedData3), typeof(SharedData4), typeof(SharedData5), typeof(SharedData6), typeof(SharedData7), typeof(SharedData8)); Entity e = m_Manager.CreateEntity(archetype); EntityQuery q = m_Manager.CreateEntityQuery(typeof(EcsTestData)); Assert.Throws <InvalidOperationException>(() => m_Manager.AddComponent <SharedData9>(q)); q.Dispose(); }
public void IJobChunkProcessChunkMultiArchetype() { var archetypeA = m_Manager.CreateArchetype(typeof(EcsTestData)); var archetypeB = m_Manager.CreateArchetype(typeof(EcsTestData), typeof(EcsTestData2)); var archetypeC = m_Manager.CreateArchetype(typeof(EcsTestData), typeof(EcsTestData2), typeof(EcsTestData3)); var entity1A = m_Manager.CreateEntity(archetypeA); var entity2A = m_Manager.CreateEntity(archetypeA); var entityB = m_Manager.CreateEntity(archetypeB); var entityC = m_Manager.CreateEntity(archetypeC); EntityQuery query = m_Manager.CreateEntityQuery(typeof(EcsTestData)); m_Manager.SetComponentData <EcsTestData>(entity1A, new EcsTestData { value = -1 }); m_Manager.SetComponentData <EcsTestData>(entity2A, new EcsTestData { value = -1 }); m_Manager.SetComponentData <EcsTestData>(entityB, new EcsTestData { value = -1 }); m_Manager.SetComponentData <EcsTestData>(entityC, new EcsTestData { value = -1 }); var job = new ProcessEntityOffset { ecsTestType = m_Manager.GetArchetypeChunkComponentType <EcsTestData>(false) }; job.Schedule(query).Complete(); Assert.AreEqual(0, m_Manager.GetComponentData <EcsTestData>(entity1A).value); Assert.AreEqual(0, m_Manager.GetComponentData <EcsTestData>(entity2A).value); Assert.AreEqual(2, m_Manager.GetComponentData <EcsTestData>(entityB).value); Assert.AreEqual(3, m_Manager.GetComponentData <EcsTestData>(entityC).value); query.Dispose(); }
private void ToComponentDataArray_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 = default(NativeArray <LargeComponent>); Measure.Method( () => { result = query.ToComponentDataArray <LargeComponent>(Allocator.TempJob); }) .CleanUp(() => { Assert.AreEqual(entityCount, result.Length); result.Dispose(); }) .SampleGroup("ToComponentDataArray") .WarmupCount(1) // make sure we're not timing job compilation on the first run .MeasurementCount(100) .Run(); query.Dispose(); }
//For Revives private void GameReset() { var query = new EntityQueryDesc { None = new ComponentType[] { typeof(Prefab), typeof(PlayerData) }, All = new ComponentType[] { typeof(Translation) } }; //EntityQuery m_Group = GameDataManager.instance.Manager.CreateEntityQuery(query); //GameDataManager.instance.Manager.DestroyEntity(GameDataManager.instance.Manager.CreateEntityQuery(query)); EntityQuery toDestroy = GameDataManager.instance.Manager.CreateEntityQuery(query); GameDataManager.instance.Manager.DestroyEntity(toDestroy); toDestroy.Dispose(); ResetWave(); Resources.UnloadUnusedAssets(); System.GC.Collect(); GameDataManager.gameState = GameState.Playing; }
public void AddMovementData() { //get query of entity matching the right criteria to add MovementData on EntityQuery queryForAddingMovementData = _entityManager.CreateEntityQuery( ComponentType.ReadWrite <RenderMesh>(), ComponentType.ReadOnly <Translation>()); NativeArray <Entity> entitiesToAddMovementData = queryForAddingMovementData.ToEntityArray(Allocator.TempJob); //add MovementDate foreach (var t in entitiesToAddMovementData) { _entityManager.AddComponent <MovementData>(t); } // query for assigning the values in MovementData EntityQuery query = _entityManager.CreateEntityQuery( ComponentType.ReadWrite <MovementData>(), ComponentType.ReadOnly <Translation>()); NativeArray <Entity> entities = query.ToEntityArray(Allocator.TempJob); //create job in charge of set MovementDataValue AssignMovementData job = new AssignMovementData() { CenterPoint = centrePoint.position, MovementDatas = query.ToComponentDataArray <MovementData>(Allocator.TempJob), Translations = query.ToComponentDataArray <Translation>(Allocator.TempJob), Entities = entities, EntityManager = _entityManager }; job.Execute(); query.Dispose(); entities.Dispose(); queryForAddingMovementData.Dispose(); entitiesToAddMovementData.Dispose(); }
public void Dispose() { m_SceneMapper.Dispose(); m_EntityDiffer.Dispose(); if (m_MainQuery != default && m_Hierarchy.World != null && m_Hierarchy.World.IsCreated && m_MainQuery != m_Hierarchy.World.EntityManager.UniversalQuery && m_Hierarchy.World.EntityManager.IsQueryValid(m_MainQuery)) { m_MainQuery.Dispose(); } foreach (var componentDataDiffer in m_ComponentDataDiffers) { componentDataDiffer.Dispose(); } foreach (var sharedComponentDataDiffer in m_SharedComponentDataDiffers) { sharedComponentDataDiffer.Dispose(); } m_NewEntities.Dispose(); m_RemovedEntities.Dispose(); m_DifferHandles.Dispose(); }
private void CopyFromComponentDataArray_Performance_SmallComponent(int entityCount, bool unique) { NativeArray <EntityArchetype> archetypes; if (unique) { archetypes = CreateUniqueArchetypes(entityCount); for (int entIter = 0; entIter < entityCount; entIter++) { m_Manager.CreateEntity(archetypes[entIter]); } } else { archetypes = CreateUniqueArchetypes(1); m_Manager.CreateEntity(archetypes[0], entityCount); } archetypes.Dispose(); EntityQuery query = m_Manager.CreateEntityQuery(ComponentType.ReadWrite(typeof(EcsTestData))); var result = query.ToComponentDataArray <EcsTestData>(Allocator.TempJob); Assert.AreEqual(entityCount, result.Length); Measure.Method( () => { query.CopyFromComponentDataArray(result); }) .SampleGroup("ToComponentDataArray") .WarmupCount(1) // make sure we're not timing job compilation on the first run .MeasurementCount(100) .Run(); result.Dispose(); query.Dispose(); }
public void Dispose() { _AddedScenesQuery.Dispose(); _RemovedScenesQuery.Dispose(); }
protected override void OnDestroy() { m_LoadingWorld.Dispose(); m_PendingRequestsQuery.Dispose(); }