protected override JobHandle OnUpdate(JobHandle inputDependencies) { inputDependencies.Complete(); var animGraphSys = World.GetExistingSystem <AnimationGraphSystem>(); // Initialize Entities .WithStructuralChanges() .WithNone <LOD>() .WithAll <Settings>() .ForEach((Entity entity) => { GameDebug.Log(World, ShowLifetime, "InitSys: Initialize DotsAnimStateCtrl:{0}", entity); // Setup lowest LOD rig var rigDataBuffer = EntityManager.GetBuffer <RigData>(entity); // var lowestLod = rigDataBuffer.Length - 1; // TODO (mogensh) for now we only use Rig LOD for selecting low lod on server var isServer = World.GetExistingSystem <ServerSimulationSystemGroup>() != null;// TODO (mogensh) cant we find better way to test for server? var lod = isServer ? 1 : 0; var rigData = rigDataBuffer[lod]; RigEntityBuilder.SetupRigEntity(entity, EntityManager, rigData.Rig); var animLocalToRigBuffer = EntityManager.AddBuffer <AnimatedLocalToRig>(entity); animLocalToRigBuffer.ResizeUninitialized(rigData.Rig.Value.Skeleton.Ids.Length); // Create root animsource var settings = EntityManager.GetComponentData <Settings>(entity); var rootAnimSourceEntity = PrefabAssetManager.CreateEntity(EntityManager, settings.RootAnimSource); #if UNITY_EDITOR var name = EntityManager.GetName(rootAnimSourceEntity) + " -> Entity " + entity.Index + ".DotsAnimStateController.RootAnimSource"; EntityManager.SetName(rootAnimSourceEntity, name); #endif AnimSource.SetAnimStateEntityOnPrefab(EntityManager, rootAnimSourceEntity, entity); var rootAnimSource = RootAnimSource.Default; rootAnimSource.Value = rootAnimSourceEntity; EntityManager.AddComponentData(entity, rootAnimSource); EntityManager.AddComponentData(entity, new LOD { Value = lod, }); }).Run(); // Deinitialize Entities .WithStructuralChanges() .WithNone <Settings>() .WithAll <LOD>() .ForEach((Entity entity, ref RootAnimSource rootAnimSource, ref OutputNode outputNode, ref GraphOutput graphOutput) => { Deinitialize(EntityManager, entity, animGraphSys); }).Run(); return(default);
protected Entity CreateNodeEntity() { var e = EntityManager.CreateEntity(); EntityManager.AddComponent <RenderNode>(e); EntityManager.AddBuffer <RenderNodeRef>(e); EntityManager.AddBuffer <RenderPassRef>(e); return(e); }
/// <summary> /// Use this to initialize a dynamic buffer just to temporary use other wise use AddBuffer() /// </summary> /// <param name="entityManager"></param> public DynamicBufferIntBufferElement(EntityManager entityManager, bool addBuffer = false) { mEntity = entityManager.CreateEntity(); entityManager.SetName(mEntity, "IntBufferElement_ComputeEntity"); if (addBuffer) { entityManager.AddBuffer <IntBufferElement>(mEntity); } }
} = 1; //GameWorld.ChunkSize * GameWorld.ChunkSize * GameWorld.ChunkSize * 6 * 6; public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem) { var voxelBuffer = dstManager.AddBuffer <TriangleBufferElement>(entity); for (var i = 0; i < TriangleArrayLength; ++i) { voxelBuffer.Add(0); } }
protected override void OnCreate() { InitAudioSystem(); m_audioEntity = EntityManager.CreateEntity(); EntityManager.AddBuffer <EntityToStop>(m_audioEntity); EntityManager.AddBuffer <SourceIDToStop>(m_audioEntity); EntityManager.AddBuffer <EntityPlaying>(m_audioEntity); }
// Initializers /// <summary> /// Use this to initialize a dynamic buffer just to temporary use other wise use AddBuffer() /// </summary> /// <param name="entityManager"></param> public DynamicBufferEntityBufferElement(EntityManager entityManager, bool addBuffer = false) { mEntity = entityManager.CreateEntity(); entityManager.SetName(mEntity, "DynamicBufferEntityBufferElement"); if (addBuffer) { entityManager.AddBuffer <EntityBufferElement>(mEntity); } }
private void handleRightMousePressed() { //Right mouse button down float3 targetPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition); Vector3Int targetCellPosition = GameHandler.instance.environmentTilemap.WorldToCell(targetPosition); Entities.WithAll <EntitySelectedComponent, UnitComponent>().ForEach((Entity entity, ref Translation translation) => { Vector3Int currentCellPosition = GameHandler.instance.environmentTilemap.WorldToCell(translation.Value); Debug.Log("start path from " + currentCellPosition.x + "," + currentCellPosition.y + " to " + targetCellPosition.x + "," + targetCellPosition.y); EntityManager.AddComponentData(entity, new PathfindingParamsComponent { startPosition = new int2(currentCellPosition.x, currentCellPosition.y), endPosition = new int2(targetCellPosition.x, targetCellPosition.y) }); EntityManager.AddBuffer <PathPosition>(entity); }); //Checking wether the target is a ressource or not /* * if (IsHarvestable(targetPosition, 0.3f)) * { * //if the target is a ressource, then only one entity will go to harvest it * int entityCount = 0; * Entities.WithAll<EntitySelectedComponent>().ForEach((Entity entity, ref MoveToComponent moveTo) => * { * if (entityCount == 0) * { * float3 ressourcePosition = RessourcePosition(targetPosition,0.3f); * ressourcePosition.x = ressourcePosition.x - 0.5f; * ressourcePosition.y = ressourcePosition.y + 0.5f; * moveTo.position = ressourcePosition; * moveTo.move = true; * //The units start harvesting and becomes unselected * PostUpdateCommands.RemoveComponent<EntitySelectedComponent>(entity); * entityCount++; * } * * }); * } else { * //If the target is not a ressource, then all the units must go there * * List<float3> movePositionList = GetPositionListAround(targetPosition, new float[] { 1f, 1.9f, 3f }, new int[] { 5, 10, 20 }); * int positionIndex = 0; * Entities.WithAll<EntitySelectedComponent>().ForEach((Entity entity, ref MoveToComponent moveTo) => * { * * moveTo.position = movePositionList[positionIndex]; * positionIndex = (positionIndex + 1) % movePositionList.Count; * moveTo.move = true; * }); * } */ }
public static void AddBufferFromString <T>(this EntityManager manager, Entity entity, string value) where T : struct, IBufferElementData { if (!manager.Exists(entity) || manager.HasComponent <T>(entity)) { return; } manager.AddBuffer <T>(entity).Reinterpret <char>().FromString(value); }
} = 1; //GameWorld.ChunkSize * GameWorld.ChunkSize * GameWorld.ChunkSize * 4 * 6; public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem) { var voxelBuffer = dstManager.AddBuffer <VertexBufferElement>(entity); for (var i = 0; i < VertexArrayLength; ++i) { voxelBuffer.Add(float3.zero); } }
public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem) { dstManager.AddComponentData(entity, new Arena { radius = radius }); dstManager.AddBuffer <UnitsBufferElement>(entity); }
protected override void OnCreate() { base.OnCreate(); var entity = EntityManager.CreateEntity(typeof(SpawnItemArray)); SetSingleton(new SpawnItemArray()); EntityManager.AddBuffer <SpawnItemRequest>(entity); }
/// <summary> /// Use this to initialize a dynamic buffer just to temporary use other wise use AddBuffer() /// </summary> /// <param name="entityManager"></param> public DynamicBufferProceduralGenerationElementBufferElement(EntityManager entityManager, bool addBuffer = false) { mEntity = entityManager.CreateEntity(); entityManager.SetName(mEntity, "ProceduralGenerationElementBufferElement"); if (addBuffer) { entityManager.AddBuffer <ProceduralGenerationElementBufferElement>(mEntity); } }
void ResolveScene(Entity sceneEntity, ref SceneReference scene, RequestSceneLoaded requestSceneLoaded, Hash128 artifactHash) { // Resolve first (Even if the file doesn't exist we want to stop continously trying to load the section) EntityManager.AddBuffer <ResolvedSectionEntity>(sceneEntity); #if UNITY_EDITOR && !USE_SUBSCENE_EDITORBUNDLES EntityManager.AddComponentData(sceneEntity, new ResolvedSceneHash { ArtifactHash = artifactHash }); UnityEditor.Experimental.AssetDatabaseExperimental.GetArtifactPaths(artifactHash, out var paths); var sceneHeaderPath = EntityScenesPaths.GetLoadPathFromArtifactPaths(paths, EntityScenesPaths.PathType.EntitiesHeader); #else var sceneHeaderPath = EntityScenesPaths.GetLoadPath(scene.SceneGUID, EntityScenesPaths.PathType.EntitiesHeader, -1); #endif #if UNITY_ANDROID && !UNITY_EDITOR var uwrFile = new UnityWebRequest(sceneHeaderPath); uwrFile.downloadHandler = new DownloadHandlerBuffer(); uwrFile.SendWebRequest(); while (!uwrFile.isDone) { } if (uwrFile.isNetworkError || uwrFile.isHttpError) { Debug.LogError($"Loading Entity Scene failed because the entity header file could not be found: {scene.SceneGUID}\nNOTE: In order to load SubScenes in the player you have to use the new BuildSettings asset based workflow to build & run your player.\n{sceneHeaderPath}"); return; } if (!BlobAssetReference <SceneMetaData> .TryRead(uwrFile.downloadHandler.data, SceneMetaDataSerializeUtility.CurrentFileFormatVersion, out var sceneMetaDataRef)) { Debug.LogError("Loading Entity Scene failed because the entity header file was an old version: " + scene.SceneGUID); return; } #else if (!File.Exists(sceneHeaderPath)) { #if UNITY_EDITOR Debug.LogError($"Loading Entity Scene failed because the entity header file could not be found: {scene.SceneGUID}\n{sceneHeaderPath}"); #else Debug.LogError($"Loading Entity Scene failed because the entity header file could not be found: {scene.SceneGUID}\nNOTE: In order to load SubScenes in the player you have to use the new BuildSettings asset based workflow to build & run your player.\n{sceneHeaderPath}"); #endif return; } if (!BlobAssetReference <SceneMetaData> .TryRead(sceneHeaderPath, SceneMetaDataSerializeUtility.CurrentFileFormatVersion, out var sceneMetaDataRef)) { Debug.LogError("Loading Entity Scene failed because the entity header file was an old version: " + scene.SceneGUID); return; } #endif LogResolving("ResolveScene (success)", scene.SceneGUID); ref var sceneMetaData = ref sceneMetaDataRef.Value;
public void CreateEntities(int count) { var settings = GameObjectConversionSettings.FromWorld(World.DefaultGameObjectInjectionWorld, blobAssetStore); var myPrefab = GameObjectConversionUtility.ConvertGameObjectHierarchy(koboltPrefab, settings); for (int i = 0; i < count; i++) { var instance = entityManager.Instantiate(myPrefab); float xValueF = UnityEngine.Random.Range(0, 10f); float yValueF = UnityEngine.Random.Range(0f, 10f); int xValueI = (int)Mathf.Round(xValueF) * (int)Mathf.Round(PathfindingGridSetup.Instance.pathfindingGrid.GetCellSize()); int yValueI = (int)Mathf.Round(yValueF) * (int)Mathf.Round(PathfindingGridSetup.Instance.pathfindingGrid.GetCellSize()); entityManager.SetComponentData(instance, new Translation() { Value = new float3(new float3(xValueF, yValueF, -0.1f)) }); entityManager.AddComponentData(instance, new IDComponent() { id = 1 }); entityManager.AddComponentData(instance, new HealthComponent() { maxHealth = 100, health = 100 }); entityManager.AddComponentData(instance, new MovementComponent() { isMoving = false, speed = 1.2f }); entityManager.AddComponentData(instance, new PathFollow() { }); entityManager.AddComponentData(instance, new Selected() { isSelected = false }); entityManager.AddBuffer <PathPosition>(instance); PathPosition someBufferElement = new PathPosition(); DynamicBuffer <PathPosition> someBuffer = entityManager.GetBuffer <PathPosition>(instance); someBufferElement.position = new int2(xValueI, yValueI); someBuffer.Add(someBufferElement); someBufferElement.position = new int2(xValueI, yValueI); someBuffer.Add(someBufferElement); } }
public unsafe void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem) { dstManager.AddComponentData(entity, new HexpedComponent()); dstManager.AddComponentData(entity, new HexpedHitComponent { HitGeneration = 0, }); dstManager.AddBuffer <LegTransform>(entity); dstManager.AddComponentData(entity, new FighterTargetable()); }
public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem) { Entity swappableDetector = conversionSystem.CreateAdditionalEntity(this); dstManager.AddBuffer <DirectContactStore>(swappableDetector); dstManager.AddComponent <Box>(swappableDetector); dstManager.AddComponent <Position>(swappableDetector); dstManager.AddComponent <IsTrigger>(swappableDetector); dstManager.AddComponentData(entity, new PlayerRoot { swappableDetector = swappableDetector } ); dstManager.AddComponent <ActivePlayer>(entity); dstManager.AddBuffer <DirectContactStore>(entity); dstManager.AddBuffer <ShadowContactStore>(entity); }
protected void SetComponentData(Entity entity, SpawnItemData item) { manager.SetComponentData(entity, new Position { Value = item.position }); manager.SetComponentData(entity, new Rotation { Value = item.rotation }); manager.AddBuffer <NeighboursBufferElement>(entity); }
public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem) { var dynamicBufferTag = new CollisionEventBuffer { CalculateDetails = CalculateDetails ? 1 : 0 }; dstManager.AddComponentData(entity, dynamicBufferTag); dstManager.AddBuffer <StatefulCollisionEvent>(entity); }
protected override void OnCreate() { _ghostCollectionSystem = World.GetOrCreateSystem <GhostCollectionSystem>(); var ent = EntityManager.CreateEntity(); EntityManager.AddComponentData(ent, default(GhostSpawnQueueComponent)); EntityManager.AddBuffer <GhostSpawnBuffer>(ent); EntityManager.AddBuffer <SnapshotDataBuffer>(ent); RequireSingletonForUpdate <NetworkIdComponent>(); }
public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem) { var buffer = dstManager.AddBuffer <TouchElement>(entity); buffer.Capacity = Capacity; for (int i = 0; i < Capacity; i++) { buffer.Add(TouchElement.Default()); } }
public DynamicBuffer <T> GetConfigBufferData <T>() where T : struct, IBufferElementData { EnsureConfigEntity(true); if (!EntityManager.HasComponent <T>(configEntity)) { return(EntityManager.AddBuffer <T>(configEntity)); } return(EntityManager.GetBuffer <T>(configEntity)); }
public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem) { dstManager.AddComponentData(entity, new MapData { width = _width, height = _height, }); var buffer = dstManager.AddBuffer <MapTiles>(entity); }
public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem) { // Add buffer fire grid buffer // See dynamic buffer doc // https://docs.unity3d.com/Packages/[email protected]/manual/dynamic_buffers.html dstManager.AddBuffer <FireBufferElement>(entity); // Add fire buffer component data for singleton retrieval dstManager.AddComponentData(entity, new FireBuffer()); }
void CreateBlockParent( Vector2 position, Vector2Int size, Flags flags, out Entity block, out DynamicBuffer <Cell> cells, out RenderMesh renderMesh ) { float scale = flags.Has(Flags.IsGrid) ? BlokkyEditor.GridScale : BlokkyEditor.UiScale; bool isDraggable = flags.Has(Flags.IsDraggable); bool isGrid = flags.Has(Flags.IsGrid); int layer = isDraggable ? 2 : 0; float3 position3D = (Vector3)position + Vector3.back * layer; // Create RenderMesh for legos Material material = new Material(legoMaterial) { color = isDraggable ? Color.gray : Color.white }; renderMesh = new RenderMesh { material = material, mesh = legoMesh }; // Create entity EntityManager entityManager = World.DefaultGameObjectInjectionWorld.EntityManager; block = entityManager.CreateEntity(); #if UNITY_EDITOR entityManager.SetName(block, "Block"); #endif // Add components entityManager.AddComponent <LocalToWorld>(block); entityManager.AddComponentData(block, new Translation { Value = position3D }); entityManager.AddComponentData(block, new Scale { Value = scale }); entityManager.AddComponentData(block, new BlockSize(new int2(size.x, size.y))); cells = entityManager.AddBuffer <Cell>(block); entityManager.AddSharedComponentData(block, renderMesh); // Add Flag components if (isDraggable) { entityManager.AddComponent <IsDraggable>(block); } if (isGrid) { entityManager.AddComponent <IsGrid>(block); } }
protected override void OnCreate() { var entity = EntityManager.CreateEntity(); #region add-with-manager EntityManager.AddBuffer <MyBufferElement>(entity); #endregion #region add-with-archetype Entity e = EntityManager.CreateEntity(typeof(MyBufferElement)); #endregion #region reinterpret-snippet DynamicBuffer <int> intBuffer = EntityManager.GetBuffer <MyBufferElement>(entity).Reinterpret <int>(); #endregion #region access-manager DynamicBuffer <MyBufferElement> dynamicBuffer = EntityManager.GetBuffer <MyBufferElement>(entity); #endregion #region lookup-snippet BufferFromEntity <MyBufferElement> lookup = GetBufferFromEntity <MyBufferElement>(); var buffer = lookup[entity]; buffer.Add(17); buffer.RemoveAt(0); #endregion #region invalidation var entity1 = EntityManager.CreateEntity(); var entity2 = EntityManager.CreateEntity(); DynamicBuffer <MyBufferElement> buffer1 = EntityManager.AddBuffer <MyBufferElement>(entity1); // This line causes a structural change and invalidates // the previously acquired dynamic buffer DynamicBuffer <MyBufferElement> buffer2 = EntityManager.AddBuffer <MyBufferElement>(entity1); // This line will cause an error: buffer1.Add(17); #endregion }
protected override void OnUpdate() { var entity = GetSingletonEntity <SpawnPlayerServer>(); var buffer = EntityManager.GetBuffer <SpawnPlayerBuffer>(entity); if (buffer.Length == 0) { return; } var spawnPlayers = buffer.ToNativeArray(Allocator.Temp); buffer.Clear(); foreach (var spawnPlayer in spawnPlayers) { //创建Player var e = EntityManager.Instantiate(playerPrefab); var position = GetSpawnPoint(); var rotation = Quaternion.identity; CreateCharacterUtilities.CreateCharacterComponent(EntityManager, e, position, rotation); EntityManager.AddBuffer <UserCommandBuffer>(e); if (spawnPlayer.IsRobot) { EntityManager.AddComponentData(e, new Robot()); } else { EntityManager.AddComponentData(e, new Connection { SessionId = spawnPlayer.PlayerId }); } var id = networkServerSystem.RegisterEntity(-1, (ushort)EntityType.Character, spawnPlayer.PlayerId, e); //var interpolatedState = EntityManager.GetComponentData<CharacterInterpolatedState>(e); //interpolatedState.MaterialId = (byte) (spawnPlayer.PlayerId % 4); //EntityManager.SetComponentData(e, interpolatedState); EntityManager.SetComponentData(e, new ReplicatedEntityData { Id = id, PredictingPlayerId = spawnPlayer.PlayerId }); } spawnPlayers.Dispose(); }
public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem) { dstManager.AddComponentData(entity, new MoveSpeed() { Value = (fix)MaximumSpeed }); dstManager.AddComponentData(entity, new MovingPlatformSettings() { MoveMode = MoveMode, PauseOnNodesDuration = PauseOnPoints ? PauseDuration : TimeValue.Zero, SlowDownNearNodes = SlowDownNearPoints }); dstManager.AddComponentData(entity, new MovingPlatformState() { }); DynamicBuffer <PathPosition> points = dstManager.AddBuffer <PathPosition>(entity); Vector2 positionOffset = transform.position; if (MoveMode == PlatformMoveMode.Signals) { var signalPositions = dstManager.AddBuffer <MovingPlatformSignalPosition>(entity); signalPositions.Capacity = MovePoints.Length; foreach (var item in MovePoints) { signalPositions.Add(new MovingPlatformSignalPosition() { Position = (fix2)(positionOffset + item.Position), ConditionalEmitter = item.ConditionalEmitter == null ? Entity.Null : conversionSystem.GetPrimaryEntity(item.ConditionalEmitter) }); } } else { points.Capacity = MovePoints.Length; foreach (var item in MovePoints) { points.Add((fix2)(positionOffset + item.Position)); } } }
private static int ConvertSimpleDirectional2DBlendTree(BlendTree blendTree, Entity entity, EntityManager entityManager, BakeOptions bakeOptions) { if (!entityManager.HasComponent <BlendTree2DResource>(entity)) { entityManager.AddBuffer <BlendTree2DResource>(entity); } if (!entityManager.HasComponent <BlendTree2DMotionData>(entity)) { entityManager.AddBuffer <BlendTree2DMotionData>(entity); } var blendTreeResources = entityManager.GetBuffer <BlendTree2DResource>(entity); var blendTreeMotionData = entityManager.GetBuffer <BlendTree2DMotionData>(entity); var blendTreeIndex = blendTreeResources.Length; blendTreeResources.Add(new BlendTree2DResource { MotionCount = blendTree.children.Length, MotionStartIndex = blendTreeMotionData.Length }); for (int i = 0; i < blendTree.children.Length; i++) { var motionData = new BlendTree2DMotionData { MotionPosition = blendTree.children[i].position, MotionSpeed = blendTree.children[i].timeScale, }; var clip = ClipBuilder.AnimationClipToDenseClip(blendTree.children[i].motion as AnimationClip); if (bakeOptions.NeedBaking) { clip = UberClipNode.Bake(bakeOptions.RigDefinition, clip, bakeOptions.ClipConfiguration, bakeOptions.SampleRate); } motionData.Motion.Clip = clip; blendTreeMotionData.Add(motionData); } return(blendTreeIndex); }
public static DynamicBuffer <T> GetOrAddBuffer <T>(this EntityManager em, Entity entity) where T : struct, IBufferElementData { if (TryGetBuffer(em, entity, out DynamicBuffer <T> buffer)) { return(buffer); } buffer = em.AddBuffer <T>(entity); return(buffer); }
public void Convert(Entity entity, EntityManager manager, GameObjectConversionSystem conversionSystem) { if (receiveEvents) { manager.AddBuffer <PlayerInputEvent>(entity); } if (receiveState) { manager.AddComponent <PlayerInputState>(entity); } }