public bool AgregarRecurso(RecursosPlantilla recursoPlantilla) { if (!contenedorRecursos.ContainsKey(recursoPlantilla.idRecurso)) { contenedorRecursos.Add(recursoPlantilla.idRecurso, recursoPlantilla); return(true); } return(false); }
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 void AgregarRecurso(int idRecurso, Vector3Int posicion, Vector2 ini, Vector2 fin) { if (PosicionValida(posicion)) { posicion.y = posicion.y + 1; if (!mapaVoxel.ExisteVoxel(posicion)) { RecursosPlantilla rp = AdministradorRecursos.Instanciar().ObtenerRecurso(idRecurso); bool flag = false; for (int x = (int)ini.x; x <= (int)fin.x; x++) { for (int z = (int)ini.y; z <= (int)fin.y; z++) { if (!mapaPosiciones.PosicionLibre(new Vector3Int(x, posicion.y, z))) { return; } flag = true; } } if (flag) { Entity ent = AdministradorRecursos.Instanciar().CrearRecurso(idRecurso, new Unity.Mathematics.float3(posicion.x - 1, posicion.y, posicion.z - 1)); mapaRecursos.AgregarAzulejo(ent, new Vector3Int(posicion.x, posicion.y - 1, posicion.z)); for (int x = (int)ini.x; x <= (int)fin.x; x++) { for (int z = (int)ini.y; z <= (int)fin.y; z++) { mapaPosiciones.AgregarAzulejo(1, new Vector3Int(x, posicion.y, z)); } } } } } }
protected override void OnUpdate() { // Assign values to local variables captured in your job here, so that it has // everything it needs to do its work when it runs later. // For example, // float deltaTime = Time.DeltaTime; // This declares a new kind of job, which is a unit of work to do. // The job is declared as an Entities.ForEach with the target components as parameters, // meaning it will process all entities in the world that have both // Translation and Rotation components. Change it to process the component // types you want. Entities.ForEach((ref EdicionModoActualData modo) => { ModoEdicion modoEdicion = modo.modoEdicion; TipoEdicion tipoEdicion = modo.tipoEdicion; int idAnterior = modo.idAnterior; capa = modo.capaActual; int idAzulejo = modo.idActual; modo.posicionValida = 0; Vector3Int pos = AdministradorMundos.MundoActual().ObtenerPosicionIsometrica(capa); if (pos.x > 0 && pos.z > 0) { Vector3 posPreview = new Vector3(0, capa - 0.48f, 0); if (modoEdicion == ModoEdicion.Crear) { if (tipoEdicion == TipoEdicion.Recursos && idAnterior != idAzulejo) { modo.idAnterior = idAzulejo; Entity entidadPreview = AdministradorRecursos.Instanciar().CrearRecurso(idAzulejo, new Unity.Mathematics.float3(0, 0, 0)); EntityManager entityManager = World.DefaultGameObjectInjectionWorld.EntityManager; entityManager.SetName(entidadPreview, "AzulejoPreview"); Rotation rotation = new Rotation { Value = quaternion.Euler(0, 45, 0) }; Translation translation = new Translation { Value = new float3(0, 0, 0) }; entityManager.AddComponent <AzulejoPreviewComponent>(entidadPreview); //entityManager.AddComponent<EdicionModoActualData>(entidad); entityManager.AddComponentData(entidadPreview, rotation); entityManager.AddComponentData(entidadPreview, translation); RecursosPlantilla recurso = AdministradorRecursos.Instanciar().ObtenerRecurso(idAzulejo); xAzul = recurso.xMax; zAzul = recurso.zMax; gridPrevioGameObject.transform.localScale = new Vector3(0.1f * recurso.xMax, 1, 0.1f * recurso.zMax); gridPrevioGameObject.GetComponent <Renderer>().material.SetVector("Vector2_642EB6F1", new Vector4(recurso.xMax, recurso.zMax, 0, 0)); } } if (modoEdicion == ModoEdicion.Seleccion || modoEdicion == ModoEdicion.Eliminar) { if (HasSingleton <AzulejoPreviewComponent>()) { modo.idActual = modo.idAnterior; modo.idAnterior = -1; Entity ent = GetSingletonEntity <AzulejoPreviewComponent>(); EntityManager entityManager = World.DefaultGameObjectInjectionWorld.EntityManager; entityManager.DestroyEntity(ent); Debug.Log("entre seleccion"); } xAzul = 1; zAzul = 1; } modo.posicionTileActual = pos; modo.posicionValida = 1; actualizarPosicionGrid(posPreview, pos); } }); Entities.ForEach((ref AzulejoPreviewComponent azulejoPreview, ref Translation translation, ref Rotation rotation, ref LocalToWorld localToWorld) => { Vector3Int pos = AdministradorMundos.MundoActual().ObtenerPosicionIsometrica(capa); if (pos.x > 0 && pos.z > 0) { azulejoPreview.posicionInicial = new Vector2(pos.x - xInferiorAzul, pos.z - zInferiorAzul); azulejoPreview.posicionFinal = new Vector2(pos.x + xMedioAzul, pos.z + zMedioAzul); azulejoPreview.posicionAzulejo = pos; pos.x = pos.x - 1; pos.z = pos.z - 1; Vector3 medio = puntoMedio(pos, new Vector3(pos.x + xAzul, 0, pos.z + zAzul)); localToWorld.Value = float4x4.TRS(new float3(medio.x - (0.5f * xAzul), pos.y + 1, medio.z - (0.5f * zAzul)), Quaternion.Euler(0, 45, 0), new float3(1, 1, 1)); /* translation = new Translation { Value = new float3(pos.x-1, pos.y+1, pos.z-1) }; * rotation = new Rotation { Value = quaternion.Euler(0, 45, 0) };*/ } }); }