Esempio n. 1
0
    private void creacionInicial()
    {
        Debug.Log(FuncTablero.formateaTiempo() + ": Iniciando la creacion desde cero...");
        //Trabajar con la textura Textura_Planeta y crear el mapa lógico a la vez
        Texture2D texturaBase = objetoRoca.renderer.sharedMaterial.mainTexture as Texture2D;

        Color[] pixels = new Color[texturaBase.width * texturaBase.height];
        FuncTablero.inicializa(texturaBase);
        Debug.Log(FuncTablero.formateaTiempo() + ": Creando ruido...");
        pixels = FuncTablero.ruidoTextura();                                                            //Se crea el ruido para la textura base y normales...
        Debug.Log(FuncTablero.formateaTiempo() + ": Completado. Suavizando polos y bordes...");
        pixels = FuncTablero.suavizaBordeTex(pixels, texturaBase.width / 20);                           //Se suaviza el borde lateral...
        pixels = FuncTablero.suavizaPoloTex(pixels);                                                    //Se suavizan los polos...
        Debug.Log(FuncTablero.formateaTiempo() + ": Completado. Aplicando cambios...");
        texturaBase.SetPixels(pixels);
        texturaBase.Apply();
        Debug.Log(FuncTablero.formateaTiempo() + ": Completado. Extruyendo vertices de la roca...");
        float      extrusion = 0.45f;
        MeshFilter Roca      = objetoRoca.GetComponent <MeshFilter>();
        Mesh       meshTemp  = Roca.mesh;

        meshTemp  = FuncTablero.extruyeVerticesTex(meshTemp, texturaBase, extrusion, objetoRoca.transform.position);
        Roca.mesh = meshTemp;
        Debug.Log(FuncTablero.formateaTiempo() + ": Completado. Construyendo collider...");
        //Se añade el collider aqui, para que directamente tenga la mesh adecuada
        objetoRoca.AddComponent <MeshCollider>();
        objetoRoca.GetComponent <MeshCollider>().sharedMesh = meshTemp;
        Debug.Log(FuncTablero.formateaTiempo() + ": Completado. Calculando y extruyendo vertices del oceano...");
        MeshFilter Agua     = objetoOceano.GetComponent <MeshFilter>();
        Mesh       meshAgua = Agua.mesh;

        meshAgua  = FuncTablero.extruyeVerticesValor(meshAgua, FuncTablero.getNivelAgua(), extrusion, objetoOceano.transform.position);
        Agua.mesh = meshAgua;
        Debug.Log(FuncTablero.formateaTiempo() + ": Completado. Rellenando detalles...");
        //se ajusta la propiedad de nivel de agua del shader
        objetoOceano.renderer.sharedMaterial.SetFloat("_nivelMar", FuncTablero.getNivelAgua());
        objetoOceano.renderer.sharedMaterial.SetFloat("_tamPlaya", FuncTablero.getTamanoPlaya());

        Debug.Log(FuncTablero.formateaTiempo() + ": Terminado. Cargando texturas de habitats...");
        //obtener la textura de habitats del array de materiales de roca. Habitats esta en la 1ª posicion.
        Texture2D texElems = objetoRoca.renderer.sharedMaterials[2].mainTexture as Texture2D;
        //Texture2D texPlantas = objetoRoca.renderer.sharedMaterials[2].mainTexture as Texture2D;
        Texture2D texHabitatsEstetica = objetoRoca.renderer.sharedMaterials[1].mainTexture as Texture2D;
        Texture2D texHabitats         = objetoRoca.renderer.sharedMaterials[1].GetTexture("_FiltroTex") as Texture2D;

        Debug.Log(FuncTablero.formateaTiempo() + ": Terminado. Creando el tablero...");
        Casilla[,] tablero = FuncTablero.iniciaTablero(texturaBase, texHabitats, texHabitatsEstetica, texElems, Roca.mesh, objetoRoca.transform.position);
        Debug.Log(FuncTablero.formateaTiempo() + ": Terminado. Creando Vida...");
        vida = new Vida(tablero, objetoRoca.transform);
        Debug.Log(FuncTablero.formateaTiempo() + ": Completada la creacion del planeta.");
    }
Esempio n. 2
0
    private IEnumerator creacionParte1()
    {
        trabajando  = true;
        progreso    = 0.0f;
        GUI.enabled = false;
        Debug.Log(FuncTablero.formateaTiempo() + ": Iniciando creacionParte1()...");
        yield return(new WaitForSeconds(0.1f));

        progreso = 0.1f;
        Debug.Log(FuncTablero.formateaTiempo() + ": Creando ruido...");
        yield return(new WaitForSeconds(0.01f));

        pixels   = FuncTablero.ruidoTextura();                                                                                  //Se crea el ruido para la textura base y normales...
        progreso = 0.7f;
        Debug.Log(FuncTablero.formateaTiempo() + ": Completado. Suavizando borde...");
        yield return(new WaitForSeconds(0.01f));

        pixels   = FuncTablero.suavizaBordeTex(pixels, texturaBase.width / 20);                 //Se suaviza el borde lateral...
        progreso = 0.8f;
        Debug.Log(FuncTablero.formateaTiempo() + ": Completado. Suavizando polos...");
        yield return(new WaitForSeconds(0.01f));

        pixels   = FuncTablero.suavizaPoloTex(pixels);                                                                  //Se suavizan los polos...
        progreso = 0.9f;
        Debug.Log(FuncTablero.formateaTiempo() + ": Completado. Aplicando cambios...");
        yield return(new WaitForSeconds(0.01f));

        texturaBase.SetPixels(pixels);
        texturaBase.Apply();
        progreso = 1.0f;
        Debug.Log(FuncTablero.formateaTiempo() + ": Completada creacionParte1().");
        yield return(new WaitForSeconds(0.01f));

        progreso        = 0.0f;
        trabajando      = false;
        GUI.enabled     = true;
        paso1Completado = true;
    }