add mono c# (using dotnet9.0 from https://github.com/dotnet/runtime), add ECS (entt), add some c# code, add fastNoise
This commit is contained in:
84
ExampleApp/Src/MapGenerator.cs
Normal file
84
ExampleApp/Src/MapGenerator.cs
Normal file
@ -0,0 +1,84 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Prism;
|
||||
|
||||
namespace Example
|
||||
{
|
||||
public class MapGenerator : Entity
|
||||
{
|
||||
// TODO: [EditorSlider("MapWidth Custom Name", 2, 0, 1024)]
|
||||
public int MapWidth = 128;
|
||||
public int MapHeight = 128;
|
||||
public int Octaves = 4;
|
||||
public float Persistance = 0.74f;
|
||||
public int Seed = 21;
|
||||
public float Lacunarity = 3.0f;
|
||||
public Vec2 Offset = new Vec2(13.4f, 6.26f);
|
||||
public float NoiseScale = 0.5f;
|
||||
|
||||
public void GenerateMap()
|
||||
{
|
||||
// float[,] noiseMap = Noise.GenerateNoiseMap(MapWidth, MapHeight, NoiseScale);
|
||||
float[,] noiseMap;
|
||||
try
|
||||
{
|
||||
noiseMap = Noise.GenerateNoiseMap(MapWidth, MapHeight, Seed, NoiseScale, Octaves, Persistance, Lacunarity, Offset);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e);
|
||||
throw;
|
||||
}
|
||||
|
||||
uint width = (uint)noiseMap.GetLength(0);
|
||||
uint height = (uint)noiseMap.GetLength(1);
|
||||
|
||||
|
||||
Texture2D texture = new Texture2D(width, height);
|
||||
Vec4[] colorMap = new Vec4[width * height];
|
||||
for (int y = 0; y < height; y++)
|
||||
{
|
||||
for (int x = 0; x < width; x++)
|
||||
{
|
||||
colorMap[x + y * width] = Vec4.Lerp(Color.Black, Color.White, noiseMap[x, y]);
|
||||
}
|
||||
}
|
||||
|
||||
texture.SetData(colorMap);
|
||||
|
||||
Console.WriteLine("HasComponent - TransformComponent = {0}", HasComponent<TransformComponent>());
|
||||
Console.WriteLine("HasComponent - ScriptComponent = {0}", HasComponent<ScriptComponent>());
|
||||
Console.WriteLine("HasComponent - MeshComponent = {0}", HasComponent<MeshComponent>());
|
||||
|
||||
MeshComponent meshComponent = GetComponent<MeshComponent>();
|
||||
if (meshComponent == null)
|
||||
{
|
||||
Console.WriteLine("MeshComponent is null!");
|
||||
meshComponent = CreateComponent<MeshComponent>();
|
||||
}
|
||||
meshComponent.Mesh = MeshFactory.CreatePlane(1.0f, 1.0f);
|
||||
|
||||
Console.WriteLine("Mesh has {0} materials!", meshComponent.Mesh.GetMaterialCount());
|
||||
|
||||
MaterialInstance material = meshComponent.Mesh.GetMaterial(1);
|
||||
material.Set("u_AlbedoTexToggle", 1.0f);
|
||||
material.Set("u_AlbedoTexture", texture);
|
||||
}
|
||||
|
||||
void OnCreate()
|
||||
{
|
||||
GenerateMap();
|
||||
}
|
||||
|
||||
void OnUpdate(float ts)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user