本文整理汇总了C#中EntityManager.AddComponentToEntity方法的典型用法代码示例。如果您正苦于以下问题:C# EntityManager.AddComponentToEntity方法的具体用法?C# EntityManager.AddComponentToEntity怎么用?C# EntityManager.AddComponentToEntity使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EntityManager
的用法示例。
在下文中一共展示了EntityManager.AddComponentToEntity方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateNode
private Node CreateNode(Box3D bounds, int level, EntityManager entityManager)
{
var mesh = MeshCreator.CreateXZGrid(10, 10);
var staticMesh = new StaticMesh
{
Color = new Vector4(0f, 0f, 1f, 1f),
ModelMatrix = Matrix4.Identity,
};
var size = bounds.Max - bounds.Min;
var mesh3V3N = mesh.Transformed(Matrix4.CreateScale((float)size.X, 1, (float)size.Z) * Matrix4.CreateTranslation((Vector3)bounds.Center));
var improvedPerlinNoise = new ImprovedPerlinNoise(4711);
for (int i = 0; i < mesh3V3N.Vertices.Length; i++)
{
var vertex = mesh3V3N.Vertices[i];
var height = improvedPerlinNoise.Noise(vertex.Position.X, vertex.Position.Z) * 0.2;
mesh3V3N.Vertices[i] = new Vertex3V3N
{
Normal = new Vector3(0, 1, 0),
Position = new Vector3(vertex.Position.X, (float)height, vertex.Position.Z)
};
}
staticMesh.Update(mesh3V3N);
var entity = new Entity(Guid.NewGuid().ToString());
entityManager.Add(entity);
entityManager.AddComponentToEntity(entity, staticMesh);
if (level == 0)
{
return new Node(bounds, new Node[] { }, entity, 1);
}
var min = bounds.Min;
var max = bounds.Max;
var center = bounds.Center;
return new Node(bounds,
new[]
{
CreateNode(new Box3D(bounds.Min, center), level -1, entityManager),
CreateNode(new Box3D(new Vector3d(center.X, 0, min.Z), new Vector3d(max.X, 0, center.Z)), level -1, entityManager),
CreateNode(new Box3D(new Vector3d(min.X, 0, center.Z), new Vector3d(center.X, 0, max.Z)), level - 1, entityManager),
CreateNode(new Box3D(center, max), level - 1, entityManager)
}, entity, Math.Pow(2, level));
}
示例2: OnLoad
protected override void OnLoad(EventArgs e)
{
StartJobThread();
StartJobThread();
StartJobThread();
StartJobThread();
StartJobThread();
StartJobThread();
StartJobThread();
StartJobThread();
_stopwatch = new Stopwatch();
_stopwatch.Start();
_keyboardInputObservable.SubscribeKey(KeyCombination.LeftAlt && KeyCombination.Enter, CombinationDirection.Down, ToggleFullScren);
_keyboardInputObservable.SubscribeKey(KeyCombination.Esc, CombinationDirection.Down, Exit);
_keyboardInputObservable.SubscribeKey(KeyCombination.P, CombinationDirection.Down, () => _camera.Projection = ProjectionMode.Perspective);
_keyboardInputObservable.SubscribeKey(KeyCombination.O, CombinationDirection.Down, () => _camera.Projection = ProjectionMode.Orthographic);
_keyboardInputObservable.SubscribeKey(KeyCombination.F, CombinationDirection.Down, () => _synchronizeCameras = !_synchronizeCameras);
_entityManager = new EntityManager();
var terrainSystem = new TerrainSystem(FractalBrownianMotionSettings.Default);
_systems = new List<IEntitySystem>
{
terrainSystem,
new FreeCameraSystem(_keyboardInputProcessor, _mouseInputProcessor,_camera),
new LightMoverSystem(),
new OceanSystem(),
new CubeMeshSystem(),
new InputSystem(_keyboardInputProcessor)
//new ChunkedLODSystem(_lodCamera),
//new RenderSystem(_camera),
};
var light = new Entity(Guid.NewGuid().ToString());
_entityManager.Add(light);
_entityManager.AddComponentToEntity(light, new PositionalLightComponent { Position = new Vector3d(0, 20, 0) });
_entityManager.AddComponentToEntity(light, new InputComponent(Key.J, Key.L, Key.M, Key.N, Key.U, Key.I));
const int numberOfChunksX = 20;
const int numberOfChunksY = 20;
for (var i = 0; i < numberOfChunksX; i++)
{
for (var j = 0; j < numberOfChunksY; j++)
{
var entity = new Entity(Guid.NewGuid().ToString());
_entityManager.Add(entity);
_entityManager.AddComponentToEntity(entity, new ChunkComponent(i, j));
_entityManager.AddComponentToEntity(entity, new StaticMesh());
}
}
var settingsViewModel = new SettingsViewModel(new NoiseFactory.NoiseParameters());
settingsViewModel.SettingsChanged += () =>
{
var settings = settingsViewModel.Assemble();
terrainSystem.SetTerrainSettings(new NoiseFactory.RidgedMultiFractal().Create(settings));
};
_terrain = new Terrain(new ChunkedLod());
_cube = new Cube();
}
示例3: Update
public void Update(double elapsedTime, EntityManager entityManager)
{
foreach (var water in entityManager.GetEntitiesWithComponent<OceanComponent>())
{
var waterComponent = entityManager.GetComponent<OceanComponent>(water);
var waterMesh = entityManager.GetComponent<StaticMesh>(water);
if (waterMesh == null)
{
waterMesh = new StaticMesh
{
Color = new Vector4(0f, 0f, 1f, 0f),
ModelMatrix = Matrix4.Identity
};
entityManager.AddComponentToEntity(water, waterMesh);
}
var mesh = CreateMesh(waterComponent);
waterMesh.Update(mesh);
for (var i = 0; i < waterMesh.Mesh.Vertices.Length; i++)
{
var position = waterMesh.Mesh.Vertices[i].Position;
var vector3D = Gerstner2.CalculateWave((Vector3d)position, elapsedTime, _waveSettings);
waterMesh.Mesh.Vertices[i] = new Vertex3V3N
{
Position = (Vector3)vector3D
};
}
waterMesh.Mesh.CalculateNormals();
waterMesh.Update(waterMesh.Mesh);
}
}