public static Entity CreateEntityAndAppend(this EntityManager manager, EntityArchetype archetype) { var entity = manager.CreateEntity(); manager.AddComponents(entity, archetype.ToComponentTypes()); return(entity); }
public static void InitializeChunkEntity(Entity e, EntityManager em) { em.AddComponents(e, GetInitialChunkComponents()); em.SetComponentData(e, (MarchingChunk)math.int3(int.MaxValue)); em.AddBuffer <Vertex>(e); em.AddBuffer <Triangle>(e); em.SetName(e, "Chunk"); InitializeEntityMesh(e, em); }
public static Particle2DEmitterBuilder AddParticleEmitterComponents(EntityManager em, Entity e) { em.AddComponents(e, particleSystemComponents); return(new Particle2DEmitterBuilder(em, e)); //em.SetComponentData<Particle2DCountMax>(e, maxParticles); //em.SetComponentData<Particle2DEmissionRate>(e, emissionRate); //em.SetComponentData<Particle2DNewParticleLifetime>(e, particleLifetime); }
public static TerminalBuilder AddComponents(EntityManager em, Entity e) { em.AddComponents(e, TerminalComponents); em.SetComponentData <TileSize>(e, new float2(1, 1)); em.SetComponentData <TerminalSize>(e, new int2(10, 10)); #if UNITY_EDITOR em.SetName(e, "Terminal"); #endif return(new TerminalBuilder(em, e)); }
/// <summary> /// A function which converts our Player authoring GameObject to a more optimized Entity representation /// </summary> /// <param name="entity">A reference to the entity this GameObject will become</param> /// <param name="dstManager">The EntityManager is used to make changes to Entity data.</param> /// <param name="conversionSystem">Used for more advanced conversion features. Not used here</param> public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem) { // Here we add all of the components needed by the player dstManager.AddComponents(entity, new ComponentTypes( typeof(PlayerTag), typeof(UserInputData), typeof(MovementSpeed))); // Set the movement speed value from the authoring component dstManager.SetComponentData(entity, new MovementSpeed { MetersPerSecond = MovementSpeedMetersPerSecond }); }
private void InitPlayer() { EntityManager entityManager = World.Active.EntityManager; Entity playerEntity = entityManager.Instantiate(playerEntityPrefab); entityManager.AddComponents(playerEntity, new ComponentTypes(typeof(PlayerInput))); if (settings.MakePlayerInvincible) { entityManager.SetComponentData(playerEntity, new Health { Value = 25000 }); } this.PlayerEntity = playerEntity; playerInputBehaviour.SetPlayer(playerEntity); }
/// <summary> /// A function which converts our Guard authoring GameObject to a more optimized Entity representation /// </summary> /// <param name="entity">A reference to the entity this GameObject will become</param> /// <param name="dstManager">The EntityManager is used to make changes to Entity data.</param> /// <param name="conversionSystem">Used for more advanced conversion features. Not used here.</param> public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem) { // Here we add all of the components needed to start the guard off in the "Patrol" state // i.e. We add TargetPosition, and don't add IdleTimer or IsChasing tag dstManager.AddComponents(entity, new ComponentTypes( new ComponentType[] { typeof(CooldownTime), typeof(NextWaypointIndex), typeof(TargetPosition), typeof(WaypointPosition), typeof(VisionCone), typeof(MovementSpeed), typeof(IsInTransitionTag) })); // Since we've already added the WaypointPosition IBufferElementData to the entity, we need to Get the buffer to fill it var buffer = dstManager.GetBuffer <WaypointPosition>(entity); foreach (var waypointTransform in Waypoints) { buffer.Add(new WaypointPosition { Value = waypointTransform.position }); } // Transfer the values from the authoring component to the entity data dstManager.SetComponentData(entity, new CooldownTime { Value = IdleCooldownTime }); dstManager.SetComponentData(entity, new NextWaypointIndex { Value = 0 }); dstManager.SetComponentData(entity, new TargetPosition { Value = buffer[0].Value }); dstManager.SetComponentData(entity, new MovementSpeed { MetersPerSecond = MovementSpeedMetersPerSecond }); // Note: The authoring component uses Degrees and non-squared distance, while the runtime uses radians and squared distance // We want the authoring component to use the most user-friendly data formats, but the runtime to use a more optimized format // GameObject Conversion is perfect for this. During conversion, we convert to the more optimized units. dstManager.SetComponentData(entity, new VisionCone { AngleRadians = math.radians(VisionAngleDegrees), ViewDistanceSq = VisionMaxDistance * VisionMaxDistance }); }
public static void AddRenderMeshRenderer(EntityManager em, Entity e, Material mat = default) { mat = mat == default ? Resources.Load <Material>("Terminal8x8") : mat; em.AddComponents(e, _meshDataTypes); var mesh = new Mesh(); mesh.MarkDynamic(); RenderMeshUtility.AddComponents(e, em, new RenderMeshDescription { RenderMesh = new RenderMesh { mesh = mesh, material = mat } }); }
public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem) { dstManager.AddComponents(entity, new ComponentTypes(typeof(ProceduralScatterPrefab), typeof(TrivialScatterPrefabSettings))); var scatterBuffer = dstManager.GetBuffer <ProceduralScatterPrefab>(entity); var scatterSettings = dstManager.GetBuffer <TrivialScatterPrefabSettings>(entity); for (int i = 0; i != Prefabs.Length; i++) { var prefabEntity = conversionSystem.GetPrimaryEntity(Prefabs[i].Prefab); scatterBuffer.Add(new ProceduralScatterPrefab { Prefab = prefabEntity }); scatterSettings.Add(new TrivialScatterPrefabSettings { ScatterRadius = Prefabs[i].ScatterRadius }); } }
public void Convert(Entity entity, EntityManager entityManager, GameObjectConversionSystem conversionSystem) { entityManager.AddComponents(entity, new ComponentTypes( typeof(PitchYaw), typeof(PlayerDistance), typeof(RotationSpeed), typeof(CameraFOV), typeof(TakeoffHeight))); entityManager.SetComponentData(entity, new PlayerDistance { Value = 5.5f }); entityManager.SetComponentData(entity, new RotationSpeed { Value = rotationSpeed }); entityManager.SetComponentData(entity, new CameraFOV { Value = 80 }); }
public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem) { dstManager.AddComponents(entity, Prototypes.segment_component_types); dstManager.SetComponentData(entity, new Segment { start = this.start, end = this.end }); dstManager.SetComponentData(entity, new SegmentWidth { Value = (half)this.width }); var renderMesh = Prototypes.renderMesh; if (materialOverride != null) { renderMesh.material = materialOverride; } Assert.IsNotNull(renderMesh.material, "renderMesh.material is null"); dstManager.SetSharedComponentData(entity, renderMesh); dstManager.SetComponentData <RenderBounds>(entity, Prototypes.renderBounds); dstManager.AddComponent <MaterialColor>(entity); dstManager.SetComponentData(entity, new MaterialColor { Value = new float4 { x = color.r, y = color.g, z = color.b, w = color.a } }); // we don't need those components: dstManager.RemoveComponent <Translation>(entity); dstManager.RemoveComponent <Rotation>(entity); dstManager.RemoveComponent <LocalToParent>(entity); dstManager.RemoveComponent <Parent>(entity); #if DEBUG dstManager.SetName(entity, gameObject.name); #endif }
public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem) { //var top = this.GetComponentInParent<CharacterModelAuthoring>();// プレハブだとできない( children はできるのに) var top = this.gameObject.Ancestors().First(go => go.GetComponent <CharacterModelAuthoring>()); var main = top.transform.GetChild(0).gameObject; var waponSelectorEntity = conversionSystem.CreateAdditionalEntity(this.gameObject); dstManager.SetName_(waponSelectorEntity, $"{main.name} wapon selector"); var types = new ComponentTypes ( typeof(WaponSelector.LinkData), typeof(WaponSelector.ToggleModeData), typeof(WaponSelector.WaponLink0) //typeof(Disabled)// 何も持っていない状態用 ); dstManager.AddComponents(waponSelectorEntity, types); dstManager.SetComponentData(waponSelectorEntity, new WaponSelector.LinkData { OwnerMainEntity = conversionSystem.GetPrimaryEntity(main), muzzleBodyEntity = entity, } ); dstManager.SetComponentData(waponSelectorEntity, new WaponSelector.ToggleModeData { CurrentWaponCarryId = 0, WaponCarryLength = 0, } ); if (this.Wapons.Length >= 2) { dstManager.AddComponentData(waponSelectorEntity, new WaponSelector.WaponLink1 { }); } if (this.Wapons.Length >= 3) { dstManager.AddComponentData(waponSelectorEntity, new WaponSelector.WaponLink2 { }); } if (this.Wapons.Length >= 4) { dstManager.AddComponentData(waponSelectorEntity, new WaponSelector.WaponLink3 { }); } if (this.Wapons.Length > 0) { var msg = new WaponMessage.ReplaceWapon4MsgData { NumPeplace = math.min(this.Wapons.Where(x => x != null).Count(), 4), WaponPrefab0 = this.Wapons.Length >= 1 ? conversionSystem.GetPrimaryEntity(this.Wapons[0]) : Entity.Null, WaponPrefab1 = this.Wapons.Length >= 2 ? conversionSystem.GetPrimaryEntity(this.Wapons[1]) : Entity.Null, WaponPrefab2 = this.Wapons.Length >= 3 ? conversionSystem.GetPrimaryEntity(this.Wapons[2]) : Entity.Null, WaponPrefab3 = this.Wapons.Length >= 4 ? conversionSystem.GetPrimaryEntity(this.Wapons[3]) : Entity.Null, }; dstManager.AddComponentData(waponSelectorEntity, msg); } //var waponEnities = this.Wapons // .Where(x => x != null) // .Take(4) // .Select(w => conversionSystem.GetPrimaryEntity(w)) // .ToArray(); //if (waponEnities.Length >= 1) // dstManager.AddComponentData(waponSelectorEntity, new WaponSelector.WaponPrefab0 { WaponPrefab = waponEnities[0] }); //if (waponEnities.Length >= 2) // dstManager.AddComponentData(waponSelectorEntity, new WaponSelector.WaponPrefab1 { WaponPrefab = waponEnities[1] }); //if (waponEnities.Length >= 3) // dstManager.AddComponentData(waponSelectorEntity, new WaponSelector.WaponPrefab2 { WaponPrefab = waponEnities[2] }); //if (waponEnities.Length >= 4) // dstManager.AddComponentData(waponSelectorEntity, new WaponSelector.WaponPrefab3 { WaponPrefab = waponEnities[3] }); }
// Start is called before the first frame update void Start() { //World world = new World("AAA"); ////Debug.Log(World.DefaultGameObjectInjectionWorld.Name); //foreach (var item in World.All) //{ // Debug.Log(item.Name); //} //world.Dispose(); ////查询 //foreach (var item in World.DefaultGameObjectInjectionWorld.Systems) //{ // Debug.Log(item.ToString()); //} //PrintSystem1 printSystem1 = World.DefaultGameObjectInjectionWorld.GetOrCreateSystem<PrintSystem1>(); //Debug.Log(printSystem1.ToString()); ////创建 //World newWorld = new World("AAA"); //newWorld.AddSystem(printSystem1); ////删除 //InitializationSystemGroup systemGroup = World.DefaultGameObjectInjectionWorld.GetExistingSystem<InitializationSystemGroup>(); //systemGroup.RemoveSystemFromUpdateList(printSystem1); //newWorld.DestroySystem(printSystem1); #region Entity //创建 //1.GameObject To Entity //IConvertGameObjectToEntity //GameObjectCoversionUtility.ConvertGameObjectHierarchy() //SubScene //2.从0开始创建Entity EntityManager entityManager = World.DefaultGameObjectInjectionWorld.EntityManager; Entity entity = entityManager.CreateEntity(typeof(PrintComponentData1), typeof(RotationEulerXYZ)); entityManager.Instantiate(entity); EntityArchetype entityArchetype = entityManager.CreateArchetype(typeof(PrintComponentData1), typeof(RotationEulerXYZ)); //for (int i = 0; i < 100; ++i) //{ // entityManager.CreateEntity(entityArchetype); //} NativeArray <Entity> nativeArray = new NativeArray <Entity>(5, Allocator.TempJob); entityManager.CreateEntity(entityArchetype, nativeArray); //查找 NativeArray <Entity> entitis = entityManager.GetAllEntities(); foreach (var item in entitis) { Debug.Log(item.Index); } EntityQuery entityQuery = entityManager.CreateEntityQuery(typeof(PrintComponentData1)); NativeArray <Entity> entites2 = entityQuery.ToEntityArray(Allocator.Temp); foreach (var item in entites2) { Debug.Log("查询实体索引:" + item.Index); } //删除 //entityManager.DestroyEntity(entity); //entityManager.DestroyEntity(entitis); #endregion #region Component //1.组件的创建方式 Entity entity2 = entityManager.CreateEntity(typeof(RotationEulerXYZ)); entityManager.AddComponent(entity2, typeof(PrintComponentData1)); //entityManager.AddComponent<PrintComponentData1>(entites2); //entityManager.AddComponent<PrintComponentData1>(entityQuery); entityManager.AddComponents(entity2, new ComponentTypes(typeof(PrintComponentData1), typeof(RotationEulerXYZ))); entityManager.AddComponentData(entity2, new PrintComponentData1 { printData = 5 }); //2.组件的查询 RotationEulerXYZ rotationEulerXYZ = entityManager.GetComponentData <RotationEulerXYZ>(entity2); Debug.Log(rotationEulerXYZ); //3.组件的修改 //rotationEulerXYZ.Value = new float3(-1, -1, -1); //错误类型,这是struct类型 entityManager.SetComponentData <RotationEulerXYZ>(entity2, new RotationEulerXYZ() { Value = new float3(-55, -1, -1) }); //4.组件的删除 entityManager.RemoveComponent(entity2, typeof(RotationEulerXYZ)); #endregion nativeArray.Dispose(); entitis.Dispose(); entites2.Dispose(); }
public static void AppendArchetype(this EntityManager manager, Entity entity, EntityArchetype archetype) { manager.AddComponents(entity, archetype.ToComponentTypes()); }
public static void AddMeshDataComponents(EntityManager em, Entity e) { em.AddComponents(e, _meshDataTypes); }
void ISimWorldWriteAccessor.AddComponents(Entity entity, ComponentTypes types) => EntityManager.AddComponents(entity, types);