public static AdministradorMateriales Instanciar() { if (instancia == default) { instancia = new AdministradorMateriales(); } return(instancia); }
public Entity CrearRecurso(int idRecurso, float3 posicion) { if (contenedorRecursos.ContainsKey(idRecurso)) { AdministradorMateriales adminMaterial = AdministradorMateriales.Instanciar(); RecursosPlantilla recursoPlantilla = contenedorRecursos[idRecurso]; LocalToWorld localToWorld = new LocalToWorld(); localToWorld.Value = float4x4.TRS(posicion, Quaternion.Euler(0, recursoPlantilla.angulo, 0), new float3(1, 1, 1)); Translation translation = new Translation { Value = posicion }; RenderMesh renderMesh = new RenderMesh { mesh = recursoPlantilla.mallaMaestra, material = adminMaterial.ObtenerMaterial(recursoPlantilla.idMaterial).material, layer = 1 }; RenderBounds redn = new RenderBounds(); //redn.Value = recursoPlantilla.mallaMaestra.bounds.ToAABB().Extents; /* redn.Value = new AABB * { * Center = posicion * ,Extents = recursoPlantilla.mallaMaestra.bounds.ToAABB().Extents * * };*/ Recurso recurso = new Recurso { idRecurso = recursoPlantilla.idRecurso, cantidadRecurso = recursoPlantilla.cantidadRecurso }; EntityManager entityManager = World.DefaultGameObjectInjectionWorld.EntityManager; EntityArchetype archetype = entityManager.CreateArchetype( typeof(RenderMesh), typeof(RenderBounds), typeof(LocalToWorld), typeof(Recurso) ); Entity myEntity = entityManager.CreateEntity(archetype); entityManager.AddComponentData(myEntity, localToWorld); // entityManager.AddComponentData(myEntity, translation); // entityManager.AddComponentData(myEntity, redn); entityManager.AddSharedComponentData(myEntity, renderMesh); entityManager.AddComponentData(myEntity, recurso); return(myEntity); } return(default);
public MapaVoxel(string nombre, int idMaterial, Vector3Int mapaTam, int texturasCuadrante) { this.idMaterial = idMaterial; this.material = AdministradorMateriales.Instanciar().ObtenerMaterial(idMaterial).material; this.nombre = "MapaVoxel_" + nombre; this.mapaTam = mapaTam; this.texturasCuadrante = texturasCuadrante; voxelTam = new Vector3Int(10, mapaTam.y, 10); xV = (int)(mapaTam.x / voxelTam.x); zV = (int)(mapaTam.z / voxelTam.z); contenedorVoxels = new BloqueVoxel[xV, zV]; this.gameObject = new GameObject(nombre); Debug.Log("MapaTam:" + mapaTam); /* for (int x = 0; x < xV; x++) * { * for (int z = 0; z < zV; z++) * { * BloqueVoxel nuevo = new BloqueVoxel(this, new Vector3(x, 0, z)); * contenedorVoxels[x, z] = nuevo; * } * }*/ }
public void CargarMapa(string rutaArchivo, string nombre, DataFormat tipoFormato) { string ruta = rutaArchivo + "/MapaVoxel_" + nombre; string rutaNombre = ruta + "/MapaVoxel_" + nombre + ".jcc"; if (!File.Exists(rutaNombre)) { return; // No state to load } else { byte[] bytes = File.ReadAllBytes(rutaNombre); MapaVoxel temp = SerializationUtility.DeserializeValue <MapaVoxel>(bytes, tipoFormato); this.mapaTam = temp.mapaTam; this.nombre = temp.nombre; this.texturasCuadrante = temp.texturasCuadrante; this.voxelTam = temp.voxelTam; this.xV = temp.xV; this.zV = temp.zV; this.idMaterial = temp.idMaterial; this.material = AdministradorMateriales.Instanciar().ObtenerMaterial(temp.idMaterial).material; /*-----*/ this.gameObject = new GameObject(nombre + "Cargado"); contenedorVoxels = new BloqueVoxel[this.xV, this.zV]; for (int x = 0; x < xV; x++) { for (int z = 0; z < zV; z++) { BloqueVoxel nuevo = new BloqueVoxel(this, new Vector3(x, 0, z)); nuevo.CargarBloque(ruta, tipoFormato); contenedorVoxels[x, z] = nuevo; } } } }
public void Awake() { admin = AdministradorAzulejos.Instanciar(); adminVoxel = AdministradorAzulejosVoxel.Instanciar(); adminMateriales = AdministradorMateriales.Instanciar(); adminRecursos = AdministradorRecursos.Instanciar(); foreach (AzulejoPlantilla item in Azulejos) { admin.AgregarAzulejo(ClaseAzulejo.Terreno, item); } foreach (AzulejoVoxelPlantilla item in AzulejosVoxel) { adminVoxel.AgregarAzulejo(item); } foreach (MaterialPlantilla item in Materiales) { adminMateriales.AgregarMaterial(item.id, item); } foreach (RecursosPlantilla item in Recursos) { adminRecursos.AgregarRecurso(item); } }